File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,23 +30,24 @@ func (p *ProposalStore[H]) Get(key H) *builder.BuildResult {
3030}
3131
3232func (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
4948func (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 }
You can’t perform that action at this time.
0 commit comments