From 748643aa137825fa24d7b43a92580a92f577c1f9 Mon Sep 17 00:00:00 2001 From: envestcc Date: Thu, 20 Nov 2025 09:25:53 +0800 Subject: [PATCH 1/2] 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/2] 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()