Skip to content

Commit 668f793

Browse files
committed
sequence data -> finalized block rename
1 parent 3eadaae commit 668f793

File tree

6 files changed

+36
-39
lines changed

6 files changed

+36
-39
lines changed

epoch.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ func (e *Epoch) indexFinalizationCertificates(startRound uint64) {
695695
return
696696
}
697697
if round.fCert.Finalization.Seq != e.Storage.Height() {
698-
e.Logger.Debug("Finalization certificate does not correspond to the next sequence to commit",
698+
e.Logger.Debug("Finalization certificate does not correspond to the next sequence to commit",
699699
zap.Uint64("seq", round.fCert.Finalization.Seq), zap.Uint64("height", e.Storage.Height()))
700700
return
701701
}
@@ -852,7 +852,6 @@ func (e *Epoch) handleNotarizationMessage(message *Notarization, from NodeID) er
852852
return e.persistNotarization(*message)
853853
}
854854

855-
856855
func (e *Epoch) handleBlockMessage(message *BlockMessage, from NodeID) error {
857856
block := message.Block
858857
if block == nil {
@@ -961,20 +960,22 @@ func (e *Epoch) handleBlockMessage(message *BlockMessage, from NodeID) error {
961960
return nil
962961
}
963962

964-
func (e *Epoch) processFinalizedBlock(sequenceData *SequenceData) error {
965-
round, exists := e.rounds[sequenceData.FCert.Finalization.Round]
963+
// processFinalizedBlock processes a block that has a finalization certificate.
964+
// if the block has already been verified, it will index the finalization certificate,
965+
// otherwise it will verify the block first.
966+
func (e *Epoch) processFinalizedBlock(finalizedBlock *FinalizedBlock) error {
967+
round, exists := e.rounds[finalizedBlock.FCert.Finalization.Round]
966968
// dont create a block verification task if the block is already in the rounds map
967969
if exists {
968970
roundDigest := round.block.BlockHeader().Digest
969-
seqDigest := sequenceData.FCert.Finalization.BlockHeader.Digest
971+
seqDigest := finalizedBlock.FCert.Finalization.BlockHeader.Digest
970972
if !bytes.Equal(roundDigest[:], seqDigest[:]) {
971973
e.Logger.Warn("Received finalized block that is different from the one we have in the rounds map",
972974
zap.Stringer("roundDigest", roundDigest), zap.Stringer("seqDigest", seqDigest))
973975
return nil
974976
}
975-
round.fCert = &sequenceData.FCert
977+
round.fCert = &finalizedBlock.FCert
976978
e.indexFinalizationCertificates(round.num)
977-
e.replicationState.maybeCollectFutureFinalizationCertificates(e.round, e.Storage.Height())
978979
e.processReplicationState()
979980
return e.maybeLoadFutureMessages()
980981
}
@@ -984,14 +985,14 @@ func (e *Epoch) processFinalizedBlock(sequenceData *SequenceData) error {
984985
e.Logger.Warn("Too many blocks being verified to ingest another one", zap.Int("pendingBlocks", pendingBlocks))
985986
return nil
986987
}
987-
md := sequenceData.Block.BlockHeader()
988-
if !e.verifyProposalIsPartOfOurChain(sequenceData.Block) {
988+
md := finalizedBlock.Block.BlockHeader()
989+
if !e.verifyProposalIsPartOfOurChain(finalizedBlock.Block) {
989990
e.Logger.Debug("Got invalid block in a BlockMessage")
990991
return nil
991992
}
992993

993994
// Create a task that will verify the block in the future, after its predecessors have also been verified.
994-
task := e.createBlockFinalizedVerificationTask(*sequenceData)
995+
task := e.createBlockFinalizedVerificationTask(*finalizedBlock)
995996

996997
// isBlockReadyToBeScheduled checks if the block is known to us either from some previous round,
997998
// or from storage. If so, then we have verified it in the past, since only verified blocks are saved in memory.
@@ -1053,8 +1054,8 @@ func (e *Epoch) createBlockVerificationTask(block Block, from NodeID, vote Vote)
10531054
}
10541055
}
10551056

1056-
func (e *Epoch) createBlockFinalizedVerificationTask(sequenceData SequenceData) func() Digest {
1057-
block := sequenceData.Block
1057+
func (e *Epoch) createBlockFinalizedVerificationTask(finalizedBlock FinalizedBlock) func() Digest {
1058+
block := finalizedBlock.Block
10581059
return func() Digest {
10591060
md := block.BlockHeader()
10601061

@@ -1086,10 +1087,9 @@ func (e *Epoch) createBlockFinalizedVerificationTask(sequenceData SequenceData)
10861087
e.Logger.Error("programming error: round not found", zap.Uint64("round", md.Round))
10871088
return md.Digest
10881089
}
1089-
round.fCert = &sequenceData.FCert
1090+
round.fCert = &finalizedBlock.FCert
10901091

10911092
e.indexFinalizationCertificates(round.num)
1092-
e.replicationState.maybeCollectFutureFinalizationCertificates(e.round, e.Storage.Height())
10931093
e.processReplicationState()
10941094
err := e.maybeLoadFutureMessages()
10951095
if err != nil {

epoch_multinode_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (t *testNode) start() {
4444
require.NoError(t.t, t.e.Start())
4545
}
4646

47-
func newSimplexNodeWithStorage(t *testing.T, nodeID NodeID, net *inMemNetwork, bb BlockBuilder, storage []SequenceData) *testNode {
47+
func newSimplexNodeWithStorage(t *testing.T, nodeID NodeID, net *inMemNetwork, bb BlockBuilder, storage []FinalizedBlock) *testNode {
4848
wal := newTestWAL(t)
4949
conf := defaultTestNodeEpochConfig(t, nodeID, net, wal, bb)
5050
for _, data := range storage {

message_handler.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ type FinalizationCertificateRequest struct {
2222
Sequences []uint64
2323
}
2424

25-
type SequenceData struct {
25+
type FinalizedBlock struct {
2626
Block Block
2727
FCert FinalizationCertificate
2828
}
2929

3030
type FinalizationCertificateResponse struct {
31-
Data []SequenceData
31+
Data []FinalizedBlock
3232
}
3333

3434
// HandleRequest processes a request and returns a response. It also sends a response to the sender.
@@ -48,15 +48,15 @@ func (e *Epoch) handleFinalizationCertificateRequest(req *FinalizationCertificat
4848
e.Logger.Debug("Received finalization certificate request", zap.Int("num seqs", len(req.Sequences)))
4949
seqs := req.Sequences
5050
slices.Sort(seqs)
51-
data := make([]SequenceData, len(seqs))
51+
data := make([]FinalizedBlock, len(seqs))
5252
for i, seq := range seqs {
5353
block, fCert, exists := e.Storage.Retrieve(seq)
5454
if !exists {
5555
// since we are sorted, we can break early
5656
data = data[:i]
5757
break
5858
}
59-
data[i] = SequenceData{
59+
data[i] = FinalizedBlock{
6060
Block: block,
6161
FCert: fCert,
6262
}
@@ -83,7 +83,7 @@ func (e *Epoch) handleFinalizationCertificateResponse(resp *FinalizationCertific
8383
continue
8484
}
8585

86-
err := e.replicationState.StoreSequenceData(data)
86+
err := e.replicationState.StoreFinalizedBlock(data)
8787
if err != nil {
8888
e.Logger.Error("Failed to store sequence data", zap.Error(err), zap.Uint64("seq", data.FCert.Finalization.Seq), zap.String("from", from.String()))
8989
continue
@@ -95,14 +95,12 @@ func (e *Epoch) handleFinalizationCertificateResponse(resp *FinalizationCertific
9595
}
9696

9797
func (e *Epoch) processReplicationState() {
98-
// next sequence to commit
9998
nextSeqToCommit := e.Storage.Height()
100-
sequenceData, ok := e.replicationState.receivedFinalizationCertificates[nextSeqToCommit]
99+
finalizedBlock, ok := e.replicationState.receivedFinalizationCertificates[nextSeqToCommit]
101100
if !ok {
102-
// we are missing the finalization certificate for the next sequence to commit
103101
return
104102
}
105-
106-
// process block should not verify the block if its in e.round map
107-
e.processFinalizedBlock(&sequenceData)
103+
104+
e.replicationState.maybeCollectFutureFinalizationCertificates(e.round, e.Storage.Height())
105+
e.processFinalizedBlock(&finalizedBlock)
108106
}

replication.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type ReplicationState struct {
1616
maxRoundWindow uint64
1717
comm Communication
1818
id NodeID
19-
quorumSize int
19+
quorumSize int
2020

2121
// latest seq requested
2222
lastSequenceRequested uint64
@@ -25,17 +25,17 @@ type ReplicationState struct {
2525
highestFCertReceived *FinalizationCertificate
2626

2727
// received
28-
receivedFinalizationCertificates map[uint64]SequenceData
28+
receivedFinalizationCertificates map[uint64]FinalizedBlock
2929
}
3030

3131
func NewReplicationState(logger Logger, comm Communication, id NodeID, maxRoundWindow uint64) *ReplicationState {
3232
return &ReplicationState{
33-
quorumSize: Quorum(len(comm.ListNodes())),
34-
logger: logger,
35-
comm: comm,
36-
id: id,
37-
maxRoundWindow: maxRoundWindow,
38-
receivedFinalizationCertificates: make(map[uint64]SequenceData),
33+
quorumSize: Quorum(len(comm.ListNodes())),
34+
logger: logger,
35+
comm: comm,
36+
id: id,
37+
maxRoundWindow: maxRoundWindow,
38+
receivedFinalizationCertificates: make(map[uint64]FinalizedBlock),
3939
}
4040
}
4141

@@ -118,7 +118,7 @@ func (r *ReplicationState) ShouldReplicate(round uint64) bool {
118118
return r.highestFCertReceived.Finalization.BlockHeader.Round >= round
119119
}
120120

121-
func (r *ReplicationState) StoreSequenceData(data SequenceData) (error) {
121+
func (r *ReplicationState) StoreFinalizedBlock(data FinalizedBlock) error {
122122
// ensure the finalization certificate we get relates to the block
123123
blockDigest := data.Block.BlockHeader().Digest
124124
if !bytes.Equal(blockDigest[:], data.FCert.Finalization.BlockHeader.Digest[:]) {

replication_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ func TestReplicationStartsBeforeCurrentRound(t *testing.T) {
164164
}
165165
}
166166

167-
func createBlocks(t *testing.T, nodes []simplex.NodeID, bb simplex.BlockBuilder, seqCount uint64) []simplex.SequenceData {
167+
func createBlocks(t *testing.T, nodes []simplex.NodeID, bb simplex.BlockBuilder, seqCount uint64) []simplex.FinalizedBlock {
168168
logger := testutil.MakeLogger(t, int(0))
169169
ctx := context.Background()
170-
data := make([]simplex.SequenceData, 0, seqCount)
170+
data := make([]simplex.FinalizedBlock, 0, seqCount)
171171
var prev simplex.Digest
172172
for i := uint64(0); i < seqCount; i++ {
173173
protocolMetadata := simplex.ProtocolMetadata{
@@ -180,7 +180,7 @@ func createBlocks(t *testing.T, nodes []simplex.NodeID, bb simplex.BlockBuilder,
180180
require.True(t, ok)
181181
prev = block.BlockHeader().Digest
182182
fCert, _ := newFinalizationRecord(t, logger, &testSignatureAggregator{}, block, nodes)
183-
data = append(data, simplex.SequenceData{
183+
data = append(data, simplex.FinalizedBlock{
184184
Block: block,
185185
FCert: fCert,
186186
})

util.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func RetrieveLastIndexFromStorage(s Storage) (Block, *FinalizationCertificate, e
2424
return lastBlock, &fCert, nil
2525
}
2626

27-
2827
func isFinalizationCertificateValid(fCert *FinalizationCertificate, quorumSize int, logger Logger) (bool, error) {
2928
valid, err := validateFinalizationQC(fCert, quorumSize, logger)
3029
if err != nil {

0 commit comments

Comments
 (0)