From fc146e9f23423397fdbfff854646e2c4d1db0fa5 Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Thu, 12 Dec 2024 13:42:40 -0600 Subject: [PATCH] support partial sync test l1s --- tests/flows/teleporter/validator_churn.go | 2 +- tests/interfaces/subnet_test_info.go | 13 ++-- tests/network/network.go | 62 ++++++++++++------- .../teleporter/teleporter_suite_test.go | 26 ++++---- .../validator_manager_suite_test.go | 14 +++-- tests/utils/chain.go | 7 ++- tests/utils/warp-genesis-template.json | 3 +- 7 files changed, 78 insertions(+), 49 deletions(-) diff --git a/tests/flows/teleporter/validator_churn.go b/tests/flows/teleporter/validator_churn.go index 4387fba31..f33da91a9 100644 --- a/tests/flows/teleporter/validator_churn.go +++ b/tests/flows/teleporter/validator_churn.go @@ -87,7 +87,7 @@ func ValidatorChurn(network *localnetwork.LocalNetwork, teleporter utils.Telepor pChainInfo := utils.GetPChainInfo(network.GetPrimaryNetworkInfo()) Expect(err).Should(BeNil()) - l1AInfo = network.AddSubnetValidators(newNodes, l1AInfo) + l1AInfo = network.AddSubnetValidators(newNodes, l1AInfo, true) for i := 0; i < newNodeCount; i++ { expiry := uint64(time.Now().Add(24 * time.Hour).Unix()) diff --git a/tests/interfaces/subnet_test_info.go b/tests/interfaces/subnet_test_info.go index cac949ccc..d88a8f1ce 100644 --- a/tests/interfaces/subnet_test_info.go +++ b/tests/interfaces/subnet_test_info.go @@ -9,10 +9,11 @@ import ( // Tracks information about a test L1 used for executing tests against. type L1TestInfo struct { - L1ID ids.ID - BlockchainID ids.ID - NodeURIs []string - WSClient ethclient.Client - RPCClient ethclient.Client - EVMChainID *big.Int + L1ID ids.ID + BlockchainID ids.ID + NodeURIs []string + WSClient ethclient.Client + RPCClient ethclient.Client + EVMChainID *big.Int + RequirePrimaryNetworkSigners bool } diff --git a/tests/network/network.go b/tests/network/network.go index 22826aa93..b08fdf9ff 100644 --- a/tests/network/network.go +++ b/tests/network/network.go @@ -47,6 +47,7 @@ type LocalNetwork struct { globalFundedKey *secp256k1.PrivateKey validatorManagers map[ids.ID]common.Address logger logging.Logger + deployedL1Specs map[string]L1Spec } const ( @@ -60,9 +61,10 @@ type L1Spec struct { NodeCount int // Optional fields - TeleporterContractAddress common.Address - TeleporterDeployedBytecode string - TeleporterDeployerAddress common.Address + TeleporterContractAddress common.Address + TeleporterDeployedBytecode string + TeleporterDeployerAddress common.Address + RequirePrimaryNetworkSigners bool } func NewLocalNetwork( @@ -88,6 +90,7 @@ func NewLocalNetwork( Expect(err).Should(BeNil()) var l1s []*tmpnet.Subnet + deployedL1Specs := make(map[string]L1Spec) bootstrapNodes := subnetEvmTestUtils.NewTmpnetNodes(numPrimaryNetworkValidators) for i, l1Spec := range l1Specs { // Create a single bootstrap node. This will be removed from the L1 validator set after it is converted, @@ -106,10 +109,12 @@ func NewLocalNetwork( l1Spec.TeleporterContractAddress, l1Spec.TeleporterDeployedBytecode, l1Spec.TeleporterDeployerAddress, + l1Spec.RequirePrimaryNetworkSigners, ), utils.WarpEnabledChainConfig, initialL1Bootstrapper, ) + deployedL1Specs[l1Spec.Name] = l1Spec l1.OwningKey = globalFundedKey l1s = append(l1s, l1) } @@ -166,6 +171,7 @@ func NewLocalNetwork( primaryNetworkValidators: primaryNetworkValidators, validatorManagers: make(map[ids.ID]common.Address), logger: logger, + deployedL1Specs: deployedL1Specs, } return localNetwork @@ -236,7 +242,7 @@ func (n *LocalNetwork) ConvertSubnet( ) Expect(err).Should(BeNil()) - l1 = n.AddSubnetValidators(tmpnetNodes, l1) + l1 = n.AddSubnetValidators(tmpnetNodes, l1, true) utils.PChainProposerVMWorkaround(pChainWallet) utils.AdvanceProposerVM(ctx, l1, senderKey, 5) @@ -274,6 +280,7 @@ func (n *LocalNetwork) ConvertSubnet( func (n *LocalNetwork) AddSubnetValidators( nodes []*tmpnet.Node, l1 interfaces.L1TestInfo, + partialSync bool, ) interfaces.L1TestInfo { // Modify the each node's config to track the l1 for _, node := range nodes { @@ -286,6 +293,10 @@ func (n *LocalNetwork) AddSubnetValidators( } node.Flags[config.TrackSubnetsKey] = l1.L1ID.String() + if partialSync { + node.Flags[config.PartialSyncPrimaryNetworkKey] = true + } + // Add the node to the network n.Network.Nodes = append(n.Network.Nodes, node) } @@ -352,12 +363,13 @@ func (n *LocalNetwork) GetPrimaryNetworkInfo() interfaces.L1TestInfo { evmChainID, err := rpcClient.ChainID(context.Background()) Expect(err).Should(BeNil()) return interfaces.L1TestInfo{ - L1ID: ids.Empty, - BlockchainID: cChainBlockchainID, - NodeURIs: nodeURIs, - WSClient: wsClient, - RPCClient: rpcClient, - EVMChainID: evmChainID, + L1ID: ids.Empty, + BlockchainID: cChainBlockchainID, + NodeURIs: nodeURIs, + WSClient: wsClient, + RPCClient: rpcClient, + EVMChainID: evmChainID, + RequirePrimaryNetworkSigners: false, } } @@ -379,13 +391,16 @@ func (n *LocalNetwork) GetL1Info(l1ID ids.ID) interfaces.L1TestInfo { Expect(err).Should(BeNil()) evmChainID, err := rpcClient.ChainID(context.Background()) Expect(err).Should(BeNil()) + spec, ok := n.deployedL1Specs[l1.Name] + Expect(ok).Should(BeTrue()) return interfaces.L1TestInfo{ - L1ID: l1ID, - BlockchainID: blockchainID, - NodeURIs: nodeURIs, - WSClient: wsClient, - RPCClient: rpcClient, - EVMChainID: evmChainID, + L1ID: l1ID, + BlockchainID: blockchainID, + NodeURIs: nodeURIs, + WSClient: wsClient, + RPCClient: rpcClient, + EVMChainID: evmChainID, + RequirePrimaryNetworkSigners: spec.RequirePrimaryNetworkSigners, } } } @@ -411,13 +426,16 @@ func (n *LocalNetwork) GetL1Infos() []interfaces.L1TestInfo { Expect(err).Should(BeNil()) evmChainID, err := rpcClient.ChainID(context.Background()) Expect(err).Should(BeNil()) + spec, ok := n.deployedL1Specs[l1.Name] + Expect(ok).Should(BeTrue()) l1s[i] = interfaces.L1TestInfo{ - L1ID: l1.SubnetID, - BlockchainID: blockchainID, - NodeURIs: nodeURIs, - WSClient: wsClient, - RPCClient: rpcClient, - EVMChainID: evmChainID, + L1ID: l1.SubnetID, + BlockchainID: blockchainID, + NodeURIs: nodeURIs, + WSClient: wsClient, + RPCClient: rpcClient, + EVMChainID: evmChainID, + RequirePrimaryNetworkSigners: spec.RequirePrimaryNetworkSigners, } } return l1s diff --git a/tests/suites/teleporter/teleporter_suite_test.go b/tests/suites/teleporter/teleporter_suite_test.go index d2a9a9ea1..944dab1a3 100644 --- a/tests/suites/teleporter/teleporter_suite_test.go +++ b/tests/suites/teleporter/teleporter_suite_test.go @@ -67,20 +67,22 @@ var _ = ginkgo.BeforeSuite(func() { warpGenesisTemplateFile, []network.L1Spec{ { - Name: "A", - EVMChainID: 12345, - TeleporterContractAddress: teleporterContractAddress, - TeleporterDeployedBytecode: teleporterDeployedBytecode, - TeleporterDeployerAddress: teleporterDeployerAddress, - NodeCount: 5, + Name: "A", + EVMChainID: 12345, + TeleporterContractAddress: teleporterContractAddress, + TeleporterDeployedBytecode: teleporterDeployedBytecode, + TeleporterDeployerAddress: teleporterDeployerAddress, + NodeCount: 5, + RequirePrimaryNetworkSigners: true, }, { - Name: "B", - EVMChainID: 54321, - TeleporterContractAddress: teleporterContractAddress, - TeleporterDeployedBytecode: teleporterDeployedBytecode, - TeleporterDeployerAddress: teleporterDeployerAddress, - NodeCount: 5, + Name: "B", + EVMChainID: 54321, + TeleporterContractAddress: teleporterContractAddress, + TeleporterDeployedBytecode: teleporterDeployedBytecode, + TeleporterDeployerAddress: teleporterDeployerAddress, + NodeCount: 5, + RequirePrimaryNetworkSigners: true, }, }, 2, diff --git a/tests/suites/validator-manager/validator_manager_suite_test.go b/tests/suites/validator-manager/validator_manager_suite_test.go index 765f2919d..1c5ff81b1 100644 --- a/tests/suites/validator-manager/validator_manager_suite_test.go +++ b/tests/suites/validator-manager/validator_manager_suite_test.go @@ -42,14 +42,16 @@ var _ = ginkgo.BeforeEach(func() { warpGenesisTemplateFile, []localnetwork.L1Spec{ { - Name: "A", - EVMChainID: 12345, - NodeCount: 2, + Name: "A", + EVMChainID: 12345, + NodeCount: 2, + RequirePrimaryNetworkSigners: true, }, { - Name: "B", - EVMChainID: 54321, - NodeCount: 2, + Name: "B", + EVMChainID: 54321, + NodeCount: 2, + RequirePrimaryNetworkSigners: true, }, }, 2, diff --git a/tests/utils/chain.go b/tests/utils/chain.go index e850a51a8..50d20b267 100644 --- a/tests/utils/chain.go +++ b/tests/utils/chain.go @@ -489,6 +489,7 @@ func InstantiateGenesisTemplate( teleporterContractAddress common.Address, teleporterDeployedBytecode string, teleporterDeployerAddress common.Address, + requirePrimaryNetworkSigners bool, ) string { if teleporterContractAddress.Big().Cmp(big.NewInt(0)) == 0 { teleporterContractAddress = common.HexToAddress("0xffffffffffffffffffffffffffffffffffffffff") @@ -520,6 +521,10 @@ func InstantiateGenesisTemplate( "", teleporterDeployerAddress.Hex(), }, + { + "", + strconv.FormatBool(requirePrimaryNetworkSigners), + }, } templateFileBytes, err := os.ReadFile(templateFileName) @@ -679,7 +684,7 @@ func GetSignedMessage( signatureAggregator *aggregator.SignatureAggregator, ) *avalancheWarp.Message { signingL1ID := source.L1ID - if source.L1ID == constants.PrimaryNetworkID { + if source.L1ID == constants.PrimaryNetworkID && !destination.RequirePrimaryNetworkSigners { signingL1ID = destination.L1ID } diff --git a/tests/utils/warp-genesis-template.json b/tests/utils/warp-genesis-template.json index 4cf2d62eb..3ac111e02 100644 --- a/tests/utils/warp-genesis-template.json +++ b/tests/utils/warp-genesis-template.json @@ -22,7 +22,8 @@ "blockGasCostStep": 500000 }, "warpConfig": { - "blockTimestamp": 1719343601 + "blockTimestamp": 1719343601, + "requirePrimaryNetworkSigners" : }, "contractNativeMinterConfig": { "blockTimestamp": 0,