TypedTransaction (EIP-2718) and Optional access list (EIP-2930) (#135)
This commit is contained in:
@@ -80,7 +80,10 @@ pub mod blocks {
|
||||
|
||||
use engines::EthEngine;
|
||||
use error::{BlockError, Error, ErrorKind};
|
||||
use types::{header::Header, transaction::UnverifiedTransaction};
|
||||
use types::{
|
||||
header::Header,
|
||||
transaction::{TypedTransaction, UnverifiedTransaction},
|
||||
};
|
||||
use verification::{verify_block_basic, verify_block_unordered, PreverifiedBlock};
|
||||
|
||||
use bytes::Bytes;
|
||||
@@ -151,7 +154,7 @@ pub mod blocks {
|
||||
let (header, transactions, uncles) = {
|
||||
let rlp = Rlp::new(&bytes);
|
||||
let header = rlp.val_at(0)?;
|
||||
let transactions = rlp.list_at(1)?;
|
||||
let transactions = TypedTransaction::decode_rlp_list(&rlp.at(1)?)?;
|
||||
let uncles = rlp.list_at(2)?;
|
||||
(header, transactions, uncles)
|
||||
};
|
||||
|
||||
@@ -133,7 +133,7 @@ pub fn verify_block_unordered(
|
||||
let t = engine.verify_transaction_unordered(t, &header)?;
|
||||
// t_nb 5.3.2 check if nonce is more then max nonce (EIP-168 and EIP169)
|
||||
if let Some(max_nonce) = nonce_cap {
|
||||
if t.nonce >= max_nonce {
|
||||
if t.tx().nonce >= max_nonce {
|
||||
return Err(BlockError::TooManyTransactions(t.sender()).into());
|
||||
}
|
||||
}
|
||||
@@ -493,7 +493,16 @@ fn verify_parent(header: &Header, parent: &Header, engine: &dyn EthEngine) -> Re
|
||||
fn verify_block_integrity(block: &Unverified) -> Result<(), Error> {
|
||||
let block_rlp = Rlp::new(&block.bytes);
|
||||
let tx = block_rlp.at(1)?;
|
||||
let expected_root = ordered_trie_root(tx.iter().map(|r| r.as_raw()));
|
||||
let expected_root = ordered_trie_root(tx.iter().map(|r| {
|
||||
if r.is_list() {
|
||||
r.as_raw()
|
||||
} else {
|
||||
// This is already checked in Unverified structure and that is why we are okay to asume that data is valid.
|
||||
r.data().expect(
|
||||
"Unverified block should already check if raw list of transactions is valid",
|
||||
)
|
||||
}
|
||||
}));
|
||||
if &expected_root != block.header.transactions_root() {
|
||||
bail!(BlockError::InvalidTransactionsRoot(Mismatch {
|
||||
expected: expected_root,
|
||||
@@ -531,7 +540,7 @@ mod tests {
|
||||
use types::{
|
||||
encoded,
|
||||
log_entry::{LocalizedLogEntry, LogEntry},
|
||||
transaction::{Action, SignedTransaction, Transaction, UnverifiedTransaction},
|
||||
transaction::{Action, SignedTransaction, Transaction, TypedTransaction},
|
||||
};
|
||||
|
||||
fn check_ok(result: Result<(), Error>) {
|
||||
@@ -764,34 +773,34 @@ mod tests {
|
||||
|
||||
let keypair = Random.generate().unwrap();
|
||||
|
||||
let tr1 = Transaction {
|
||||
let tr1 = TypedTransaction::Legacy(Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::from(0),
|
||||
data: Bytes::new(),
|
||||
gas: U256::from(30_000),
|
||||
gas_price: U256::from(40_000),
|
||||
nonce: U256::one(),
|
||||
}
|
||||
})
|
||||
.sign(keypair.secret(), None);
|
||||
|
||||
let tr2 = Transaction {
|
||||
let tr2 = TypedTransaction::Legacy(Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::from(0),
|
||||
data: Bytes::new(),
|
||||
gas: U256::from(30_000),
|
||||
gas_price: U256::from(40_000),
|
||||
nonce: U256::from(2),
|
||||
}
|
||||
})
|
||||
.sign(keypair.secret(), None);
|
||||
|
||||
let tr3 = Transaction {
|
||||
let tr3 = TypedTransaction::Legacy(Transaction {
|
||||
action: Action::Call(0x0.into()),
|
||||
value: U256::from(0),
|
||||
data: Bytes::new(),
|
||||
gas: U256::from(30_000),
|
||||
gas_price: U256::from(0),
|
||||
nonce: U256::zero(),
|
||||
}
|
||||
})
|
||||
.null_sign(0);
|
||||
|
||||
let good_transactions = [tr1.clone(), tr2.clone()];
|
||||
@@ -834,16 +843,10 @@ mod tests {
|
||||
let mut uncles_rlp = RlpStream::new();
|
||||
uncles_rlp.append_list(&good_uncles);
|
||||
let good_uncles_hash = keccak(uncles_rlp.as_raw());
|
||||
let good_transactions_root = ordered_trie_root(
|
||||
good_transactions
|
||||
.iter()
|
||||
.map(|t| ::rlp::encode::<UnverifiedTransaction>(t)),
|
||||
);
|
||||
let eip86_transactions_root = ordered_trie_root(
|
||||
eip86_transactions
|
||||
.iter()
|
||||
.map(|t| ::rlp::encode::<UnverifiedTransaction>(t)),
|
||||
);
|
||||
let good_transactions_root =
|
||||
ordered_trie_root(good_transactions.iter().map(|t| t.encode()));
|
||||
let eip86_transactions_root =
|
||||
ordered_trie_root(eip86_transactions.iter().map(|t| t.encode()));
|
||||
|
||||
let mut parent = good.clone();
|
||||
parent.set_number(9);
|
||||
@@ -1114,14 +1117,14 @@ mod tests {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let bad_transactions: Vec<_> = (0..3)
|
||||
.map(|i| {
|
||||
Transaction {
|
||||
TypedTransaction::Legacy(Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::zero(),
|
||||
data: Vec::new(),
|
||||
gas: 0.into(),
|
||||
gas_price: U256::zero(),
|
||||
nonce: i.into(),
|
||||
}
|
||||
})
|
||||
.sign(keypair.secret(), None)
|
||||
})
|
||||
.collect();
|
||||
|
||||
Reference in New Issue
Block a user