Skip to content
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

add network upgrades to chain ctx #3283

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,12 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c

ctx := &snow.ConsensusContext{
Context: &snow.Context{
NetworkID: m.NetworkID,
SubnetID: chainParams.SubnetID,
ChainID: chainParams.ID,
NodeID: m.NodeID,
PublicKey: bls.PublicFromSecretKey(m.StakingBLSKey),
NetworkID: m.NetworkID,
SubnetID: chainParams.SubnetID,
ChainID: chainParams.ID,
NodeID: m.NodeID,
PublicKey: bls.PublicFromSecretKey(m.StakingBLSKey),
NetworkUpgrades: m.Upgrades,

XChainID: m.XChainID,
CChainID: m.CChainID,
Expand Down
826 changes: 419 additions & 407 deletions proto/pb/vm/vm.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions proto/vm/vm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ message InitializeRequest {
// the messenger, keystore, shared memory, blockchain alias,
// subnet alias, and appSender services
string server_addr = 14;
// network_upgrades_bytes is the json encoded network upgrades
bytes network_upgrades_bytes = 15;
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
}

message InitializeResponse {
Expand Down
12 changes: 7 additions & 5 deletions snow/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/logging"
Expand All @@ -31,11 +32,12 @@ type ContextInitializable interface {
// [ChainID] is the ID of the chain this context exists within.
// [NodeID] is the ID of this node
type Context struct {
NetworkID uint32
SubnetID ids.ID
ChainID ids.ID
NodeID ids.NodeID
PublicKey *bls.PublicKey
NetworkID uint32
SubnetID ids.ID
ChainID ids.ID
NodeID ids.NodeID
PublicKey *bls.PublicKey
NetworkUpgrades upgrade.Config

XChainID ids.ID
CChainID ids.ID
Expand Down
12 changes: 7 additions & 5 deletions snow/snowtest/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/validators/validatorstest"
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/logging"
Expand Down Expand Up @@ -78,11 +79,12 @@ func Context(tb testing.TB, chainID ids.ID) *snow.Context {
}

return &snow.Context{
NetworkID: constants.UnitTestID,
SubnetID: constants.PrimaryNetworkID,
ChainID: chainID,
NodeID: ids.EmptyNodeID,
PublicKey: publicKey,
NetworkID: constants.UnitTestID,
SubnetID: constants.PrimaryNetworkID,
ChainID: chainID,
NodeID: ids.EmptyNodeID,
PublicKey: publicKey,
NetworkUpgrades: upgrade.Default,

XChainID: XChainID,
CChainID: CChainID,
Expand Down
34 changes: 20 additions & 14 deletions vms/rpcchainvm/vm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,27 @@ func (vm *VMClient) Initialize(
zap.String("address", serverAddr),
)

networkUpgradeBytes, err := json.Marshal(chainCtx.NetworkUpgrades)
if err != nil {
return err
}

resp, err := vm.client.Initialize(ctx, &vmpb.InitializeRequest{
NetworkId: chainCtx.NetworkID,
SubnetId: chainCtx.SubnetID[:],
ChainId: chainCtx.ChainID[:],
NodeId: chainCtx.NodeID.Bytes(),
PublicKey: bls.PublicKeyToCompressedBytes(chainCtx.PublicKey),
XChainId: chainCtx.XChainID[:],
CChainId: chainCtx.CChainID[:],
AvaxAssetId: chainCtx.AVAXAssetID[:],
ChainDataDir: chainCtx.ChainDataDir,
GenesisBytes: genesisBytes,
UpgradeBytes: upgradeBytes,
ConfigBytes: configBytes,
DbServerAddr: dbServerAddr,
ServerAddr: serverAddr,
NetworkId: chainCtx.NetworkID,
SubnetId: chainCtx.SubnetID[:],
ChainId: chainCtx.ChainID[:],
NodeId: chainCtx.NodeID.Bytes(),
PublicKey: bls.PublicKeyToCompressedBytes(chainCtx.PublicKey),
NetworkUpgradesBytes: networkUpgradeBytes,
XChainId: chainCtx.XChainID[:],
CChainId: chainCtx.CChainID[:],
AvaxAssetId: chainCtx.AVAXAssetID[:],
ChainDataDir: chainCtx.ChainDataDir,
GenesisBytes: genesisBytes,
UpgradeBytes: upgradeBytes,
ConfigBytes: configBytes,
DbServerAddr: dbServerAddr,
ServerAddr: serverAddr,
})
if err != nil {
return err
Expand Down
17 changes: 12 additions & 5 deletions vms/rpcchainvm/vm_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/ava-labs/avalanchego/snow/engine/common/appsender"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/snow/validators/gvalidators"
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/logging"
Expand Down Expand Up @@ -112,6 +113,11 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest)
if err != nil {
return nil, err
}
networkUpgrades := upgrade.Config{}
if err := json.Unmarshal(req.NetworkUpgradesBytes, &networkUpgrades); err != nil {
return nil, err
}

xChainID, err := ids.ToID(req.XChainId)
if err != nil {
return nil, err
Expand Down Expand Up @@ -230,11 +236,12 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest)
}()

vm.ctx = &snow.Context{
NetworkID: req.NetworkId,
SubnetID: subnetID,
ChainID: chainID,
NodeID: nodeID,
PublicKey: publicKey,
NetworkID: req.NetworkId,
SubnetID: subnetID,
ChainID: chainID,
NodeID: nodeID,
PublicKey: publicKey,
NetworkUpgrades: networkUpgrades,

XChainID: xChainID,
CChainID: cChainID,
Expand Down
Loading