-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dsmr: replace hard coded validators with ChainState #1894
Conversation
…va-labs/hypersdk into tsachi/configurable-chunk-rate-limiter
…ava-labs/hypersdk into tsachi/configurable-chunk-rate-limiter2
…ava-labs/hypersdk into tsachi/configurable-chunk-rate-limiter2
tests/e2e/e2e.go
Outdated
// Tsachi : The following line was commented out, as it's no longer supported by avalanchego. | ||
// require.NoError(syncNode.SaveAPIPort()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we remove this comment as it's not relevant after this change?
For comments like this, could we make them on the diff in the PR as opposed to putting them in the code itself where they will go out of date once they're merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove the TODO
above this as well since it was documenting that we should be able to get rid of this call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to figure out if this is no longer needed. Can you take a look https://github.com/ava-labs/avalanchego/pull/3650/files and let me know what you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm it looks like with the new behavior the URI to access the node may change, so this does not look correct to me.
In the test above, we have saved the syncNodeURI
and added it to uris
, which we use throughout the tests below, so if that URI is not guaranteed to be reachable after the restart we may fail.
If AvalancheGo deprecated support for this feature, then we'll need to make sure to either switch away from saving them to uris
and syncNodeURI
and creating them on demand from the updated node instance or update those variables in place after the restart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to explain the failing e2e sync test: https://github.com/ava-labs/hypersdk/actions/runs/13078267879/job/36495962625?pr=1894#step:4:312
x/dsmr/node.go
Outdated
type ChainState interface { | ||
GetNetworkParams() (networdID uint32, subnetID, chainID ids.ID) | ||
GetSignatureParams(ctx context.Context) (validators warp.CanonicalValidatorSet, quorumNum uint64, quorumDen uint64, err error) | ||
GetLatestValidatorSet(ctx context.Context) (map[ids.NodeID]*snowValidators.GetValidatorOutput, error) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we break this into individual accessors rather than grouping them based on what we will need at different points? This way when we need networkID
and chainID
, we can access those two rather than grouping all the network params defined by this function together.
In the future, we may want to make the rules configurable based on the block timestamp and fetch the validator set based off of the P-Chain height (both fine to leave as is for now). WIP for adding ProposerVM block context into the block is here: #1897.
For now, can we break this up to fetch the immutable params individually ie. networkID
, subnetID
, chainID
, quorumNum
, and quorumDenom
. Can we also switch to two functions to fetch the canonical validator set and check whether a specific nodeID is a validator (can add P-Chain height as a parameter in the future)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
examples/morpheusvm/go.mod
Outdated
@@ -3,8 +3,8 @@ module github.com/ava-labs/hypersdk/examples/morpheusvm | |||
go 1.22.8 | |||
|
|||
require ( | |||
github.com/ava-labs/avalanchego v1.11.13-0.20241230212828-6dea1b366756 | |||
github.com/ava-labs/hypersdk v0.0.1 | |||
github.com/ava-labs/avalanchego v1.12.3-warp-verify5.0.20250129181352-a1aff06d0fef |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to update avalanchego to use the new localsigner
? I think we can replace the usage of the hard-coded validator set w/out a version upgrade
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not about the upgrade to localsigner
. The goal here was to be able to verify the signature c.Signature.Verify
without providing it with pseudo interface. ( i.e. provide it with the data it truly needs to consume ). see ava-labs/avalanchego#3679 for more details.
x/dsmr/node.go
Outdated
GetNetworkParams() (networdID uint32, subnetID, chainID ids.ID) | ||
GetSignatureParams(ctx context.Context) (validators warp.CanonicalValidatorSet, quorumNum uint64, quorumDen uint64, err error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we making this a part of this interface? If it's to support forking live networks I think this is a premature abstraction and as a tradeoff it bloats this interface (and if we wanted to support that I think this interface would need some time parameter/block height parameter to support that). IMO this interface should just return validator sets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it's meant to support live networks. I believe that @aaronbuchwald has some additions he plans to add on top of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to support forking live networks I think we need some timestamp/block height parameter in this interface then
x/dsmr/node_test.go
Outdated
} | ||
|
||
func (*testChainState) GetNetworkParams() (uint32, ids.ID, ids.ID) { | ||
return networkID /*subnetID*/, ids.Empty, chainID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: don't leave these comments
x/dsmr/node_test.go
Outdated
ctx, | ||
pChain, | ||
0, | ||
ids.Empty, /*subnetID*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same nit here
return networkID /*subnetID*/, ids.Empty, chainID | ||
} | ||
|
||
func (t *testChainState) getValidatorSet() map[ids.NodeID]*validators.GetValidatorOutput { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this introduces complexity, can we just cache this in the testChainState
struct instead of having to re-call this function every time you want to get the validator set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method is being used only in a single place ( within GetCanonicalValidatorSet
), and exclusively used for testing purposes. It doesn't seems that we would gain much by caching the map here. We could use a map as the backing storage ( instead of a slice ).
x/dsmr/node_test.go
Outdated
pChain := &validatorstest.State{ | ||
GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) { | ||
return t.GetSubnetID(), nil | ||
}, | ||
GetValidatorSetF: func( | ||
context.Context, | ||
uint64, | ||
ids.ID, | ||
) (map[ids.NodeID]*validators.GetValidatorOutput, error) { | ||
return t.getValidatorSet(), nil | ||
}, | ||
} | ||
|
||
canonicalValidators, err := warp.GetCanonicalValidatorSetFromSubnetID( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we need this, can we include it in the testChainState
type rather than constructing it on demand in this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure. it would require a constructor, but no prob.
x/dsmr/node.go
Outdated
@@ -157,15 +152,16 @@ func (n *Node[T]) BuildChunk( | |||
return ErrEmptyChunk | |||
} | |||
|
|||
networkID, chainID := n.chainState.GetNetworkID(), n.chainState.GetChainID() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we break this into two separate lines?
x/dsmr/node_test.go
Outdated
canonicalValidators, err := warp.GetCanonicalValidatorSetFromSubnetID( | ||
ctx, | ||
t, | ||
0, | ||
ids.Empty, | ||
) | ||
if err != nil { | ||
return warp.CanonicalValidatorSet{}, err | ||
} | ||
return canonicalValidators, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be a single line?
quorumDen uint64 | ||
} | ||
|
||
func newTestChainState(validatorsSlice []Validator, quorumNum, quorumDen uint64) *testChainState { //nolint:unparam |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This nolint label should not be necessary since each of the parameters is used, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the test, we only use (1,1) for the quorum params. Its ok, since we don't really want to test that, but the linter alert anyway.
What ?
This PR replaces the hard coded
validators
list and few more parameters that were previously hard-coded into the node with a dynamicChainState
interface.The node test is currently have an implementation for that interface, which is used during testing.
Node creation
The node constructor which used to look like this:
looks now like that:
and the
ChainState
is defined as :