Skip to content

Commit

Permalink
vochain: format error with correct cost on set process census
Browse files Browse the repository at this point in the history
Signed-off-by: p4u <[email protected]>
  • Loading branch information
p4u committed Jun 27, 2024
1 parent 874ebb5 commit 1aef43d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions vochain/transaction/election_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (t *TransactionHandler) SetProcessTxCheck(vtx *vochaintx.Tx) (ethereum.Addr
if err != nil {
return ethereum.Address{}, fmt.Errorf("cannot get %s transaction cost: %w", tx.Txtype, err)
}
// check balance and nonce
// check base cost
if acc.Balance < cost {
return ethereum.Address{}, vstate.ErrNotEnoughBalance
}
Expand All @@ -232,8 +232,9 @@ func (t *TransactionHandler) SetProcessTxCheck(vtx *vochaintx.Tx) (ethereum.Addr
if err := t.checkMaxCensusSize(process); err != nil {
return ethereum.Address{}, err
}
cost = t.txCostIncreaseCensusSize(process, tx.GetCensusSize())
// get Tx cost, since it is a new census size, we should use the election price calculator
if acc.Balance < t.txCostIncreaseCensusSize(process, tx.GetCensusSize()) {
if acc.Balance < cost {
return ethereum.Address{}, fmt.Errorf("%w: required %d, got %d", vstate.ErrNotEnoughBalance, cost, acc.Balance)
}
}
Expand All @@ -246,7 +247,8 @@ func (t *TransactionHandler) SetProcessTxCheck(vtx *vochaintx.Tx) (ethereum.Addr
)
case models.TxType_SET_PROCESS_DURATION:
// get Tx cost, since it modifies the process duration, we should use the election price calculator
if acc.Balance < t.txCostIncreaseDuration(process, tx.GetDuration()) {
cost = t.txCostIncreaseDuration(process, tx.GetDuration())
if acc.Balance < cost {
return ethereum.Address{}, fmt.Errorf("%w: required %d, got %d", vstate.ErrNotEnoughBalance, cost, acc.Balance)
}
return ethereum.Address(*addr), t.state.SetProcessDuration(process.ProcessId, tx.GetDuration(), false)
Expand Down

0 comments on commit 1aef43d

Please sign in to comment.