TypedTransaction (EIP-2718) and Optional access list (EIP-2930) (#135)
This commit is contained in:
@@ -34,7 +34,7 @@ use common_types::{
|
||||
},
|
||||
header::{ExtendedHeader, Header},
|
||||
log_entry::{LocalizedLogEntry, LogEntry},
|
||||
receipt::Receipt,
|
||||
receipt::TypedReceipt,
|
||||
transaction::LocalizedTransaction,
|
||||
tree_route::TreeRoute,
|
||||
view,
|
||||
@@ -460,13 +460,13 @@ impl BlockProvider for BlockChain {
|
||||
warn!("Block {} ({}) has different number of receipts ({}) to transactions ({}). Database corrupt?", number, hash, receipts.len(), hashes.len());
|
||||
assert!(false);
|
||||
}
|
||||
let mut log_index = receipts.iter().fold(0, |sum, receipt| sum + receipt.logs.len());
|
||||
let mut log_index = receipts.iter().fold(0, |sum, receipt| sum + receipt.receipt().logs.len());
|
||||
|
||||
let receipts_len = receipts.len();
|
||||
hashes.reverse();
|
||||
receipts.reverse();
|
||||
receipts.into_iter()
|
||||
.map(|receipt| receipt.logs)
|
||||
.map(|receipt| receipt.receipt().logs.clone())
|
||||
.zip(hashes)
|
||||
.enumerate()
|
||||
.flat_map(move |(index, (mut logs, tx_hash))| {
|
||||
@@ -895,7 +895,7 @@ impl BlockChain {
|
||||
&self,
|
||||
batch: &mut DBTransaction,
|
||||
block: encoded::Block,
|
||||
receipts: Vec<Receipt>,
|
||||
receipts: Vec<TypedReceipt>,
|
||||
parent_td: Option<U256>,
|
||||
is_best: bool,
|
||||
is_ancient: bool,
|
||||
@@ -1265,7 +1265,7 @@ impl BlockChain {
|
||||
&self,
|
||||
batch: &mut DBTransaction,
|
||||
block: encoded::Block,
|
||||
receipts: Vec<Receipt>,
|
||||
receipts: Vec<TypedReceipt>,
|
||||
extras: ExtrasInsert,
|
||||
) -> ImportRoute {
|
||||
let parent_hash = block.header_view().parent_hash();
|
||||
@@ -1283,7 +1283,7 @@ impl BlockChain {
|
||||
&self,
|
||||
batch: &mut DBTransaction,
|
||||
block: encoded::Block,
|
||||
receipts: Vec<Receipt>,
|
||||
receipts: Vec<TypedReceipt>,
|
||||
route: TreeRoute,
|
||||
extras: ExtrasInsert,
|
||||
) -> ImportRoute {
|
||||
@@ -1659,7 +1659,7 @@ impl BlockChain {
|
||||
/// This function returns modified block receipts.
|
||||
fn prepare_block_receipts_update(
|
||||
&self,
|
||||
receipts: Vec<Receipt>,
|
||||
receipts: Vec<TypedReceipt>,
|
||||
info: &BlockInfo,
|
||||
) -> HashMap<H256, BlockReceipts> {
|
||||
let mut block_receipts = HashMap::new();
|
||||
@@ -1921,8 +1921,8 @@ mod tests {
|
||||
|
||||
use crate::generator::{BlockBuilder, BlockGenerator, BlockOptions};
|
||||
use common_types::{
|
||||
receipt::{Receipt, TransactionOutcome},
|
||||
transaction::{Action, Transaction},
|
||||
receipt::{LegacyReceipt, TransactionOutcome, TypedReceipt},
|
||||
transaction::{Action, Transaction, TypedTransaction},
|
||||
};
|
||||
use ethkey::Secret;
|
||||
use keccak_hash::keccak;
|
||||
@@ -1975,7 +1975,7 @@ mod tests {
|
||||
db: &Arc<dyn BlockChainDB>,
|
||||
bc: &BlockChain,
|
||||
block: encoded::Block,
|
||||
receipts: Vec<Receipt>,
|
||||
receipts: Vec<TypedReceipt>,
|
||||
) -> ImportRoute {
|
||||
insert_block_commit(db, bc, block, receipts, true)
|
||||
}
|
||||
@@ -1984,7 +1984,7 @@ mod tests {
|
||||
db: &Arc<dyn BlockChainDB>,
|
||||
bc: &BlockChain,
|
||||
block: encoded::Block,
|
||||
receipts: Vec<Receipt>,
|
||||
receipts: Vec<TypedReceipt>,
|
||||
commit: bool,
|
||||
) -> ImportRoute {
|
||||
let mut batch = db.key_value().transaction();
|
||||
@@ -2000,7 +2000,7 @@ mod tests {
|
||||
batch: &mut DBTransaction,
|
||||
bc: &BlockChain,
|
||||
block: encoded::Block,
|
||||
receipts: Vec<Receipt>,
|
||||
receipts: Vec<TypedReceipt>,
|
||||
) -> ImportRoute {
|
||||
let fork_choice = {
|
||||
let header = block.header_view();
|
||||
@@ -2157,7 +2157,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_fork_transaction_addresses() {
|
||||
let t1 = Transaction {
|
||||
let t1 = TypedTransaction::Legacy(Transaction {
|
||||
nonce: 0.into(),
|
||||
gas_price: 0.into(),
|
||||
gas: 100_000.into(),
|
||||
@@ -2166,7 +2166,7 @@ mod tests {
|
||||
data: "601080600c6000396000f3006000355415600957005b60203560003555"
|
||||
.from_hex()
|
||||
.unwrap(),
|
||||
}
|
||||
})
|
||||
.sign(&secret(), None);
|
||||
|
||||
let t1_hash = t1.hash();
|
||||
@@ -2211,7 +2211,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_overwriting_transaction_addresses() {
|
||||
let t1 = Transaction {
|
||||
let t1 = TypedTransaction::Legacy(Transaction {
|
||||
nonce: 0.into(),
|
||||
gas_price: 0.into(),
|
||||
gas: 100_000.into(),
|
||||
@@ -2220,10 +2220,10 @@ mod tests {
|
||||
data: "601080600c6000396000f3006000355415600957005b60203560003555"
|
||||
.from_hex()
|
||||
.unwrap(),
|
||||
}
|
||||
})
|
||||
.sign(&secret(), None);
|
||||
|
||||
let t2 = Transaction {
|
||||
let t2 = TypedTransaction::Legacy(Transaction {
|
||||
nonce: 1.into(),
|
||||
gas_price: 0.into(),
|
||||
gas: 100_000.into(),
|
||||
@@ -2232,10 +2232,10 @@ mod tests {
|
||||
data: "601080600c6000396000f3006000355415600957005b60203560003555"
|
||||
.from_hex()
|
||||
.unwrap(),
|
||||
}
|
||||
})
|
||||
.sign(&secret(), None);
|
||||
|
||||
let t3 = Transaction {
|
||||
let t3 = TypedTransaction::Legacy(Transaction {
|
||||
nonce: 2.into(),
|
||||
gas_price: 0.into(),
|
||||
gas: 100_000.into(),
|
||||
@@ -2244,7 +2244,7 @@ mod tests {
|
||||
data: "601080600c6000396000f3006000355415600957005b60203560003555"
|
||||
.from_hex()
|
||||
.unwrap(),
|
||||
}
|
||||
})
|
||||
.sign(&secret(), None);
|
||||
|
||||
let genesis = BlockBuilder::genesis();
|
||||
@@ -2509,7 +2509,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_logs() {
|
||||
let t1 = Transaction {
|
||||
let t1 = TypedTransaction::Legacy(Transaction {
|
||||
nonce: 0.into(),
|
||||
gas_price: 0.into(),
|
||||
gas: 100_000.into(),
|
||||
@@ -2518,9 +2518,9 @@ mod tests {
|
||||
data: "601080600c6000396000f3006000355415600957005b60203560003555"
|
||||
.from_hex()
|
||||
.unwrap(),
|
||||
}
|
||||
})
|
||||
.sign(&secret(), None);
|
||||
let t2 = Transaction {
|
||||
let t2 = TypedTransaction::Legacy(Transaction {
|
||||
nonce: 0.into(),
|
||||
gas_price: 0.into(),
|
||||
gas: 100_000.into(),
|
||||
@@ -2529,9 +2529,9 @@ mod tests {
|
||||
data: "601080600c6000396000f3006000355415600957005b60203560003555"
|
||||
.from_hex()
|
||||
.unwrap(),
|
||||
}
|
||||
})
|
||||
.sign(&secret(), None);
|
||||
let t3 = Transaction {
|
||||
let t3 = TypedTransaction::Legacy(Transaction {
|
||||
nonce: 0.into(),
|
||||
gas_price: 0.into(),
|
||||
gas: 100_000.into(),
|
||||
@@ -2540,9 +2540,9 @@ mod tests {
|
||||
data: "601080600c6000396000f3006000355415600957005b60203560003555"
|
||||
.from_hex()
|
||||
.unwrap(),
|
||||
}
|
||||
})
|
||||
.sign(&secret(), None);
|
||||
let t4 = Transaction {
|
||||
let t4 = TypedTransaction::Legacy(Transaction {
|
||||
nonce: 0.into(),
|
||||
gas_price: 0.into(),
|
||||
gas: 100_000.into(),
|
||||
@@ -2551,7 +2551,7 @@ mod tests {
|
||||
data: "601080600c6000396000f3006000355415600957005b60203560003555"
|
||||
.from_hex()
|
||||
.unwrap(),
|
||||
}
|
||||
})
|
||||
.sign(&secret(), None);
|
||||
let tx_hash1 = t1.hash();
|
||||
let tx_hash2 = t2.hash();
|
||||
@@ -2580,7 +2580,7 @@ mod tests {
|
||||
&bc,
|
||||
b1.last().encoded(),
|
||||
vec![
|
||||
Receipt {
|
||||
TypedReceipt::Legacy(LegacyReceipt {
|
||||
outcome: TransactionOutcome::StateRoot(H256::default()),
|
||||
gas_used: 10_000.into(),
|
||||
log_bloom: Default::default(),
|
||||
@@ -2596,8 +2596,8 @@ mod tests {
|
||||
data: vec![2],
|
||||
},
|
||||
],
|
||||
},
|
||||
Receipt {
|
||||
}),
|
||||
TypedReceipt::Legacy(LegacyReceipt {
|
||||
outcome: TransactionOutcome::StateRoot(H256::default()),
|
||||
gas_used: 10_000.into(),
|
||||
log_bloom: Default::default(),
|
||||
@@ -2606,14 +2606,14 @@ mod tests {
|
||||
topics: vec![],
|
||||
data: vec![3],
|
||||
}],
|
||||
},
|
||||
}),
|
||||
],
|
||||
);
|
||||
insert_block(
|
||||
&db,
|
||||
&bc,
|
||||
b2.last().encoded(),
|
||||
vec![Receipt {
|
||||
vec![TypedReceipt::Legacy(LegacyReceipt {
|
||||
outcome: TransactionOutcome::StateRoot(H256::default()),
|
||||
gas_used: 10_000.into(),
|
||||
log_bloom: Default::default(),
|
||||
@@ -2622,13 +2622,13 @@ mod tests {
|
||||
topics: vec![],
|
||||
data: vec![4],
|
||||
}],
|
||||
}],
|
||||
})],
|
||||
);
|
||||
insert_block(
|
||||
&db,
|
||||
&bc,
|
||||
b3.last().encoded(),
|
||||
vec![Receipt {
|
||||
vec![TypedReceipt::Legacy(LegacyReceipt {
|
||||
outcome: TransactionOutcome::StateRoot(H256::default()),
|
||||
gas_used: 10_000.into(),
|
||||
log_bloom: Default::default(),
|
||||
@@ -2637,7 +2637,7 @@ mod tests {
|
||||
topics: vec![],
|
||||
data: vec![5],
|
||||
}],
|
||||
}],
|
||||
})],
|
||||
);
|
||||
|
||||
// when
|
||||
|
||||
@@ -22,17 +22,16 @@ use std::collections::VecDeque;
|
||||
use common_types::{
|
||||
encoded,
|
||||
header::Header,
|
||||
transaction::{Action, SignedTransaction, Transaction},
|
||||
transaction::{Action, SignedTransaction, Transaction, TypedTransaction},
|
||||
view,
|
||||
views::BlockView,
|
||||
};
|
||||
use keccak_hash::keccak;
|
||||
use rlp::encode;
|
||||
use rlp_derive::RlpEncodable;
|
||||
use rlp::{encode, RlpStream};
|
||||
use triehash_ethereum::ordered_trie_root;
|
||||
|
||||
/// Helper structure, used for encoding blocks.
|
||||
#[derive(Default, Clone, RlpEncodable)]
|
||||
#[derive(Default, Clone)]
|
||||
pub struct Block {
|
||||
/// Block header
|
||||
pub header: Header,
|
||||
@@ -42,6 +41,15 @@ pub struct Block {
|
||||
pub uncles: Vec<Header>,
|
||||
}
|
||||
|
||||
impl rlp::Encodable for Block {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
s.begin_list(3);
|
||||
s.append(&self.header);
|
||||
SignedTransaction::rlp_append_list(s, &self.transactions);
|
||||
s.append_list(&self.uncles);
|
||||
}
|
||||
}
|
||||
|
||||
impl Block {
|
||||
/// Get a copy of the header
|
||||
#[inline]
|
||||
@@ -154,14 +162,14 @@ impl BlockBuilder {
|
||||
let data = std::iter::repeat_with(|| rand::random::<u8>())
|
||||
.take(data_len as usize)
|
||||
.collect::<Vec<_>>();
|
||||
Transaction {
|
||||
TypedTransaction::Legacy(Transaction {
|
||||
nonce: 0.into(),
|
||||
gas_price: 0.into(),
|
||||
gas: 100_000.into(),
|
||||
action: Action::Create,
|
||||
value: 100.into(),
|
||||
data,
|
||||
}
|
||||
})
|
||||
.sign(&keccak("").into(), None)
|
||||
})
|
||||
.take(count);
|
||||
@@ -205,7 +213,7 @@ impl BlockBuilder {
|
||||
let metadata = get_metadata();
|
||||
let block_number = parent_number + 1;
|
||||
let transactions = metadata.transactions;
|
||||
let transactions_root = ordered_trie_root(transactions.iter().map(rlp::encode));
|
||||
let transactions_root = ordered_trie_root(transactions.iter().map(|tx| tx.encode()));
|
||||
|
||||
block.header.set_parent_hash(parent_hash);
|
||||
block.header.set_number(block_number);
|
||||
|
||||
Reference in New Issue
Block a user