Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions action/protocol/staking/candidate_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
package staking

import (
"bytes"
"context"
"slices"
"sync"

"github.com/iotexproject/iotex-address/address"
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 5 additions & 2 deletions state/factory/workingset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading