Skip to content

Commit

Permalink
Merge pull request #683 from ava-labs/test-partial-sync
Browse files Browse the repository at this point in the history
Support partial sync for test l1s
  • Loading branch information
cam-schultz authored Dec 13, 2024
2 parents a994a2f + fc146e9 commit 046ca6d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 49 deletions.
2 changes: 1 addition & 1 deletion tests/flows/teleporter/validator_churn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
13 changes: 7 additions & 6 deletions tests/interfaces/subnet_test_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
62 changes: 40 additions & 22 deletions tests/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type LocalNetwork struct {
globalFundedKey *secp256k1.PrivateKey
validatorManagers map[ids.ID]common.Address
logger logging.Logger
deployedL1Specs map[string]L1Spec
}

const (
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -166,6 +171,7 @@ func NewLocalNetwork(
primaryNetworkValidators: primaryNetworkValidators,
validatorManagers: make(map[ids.ID]common.Address),
logger: logger,
deployedL1Specs: deployedL1Specs,
}

return localNetwork
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
}
}

Expand All @@ -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,
}
}
}
Expand All @@ -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
Expand Down
26 changes: 14 additions & 12 deletions tests/suites/teleporter/teleporter_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 8 additions & 6 deletions tests/suites/validator-manager/validator_manager_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion tests/utils/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -520,6 +521,10 @@ func InstantiateGenesisTemplate(
"<TELEPORTER_MESSENGER_DEPLOYER_ADDRESS>",
teleporterDeployerAddress.Hex(),
},
{
"<REQUIRE_PRIMARY_NETWORK_SIGNERS>",
strconv.FormatBool(requirePrimaryNetworkSigners),
},
}

templateFileBytes, err := os.ReadFile(templateFileName)
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion tests/utils/warp-genesis-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"blockGasCostStep": 500000
},
"warpConfig": {
"blockTimestamp": 1719343601
"blockTimestamp": 1719343601,
"requirePrimaryNetworkSigners" : <REQUIRE_PRIMARY_NETWORK_SIGNERS>
},
"contractNativeMinterConfig": {
"blockTimestamp": 0,
Expand Down

0 comments on commit 046ca6d

Please sign in to comment.