-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathspan_block_producer_selection.go
71 lines (63 loc) · 2.64 KB
/
span_block_producer_selection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2024 The Erigon Authors
// This file is part of Erigon.
//
// Erigon is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Erigon is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Erigon. If not, see <http://www.gnu.org/licenses/>.
package heimdall
import (
"github.com/erigontech/erigon/polygon/bor/valset"
)
// SpanBlockProducerSelection represents the block producer selection at each epoch
// with their corresponding accumulated ProposerPriority.
//
// In the context of the bor chain, an epoch is equal to 1 span, while
// in the context of the heimdall chain, an epoch is equal to 1 checkpoint.
// This data type aims to make this distinction a bit more visible and is
// intended to be used specifically for span based epochs.
//
// The difference between SpanBlockProducerSelection and Span.SelectedProducers
// is that SpanBlockProducerSelection contains the correct accumulated
// ProposerPriority for each selected producer, while Span.SelectedProducers
// always has ProposerPriority=0.
//
// This is because the heimdall/bor/span/<spanId>
// API only tells us what the "frozen" selected producers for the next span epoch
// are. More info about how that works can be found in the "FreezeSet" logic in
// heimdall at https://github.com/maticnetwork/heimdall/tree/master/bor#how-does-it-work.
//
// However, to correctly calculate the accumulated proposer priorities, one has to start
// from span zero, create a valset.ValidatorSet, call IncrementProposerPriority(spanSprintCount)
// and at every next span call bor.GetUpdatedValidatorSet(oldValidatorSet, span.SelectedProducers)
// and repeat.
type SpanBlockProducerSelection struct {
SpanId SpanId
StartBlock uint64
EndBlock uint64
Producers *valset.ValidatorSet
}
var _ Entity = (*SpanBlockProducerSelection)(nil)
func (s *SpanBlockProducerSelection) RawId() uint64 {
return uint64(s.SpanId)
}
func (s *SpanBlockProducerSelection) BlockNumRange() ClosedRange {
return ClosedRange{
Start: s.StartBlock,
End: s.EndBlock,
}
}
func (s *SpanBlockProducerSelection) SetRawId(id uint64) {
s.SpanId = SpanId(id)
}
func (s *SpanBlockProducerSelection) CmpRange(n uint64) int {
return cmpBlockRange(s.StartBlock, s.EndBlock, n)
}