Skip to content

Commit 4bb9252

Browse files
authored
params: fix type V2 not equal bug, close XFN-45 (XinFinOrg#1737)
1 parent 7aaa541 commit 4bb9252

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

params/config.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ package params
1818

1919
import (
2020
"fmt"
21+
"maps"
2122
"math/big"
23+
"slices"
2224
"strings"
2325
"sync"
2426

@@ -530,22 +532,15 @@ func V2Equal(a, b *V2) bool {
530532
if a == nil || b == nil {
531533
return a == b
532534
}
533-
if a.SwitchEpoch != b.SwitchEpoch || a.SkipV2Validation != b.SkipV2Validation || !configNumEqual(a.SwitchBlock, b.SwitchBlock) || len(a.configIndex) != len(b.configIndex) || len(a.configIndex) != len(a.AllConfigs) || len(b.configIndex) != len(b.AllConfigs) {
534-
return false
535-
}
536-
for i, idx := range a.configIndex {
537-
if idx != b.configIndex[i] {
538-
return false
539-
}
540-
if !V2ConfigEqual(a.AllConfigs[idx], b.AllConfigs[idx]) {
541-
return false
542-
}
543-
}
544-
return true
535+
536+
return a.SwitchEpoch == b.SwitchEpoch && configNumEqual(a.SwitchBlock, b.SwitchBlock) && slices.Equal(a.configIndex, b.configIndex) && maps.EqualFunc(a.AllConfigs, b.AllConfigs, V2ConfigEqual)
545537
}
546538

547539
func V2ConfigEqual(a, b *V2Config) bool {
548-
return a != nil && b != nil && *a == *b
540+
if a == nil || b == nil {
541+
return a == b
542+
}
543+
return *a == *b
549544
}
550545

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

0 commit comments

Comments
 (0)