@@ -27,7 +27,9 @@ func newHeaviestChainCandidate(chains *Chains, weightVariable func(element *Comm
27
27
}
28
28
29
29
func (h * HeaviestChainCandidate ) measureAt (slot iotago.SlotIndex ) (teardown func ()) {
30
- if slot < chainSwitchingThreshold {
30
+ chainSwitchingThreshold := h .chains .protocol .APIForSlot (slot ).ProtocolParameters ().ChainSwitchingThreshold ()
31
+
32
+ if slot < iotago .SlotIndex (chainSwitchingThreshold ) {
31
33
return
32
34
}
33
35
@@ -40,18 +42,18 @@ func (h *HeaviestChainCandidate) measureAt(slot iotago.SlotIndex) (teardown func
40
42
var teardownFunctions []func ()
41
43
42
44
if heaviestChain := heaviestCommitment .Chain .Get (); heaviestChain != h .chains .Main .Get () {
43
- slotsWithHeaviestChain := reactive.NewCounter [* Commitment ](func (commitment * Commitment ) bool {
45
+ slotsWithSameChain := reactive.NewCounter [* Commitment ](func (commitment * Commitment ) bool {
44
46
return commitment .Chain .Get () == heaviestChain
45
47
})
46
48
47
- for i := iotago . SlotIndex (1 ); i < chainSwitchingThreshold ; i ++ {
48
- if earlierCommitments , earlierCommitmentsExist := h .weightedCommitmentsBySlot .Get (slot - i ); earlierCommitmentsExist {
49
- teardownFunctions = append (teardownFunctions , slotsWithHeaviestChain .Monitor (earlierCommitments .HeaviestElement ()))
49
+ for i := uint8 (1 ); i < chainSwitchingThreshold ; i ++ {
50
+ if earlierCommitments , earlierCommitmentsExist := h .weightedCommitmentsBySlot .Get (slot - iotago . SlotIndex ( i ) ); earlierCommitmentsExist {
51
+ teardownFunctions = append (teardownFunctions , slotsWithSameChain .Monitor (earlierCommitments .HeaviestElement ()))
50
52
}
51
53
}
52
54
53
- teardownFunctions = append (teardownFunctions , slotsWithHeaviestChain .OnUpdate (func (_ int , slotsWithHeaviestChain int ) {
54
- if iotago . SlotIndex ( slotsWithHeaviestChain ) >= chainSwitchingThreshold - 1 {
55
+ teardownFunctions = append (teardownFunctions , slotsWithSameChain .OnUpdate (func (_ int , slotsWithSameChain int ) {
56
+ if slotsWithSameChain >= int ( chainSwitchingThreshold ) - 1 {
55
57
h .Set (heaviestChain )
56
58
} else {
57
59
h .Set (nil )
0 commit comments