Skip to content

Commit 40838e9

Browse files
authored
[staking] fix alias for non-stop node (#4503)
1 parent 36a8913 commit 40838e9

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

action/protocol/staking/builder.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type (
88
BuilderConfig struct {
99
Staking genesis.Staking
1010
PersistStakingPatchBlock uint64
11+
FixAliasForNonStopHeight uint64
1112
StakingPatchDir string
1213
Revise ReviseConfig
1314
}

action/protocol/staking/protocol.go

+19-5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type (
9494
MinStakeAmount *big.Int
9595
BootstrapCandidates []genesis.BootstrapCandidate
9696
PersistStakingPatchBlock uint64
97+
FixAliasForNonStopHeight uint64
9798
EndorsementWithdrawWaitingBlocks uint64
9899
MigrateContractAddress string
99100
}
@@ -167,6 +168,7 @@ func NewProtocol(
167168
MinStakeAmount: minStakeAmount,
168169
BootstrapCandidates: cfg.Staking.BootstrapCandidates,
169170
PersistStakingPatchBlock: cfg.PersistStakingPatchBlock,
171+
FixAliasForNonStopHeight: cfg.FixAliasForNonStopHeight,
170172
EndorsementWithdrawWaitingBlocks: cfg.Staking.EndorsementWithdrawWaitingBlocks,
171173
MigrateContractAddress: migrateContractAddress,
172174
},
@@ -277,10 +279,12 @@ func (p *Protocol) CreateGenesisStates(
277279

278280
// CreatePreStates updates state manager
279281
func (p *Protocol) CreatePreStates(ctx context.Context, sm protocol.StateManager) error {
280-
g := genesis.MustExtractGenesisContext(ctx)
281-
blkCtx := protocol.MustGetBlockCtx(ctx)
282-
featureCtx := protocol.MustGetFeatureCtx(ctx)
283-
featureWithHeightCtx := protocol.MustGetFeatureWithHeightCtx(ctx)
282+
var (
283+
g = genesis.MustExtractGenesisContext(ctx)
284+
blkCtx = protocol.MustGetBlockCtx(ctx)
285+
featureCtx = protocol.MustGetFeatureCtx(ctx)
286+
featureWithHeightCtx = protocol.MustGetFeatureWithHeightCtx(ctx)
287+
)
284288
if blkCtx.BlockHeight == g.GreenlandBlockHeight {
285289
csr, err := ConstructBaseView(sm)
286290
if err != nil {
@@ -290,7 +294,17 @@ func (p *Protocol) CreatePreStates(ctx context.Context, sm protocol.StateManager
290294
return err
291295
}
292296
}
293-
297+
if blkCtx.BlockHeight == p.config.FixAliasForNonStopHeight {
298+
csm, err := NewCandidateStateManager(sm, featureWithHeightCtx.ReadStateFromDB(blkCtx.BlockHeight))
299+
if err != nil {
300+
return err
301+
}
302+
base := csm.DirtyView().candCenter.base
303+
owners := base.all()
304+
if err := base.loadNameOperatorMapOwnerList(owners, owners, nil); err != nil {
305+
return err
306+
}
307+
}
294308
if p.voteReviser.NeedRevise(blkCtx.BlockHeight) {
295309
csm, err := NewCandidateStateManager(sm, featureWithHeightCtx.ReadStateFromDB(blkCtx.BlockHeight))
296310
if err != nil {

blockchain/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type (
7474
StreamingBlockBufferSize uint64 `yaml:"streamingBlockBufferSize"`
7575
// PersistStakingPatchBlock is the block to persist staking patch
7676
PersistStakingPatchBlock uint64 `yaml:"persistStakingPatchBlock"`
77+
// FixAliasForNonStopHeight is the height to fix candidate alias for a non-stopping node
78+
FixAliasForNonStopHeight uint64 `yaml:"fixAliasForNonStopHeight"`
7779
// FactoryDBType is the type of factory db
7880
FactoryDBType string `yaml:"factoryDBType"`
7981
// MintTimeout is the timeout for minting
@@ -120,6 +122,7 @@ var (
120122
WorkingSetCacheSize: 20,
121123
StreamingBlockBufferSize: 200,
122124
PersistStakingPatchBlock: 19778037,
125+
FixAliasForNonStopHeight: 19778036,
123126
FactoryDBType: db.DBBolt,
124127
MintTimeout: 1500 * time.Millisecond, // valued with block accept ttl - 500ms(tolerate network delay)
125128
}

chainservice/builder.go

+1
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ func (builder *Builder) registerStakingProtocol() error {
667667
&staking.BuilderConfig{
668668
Staking: builder.cfg.Genesis.Staking,
669669
PersistStakingPatchBlock: builder.cfg.Chain.PersistStakingPatchBlock,
670+
FixAliasForNonStopHeight: builder.cfg.Chain.FixAliasForNonStopHeight,
670671
StakingPatchDir: builder.cfg.Chain.StakingPatchDir,
671672
Revise: staking.ReviseConfig{
672673
VoteWeight: builder.cfg.Genesis.VoteWeightCalConsts,

0 commit comments

Comments
 (0)