Skip to content

Commit e6b1fe9

Browse files
authored
params: compare V2 between different versions, close XFN-45 (XinFinOrg#1807)
1 parent 25f07b1 commit e6b1fe9

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

params/config.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package params
1818

1919
import (
2020
"fmt"
21-
"maps"
2221
"math/big"
2322
"slices"
2423
"strings"
@@ -530,15 +529,28 @@ func V2Equal(a, b *V2) bool {
530529
if a == nil || b == nil {
531530
return a == b
532531
}
533-
534-
return a.SwitchEpoch == b.SwitchEpoch && configNumEqual(a.SwitchBlock, b.SwitchBlock) && slices.Equal(a.configIndex, b.configIndex) && maps.EqualFunc(a.AllConfigs, b.AllConfigs, V2ConfigEqual)
532+
if a.SwitchEpoch != b.SwitchEpoch || !configNumEqual(a.SwitchBlock, b.SwitchBlock) || !slices.Equal(a.configIndex, b.configIndex) {
533+
return false
534+
}
535+
// compare AllConfigs according to smaller map
536+
smallerMap, largerMap := a.AllConfigs, b.AllConfigs
537+
if len(smallerMap) > len(largerMap) {
538+
smallerMap, largerMap = largerMap, smallerMap
539+
}
540+
for key, cfg1 := range smallerMap {
541+
cfg2, ok := largerMap[key]
542+
if !ok || !V2ConfigEqual(cfg1, cfg2) {
543+
return false
544+
}
545+
}
546+
return true
535547
}
536548

537549
func V2ConfigEqual(a, b *V2Config) bool {
538550
if a == nil || b == nil {
539551
return a == b
540552
}
541-
return *a == *b
553+
return a.MaxMasternodes == b.MaxMasternodes && a.SwitchRound == b.SwitchRound && a.CertThreshold == b.CertThreshold
542554
}
543555

544556
func (c *XDPoSConfig) String() string {

0 commit comments

Comments
 (0)