From 40838e99ae9fc2de5ee8cc09799b2b4659670da3 Mon Sep 17 00:00:00 2001 From: dustinxie Date: Mon, 30 Dec 2024 22:54:19 -0800 Subject: [PATCH] [staking] fix alias for non-stop node (#4503) --- action/protocol/staking/builder.go | 1 + action/protocol/staking/protocol.go | 24 +++++++++++++++++++----- blockchain/config.go | 3 +++ chainservice/builder.go | 1 + 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/action/protocol/staking/builder.go b/action/protocol/staking/builder.go index e3a57adc1d..ba213f052c 100644 --- a/action/protocol/staking/builder.go +++ b/action/protocol/staking/builder.go @@ -8,6 +8,7 @@ type ( BuilderConfig struct { Staking genesis.Staking PersistStakingPatchBlock uint64 + FixAliasForNonStopHeight uint64 StakingPatchDir string Revise ReviseConfig } diff --git a/action/protocol/staking/protocol.go b/action/protocol/staking/protocol.go index 0932a79065..9a42173248 100644 --- a/action/protocol/staking/protocol.go +++ b/action/protocol/staking/protocol.go @@ -94,6 +94,7 @@ type ( MinStakeAmount *big.Int BootstrapCandidates []genesis.BootstrapCandidate PersistStakingPatchBlock uint64 + FixAliasForNonStopHeight uint64 EndorsementWithdrawWaitingBlocks uint64 MigrateContractAddress string } @@ -167,6 +168,7 @@ func NewProtocol( MinStakeAmount: minStakeAmount, BootstrapCandidates: cfg.Staking.BootstrapCandidates, PersistStakingPatchBlock: cfg.PersistStakingPatchBlock, + FixAliasForNonStopHeight: cfg.FixAliasForNonStopHeight, EndorsementWithdrawWaitingBlocks: cfg.Staking.EndorsementWithdrawWaitingBlocks, MigrateContractAddress: migrateContractAddress, }, @@ -277,10 +279,12 @@ func (p *Protocol) CreateGenesisStates( // CreatePreStates updates state manager func (p *Protocol) CreatePreStates(ctx context.Context, sm protocol.StateManager) error { - g := genesis.MustExtractGenesisContext(ctx) - blkCtx := protocol.MustGetBlockCtx(ctx) - featureCtx := protocol.MustGetFeatureCtx(ctx) - featureWithHeightCtx := protocol.MustGetFeatureWithHeightCtx(ctx) + var ( + g = genesis.MustExtractGenesisContext(ctx) + blkCtx = protocol.MustGetBlockCtx(ctx) + featureCtx = protocol.MustGetFeatureCtx(ctx) + featureWithHeightCtx = protocol.MustGetFeatureWithHeightCtx(ctx) + ) if blkCtx.BlockHeight == g.GreenlandBlockHeight { csr, err := ConstructBaseView(sm) if err != nil { @@ -290,7 +294,17 @@ func (p *Protocol) CreatePreStates(ctx context.Context, sm protocol.StateManager return err } } - + if blkCtx.BlockHeight == p.config.FixAliasForNonStopHeight { + csm, err := NewCandidateStateManager(sm, featureWithHeightCtx.ReadStateFromDB(blkCtx.BlockHeight)) + if err != nil { + return err + } + base := csm.DirtyView().candCenter.base + owners := base.all() + if err := base.loadNameOperatorMapOwnerList(owners, owners, nil); err != nil { + return err + } + } if p.voteReviser.NeedRevise(blkCtx.BlockHeight) { csm, err := NewCandidateStateManager(sm, featureWithHeightCtx.ReadStateFromDB(blkCtx.BlockHeight)) if err != nil { diff --git a/blockchain/config.go b/blockchain/config.go index 8993e92adc..32336e8fbc 100644 --- a/blockchain/config.go +++ b/blockchain/config.go @@ -74,6 +74,8 @@ type ( StreamingBlockBufferSize uint64 `yaml:"streamingBlockBufferSize"` // PersistStakingPatchBlock is the block to persist staking patch PersistStakingPatchBlock uint64 `yaml:"persistStakingPatchBlock"` + // FixAliasForNonStopHeight is the height to fix candidate alias for a non-stopping node + FixAliasForNonStopHeight uint64 `yaml:"fixAliasForNonStopHeight"` // FactoryDBType is the type of factory db FactoryDBType string `yaml:"factoryDBType"` // MintTimeout is the timeout for minting @@ -120,6 +122,7 @@ var ( WorkingSetCacheSize: 20, StreamingBlockBufferSize: 200, PersistStakingPatchBlock: 19778037, + FixAliasForNonStopHeight: 19778036, FactoryDBType: db.DBBolt, MintTimeout: 1500 * time.Millisecond, // valued with block accept ttl - 500ms(tolerate network delay) } diff --git a/chainservice/builder.go b/chainservice/builder.go index 69664e37f9..19cbeaaf66 100644 --- a/chainservice/builder.go +++ b/chainservice/builder.go @@ -667,6 +667,7 @@ func (builder *Builder) registerStakingProtocol() error { &staking.BuilderConfig{ Staking: builder.cfg.Genesis.Staking, PersistStakingPatchBlock: builder.cfg.Chain.PersistStakingPatchBlock, + FixAliasForNonStopHeight: builder.cfg.Chain.FixAliasForNonStopHeight, StakingPatchDir: builder.cfg.Chain.StakingPatchDir, Revise: staking.ReviseConfig{ VoteWeight: builder.cfg.Genesis.VoteWeightCalConsts,