Skip to content

Commit ced37fe

Browse files
committed
chore: chainToSubnet
1 parent 3b45a8d commit ced37fe

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

tests/reexecute/c/vm_reexecute_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/ava-labs/avalanchego/api/metrics"
2525
"github.com/ava-labs/avalanchego/database/leveldb"
2626
"github.com/ava-labs/avalanchego/genesis"
27+
"github.com/ava-labs/avalanchego/ids"
2728
"github.com/ava-labs/avalanchego/tests"
2829
"github.com/ava-labs/avalanchego/tests/reexecute"
2930
"github.com/ava-labs/avalanchego/utils/constants"
@@ -214,6 +215,11 @@ func benchmarkReexecuteRange(
214215
ConfigBytes: configBytes,
215216
SubnetID: constants.PrimaryNetworkID,
216217
ChainID: reexecute.MainnetCChainID,
218+
ChainToSubnet: map[ids.ID]ids.ID{
219+
reexecute.MainnetXChainID: constants.PrimaryNetworkID,
220+
reexecute.MainnetCChainID: constants.PrimaryNetworkID,
221+
ids.Empty: constants.PrimaryNetworkID,
222+
},
217223
}
218224

219225
vm, err := reexecute.NewMainnetVM(

tests/reexecute/vm_executor.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import (
3737

3838
var (
3939
MainnetCChainID = ids.FromStringOrPanic("2q9e4r6Mu3U68nU1fYjgbR6JvwrRx36CohpAX5UQxse55x1Q5")
40+
MainnetXChainID = ids.FromStringOrPanic("2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM")
4041

41-
mainnetXChainID = ids.FromStringOrPanic("2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM")
4242
mainnetAvaxAssetID = ids.FromStringOrPanic("FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z")
4343
)
4444

@@ -187,6 +187,9 @@ type VMParams struct {
187187
ConfigBytes []byte
188188
SubnetID ids.ID
189189
ChainID ids.ID
190+
// ChainToSubnet maps chain IDs to their subnet IDs. This mapping is used by
191+
// the VM to validate cross-chain operations and warp messages.
192+
ChainToSubnet map[ids.ID]ids.ID
190193
}
191194

192195
// NewMainnetVM creates and initializes a VM configured for mainnet block
@@ -218,13 +221,6 @@ func NewMainnetVM(
218221
sharedMemoryDB := prefixdb.New([]byte("sharedmemory"), db)
219222
atomicMemory := atomic.NewMemory(sharedMemoryDB)
220223

221-
chainIDToSubnetID := map[ids.ID]ids.ID{
222-
mainnetXChainID: constants.PrimaryNetworkID,
223-
MainnetCChainID: constants.PrimaryNetworkID,
224-
vmParams.ChainID: vmParams.SubnetID,
225-
ids.Empty: constants.PrimaryNetworkID,
226-
}
227-
228224
if err := vm.Initialize(
229225
ctx,
230226
&snow.Context{
@@ -235,7 +231,7 @@ func NewMainnetVM(
235231
PublicKey: blsPublicKey,
236232
NetworkUpgrades: upgrade.Mainnet,
237233

238-
XChainID: mainnetXChainID,
234+
XChainID: MainnetXChainID,
239235
CChainID: MainnetCChainID,
240236
AVAXAssetID: mainnetAvaxAssetID,
241237

@@ -248,7 +244,7 @@ func NewMainnetVM(
248244

249245
ValidatorState: &validatorstest.State{
250246
GetSubnetIDF: func(_ context.Context, chainID ids.ID) (ids.ID, error) {
251-
subnetID, ok := chainIDToSubnetID[chainID]
247+
subnetID, ok := vmParams.ChainToSubnet[chainID]
252248
if ok {
253249
return subnetID, nil
254250
}

0 commit comments

Comments
 (0)