diff --git a/epoch.go b/epoch.go index 43184b09..a7b43ec3 100644 --- a/epoch.go +++ b/epoch.go @@ -663,6 +663,14 @@ func (e *Epoch) handleFinalizeVoteMessage(message *FinalizeVote, from NodeID) er if round.finalization != nil { e.Logger.Debug("Received finalize vote for an already finalized round", zap.Uint64("round", vote.Round)) + + if from.Equals(e.ID) { + return nil + } + // send the finalization to the sender in case they missed it + e.Comm.Send(&Message{ + Finalization: round.finalization, + }, from) return nil } @@ -1113,7 +1121,7 @@ func (e *Epoch) rebroadcastPastFinalizeVotes() error { } finalizeVoteMessage = msg } - e.Logger.Debug("Rebroadcasting finalization", zap.Uint64("round", r), zap.Uint64("seq", finalizeVoteMessage.FinalizeVote.Finalization.Seq)) + e.Logger.Debug("Rebroadcasting finalize vote", zap.Uint64("round", r), zap.Uint64("seq", finalizeVoteMessage.FinalizeVote.Finalization.Seq)) e.Comm.Broadcast(finalizeVoteMessage) } diff --git a/replication_test.go b/replication_test.go index cc140016..879339d4 100644 --- a/replication_test.go +++ b/replication_test.go @@ -558,15 +558,6 @@ func testReplicationAfterNodeDisconnects(t *testing.T, nodes []simplex.NodeID, s } } -func onlyAllowBlockProposalsAndNotarizations(msg *simplex.Message, _, to simplex.NodeID) bool { - // TODO: remove hardcoded node id - if to.Equals(simplex.NodeID{4}) { - return (msg.BlockMessage != nil || msg.VerifiedBlockMessage != nil || msg.Notarization != nil) - } - - return true -} - // sendVotesToOneNode allows block messages to be sent to all nodes, and only // passes vote messages to one node. This will allows that node to notarize the block, // while the other blocks will timeout @@ -849,6 +840,14 @@ func TestReplicationNotarizationWithoutFinalizations(t *testing.T) { func testReplicationNotarizationWithoutFinalizations(t *testing.T, numBlocks uint64, nodes []simplex.NodeID) { net := NewInMemNetwork(t, nodes) + onlyAllowBlockProposalsAndNotarizations := func(msg *simplex.Message, _, to simplex.NodeID) bool { + if to.Equals(nodes[3]) { + return (msg.BlockMessage != nil || msg.VerifiedBlockMessage != nil || msg.Notarization != nil) + } + + return true + } + nodeConfig := func(from simplex.NodeID) *TestNodeConfig { comm := NewTestComm(from, net, onlyAllowBlockProposalsAndNotarizations) return &TestNodeConfig{ @@ -875,7 +874,6 @@ func testReplicationNotarizationWithoutFinalizations(t *testing.T, numBlocks uin for _, n := range net.Instances[:3] { n.Storage.WaitForBlockCommit(uint64(i)) } - } laggingNode.WAL.AssertNotarization(numBlocks - 1) diff --git a/testutil/comm.go b/testutil/comm.go index f9225c72..4aa72e81 100644 --- a/testutil/comm.go +++ b/testutil/comm.go @@ -5,6 +5,7 @@ package testutil import ( "bytes" + "fmt" "sync" "github.com/ava-labs/simplex" @@ -69,11 +70,17 @@ func (c *TestComm) Send(msg *simplex.Message, destination simplex.NodeID) { for _, instance := range c.net.Instances { if bytes.Equal(instance.E.ID, destination) { - instance.ingress <- struct { + select { + case instance.ingress <- struct { msg *simplex.Message from simplex.NodeID - }{msg: msg, from: c.from} - return + }{msg: msg, from: c.from}: + return + default: + // drop the message if the ingress channel is full + formattedString := fmt.Sprintf("Ingress channel is too full, failing test. From %v -> to %v", c.from, destination) + panic(formattedString) + } } } } diff --git a/testutil/node.go b/testutil/node.go index f11b52a7..ffc9cc1e 100644 --- a/testutil/node.go +++ b/testutil/node.go @@ -49,7 +49,7 @@ func NewSimplexNode(t *testing.T, nodeID simplex.NodeID, net *InMemNetwork, conf ingress: make(chan struct { msg *simplex.Message from simplex.NodeID - }, 100)} + }, 1000)} ti.currentTime.Store(epochConfig.StartTime.UnixMilli())