block view! removal in progress (#9397)
This commit is contained in:
parent
0b34579b04
commit
b87c7cac54
@ -637,10 +637,11 @@ mod tests {
|
||||
use ethereum_types::Address;
|
||||
use std::sync::Arc;
|
||||
use transaction::SignedTransaction;
|
||||
use verification::queue::kind::blocks::Unverified;
|
||||
|
||||
/// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header
|
||||
fn enact_bytes(
|
||||
block_bytes: &[u8],
|
||||
block_bytes: Vec<u8>,
|
||||
engine: &EthEngine,
|
||||
tracing: bool,
|
||||
db: StateDB,
|
||||
@ -648,10 +649,10 @@ mod tests {
|
||||
last_hashes: Arc<LastHashes>,
|
||||
factories: Factories,
|
||||
) -> Result<LockedBlock, Error> {
|
||||
let block = view!(BlockView, block_bytes);
|
||||
let header = block.header();
|
||||
let block = Unverified::from_rlp(block_bytes)?;
|
||||
let header = block.header;
|
||||
let transactions: Result<Vec<_>, Error> = block
|
||||
.transactions()
|
||||
.transactions
|
||||
.into_iter()
|
||||
.map(SignedTransaction::new)
|
||||
.map(|r| r.map_err(Into::into))
|
||||
@ -683,8 +684,8 @@ mod tests {
|
||||
b.populate_from(&header);
|
||||
b.push_transactions(transactions)?;
|
||||
|
||||
for u in &block.uncles() {
|
||||
b.push_uncle(u.clone())?;
|
||||
for u in block.uncles {
|
||||
b.push_uncle(u)?;
|
||||
}
|
||||
|
||||
b.close_and_lock()
|
||||
@ -692,7 +693,7 @@ mod tests {
|
||||
|
||||
/// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header. Seal the block aferwards
|
||||
fn enact_and_seal(
|
||||
block_bytes: &[u8],
|
||||
block_bytes: Vec<u8>,
|
||||
engine: &EthEngine,
|
||||
tracing: bool,
|
||||
db: StateDB,
|
||||
@ -700,8 +701,9 @@ mod tests {
|
||||
last_hashes: Arc<LastHashes>,
|
||||
factories: Factories,
|
||||
) -> Result<SealedBlock, Error> {
|
||||
let header = view!(BlockView, block_bytes).header_view();
|
||||
Ok(enact_bytes(block_bytes, engine, tracing, db, parent, last_hashes, factories)?.seal(engine, header.seal())?)
|
||||
let header = Unverified::from_rlp(block_bytes.clone())?.header;
|
||||
Ok(enact_bytes(block_bytes, engine, tracing, db, parent, last_hashes, factories)?
|
||||
.seal(engine, header.seal().to_vec())?)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -731,7 +733,7 @@ mod tests {
|
||||
let orig_db = b.drain().state.drop().1;
|
||||
|
||||
let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap();
|
||||
let e = enact_and_seal(&orig_bytes, engine, false, db, &genesis_header, last_hashes, Default::default()).unwrap();
|
||||
let e = enact_and_seal(orig_bytes.clone(), engine, false, db, &genesis_header, last_hashes, Default::default()).unwrap();
|
||||
|
||||
assert_eq!(e.rlp_bytes(), orig_bytes);
|
||||
|
||||
@ -762,7 +764,7 @@ mod tests {
|
||||
let orig_db = b.drain().state.drop().1;
|
||||
|
||||
let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap();
|
||||
let e = enact_and_seal(&orig_bytes, engine, false, db, &genesis_header, last_hashes, Default::default()).unwrap();
|
||||
let e = enact_and_seal(orig_bytes.clone(), engine, false, db, &genesis_header, last_hashes, Default::default()).unwrap();
|
||||
|
||||
let bytes = e.rlp_bytes();
|
||||
assert_eq!(bytes, orig_bytes);
|
||||
|
@ -376,7 +376,6 @@ mod tests {
|
||||
use types::log_entry::{LogEntry, LocalizedLogEntry};
|
||||
use rlp;
|
||||
use triehash::ordered_trie_root;
|
||||
use views::BlockView;
|
||||
|
||||
fn check_ok(result: Result<(), Error>) {
|
||||
result.unwrap_or_else(|e| panic!("Block verification failed: {:?}", e));
|
||||
@ -420,10 +419,10 @@ mod tests {
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, bytes: Bytes) {
|
||||
let number = view!(BlockView, &bytes).header_view().number();
|
||||
let hash = view!(BlockView, &bytes).header_view().hash();
|
||||
self.blocks.insert(hash.clone(), bytes);
|
||||
self.numbers.insert(number, hash.clone());
|
||||
let header = Unverified::from_rlp(bytes.clone()).unwrap().header;
|
||||
let hash = header.hash();
|
||||
self.blocks.insert(hash, bytes);
|
||||
self.numbers.insert(header.number(), hash);
|
||||
}
|
||||
}
|
||||
|
||||
@ -460,11 +459,11 @@ mod tests {
|
||||
/// Get the familial details concerning a block.
|
||||
fn block_details(&self, hash: &H256) -> Option<BlockDetails> {
|
||||
self.blocks.get(hash).map(|bytes| {
|
||||
let header = view!(BlockView, bytes).header();
|
||||
let header = Unverified::from_rlp(bytes.to_vec()).unwrap().header;
|
||||
BlockDetails {
|
||||
number: header.number(),
|
||||
total_difficulty: header.difficulty().clone(),
|
||||
parent: header.parent_hash().clone(),
|
||||
total_difficulty: *header.difficulty(),
|
||||
parent: *header.parent_hash(),
|
||||
children: Vec::new(),
|
||||
is_finalized: false,
|
||||
}
|
||||
@ -501,9 +500,9 @@ mod tests {
|
||||
}
|
||||
|
||||
fn family_test<BC>(bytes: &[u8], engine: &EthEngine, bc: &BC) -> Result<(), Error> where BC: BlockProvider {
|
||||
let view = view!(BlockView, bytes);
|
||||
let header = view.header();
|
||||
let transactions: Vec<_> = view.transactions()
|
||||
let block = Unverified::from_rlp(bytes.to_vec()).unwrap();
|
||||
let header = block.header;
|
||||
let transactions: Vec<_> = block.transactions
|
||||
.into_iter()
|
||||
.map(SignedTransaction::new)
|
||||
.collect::<Result<_,_>>()?;
|
||||
@ -520,7 +519,7 @@ mod tests {
|
||||
let block = PreverifiedBlock {
|
||||
header,
|
||||
transactions,
|
||||
uncles: view.uncles(),
|
||||
uncles: block.uncles,
|
||||
bytes: bytes.to_vec(),
|
||||
};
|
||||
|
||||
@ -533,7 +532,6 @@ mod tests {
|
||||
}
|
||||
|
||||
fn unordered_test(bytes: &[u8], engine: &EthEngine) -> Result<(), Error> {
|
||||
use verification::queue::kind::blocks::Unverified;
|
||||
let un = Unverified::from_rlp(bytes.to_vec())?;
|
||||
verify_block_unordered(un, engine, false)?;
|
||||
Ok(())
|
||||
|
@ -31,6 +31,7 @@ known_heap_size!(0, HeaderId);
|
||||
|
||||
type SmallHashVec = SmallVec<[H256; 1]>;
|
||||
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
pub struct SyncHeader {
|
||||
pub bytes: Bytes,
|
||||
pub header: BlockHeader,
|
||||
@ -578,7 +579,6 @@ mod test {
|
||||
use ethcore::client::{TestBlockChainClient, EachBlockWith, BlockId, BlockChainClient};
|
||||
use ethcore::header::BlockNumber;
|
||||
use ethcore::verification::queue::kind::blocks::Unverified;
|
||||
use ethcore::views::HeaderView;
|
||||
use rlp::*;
|
||||
|
||||
fn is_empty(bc: &BlockCollection) -> bool {
|
||||
@ -614,9 +614,9 @@ mod test {
|
||||
let blocks: Vec<_> = (0..nblocks)
|
||||
.map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).unwrap().into_inner())
|
||||
.collect();
|
||||
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).unwrap().as_raw().to_vec()).collect();
|
||||
let hashes: Vec<_> = headers.iter().map(|h| view!(HeaderView, h).hash()).collect();
|
||||
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
|
||||
let headers: Vec<_> = blocks.iter().map(|b| SyncHeader::from_rlp(Rlp::new(b).at(0).unwrap().as_raw().to_vec()).unwrap()).collect();
|
||||
let hashes: Vec<_> = headers.iter().map(|h| h.header.hash()).collect();
|
||||
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(*h) } else { None }).collect();
|
||||
bc.reset_to(heads);
|
||||
assert!(!bc.is_empty());
|
||||
assert_eq!(hashes[0], bc.heads[0]);
|
||||
@ -631,7 +631,7 @@ mod test {
|
||||
assert_eq!(bc.downloading_headers.len(), 1);
|
||||
assert!(bc.drain().is_empty());
|
||||
|
||||
bc.insert_headers(headers[0..6].iter().map(|h| SyncHeader::from_rlp(h.to_vec()).unwrap()).collect());
|
||||
bc.insert_headers(headers[0..6].into_iter().map(Clone::clone).collect());
|
||||
assert_eq!(hashes[5], bc.heads[0]);
|
||||
for h in &hashes[0..6] {
|
||||
bc.clear_header_download(h)
|
||||
@ -651,9 +651,9 @@ mod test {
|
||||
assert_eq!(hashes[5], h);
|
||||
let (h, _) = bc.needed_headers(6, false).unwrap();
|
||||
assert_eq!(hashes[20], h);
|
||||
bc.insert_headers(headers[10..16].iter().map(|h| SyncHeader::from_rlp(h.to_vec()).unwrap()).collect());
|
||||
bc.insert_headers(headers[10..16].into_iter().map(Clone::clone).collect());
|
||||
assert!(bc.drain().is_empty());
|
||||
bc.insert_headers(headers[5..10].iter().map(|h| SyncHeader::from_rlp(h.to_vec()).unwrap()).collect());
|
||||
bc.insert_headers(headers[5..10].into_iter().map(Clone::clone).collect());
|
||||
assert_eq!(
|
||||
bc.drain().into_iter().map(|b| b.block).collect::<Vec<_>>(),
|
||||
blocks[6..16].iter().map(|b| Unverified::from_rlp(b.to_vec()).unwrap()).collect::<Vec<_>>()
|
||||
@ -661,7 +661,7 @@ mod test {
|
||||
|
||||
assert_eq!(hashes[15], bc.heads[0]);
|
||||
|
||||
bc.insert_headers(headers[15..].iter().map(|h| SyncHeader::from_rlp(h.to_vec()).unwrap()).collect());
|
||||
bc.insert_headers(headers[15..].into_iter().map(Clone::clone).collect());
|
||||
bc.drain();
|
||||
assert!(bc.is_empty());
|
||||
}
|
||||
@ -676,16 +676,16 @@ mod test {
|
||||
let blocks: Vec<_> = (0..nblocks)
|
||||
.map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).unwrap().into_inner())
|
||||
.collect();
|
||||
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).unwrap().as_raw().to_vec()).collect();
|
||||
let hashes: Vec<_> = headers.iter().map(|h| view!(HeaderView, h).hash()).collect();
|
||||
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
|
||||
let headers: Vec<_> = blocks.iter().map(|b| SyncHeader::from_rlp(Rlp::new(b).at(0).unwrap().as_raw().to_vec()).unwrap()).collect();
|
||||
let hashes: Vec<_> = headers.iter().map(|h| h.header.hash()).collect();
|
||||
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(*h) } else { None }).collect();
|
||||
bc.reset_to(heads);
|
||||
|
||||
bc.insert_headers(headers[2..22].iter().map(|h| SyncHeader::from_rlp(h.to_vec()).unwrap()).collect());
|
||||
bc.insert_headers(headers[2..22].into_iter().map(Clone::clone).collect());
|
||||
assert_eq!(hashes[0], bc.heads[0]);
|
||||
assert_eq!(hashes[21], bc.heads[1]);
|
||||
assert!(bc.head.is_none());
|
||||
bc.insert_headers(headers[0..2].iter().map(|h| SyncHeader::from_rlp(h.to_vec()).unwrap()).collect());
|
||||
bc.insert_headers(headers[0..2].into_iter().map(Clone::clone).collect());
|
||||
assert!(bc.head.is_some());
|
||||
assert_eq!(hashes[21], bc.heads[0]);
|
||||
}
|
||||
@ -700,14 +700,14 @@ mod test {
|
||||
let blocks: Vec<_> = (0..nblocks)
|
||||
.map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).unwrap().into_inner())
|
||||
.collect();
|
||||
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).unwrap().as_raw().to_vec()).collect();
|
||||
let hashes: Vec<_> = headers.iter().map(|h| view!(HeaderView, h).hash()).collect();
|
||||
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
|
||||
let headers: Vec<_> = blocks.iter().map(|b| SyncHeader::from_rlp(Rlp::new(b).at(0).unwrap().as_raw().to_vec()).unwrap()).collect();
|
||||
let hashes: Vec<_> = headers.iter().map(|h| h.header.hash()).collect();
|
||||
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(*h) } else { None }).collect();
|
||||
bc.reset_to(heads);
|
||||
|
||||
bc.insert_headers(headers[1..2].iter().map(|h| SyncHeader::from_rlp(h.to_vec()).unwrap()).collect());
|
||||
bc.insert_headers(headers[1..2].into_iter().map(Clone::clone).collect());
|
||||
assert!(bc.drain().is_empty());
|
||||
bc.insert_headers(headers[0..1].iter().map(|h| SyncHeader::from_rlp(h.to_vec()).unwrap()).collect());
|
||||
bc.insert_headers(headers[0..1].into_iter().map(Clone::clone).collect());
|
||||
assert_eq!(bc.drain().len(), 2);
|
||||
}
|
||||
}
|
||||
|
@ -307,11 +307,11 @@ mod test {
|
||||
use bytes::Bytes;
|
||||
use rlp::{Rlp, RlpStream};
|
||||
use super::{*, super::tests::*};
|
||||
use blocks::SyncHeader;
|
||||
use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient};
|
||||
|
||||
#[test]
|
||||
fn return_block_headers() {
|
||||
use ethcore::views::HeaderView;
|
||||
fn make_hash_req(h: &H256, count: usize, skip: usize, reverse: bool) -> Bytes {
|
||||
let mut rlp = RlpStream::new_list(4);
|
||||
rlp.append(h);
|
||||
@ -329,16 +329,16 @@ mod test {
|
||||
rlp.append(&if reverse {1u32} else {0u32});
|
||||
rlp.out()
|
||||
}
|
||||
fn to_header_vec(rlp: ::chain::RlpResponseResult) -> Vec<Bytes> {
|
||||
Rlp::new(&rlp.unwrap().unwrap().1.out()).iter().map(|r| r.as_raw().to_vec()).collect()
|
||||
fn to_header_vec(rlp: ::chain::RlpResponseResult) -> Vec<SyncHeader> {
|
||||
Rlp::new(&rlp.unwrap().unwrap().1.out()).iter().map(|r| SyncHeader::from_rlp(r.as_raw().to_vec()).unwrap()).collect()
|
||||
}
|
||||
|
||||
let mut client = TestBlockChainClient::new();
|
||||
client.add_blocks(100, EachBlockWith::Nothing);
|
||||
let blocks: Vec<_> = (0 .. 100)
|
||||
.map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).map(|b| b.into_inner()).unwrap()).collect();
|
||||
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).unwrap().as_raw().to_vec()).collect();
|
||||
let hashes: Vec<_> = headers.iter().map(|h| view!(HeaderView, h).hash()).collect();
|
||||
let headers: Vec<_> = blocks.iter().map(|b| SyncHeader::from_rlp(Rlp::new(b).at(0).unwrap().as_raw().to_vec()).unwrap()).collect();
|
||||
let hashes: Vec<_> = headers.iter().map(|h| h.header.hash()).collect();
|
||||
|
||||
let queue = RwLock::new(VecDeque::new());
|
||||
let ss = TestSnapshotService::new();
|
||||
|
@ -27,7 +27,6 @@ extern crate ethcore_network_devp2p as devp2p;
|
||||
extern crate parity_bytes as bytes;
|
||||
extern crate ethcore_io as io;
|
||||
extern crate ethcore_transaction as transaction;
|
||||
#[cfg_attr(test, macro_use)]
|
||||
extern crate ethcore;
|
||||
extern crate ethereum_types;
|
||||
extern crate env_logger;
|
||||
|
Loading…
Reference in New Issue
Block a user