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

Better error message for rpc gas price errors #10931

Merged
merged 5 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
12 changes: 12 additions & 0 deletions ethcore/types/src/transaction/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ pub enum Error {
/// Transaction gas price
got: U256,
},
/// Transaction has too low fee
/// (there is already a transaction with the same sender-nonce but higher 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.

We need to document this better: what is the difference between TooCheapToReplace and TxTooCheapToReplace – it is not clear to when we return the one or the other.

TxTooCheapToReplace {
/// previous transaction's gas price
prev: U256,
/// new transaction's gas price
new: U256,
},
/// Transaction's gas is below currently set minimal gas requirement.
InsufficientGas {
/// Minimal expected gas
Expand Down Expand Up @@ -102,6 +110,10 @@ impl fmt::Display for Error {
AlreadyImported => "Already imported".into(),
Old => "No longer valid".into(),
TooCheapToReplace => "Gas price too low to replace".into(),
TxTooCheapToReplace { prev, new } =>
format!("Gas price too low to replace, previous tx gas: {}, new tx gas: {}",
prev, new
),
LimitReached => "Transaction limit reached".into(),
InsufficientGasPrice { minimal, got } =>
format!("Insufficient gas price. Min={}, Given={}", minimal, got),
Expand Down
8 changes: 4 additions & 4 deletions miner/src/pool/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn should_return_correct_nonces_when_dropped_because_of_limit() {
assert_eq!(res2, vec![
// The error here indicates reaching the limit
// and minimal effective gas price taken into account.
Err(transaction::Error::InsufficientGasPrice { minimal: 2.into(), got: 1.into() }),
Err(transaction::Error::TxTooCheapToReplace { prev: 2.into(), new: 1.into() }),
Ok(())
]);
assert_eq!(txq.status().status.transaction_count, 3);
Expand Down Expand Up @@ -1027,9 +1027,9 @@ fn should_reject_early_in_case_gas_price_is_less_than_min_effective() {
let client = TestClient::new();
let tx1 = Tx::default().signed().unverified();
let res = txq.import(client.clone(), vec![tx1]);
assert_eq!(res, vec![Err(transaction::Error::InsufficientGasPrice {
minimal: 2.into(),
got: 1.into(),
assert_eq!(res, vec![Err(transaction::Error::TxTooCheapToReplace {
prev: 2.into(),
new: 1.into(),
})]);
assert!(!client.was_verification_triggered());

Expand Down
6 changes: 3 additions & 3 deletions miner/src/pool/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ impl<C: Client> txpool::Verifier<Transaction> for Verifier<C, ::pool::scoring::N
tx.gas_price(),
vtx.transaction.gas_price,
);
return Err(transaction::Error::InsufficientGasPrice {
minimal: vtx.transaction.gas_price,
got: *tx.gas_price(),
return Err(transaction::Error::TxTooCheapToReplace {
prev: vtx.transaction.gas_price,
new: *tx.gas_price(),
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions rpc/src/v1/helpers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ pub fn transaction_message(error: &TransactionError) -> String {
TooCheapToReplace => {
"Transaction gas price is too low. There is another transaction with same nonce in the queue. Try increasing the gas price or incrementing the nonce.".into()
}
TxTooCheapToReplace { prev, new } => {
dvdplm marked this conversation as resolved.
Show resolved Hide resolved
format!("Transaction gas price {}wei is too low. There is another transaction with same nonce in the queue with gas price: {}wei. Try increasing the gas price or incrementing the nonce.", new, prev)
}
LimitReached => {
"There are too many transactions in the queue. Your transaction was dropped due to limit. Try increasing the fee.".into()
}
Expand Down