Skip to content

Commit 4e0d4a8

Browse files
committed
use nil instead of empty digest
1 parent 03ed80a commit 4e0d4a8

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

epoch.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,13 +1577,13 @@ func (e *Epoch) handleBlockMessage(message *BlockMessage, from NodeID) error {
15771577
// It returns the digest of the previous block it depends on (or emptyDigest if none),
15781578
// as well as a list of rounds for which it needs to verify empty notarizations.
15791579
// TODO: we should request empty notarizations if we don't have them
1580-
func (e *Epoch) blockDependencies(bh BlockHeader) (Digest, []uint64) {
1580+
func (e *Epoch) blockDependencies(bh BlockHeader) (*Digest, []uint64) {
15811581
if bh.Seq == 0 {
15821582
// genesis block has no dependencies
1583-
return emptyDigest, nil
1583+
return nil, nil
15841584
}
15851585

1586-
prevBlockDependency := bh.Prev
1586+
prevBlockDependency := &bh.Prev
15871587

15881588
prevBlock, notarizationOrFinalization, found := e.locateBlock(bh.Seq-1, bh.Prev[:])
15891589
if !found {
@@ -1592,12 +1592,12 @@ func (e *Epoch) blockDependencies(bh BlockHeader) (Digest, []uint64) {
15921592
zap.Uint64("seq", bh.Seq-1),
15931593
zap.Stringer("prev", bh.Prev))
15941594

1595-
return emptyDigest, nil
1595+
return nil, nil
15961596
}
15971597

15981598
// no block dependency if we already have a notarization or finalization for the previous block
15991599
if notarizationOrFinalization != nil {
1600-
prevBlockDependency = emptyDigest
1600+
prevBlockDependency = nil
16011601
}
16021602

16031603
// missing empty rounds
@@ -1928,10 +1928,10 @@ func (e *Epoch) createNotarizedBlockVerificationTask(block Block, notarization N
19281928

19291929
// finalizedBlockDependency returns the dependency digest for a block that has a finalization.
19301930
// We do not care about empty notarizations since the block is finalized.
1931-
func (e *Epoch) finalizedBlockDependency(md BlockHeader) Digest {
1931+
func (e *Epoch) finalizedBlockDependency(md BlockHeader) *Digest {
19321932
if md.Seq == 0 {
19331933
// genesis block has no dependencies
1934-
return emptyDigest
1934+
return nil
19351935
}
19361936

19371937
// A block can be scheduled if its predecessor is either notarized or finalized.
@@ -1942,14 +1942,14 @@ func (e *Epoch) finalizedBlockDependency(md BlockHeader) Digest {
19421942
zap.Uint64("seq", md.Seq-1),
19431943
zap.Stringer("prev", md.Prev))
19441944

1945-
return emptyDigest
1945+
return nil
19461946
}
19471947

19481948
if notarizedOrFinalized != nil {
1949-
return emptyDigest
1949+
return nil
19501950
}
19511951

1952-
return md.Prev
1952+
return &md.Prev
19531953
}
19541954

19551955
// VerifyBlockMessageVote checks if we have the block in the future messages map.
@@ -2142,7 +2142,7 @@ func (e *Epoch) buildBlock() {
21422142
}
21432143

21442144
e.Logger.Debug("Scheduling block building", zap.Uint64("round", metadata.Round))
2145-
e.sched.Schedule(task, emptyDigest, []uint64{})
2145+
e.sched.Schedule(task, nil, []uint64{})
21462146
}
21472147

21482148
func (e *Epoch) retrieveBlacklistOfParentBlock(metadata ProtocolMetadata) (Blacklist, bool) {

sched.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (as *Scheduler) run() {
114114
}
115115
}
116116

117-
func (as *Scheduler) Schedule(f func() Digest, prevDependency Digest, emptyRounds []uint64) {
117+
func (as *Scheduler) Schedule(f func() Digest, prevDependency *Digest, emptyRounds []uint64) {
118118
as.lock.Lock()
119119
defer as.lock.Unlock()
120120

@@ -133,7 +133,7 @@ func (as *Scheduler) Schedule(f func() Digest, prevDependency Digest, emptyRound
133133
EmptyRoundsDependency: emptyRoundDependencies,
134134
}
135135

136-
ready := prevDependency == emptyDigest && len(emptyRoundDependencies) == 0
136+
ready := prevDependency == nil && len(emptyRoundDependencies) == 0
137137
if !ready {
138138
as.logger.Debug("Scheduling task", zap.Stringer("block dependency", prevDependency), zap.Uint64s("empty round dependencies", emptyRounds))
139139
as.pending.Insert(task) // (9)
@@ -184,7 +184,7 @@ func (as *Scheduler) ExecuteEmptyNotarizationDependents(round uint64) {
184184
type Task struct {
185185
F func() Digest
186186

187-
ParentBlockDependency Digest
187+
ParentBlockDependency *Digest
188188
EmptyRoundsDependency map[uint64]struct{}
189189
}
190190

@@ -218,9 +218,13 @@ func (d *dependencies) RemoveDigest(id Digest) []Task {
218218

219219
for _, task := range d.tasks {
220220
var removed bool
221+
if task.ParentBlockDependency == nil {
222+
continue
223+
}
224+
221225
// Check if the task depends on the given digest
222-
if task.ParentBlockDependency == id {
223-
task.ParentBlockDependency = emptyDigest
226+
if *task.ParentBlockDependency == id {
227+
task.ParentBlockDependency = nil
224228
// If the task has no other dependencies, it's ready to run
225229
if len(task.EmptyRoundsDependency) == 0 {
226230
ready = append(ready, task)
@@ -250,7 +254,7 @@ func (d *dependencies) RemoveEmptyNotarization(round uint64) []Task {
250254
if _, exists := task.EmptyRoundsDependency[round]; exists {
251255
delete(task.EmptyRoundsDependency, round)
252256
// If the task has no other dependencies, it's ready to run
253-
if task.ParentBlockDependency == emptyDigest && len(task.EmptyRoundsDependency) == 0 {
257+
if task.ParentBlockDependency == nil && len(task.EmptyRoundsDependency) == 0 {
254258
ready = append(ready, task)
255259
removed = true
256260
}

0 commit comments

Comments
 (0)