Skip to content

Commit

Permalink
updates min-self-staking
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanyan committed Jan 8, 2021
1 parent c4b2112 commit 9ec6652
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions params/all_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ func mainNetProtocols() VersionsMap {

v5.SignatureRequired[RoleChancellor] = false
v5.SignatureRequired[RoleSenator] = false
v5.MinSelfStakes[RoleChancellor] = 150000
v5.MinSelfStakes[RoleSenator] = 150000
v5.Version = YouV5
v5.InactivityPenaltyWaitRounds = 1024
v5.PenaltyFractionForInactive = 0
Expand Down Expand Up @@ -315,6 +317,8 @@ func testNetProtocols() VersionsMap {

v5.SignatureRequired[RoleChancellor] = false
v5.SignatureRequired[RoleSenator] = false
v5.MinSelfStakes[RoleChancellor] = 500
v5.MinSelfStakes[RoleSenator] = 500
v5.Version = YouV5
v5.InactivityPenaltyWaitRounds = 384
v5.PenaltyFractionForInactive = 1
Expand Down Expand Up @@ -441,6 +445,8 @@ func protocolsForTestCase() VersionsMap {

v5.SignatureRequired[RoleChancellor] = false
v5.SignatureRequired[RoleSenator] = false
v5.MinSelfStakes[RoleChancellor] = 500
v5.MinSelfStakes[RoleSenator] = 500
v5.Version = YouV5
v5.InactivityPenaltyWaitRounds = 32
v5.PenaltyFractionForInactive = 1
Expand Down
3 changes: 2 additions & 1 deletion params/evm_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const (
SstoreCleanRefund uint64 = 4200 // Once per SSTORE operation for resetting to the original non-zero value
SstoreClearRefund uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot

TxValidatorGas uint64 = 100000
TxValidatorGas uint64 = 100000
TxValCreationGas uint64 = 900000 // more gas for creates validator

Sha3Gas uint64 = 30 // Once per SHA3 operation.
Sha3WordGas uint64 = 6 // Once per word of the SHA3 operation's data.
Expand Down
7 changes: 7 additions & 0 deletions staking/take_effect_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ func teWithdraw(ctx *messageContext, payload []byte) error {
if withdrawToken.Cmp(newVal.SelfToken) > 0 {
changed = true
withdrawToken = new(big.Int).Set(newVal.SelfToken)
} else if ctx.Cfg.Version >= params.YouV5 {
remainToken := new(big.Int).Sub(newVal.SelfToken, withdrawToken)
remainStake := params.YOUToStake(remainToken)
if remainStake.Uint64() < ctx.Cfg.MinSelfStakes[newVal.Role] {
changed = true
withdrawToken.Set(old.SelfToken)
}
}
newVal.SelfToken.Sub(newVal.SelfToken, withdrawToken)
newStake := params.YOUToStake(newVal.SelfToken)
Expand Down
6 changes: 6 additions & 0 deletions staking/tx_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func (t *TxConverter) ApplyMessage(msgCtx *core.MessageContext) ([]byte, uint64,
}
return nil, msgCtx.InitialGas, true, nil
}
if msgCtx.Cfg.CurrYouParams.Version >= params.YouV5 && msg.Action == ValidatorCreate {
if err := msgCtx.UseGas(params.TxValCreationGas); err != nil {
logging.Warn("not enough gas for validator creation", "err", err)
return nil, msgCtx.GasUsed(), true, nil
}
}

err = getHandler(msg.Action)(msgCtx, msg.Payload)
if err != nil {
Expand Down

0 comments on commit 9ec6652

Please sign in to comment.