Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Another minor estimation fix #4133

Merged
merged 6 commits into from
Jan 11, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,14 +893,13 @@ impl BlockChainClient for Client {
ExecutionError::TransactionMalformed(message)
})?;
let balance = original_state.balance(&sender);
let needed_balance = t.value + t.gas * t.gas_price;
let needed_balance = t.value + U256::from(UPPER_CEILING) * t.gas_price;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use saturating ops to avoid overflow panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's already a lot of these in the codebase (e.g. Client::call) - better to sweep them all at once if it's actually required.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use saturating_add (if implemented for U256) to avoid overflows.

Copy link
Contributor Author

@gavofyork gavofyork Jan 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no U256::saturating_add...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error: no method named `saturating_add` found for type `util::U256` in the current scope
   --> ethcore/src/client/client.rs:903:34
    |
903 | 			let needed_balance = tx.value.saturating_add(tx.gas.saturating_mul(tx.gas_price));
    | 			                              ^^^^^^^^^^^^^^

if balance < needed_balance {
// give the sender a sufficient balance
original_state.add_balance(&sender, &(needed_balance - balance), CleanupMode::NoEmpty);
}
let options = TransactOptions { tracing: true, vm_tracing: false, check_nonce: false };
let mut tx = t.clone();
tx.gas_price = 0.into();

let mut cond = |gas| {
let mut state = original_state.clone();
Expand Down