diff --git a/action/protocol/staking/candidate_center.go b/action/protocol/staking/candidate_center.go index 1498ddc38d..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" @@ -322,16 +324,22 @@ 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 { + 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()