mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
params: compare V2 between different versions, close XFN-45 (#1807)
This commit is contained in:
parent
25f07b1040
commit
e6b1fe9595
1 changed files with 16 additions and 4 deletions
|
|
@ -18,7 +18,6 @@ package params
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -530,15 +529,28 @@ func V2Equal(a, b *V2) bool {
|
||||||
if a == nil || b == nil {
|
if a == nil || b == nil {
|
||||||
return a == b
|
return a == b
|
||||||
}
|
}
|
||||||
|
if a.SwitchEpoch != b.SwitchEpoch || !configNumEqual(a.SwitchBlock, b.SwitchBlock) || !slices.Equal(a.configIndex, b.configIndex) {
|
||||||
return a.SwitchEpoch == b.SwitchEpoch && configNumEqual(a.SwitchBlock, b.SwitchBlock) && slices.Equal(a.configIndex, b.configIndex) && maps.EqualFunc(a.AllConfigs, b.AllConfigs, V2ConfigEqual)
|
return false
|
||||||
|
}
|
||||||
|
// compare AllConfigs according to smaller map
|
||||||
|
smallerMap, largerMap := a.AllConfigs, b.AllConfigs
|
||||||
|
if len(smallerMap) > len(largerMap) {
|
||||||
|
smallerMap, largerMap = largerMap, smallerMap
|
||||||
|
}
|
||||||
|
for key, cfg1 := range smallerMap {
|
||||||
|
cfg2, ok := largerMap[key]
|
||||||
|
if !ok || !V2ConfigEqual(cfg1, cfg2) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func V2ConfigEqual(a, b *V2Config) bool {
|
func V2ConfigEqual(a, b *V2Config) bool {
|
||||||
if a == nil || b == nil {
|
if a == nil || b == nil {
|
||||||
return a == b
|
return a == b
|
||||||
}
|
}
|
||||||
return *a == *b
|
return a.MaxMasternodes == b.MaxMasternodes && a.SwitchRound == b.SwitchRound && a.CertThreshold == b.CertThreshold
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *XDPoSConfig) String() string {
|
func (c *XDPoSConfig) String() string {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue