Skip to content

Commit 1bbabbb

Browse files
authored
send finalization when received previously (#306)
1 parent a69b84e commit 1bbabbb

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

epoch.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,14 @@ func (e *Epoch) handleFinalizeVoteMessage(message *FinalizeVote, from NodeID) er
663663

664664
if round.finalization != nil {
665665
e.Logger.Debug("Received finalize vote for an already finalized round", zap.Uint64("round", vote.Round))
666+
667+
if from.Equals(e.ID) {
668+
return nil
669+
}
670+
// send the finalization to the sender in case they missed it
671+
e.Comm.Send(&Message{
672+
Finalization: round.finalization,
673+
}, from)
666674
return nil
667675
}
668676

@@ -1113,7 +1121,7 @@ func (e *Epoch) rebroadcastPastFinalizeVotes() error {
11131121
}
11141122
finalizeVoteMessage = msg
11151123
}
1116-
e.Logger.Debug("Rebroadcasting finalization", zap.Uint64("round", r), zap.Uint64("seq", finalizeVoteMessage.FinalizeVote.Finalization.Seq))
1124+
e.Logger.Debug("Rebroadcasting finalize vote", zap.Uint64("round", r), zap.Uint64("seq", finalizeVoteMessage.FinalizeVote.Finalization.Seq))
11171125
e.Comm.Broadcast(finalizeVoteMessage)
11181126
}
11191127

replication_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,6 @@ func testReplicationAfterNodeDisconnects(t *testing.T, nodes []simplex.NodeID, s
558558
}
559559
}
560560

561-
func onlyAllowBlockProposalsAndNotarizations(msg *simplex.Message, _, to simplex.NodeID) bool {
562-
// TODO: remove hardcoded node id
563-
if to.Equals(simplex.NodeID{4}) {
564-
return (msg.BlockMessage != nil || msg.VerifiedBlockMessage != nil || msg.Notarization != nil)
565-
}
566-
567-
return true
568-
}
569-
570561
// sendVotesToOneNode allows block messages to be sent to all nodes, and only
571562
// passes vote messages to one node. This will allows that node to notarize the block,
572563
// while the other blocks will timeout
@@ -849,6 +840,14 @@ func TestReplicationNotarizationWithoutFinalizations(t *testing.T) {
849840
func testReplicationNotarizationWithoutFinalizations(t *testing.T, numBlocks uint64, nodes []simplex.NodeID) {
850841
net := NewInMemNetwork(t, nodes)
851842

843+
onlyAllowBlockProposalsAndNotarizations := func(msg *simplex.Message, _, to simplex.NodeID) bool {
844+
if to.Equals(nodes[3]) {
845+
return (msg.BlockMessage != nil || msg.VerifiedBlockMessage != nil || msg.Notarization != nil)
846+
}
847+
848+
return true
849+
}
850+
852851
nodeConfig := func(from simplex.NodeID) *TestNodeConfig {
853852
comm := NewTestComm(from, net, onlyAllowBlockProposalsAndNotarizations)
854853
return &TestNodeConfig{
@@ -875,7 +874,6 @@ func testReplicationNotarizationWithoutFinalizations(t *testing.T, numBlocks uin
875874
for _, n := range net.Instances[:3] {
876875
n.Storage.WaitForBlockCommit(uint64(i))
877876
}
878-
879877
}
880878

881879
laggingNode.WAL.AssertNotarization(numBlocks - 1)

testutil/comm.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package testutil
55

66
import (
77
"bytes"
8+
"fmt"
89
"sync"
910

1011
"github.com/ava-labs/simplex"
@@ -69,11 +70,17 @@ func (c *TestComm) Send(msg *simplex.Message, destination simplex.NodeID) {
6970

7071
for _, instance := range c.net.Instances {
7172
if bytes.Equal(instance.E.ID, destination) {
72-
instance.ingress <- struct {
73+
select {
74+
case instance.ingress <- struct {
7375
msg *simplex.Message
7476
from simplex.NodeID
75-
}{msg: msg, from: c.from}
76-
return
77+
}{msg: msg, from: c.from}:
78+
return
79+
default:
80+
// drop the message if the ingress channel is full
81+
formattedString := fmt.Sprintf("Ingress channel is too full, failing test. From %v -> to %v", c.from, destination)
82+
panic(formattedString)
83+
}
7784
}
7885
}
7986
}

testutil/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewSimplexNode(t *testing.T, nodeID simplex.NodeID, net *InMemNetwork, conf
4949
ingress: make(chan struct {
5050
msg *simplex.Message
5151
from simplex.NodeID
52-
}, 100)}
52+
}, 1000)}
5353

5454
ti.currentTime.Store(epochConfig.StartTime.UnixMilli())
5555

0 commit comments

Comments
 (0)