Skip to content

Commit

Permalink
added sync test with more meta nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssd04 committed Jan 31, 2025
1 parent 8b53a28 commit 1887e15
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions integrationTests/sync/basicSync/basicSync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,97 @@ func TestSyncWorksInShard_EmptyBlocksNoForks_With_EquivalentProofs(t *testing.T)
}
}
}

func TestSyncMetaAndShard_With_EquivalentProofs(t *testing.T) {
if testing.Short() {
t.Skip("this is not a short test")
}

// 3 shard nodes and 3 metachain node
maxShards := uint32(1)
shardId := uint32(0)
numNodesPerShard := 3

enableEpochs := integrationTests.CreateEnableEpochsConfig()
enableEpochs.EquivalentMessagesEnableEpoch = uint32(0)
enableEpochs.FixedOrderInConsensusEnableEpoch = uint32(0)

nodes := make([]*integrationTests.TestProcessorNode, 2*numNodesPerShard)
leaders := make([]*integrationTests.TestProcessorNode, 0)
connectableNodes := make([]integrationTests.Connectable, 0)

for i := 0; i < numNodesPerShard; i++ {
nodes[i] = integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{
MaxShards: maxShards,
NodeShardId: shardId,
TxSignPrivKeyShardId: shardId,
WithSync: true,
EpochsConfig: &enableEpochs,
})
connectableNodes = append(connectableNodes, nodes[i])
}

idxProposerShard0 := 0
leaders = append(leaders, nodes[idxProposerShard0])

idxProposerMeta := numNodesPerShard
for i := 0; i < numNodesPerShard; i++ {
metachainNode := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{
MaxShards: maxShards,
NodeShardId: core.MetachainShardId,
TxSignPrivKeyShardId: shardId,
WithSync: true,
EpochsConfig: &enableEpochs,
})
nodes[idxProposerMeta+i] = metachainNode
connectableNodes = append(connectableNodes, metachainNode)
}
leaders = append(leaders, nodes[idxProposerMeta])

integrationTests.ConnectNodes(connectableNodes)

defer func() {
for _, n := range nodes {
n.Close()
}
}()

for _, n := range nodes {
_ = n.StartSync()
}

fmt.Println("Delaying for nodes p2p bootstrap...")
time.Sleep(integrationTests.P2pBootstrapDelay)

round := uint64(0)
nonce := uint64(0)
round = integrationTests.IncrementAndPrintRound(round)
integrationTests.UpdateRound(nodes, round)
nonce++

numRoundsToTest := 5
for i := 0; i < numRoundsToTest; i++ {
integrationTests.ProposeBlock(nodes, leaders, round, nonce)

time.Sleep(integrationTests.SyncDelay)

round = integrationTests.IncrementAndPrintRound(round)
integrationTests.UpdateRound(nodes, round)
nonce++
}

time.Sleep(integrationTests.SyncDelay)

expectedNonce := nodes[0].BlockChain.GetCurrentBlockHeader().GetNonce()
for i := 1; i < len(nodes); i++ {
if check.IfNil(nodes[i].BlockChain.GetCurrentBlockHeader()) {
assert.Fail(t, fmt.Sprintf("Node with idx %d does not have a current block", i))
} else {
if i == idxProposerMeta { // metachain node has highest nonce since it's single node and it did not synced the header
assert.Equal(t, expectedNonce, nodes[i].BlockChain.GetCurrentBlockHeader().GetNonce())
} else { // shard nodes have not managed to sync last header since there is no proof for it; in the complete flow, when nodes will be fully sinced they will get current header directly from consensus, so they will receive the proof for header
assert.Equal(t, expectedNonce-1, nodes[i].BlockChain.GetCurrentBlockHeader().GetNonce())
}
}
}
}

0 comments on commit 1887e15

Please sign in to comment.