Skip to content

Commit

Permalink
[staking] fix alias for non-stop node (#4503)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie authored Dec 31, 2024
1 parent 36a8913 commit 40838e9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions action/protocol/staking/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type (
BuilderConfig struct {
Staking genesis.Staking
PersistStakingPatchBlock uint64
FixAliasForNonStopHeight uint64
StakingPatchDir string
Revise ReviseConfig
}
Expand Down
24 changes: 19 additions & 5 deletions action/protocol/staking/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type (
MinStakeAmount *big.Int
BootstrapCandidates []genesis.BootstrapCandidate
PersistStakingPatchBlock uint64
FixAliasForNonStopHeight uint64
EndorsementWithdrawWaitingBlocks uint64
MigrateContractAddress string
}
Expand Down Expand Up @@ -167,6 +168,7 @@ func NewProtocol(
MinStakeAmount: minStakeAmount,
BootstrapCandidates: cfg.Staking.BootstrapCandidates,
PersistStakingPatchBlock: cfg.PersistStakingPatchBlock,
FixAliasForNonStopHeight: cfg.FixAliasForNonStopHeight,
EndorsementWithdrawWaitingBlocks: cfg.Staking.EndorsementWithdrawWaitingBlocks,
MigrateContractAddress: migrateContractAddress,
},
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions blockchain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions chainservice/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 40838e9

Please sign in to comment.