[txPool] added gas balance check when validating delegate transaction

pull/3648/head
Jacky Wang 4 years ago
parent 1a8494c069
commit b20f8f1edf
No known key found for this signature in database
GPG Key ID: 1085CE5F4FF5842C
  1. 14
      core/tx_pool.go

@ -839,9 +839,19 @@ func (pool *TxPool) validateStakingTx(tx *staking.StakingTransaction) error {
return err return err
} }
pendingEpoch := pool.pendingEpoch() pendingEpoch := pool.pendingEpoch()
_, _, _, err = VerifyAndDelegateFromMsg( _, delegateAmt, _, err := VerifyAndDelegateFromMsg(
pool.currentState, pendingEpoch, stkMsg, delegations, pool.chainconfig.IsRedelegation(pendingEpoch)) pool.currentState, pendingEpoch, stkMsg, delegations, pool.chainconfig.IsRedelegation(pendingEpoch))
return err if err != nil {
return err
}
// We need to deduct gas price and verify balance since txn.Cost() is not accurate for delegate
// staking transaction because of re-delegation.
gasAmt := new(big.Int).Mul(tx.GasPrice(), new(big.Int).SetUint64(tx.GasLimit())))
totalAmt := new(big.Int).Add(delegateAmt, gasAmt)
if bal := pool.currentState.GetBalance(from); bal.Cmp(totalAmt) < 0 {
return fmt.Errorf("not enough balance for delegation: %v < %v", bal, delegateAmt)
}
return nil
case staking.DirectiveUndelegate: case staking.DirectiveUndelegate:
msg, err := staking.RLPDecodeStakeMsg(tx.Data(), staking.DirectiveUndelegate) msg, err := staking.RLPDecodeStakeMsg(tx.Data(), staking.DirectiveUndelegate)
if err != nil { if err != nil {

Loading…
Cancel
Save