forked from TrueCloudLab/neoneo-go
actor: take ValidatorsHistory into account for CalculateValidUntilBlock
Which makes permanent result.Version caching safe for all cases.
This commit is contained in:
parent
95b72db707
commit
ff72ed5715
2 changed files with 27 additions and 1 deletions
|
@ -191,5 +191,14 @@ func (a *Actor) CalculateValidUntilBlock() (uint32, error) {
|
|||
if err != nil {
|
||||
return 0, fmt.Errorf("can't get block count: %w", err)
|
||||
}
|
||||
return blockCount + uint32(a.version.Protocol.ValidatorsCount) + 1, nil
|
||||
var vc = int(a.version.Protocol.ValidatorsCount)
|
||||
var bestH = uint32(0)
|
||||
for h, n := range a.version.Protocol.ValidatorsHistory { // In case it's enabled.
|
||||
if h >= bestH && h <= blockCount {
|
||||
vc = n
|
||||
bestH = h
|
||||
}
|
||||
}
|
||||
|
||||
return blockCount + uint32(vc+1), nil
|
||||
}
|
||||
|
|
|
@ -24,6 +24,23 @@ func TestCalculateValidUntilBlock(t *testing.T) {
|
|||
vub, err := a.CalculateValidUntilBlock()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint32(42+7+1), vub)
|
||||
|
||||
client.version.Protocol.ValidatorsHistory = map[uint32]int{
|
||||
0: 7,
|
||||
40: 4,
|
||||
80: 10,
|
||||
}
|
||||
a, err = NewSimple(client, acc)
|
||||
require.NoError(t, err)
|
||||
|
||||
vub, err = a.CalculateValidUntilBlock()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint32(42+4+1), vub)
|
||||
|
||||
client.bCount = 101
|
||||
vub, err = a.CalculateValidUntilBlock()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint32(101+10+1), vub)
|
||||
}
|
||||
|
||||
func TestMakeUnsigned(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue