From 748643aa137825fa24d7b43a92580a92f577c1f9 Mon Sep 17 00:00:00 2001 From: envestcc Date: Thu, 20 Nov 2025 09:25:53 +0800 Subject: [PATCH 1/3] fix candsmap not persistent --- action/protocol/staking/candidate_center.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/protocol/staking/candidate_center.go b/action/protocol/staking/candidate_center.go index 1498ddc38d..1c07ead8ce 100644 --- a/action/protocol/staking/candidate_center.go +++ b/action/protocol/staking/candidate_center.go @@ -322,7 +322,7 @@ func (m *CandidateCenter) WriteToStateDB(sm protocol.StateManager) error { name := m.base.candsInNameMap() op := m.base.candsInOperatorMap() owners := m.base.ownersList() - if len(name) == 0 || len(op) == 0 || len(owners) == 0 { + if len(name) == 0 || len(op) == 0 { return nil } if _, err := sm.PutState(name, protocol.NamespaceOption(CandsMapNS), protocol.KeyOption(_nameKey)); err != nil { From ba6f5085c44eb5137d46f04a87eca892138f7c73 Mon Sep 17 00:00:00 2001 From: envestcc Date: Tue, 25 Nov 2025 17:20:27 +0800 Subject: [PATCH 2/3] fix: view already committed before call isDirty() --- action/protocol/staking/candidate_center.go | 14 +++++++++++--- state/factory/workingset.go | 7 +++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/action/protocol/staking/candidate_center.go b/action/protocol/staking/candidate_center.go index 1c07ead8ce..aac811c47c 100644 --- a/action/protocol/staking/candidate_center.go +++ b/action/protocol/staking/candidate_center.go @@ -6,7 +6,9 @@ package staking import ( + "bytes" "context" + "slices" "sync" "github.com/iotexproject/iotex-address/address" @@ -325,13 +327,19 @@ func (m *CandidateCenter) WriteToStateDB(sm protocol.StateManager) error { if len(name) == 0 || len(op) == 0 { return nil } - if _, err := sm.PutState(name, protocol.NamespaceOption(CandsMapNS), protocol.KeyOption(_nameKey)); err != nil { + compare := func(a, b *Candidate) int { + return bytes.Compare(a.GetIdentifier().Bytes(), b.GetIdentifier().Bytes()) + } + slices.SortStableFunc(name, compare) + slices.SortStableFunc(op, compare) + slices.SortStableFunc(owners, compare) + if _, err := sm.PutState(&name, protocol.NamespaceOption(CandsMapNS), protocol.KeyOption(_nameKey)); err != nil { return err } - if _, err := sm.PutState(op, protocol.NamespaceOption(CandsMapNS), protocol.KeyOption(_operatorKey)); err != nil { + if _, err := sm.PutState(&op, protocol.NamespaceOption(CandsMapNS), protocol.KeyOption(_operatorKey)); err != nil { return err } - _, err := sm.PutState(owners, protocol.NamespaceOption(CandsMapNS), protocol.KeyOption(_ownerKey)) + _, err := sm.PutState(&owners, protocol.NamespaceOption(CandsMapNS), protocol.KeyOption(_ownerKey)) return err } diff --git a/state/factory/workingset.go b/state/factory/workingset.go index 9be142cdc9..c599ecc2c6 100644 --- a/state/factory/workingset.go +++ b/state/factory/workingset.go @@ -1000,8 +1000,11 @@ func (ws *workingSet) ValidateBlock(ctx context.Context, blk *block.Block) error log.L().Error("Failed to update state.", zap.Uint64("height", ws.height), zap.Error(err)) return err } - if err := ws.views.Commit(ctx, ws); err != nil { - return err + fwCtx := protocol.MustGetFeatureWithHeightCtx(ctx) + if !fwCtx.CandCenterHasAlias(blk.Height()) { + if err := ws.views.Commit(ctx, ws); err != nil { + return err + } } digest, err := ws.digest() From 1f861531ebb20d65aaae40d0b4cdf3d08a836856 Mon Sep 17 00:00:00 2001 From: envestcc Date: Tue, 16 Dec 2025 18:46:39 +0800 Subject: [PATCH 3/3] fix test --- go.mod | 2 +- go.sum | 4 ---- state/factory/workingset_test.go | 2 ++ 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 56931316c9..f153e20af8 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/cenkalti/backoff v2.2.1+incompatible github.com/cespare/xxhash/v2 v2.3.0 + github.com/cockroachdb/errors v1.8.1 github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 github.com/erigontech/erigon v1.9.7-0.20250305121304-76181961ed24 github.com/erigontech/erigon-lib v1.0.0 @@ -107,7 +108,6 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect github.com/btcsuite/btcd/btcutil v1.1.5 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect - github.com/cockroachdb/errors v1.8.1 // indirect github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f // indirect github.com/cockroachdb/redact v1.0.8 // indirect github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 // indirect diff --git a/go.sum b/go.sum index d47cf6ec60..ad14fe3d8f 100644 --- a/go.sum +++ b/go.sum @@ -658,10 +658,6 @@ github.com/iotexproject/go-p2p v0.3.7 h1:NtGvLb9MsLYdl+VhUkkXoulVMEU1iSAyYIP6F9F github.com/iotexproject/go-p2p v0.3.7/go.mod h1:zVhUDhhz9huiuhvR2ws7+wb3knRRdDQlQYtF99Xx++A= github.com/iotexproject/go-pkgs v0.1.16-0.20250813094138-d89b145b833c h1:eapiiTvd9sTgTHP2FbO9fSgp5bMS1mewsZBlzDKC5e8= github.com/iotexproject/go-pkgs v0.1.16-0.20250813094138-d89b145b833c/go.mod h1:UFzcLDeXZFxZqQrHXKe5P5wXMgT/lCD7NbUTBkU855Y= -github.com/iotexproject/iotex-address v0.2.8 h1:jaTR5pZe/ljiYW4OqHl9NKPs0h1o91Gi6FILOTaBCXw= -github.com/iotexproject/iotex-address v0.2.8/go.mod h1:K78yPSMB4K7gF/iQ7djT1amph0RBrP3rSkFfH7gNG70= -github.com/iotexproject/iotex-address v0.2.9-0.20251112034626-791993fb79d9 h1:/5mAjKoddCY6jIvmCTLML/eVu4TfxTjYS63Dvnnolv4= -github.com/iotexproject/iotex-address v0.2.9-0.20251112034626-791993fb79d9/go.mod h1:K78yPSMB4K7gF/iQ7djT1amph0RBrP3rSkFfH7gNG70= github.com/iotexproject/iotex-address v0.2.9-0.20251203033311-6e8aa4fd43ef h1:mQStcicCjjrh24CTIBzNg4LzqxUFdJpAWhXiw4r9SsM= github.com/iotexproject/iotex-address v0.2.9-0.20251203033311-6e8aa4fd43ef/go.mod h1:K78yPSMB4K7gF/iQ7djT1amph0RBrP3rSkFfH7gNG70= github.com/iotexproject/iotex-antenna-go/v2 v2.6.4 h1:7e0VyBDFT+iqwvr/BIk38yf7nCX5a2IEvziI88mlCQs= diff --git a/state/factory/workingset_test.go b/state/factory/workingset_test.go index dd6c5cf837..74f09b4ff5 100644 --- a/state/factory/workingset_test.go +++ b/state/factory/workingset_test.go @@ -176,6 +176,7 @@ func TestWorkingSet_ValidateBlock(t *testing.T) { zctx = protocol.WithFeatureCtx(protocol.WithBlockchainCtx(zctx, protocol.BlockchainCtx{ ChainID: 1, })) + zctx = protocol.WithFeatureWithHeightCtx(zctx) for _, f := range factories { for _, test := range tests { require.Equal(test.err, errors.Cause(f.Validate(zctx, test.block))) @@ -217,6 +218,7 @@ func TestWorkingSet_ValidateBlock_SystemAction(t *testing.T) { zctx = protocol.WithFeatureCtx(protocol.WithBlockchainCtx(zctx, protocol.BlockchainCtx{ ChainID: 1, })) + zctx = protocol.WithFeatureWithHeightCtx(zctx) t.Run("missing system action", func(t *testing.T) { digestHash, err := hash.HexStringToHash256("8f9b7694c325a4f4b0065cd382f8af0a4e913113a4ce7ef1ac899f96158c74f4")