added effectiveGasPrice to eth_getTransactionReceipt return structure (#450)

This commit is contained in:
Dusan Stanivukovic 2021-06-28 19:04:52 +02:00 committed by GitHub
parent e6f3794dd4
commit e5ae846de4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 1 deletions

View File

@ -2392,6 +2392,7 @@ impl BlockChainClient for Client {
let chain = self.chain.read();
let number = chain.block_number(&hash)?;
let body = chain.block_body(&hash)?;
let header = chain.block_header_data(&hash)?;
let mut receipts = chain.block_receipts(&hash)?.receipts;
receipts.truncate(address.index + 1);
@ -2404,6 +2405,11 @@ impl BlockChainClient for Client {
.into_iter()
.map(|receipt| receipt.logs.len())
.sum::<usize>();
let base_fee = if number >= self.engine().params().eip1559_transition {
Some(header.base_fee())
} else {
None
};
let receipt = transaction_receipt(
self.engine().machine(),
@ -2411,6 +2417,7 @@ impl BlockChainClient for Client {
receipt,
gas_used,
no_of_logs,
base_fee,
);
Some(receipt)
}
@ -2422,7 +2429,13 @@ impl BlockChainClient for Client {
let receipts = chain.block_receipts(&hash)?;
let number = chain.block_number(&hash)?;
let body = chain.block_body(&hash)?;
let header = chain.block_header_data(&hash)?;
let engine = self.engine.clone();
let base_fee = if number >= engine.params().eip1559_transition {
Some(header.base_fee())
} else {
None
};
let mut gas_used = 0.into();
let mut no_of_logs = 0;
@ -2439,6 +2452,7 @@ impl BlockChainClient for Client {
receipt,
gas_used,
no_of_logs,
base_fee,
);
gas_used = result.cumulative_gas_used;
no_of_logs += result.logs.len();
@ -3264,6 +3278,7 @@ fn transaction_receipt(
receipt: TypedReceipt,
prior_gas_used: U256,
prior_no_of_logs: usize,
base_fee: Option<U256>,
) -> LocalizedReceipt {
let sender = tx.sender();
let transaction_hash = tx.hash();
@ -3315,6 +3330,10 @@ fn transaction_receipt(
.collect(),
log_bloom: receipt.log_bloom,
outcome: receipt.outcome.clone(),
effective_gas_price: match base_fee {
Some(_) => Some(tx.effective_gas_price(base_fee)),
None => None,
},
}
}
@ -3643,7 +3662,7 @@ mod tests {
});
// when
let receipt = transaction_receipt(&machine, transaction, receipt, 5.into(), 1);
let receipt = transaction_receipt(&machine, transaction, receipt, 5.into(), 1, None);
// then
assert_eq!(
@ -3684,6 +3703,7 @@ mod tests {
],
log_bloom: Default::default(),
outcome: TransactionOutcome::StateRoot(state_root),
effective_gas_price: None,
}
);
}

View File

@ -1295,6 +1295,13 @@ impl miner::MinerService for Miner {
logs: receipt.logs.clone(),
log_bloom: receipt.log_bloom,
outcome: receipt.outcome.clone(),
effective_gas_price: if pending.header.number()
>= self.engine.params().eip1559_transition
{
Some(tx.effective_gas_price(pending.header.base_fee()))
} else {
None
},
}
})
.collect()

View File

@ -279,6 +279,8 @@ pub struct RichReceipt {
pub to: Option<H160>,
/// Sender
pub from: H160,
/// Effective gas price
pub effective_gas_price: Option<U256>,
}
/// Receipt with additional info.
@ -312,6 +314,8 @@ pub struct LocalizedReceipt {
pub to: Option<H160>,
/// Sender
pub from: H160,
/// Effective gas price
pub effective_gas_price: Option<U256>,
}
#[cfg(test)]

View File

@ -1184,6 +1184,7 @@ fn rpc_eth_transaction_receipt() {
}],
log_bloom: Bloom::zero(),
outcome: TransactionOutcome::StateRoot(H256::zero()),
effective_gas_price: None,
};
let hash =
@ -1242,6 +1243,7 @@ fn rpc_eth_pending_receipt() {
logs: Vec::new(),
log_bloom: Bloom::zero(),
outcome: TransactionOutcome::Unknown,
effective_gas_price: None,
};
let tester = EthTester::default();

View File

@ -561,6 +561,7 @@ fn rpc_parity_block_receipts() {
outcome: TransactionOutcome::Unknown,
to: None,
from: Address::from_low_u64_be(9),
effective_gas_price: None,
},
);
let io = deps.default_client();

View File

@ -55,6 +55,9 @@ pub struct Receipt {
// NOTE(niklasad1): Unknown after EIP98 rules, if it's missing then skip serializing it
#[serde(skip_serializing_if = "Option::is_none", rename = "status")]
pub status_code: Option<U64>,
/// Effective gas price
#[serde(skip_serializing_if = "Option::is_none")]
pub effective_gas_price: Option<U256>,
}
impl Receipt {
@ -90,6 +93,7 @@ impl From<LocalizedReceipt> for Receipt {
status_code: Self::outcome_to_status_code(&r.outcome),
state_root: Self::outcome_to_state_root(r.outcome),
logs_bloom: r.log_bloom,
effective_gas_price: r.effective_gas_price,
}
}
}
@ -111,6 +115,7 @@ impl From<RichReceipt> for Receipt {
status_code: Self::outcome_to_status_code(&r.outcome),
state_root: Self::outcome_to_state_root(r.outcome),
logs_bloom: r.log_bloom,
effective_gas_price: r.effective_gas_price,
}
}
}
@ -134,6 +139,7 @@ impl From<TypedReceipt> for Receipt {
status_code: Self::outcome_to_status_code(&legacy_receipt.outcome),
state_root: Self::outcome_to_state_root(legacy_receipt.outcome),
logs_bloom: legacy_receipt.log_bloom,
effective_gas_price: None,
}
}
}
@ -191,6 +197,7 @@ mod tests {
logs_bloom: Bloom::from_low_u64_be(15),
state_root: Some(H256::from_low_u64_be(10)),
status_code: Some(1u64.into()),
effective_gas_price: None,
};
let serialized = serde_json::to_string(&receipt).unwrap();