Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
76 changes: 38 additions & 38 deletions epoch_multinode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (

func TestSimplexRebroadcastFinalizationVotes(t *testing.T) {
nodes := []simplex.NodeID{{1}, {2}, {3}, {4}}
net := testutil.NewInMemNetwork(t, nodes)
net := testutil.NewControlledNetwork(t, nodes)

var allowFinalizeVotes atomic.Bool

var numFinalizeVotesSent atomic.Uint32

config := func(from simplex.NodeID) *testutil.TestNodeConfig {
return &testutil.TestNodeConfig{
Comm: testutil.NewTestComm(from, net, func(msg *simplex.Message, from simplex.NodeID, to simplex.NodeID) bool {
Comm: testutil.NewTestComm(from, net.BasicInMemoryNetwork, func(msg *simplex.Message, from simplex.NodeID, to simplex.NodeID) bool {
if msg.Finalization != nil && !allowFinalizeVotes.Load() {
return false
}
Expand All @@ -37,10 +37,10 @@ func TestSimplexRebroadcastFinalizationVotes(t *testing.T) {
}
}

testutil.NewSimplexNode(t, nodes[0], net, config(nodes[0]))
testutil.NewSimplexNode(t, nodes[1], net, config(nodes[1]))
testutil.NewSimplexNode(t, nodes[2], net, config(nodes[2]))
testutil.NewSimplexNode(t, nodes[3], net, config(nodes[3]))
testutil.NewControlledSimplexNode(t, nodes[0], net, config(nodes[0]))
testutil.NewControlledSimplexNode(t, nodes[1], net, config(nodes[1]))
testutil.NewControlledSimplexNode(t, nodes[2], net, config(nodes[2]))
testutil.NewControlledSimplexNode(t, nodes[3], net, config(nodes[3]))

net.StartInstances()
defer net.StopInstances()
Expand All @@ -61,7 +61,7 @@ func TestSimplexRebroadcastFinalizationVotes(t *testing.T) {
wg.Add(len(net.Instances))

for _, n := range net.Instances {
go func(n *testutil.TestNode) {
go func(n *testutil.ControlledNode) {
defer wg.Done()
n.Storage.EnsureNoBlockCommit(t, 0)
}(n)
Expand Down Expand Up @@ -122,11 +122,11 @@ func TestSimplexRebroadcastFinalizationVotes(t *testing.T) {

func TestSimplexMultiNodeSimple(t *testing.T) {
nodes := []simplex.NodeID{{1}, {2}, {3}, {4}}
net := testutil.NewInMemNetwork(t, nodes)
testutil.NewSimplexNode(t, nodes[0], net, nil)
testutil.NewSimplexNode(t, nodes[1], net, nil)
testutil.NewSimplexNode(t, nodes[2], net, nil)
testutil.NewSimplexNode(t, nodes[3], net, nil)
net := testutil.NewControlledNetwork(t, nodes)
testutil.NewControlledSimplexNode(t, nodes[0], net, nil)
testutil.NewControlledSimplexNode(t, nodes[1], net, nil)
testutil.NewControlledSimplexNode(t, nodes[2], net, nil)
testutil.NewControlledSimplexNode(t, nodes[3], net, nil)

net.StartInstances()
defer net.StopInstances()
Expand All @@ -148,14 +148,14 @@ func dontVoteFilter(msg *simplex.Message, _, _ simplex.NodeID) bool {

func TestSimplexMultiNodeBlacklist(t *testing.T) {
nodes := []simplex.NodeID{{1}, {2}, {3}, {4}}
net := testutil.NewInMemNetwork(t, nodes)
net := testutil.NewControlledNetwork(t, nodes)
testEpochConfig := &testutil.TestNodeConfig{
ReplicationEnabled: true,
}
testutil.NewSimplexNode(t, nodes[0], net, testEpochConfig)
testutil.NewSimplexNode(t, nodes[1], net, testEpochConfig)
testutil.NewSimplexNode(t, nodes[2], net, testEpochConfig)
testutil.NewSimplexNode(t, nodes[3], net, testEpochConfig)
testutil.NewControlledSimplexNode(t, nodes[0], net, testEpochConfig)
testutil.NewControlledSimplexNode(t, nodes[1], net, testEpochConfig)
testutil.NewControlledSimplexNode(t, nodes[2], net, testEpochConfig)
testutil.NewControlledSimplexNode(t, nodes[3], net, testEpochConfig)

net.StartInstances()
defer net.StopInstances()
Expand All @@ -172,7 +172,7 @@ func TestSimplexMultiNodeBlacklist(t *testing.T) {
net.Disconnect(nodes[3])

for i := range net.Instances[:3] {
net.Instances[i].BB.TriggerBlockShouldBeBuilt()
net.Instances[i].BlockShouldBeBuilt()
}

for _, n := range net.Instances[:3] {
Expand All @@ -199,7 +199,7 @@ func TestSimplexMultiNodeBlacklist(t *testing.T) {
net.Connect(nodes[3])

// Build another block, ensure the blacklist contains the fourth node as blacklisted.
net.Instances[1].BB.TriggerNewBlock()
net.Instances[1].TriggerNewBlock()
for _, n := range net.Instances[:3] {
block := n.Storage.WaitForBlockCommit(uint64(4))
blacklist := block.Blacklist()
Expand All @@ -211,7 +211,7 @@ func TestSimplexMultiNodeBlacklist(t *testing.T) {
}

// Wait for the node to replicate the missing blocks.
net.Instances[3].BB.TriggerNewBlock()
net.Instances[3].TriggerNewBlock()
block := net.Instances[3].Storage.WaitForBlockCommit(4)
require.Equal(t, simplex.Blacklist{
NodeCount: 4,
Expand All @@ -220,13 +220,13 @@ func TestSimplexMultiNodeBlacklist(t *testing.T) {
}, block.Blacklist())

// Make another block.
net.Instances[2].BB.TriggerNewBlock()
net.Instances[2].TriggerNewBlock()
for _, n := range net.Instances {
n.Storage.WaitForBlockCommit(uint64(5))
}

// The fourth node is still blacklisted, so it should not be able to propose a block.
net.Instances[3].BB.TriggerNewBlock() // This shouldn't be here, this is just to side-step a bug.
net.Instances[3].TriggerNewBlock() // This shouldn't be here, this is just to side-step a bug.
for _, n := range net.Instances {
testutil.WaitForBlockProposerTimeout(t, n.E, &n.E.StartTime, 7)
}
Expand All @@ -236,18 +236,18 @@ func TestSimplexMultiNodeBlacklist(t *testing.T) {
net.SetNodeMessageFilter(nodes[3], testutil.AllowAllMessages)

// Make two blocks.
allButThirdNode := []*testutil.TestNode{net.Instances[0], net.Instances[1], net.Instances[3]}
allButThirdNode := []*testutil.ControlledNode{net.Instances[0], net.Instances[1], net.Instances[3]}
for i := 0; i < 2; i++ {
net.Instances[i].BB.TriggerNewBlock()
net.Instances[i].TriggerNewBlock()
for _, n := range allButThirdNode {
n.BB.TriggerBlockShouldBeBuilt()
n.BlockShouldBeBuilt()
n.Storage.WaitForBlockCommit(uint64(6 + i))
}
}

// Skip the third node because it is disconnected.
for i := range allButThirdNode {
net.Instances[i].BB.TriggerBlockShouldBeBuilt()
net.Instances[i].BlockShouldBeBuilt()
}

for _, n := range allButThirdNode {
Expand All @@ -263,9 +263,9 @@ func TestSimplexMultiNodeBlacklist(t *testing.T) {

// Create two blocks
for i := 0; i < 2; i++ {
net.Instances[i].BB.TriggerNewBlock()
net.Instances[i].TriggerNewBlock()
for _, n := range allButThirdNode {
n.BB.TriggerBlockShouldBeBuilt()
n.BlockShouldBeBuilt()
block := n.Storage.WaitForBlockCommit(uint64(8 + i))
lastBlacklist = block.Blacklist()
}
Expand All @@ -276,17 +276,17 @@ func TestSimplexMultiNodeBlacklist(t *testing.T) {

// The third node will now time out.
for i := range allButThirdNode {
net.Instances[i].BB.TriggerBlockShouldBeBuilt()
net.Instances[i].BlockShouldBeBuilt()
}

for _, n := range allButThirdNode {
testutil.WaitForBlockProposerTimeout(t, n.E, &n.E.StartTime, 14)
}

// The fourth node should now be able to propose a block.
net.Instances[3].BB.TriggerNewBlock()
net.Instances[3].TriggerNewBlock()
for _, n := range allButThirdNode {
n.BB.TriggerBlockShouldBeBuilt()
n.BlockShouldBeBuilt()
block := n.Storage.WaitForBlockCommit(uint64(10))
lastBlacklist = block.Blacklist()
}
Expand All @@ -310,26 +310,26 @@ func onlySendBlockProposalsAndVotes(splitNodes []simplex.NodeID) testutil.Messag
// progressed due to notarizations, are able to collect the notarizations and continue
func TestSplitVotes(t *testing.T) {
nodes := []simplex.NodeID{{1}, {2}, {3}, {4}}
net := testutil.NewInMemNetwork(t, nodes)
net := testutil.NewControlledNetwork(t, nodes)

config := func(from simplex.NodeID) *testutil.TestNodeConfig {
return &testutil.TestNodeConfig{
Comm: testutil.NewTestComm(from, net, onlySendBlockProposalsAndVotes(nodes[2:])),
Comm: testutil.NewTestComm(from, net.BasicInMemoryNetwork, onlySendBlockProposalsAndVotes(nodes[2:])),
}
}

testutil.NewSimplexNode(t, nodes[0], net, config(nodes[0]))
testutil.NewSimplexNode(t, nodes[1], net, config(nodes[1]))
splitNode2 := testutil.NewSimplexNode(t, nodes[2], net, config(nodes[2]))
splitNode3 := testutil.NewSimplexNode(t, nodes[3], net, config(nodes[3]))
testutil.NewControlledSimplexNode(t, nodes[0], net, config(nodes[0]))
testutil.NewControlledSimplexNode(t, nodes[1], net, config(nodes[1]))
splitNode2 := testutil.NewControlledSimplexNode(t, nodes[2], net, config(nodes[2]))
splitNode3 := testutil.NewControlledSimplexNode(t, nodes[3], net, config(nodes[3]))

net.StartInstances()
defer net.StopInstances()

net.TriggerLeaderBlockBuilder(0)
for _, n := range net.Instances {
n.WAL.AssertBlockProposal(0)
n.BB.TriggerBlockShouldBeBuilt()
n.BlockShouldBeBuilt()

if n.E.ID.Equals(splitNode2.E.ID) || n.E.ID.Equals(splitNode3.E.ID) {
require.Equal(t, uint64(0), n.E.Metadata().Round)
Expand Down
10 changes: 5 additions & 5 deletions long_running_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
"math"
"testing"

"github.com/ava-labs/simplex/testutil"
"github.com/ava-labs/simplex/testutil/long_running"
)

func TestLongRunningSimple(t *testing.T) {
net := testutil.NewDefaultLongRunningNetwork(t, 5)
net := long_running.NewDefaultLongRunningNetwork(t, 5)

net.StartInstances()
net.WaitForNodesToEnterRound(40)
net.StopAndAssert(false)
}

func TestLongRunningReplication(t *testing.T) {
net := testutil.NewDefaultLongRunningNetwork(t, 10)
net := long_running.NewDefaultLongRunningNetwork(t, 10)
net.StartInstances()

net.WaitForNodesToEnterRound(40)
Expand All @@ -35,12 +35,12 @@ func TestLongRunningReplication(t *testing.T) {
}

func TestLongRunningCrash(t *testing.T) {
net := testutil.NewDefaultLongRunningNetwork(t, 10)
net := long_running.NewDefaultLongRunningNetwork(t, 10)

net.StartInstances()
net.WaitForNodesToEnterRound(30)
net.CrashNodes(3)
crashedNodeLatestBlock := net.Instances[3].Storage.NumBlocks()
crashedNodeLatestBlock := net.GetInstance(3).Storage.NumBlocks()

net.WaitForNodesToEnterRound(80, 1, 2, 4, 5, 6, 7, 8, 9)
net.StartNodes(3)
Expand Down
14 changes: 7 additions & 7 deletions pos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func TestPoS(t *testing.T) {
}
testConf := &testutil.TestNodeConfig{SigAggregator: posSigAggregator, ReplicationEnabled: true}

net := testutil.NewInMemNetwork(t, nodes)
testutil.NewSimplexNode(t, nodes[0], net, testConf)
testutil.NewSimplexNode(t, nodes[1], net, testConf)
testutil.NewSimplexNode(t, nodes[2], net, testConf)
testutil.NewSimplexNode(t, nodes[3], net, testConf)
net := testutil.NewControlledNetwork(t, nodes)
testutil.NewControlledSimplexNode(t, nodes[0], net, testConf)
testutil.NewControlledSimplexNode(t, nodes[1], net, testConf)
testutil.NewControlledSimplexNode(t, nodes[2], net, testConf)
testutil.NewControlledSimplexNode(t, nodes[3], net, testConf)

net.StartInstances()
defer net.StopInstances()
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestPoS(t *testing.T) {
if bytes.Equal(n.E.ID, nodes[0]) || bytes.Equal(n.E.ID, nodes[3]) {
continue
}
n.BB.TriggerBlockShouldBeBuilt()
n.BlockShouldBeBuilt()
n.AdvanceTime(n.E.EpochConfig.MaxProposalWait / 4)
}

Expand Down Expand Up @@ -145,7 +145,7 @@ func TestPoS(t *testing.T) {
if bytes.Equal(n.E.ID, nodes[2]) {
continue
}
n.BB.TriggerBlockShouldBeBuilt()
n.BlockShouldBeBuilt()
n.AdvanceTime(n.E.EpochConfig.MaxProposalWait / 4)
if n.WAL.ContainsEmptyVote(15) {
timedOut[i] = struct{}{}
Expand Down
8 changes: 4 additions & 4 deletions replication_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ func TestReplicationRequestUnknownSeqsAndRounds(t *testing.T) {

func TestNilReplicationResponse(t *testing.T) {
nodes := []simplex.NodeID{{1}, {2}, {3}, {4}}
net := testutil.NewInMemNetwork(t, nodes)
net := testutil.NewControlledNetwork(t, nodes)

normalNode0 := testutil.NewSimplexNode(t, nodes[0], net, nil)
normalNode0 := testutil.NewControlledSimplexNode(t, nodes[0], net, nil)
normalNode0.Start()

err := normalNode0.HandleMessage(&simplex.Message{
Expand All @@ -316,9 +316,9 @@ func TestNilReplicationResponse(t *testing.T) {
// finalization.
func TestMalformedReplicationResponse(t *testing.T) {
nodes := []simplex.NodeID{{1}, {2}, {3}, {4}}
net := testutil.NewInMemNetwork(t, nodes)
net := testutil.NewControlledNetwork(t, nodes)

normalNode0 := testutil.NewSimplexNode(t, nodes[0], net, nil)
normalNode0 := testutil.NewControlledSimplexNode(t, nodes[0], net, nil)
normalNode0.Start()

err := normalNode0.HandleMessage(&simplex.Message{
Expand Down
2 changes: 1 addition & 1 deletion replication_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewReplicationState(logger Logger, comm Communication, myNodeID NodeID, max
}

r.digestTimeouts = NewTimeoutHandler(logger, "digest", start, DefaultReplicationRequestTimeout, r.requestDigests)
r.emptyRoundTimeouts = NewTimeoutHandler(logger, "empty", start, DefaultReplicationRequestTimeout, r.requestEmptyRounds)
r.emptyRoundTimeouts = NewTimeoutHandler(logger, "empty round replication", start, DefaultReplicationRequestTimeout, r.requestEmptyRounds)

return r
}
Expand Down
Loading
Loading