Skip to content

Commit 33a4a22

Browse files
committed
refactor(proposal): drop redundant guard, document decisions
1 parent b12d295 commit 33a4a22

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

consensus/proposal/proposal_store.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,24 @@ func (p *ProposalStore[H]) Get(key H) *builder.BuildResult {
3030
}
3131

3232
func (p *ProposalStore[H]) Store(key H, builtResult *builder.BuildResult) {
33-
if builtResult == nil {
34-
return
35-
}
3633
height := types.Height(builtResult.PreConfirmed.Block.Number)
3734
if p.IsFinalized(height) {
3835
return
3936
}
4037
bucket := p.proposalFor(height)
4138
bucket.LoadOrStore(key, builtResult)
4239

40+
// FinalizeHeight may have raced between the initial guard and LoadOrStore;
41+
// if so, roll back so we never leave a proposal at a finalized height.
4342
if p.IsFinalized(height) {
4443
bucket.CompareAndDelete(key, builtResult)
4544
p.proposalsByHeight.CompareAndDelete(height, bucket)
4645
}
4746
}
4847

4948
func (p *ProposalStore[H]) proposalFor(height types.Height) *sync.Map {
49+
// Fast path avoids allocating a sync.Map on every call: LoadOrStore would
50+
// construct one even when the bucket already exists, only to discard it.
5051
if existing, ok := p.proposalsByHeight.Load(height); ok {
5152
return existing.(*sync.Map)
5253
}

0 commit comments

Comments
 (0)