rlp deserialization refactor, 30% faster (#4901)
* fixed naming of rlp modules * RlpStream cleanup * appending short rlp lists (0...55 bytes) is 25% faster * RlpStream does not use bytes module, nor trait Stream * removed unused code from rlp module * compiling ethcore-util with new rlp serialization * compiling parity with new rlp serialization * fixed compiling ethcore-light with new rlp serialization * fixed compiling ethsync with new rlp serialization * moved rlp benches and rlp tests * rlp deserialization refactor, 30% faster * removed redundant comment, print * fixed compiling parity with new rlp deserialization * removed redundant double-space * fixed failing test * updated rlp docs, removed unused traits * fixed rlp benchmarks * replace usage of WriteBytesExt with ByteOrder * removed unused, commented out code * fixed merge conflict
This commit is contained in:
@@ -20,7 +20,7 @@ use std::cmp;
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, Decoder, DecoderError, View};
|
||||
use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, DecoderError};
|
||||
use util::{Bytes, Address, Uint, Hashable, U256, H256, ordered_trie_root, SHA3_NULL_RLP};
|
||||
use util::error::{Mismatch, OutOfBounds};
|
||||
|
||||
@@ -67,18 +67,17 @@ impl Block {
|
||||
|
||||
|
||||
impl Decodable for Block {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
if decoder.as_raw().len() != decoder.as_rlp().payload_info()?.total() {
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
if rlp.as_raw().len() != rlp.payload_info()?.total() {
|
||||
return Err(DecoderError::RlpIsTooBig);
|
||||
}
|
||||
let d = decoder.as_rlp();
|
||||
if d.item_count() != 3 {
|
||||
if rlp.item_count()? != 3 {
|
||||
return Err(DecoderError::RlpIncorrectListLen);
|
||||
}
|
||||
Ok(Block {
|
||||
header: d.val_at(0)?,
|
||||
transactions: d.val_at(1)?,
|
||||
uncles: d.val_at(2)?,
|
||||
header: rlp.val_at(0)?,
|
||||
transactions: rlp.list_at(1)?,
|
||||
uncles: rlp.list_at(2)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,13 +154,12 @@ impl HeapSizeOf for BlockDetails {
|
||||
}
|
||||
|
||||
impl Decodable for BlockDetails {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let details = BlockDetails {
|
||||
number: d.val_at(0)?,
|
||||
total_difficulty: d.val_at(1)?,
|
||||
parent: d.val_at(2)?,
|
||||
children: d.val_at(3)?,
|
||||
number: rlp.val_at(0)?,
|
||||
total_difficulty: rlp.val_at(1)?,
|
||||
parent: rlp.val_at(2)?,
|
||||
children: rlp.list_at(3)?,
|
||||
};
|
||||
Ok(details)
|
||||
}
|
||||
@@ -190,11 +189,10 @@ impl HeapSizeOf for TransactionAddress {
|
||||
}
|
||||
|
||||
impl Decodable for TransactionAddress {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let tx_address = TransactionAddress {
|
||||
block_hash: d.val_at(0)?,
|
||||
index: d.val_at(1)?,
|
||||
block_hash: rlp.val_at(0)?,
|
||||
index: rlp.val_at(1)?,
|
||||
};
|
||||
|
||||
Ok(tx_address)
|
||||
@@ -224,9 +222,9 @@ impl BlockReceipts {
|
||||
}
|
||||
|
||||
impl Decodable for BlockReceipts {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
Ok(BlockReceipts {
|
||||
receipts: Decodable::decode(decoder)?
|
||||
receipts: rlp.as_list()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ impl Into<bc::Bloom> for Bloom {
|
||||
}
|
||||
|
||||
impl Decodable for Bloom {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
Decodable::decode(decoder).map(Bloom)
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
LogBloom::decode(rlp).map(Bloom)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ impl Into<bc::BloomGroup> for BloomGroup {
|
||||
}
|
||||
|
||||
impl Decodable for BloomGroup {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let blooms = Decodable::decode(decoder)?;
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let blooms = rlp.as_list()?;
|
||||
let group = BloomGroup {
|
||||
blooms: blooms
|
||||
};
|
||||
|
||||
@@ -66,7 +66,7 @@ use evm::{Factory as EvmFactory, Schedule};
|
||||
use miner::{Miner, MinerService, TransactionImportResult};
|
||||
use snapshot::{self, io as snapshot_io};
|
||||
use factory::Factories;
|
||||
use rlp::{View, UntrustedRlp};
|
||||
use rlp::UntrustedRlp;
|
||||
use state_db::StateDB;
|
||||
use rand::OsRng;
|
||||
use client::registry::Registry;
|
||||
@@ -539,7 +539,7 @@ impl Client {
|
||||
)?;
|
||||
|
||||
// Commit results
|
||||
let receipts = ::rlp::decode(&receipts_bytes);
|
||||
let receipts = ::rlp::decode_list(&receipts_bytes);
|
||||
let mut batch = DBTransaction::new();
|
||||
chain.insert_unordered_block(&mut batch, &block_bytes, receipts, None, false, true);
|
||||
// Final commit to the DB
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::sync::Weak;
|
||||
use std::time::{UNIX_EPOCH, Duration};
|
||||
use util::*;
|
||||
use ethkey::{verify_address, Signature};
|
||||
use rlp::{UntrustedRlp, View, encode};
|
||||
use rlp::{UntrustedRlp, encode};
|
||||
use account_provider::AccountProvider;
|
||||
use block::*;
|
||||
use spec::CommonParams;
|
||||
|
||||
@@ -138,7 +138,7 @@ impl Engine for BasicAuthority {
|
||||
}
|
||||
|
||||
fn verify_block_family(&self, header: &Header, parent: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
|
||||
use rlp::{UntrustedRlp, View};
|
||||
use rlp::UntrustedRlp;
|
||||
// Check if the signature belongs to a validator, can depend on parent state.
|
||||
let sig = UntrustedRlp::new(&header.seal()[0]).as_val::<H520>()?;
|
||||
let signer = public_to_address(&recover(&sig.into(), &header.bare_hash())?);
|
||||
|
||||
@@ -20,7 +20,7 @@ use util::*;
|
||||
use super::{Height, View, BlockHash, Step};
|
||||
use error::Error;
|
||||
use header::Header;
|
||||
use rlp::{Rlp, UntrustedRlp, RlpStream, Encodable, Decodable, Decoder, DecoderError, View as RlpView};
|
||||
use rlp::{Rlp, UntrustedRlp, RlpStream, Encodable, Decodable, DecoderError};
|
||||
use ethkey::{recover, public_to_address};
|
||||
use super::super::vote_collector::Message;
|
||||
|
||||
@@ -150,8 +150,8 @@ impl Step {
|
||||
}
|
||||
|
||||
impl Decodable for Step {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
match decoder.as_rlp().as_val()? {
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
match rlp.as_val()? {
|
||||
0u8 => Ok(Step::Propose),
|
||||
1 => Ok(Step::Prevote),
|
||||
2 => Ok(Step::Precommit),
|
||||
@@ -168,8 +168,7 @@ impl Encodable for Step {
|
||||
|
||||
/// (signature, (height, view, step, block_hash))
|
||||
impl Decodable for ConsensusMessage {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let rlp = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let m = rlp.at(1)?;
|
||||
let block_message: H256 = m.val_at(3)?;
|
||||
Ok(ConsensusMessage {
|
||||
|
||||
@@ -33,7 +33,7 @@ use error::{Error, BlockError};
|
||||
use header::Header;
|
||||
use builtin::Builtin;
|
||||
use env_info::EnvInfo;
|
||||
use rlp::{UntrustedRlp, View as RlpView};
|
||||
use rlp::UntrustedRlp;
|
||||
use ethkey::{recover, public_to_address, Signature};
|
||||
use account_provider::AccountProvider;
|
||||
use block::*;
|
||||
|
||||
@@ -27,7 +27,7 @@ use transaction::UnverifiedTransaction;
|
||||
use engines::Engine;
|
||||
use evm::Schedule;
|
||||
use ethjson;
|
||||
use rlp::{self, UntrustedRlp, View};
|
||||
use rlp::{self, UntrustedRlp};
|
||||
|
||||
/// Parity tries to round block.gas_limit to multiple of this constant
|
||||
pub const PARITY_GAS_LIMIT_DETERMINANT: U256 = U256([37, 0, 0, 0]);
|
||||
|
||||
@@ -261,9 +261,7 @@ impl Header {
|
||||
}
|
||||
|
||||
impl Decodable for Header {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let r = decoder.as_rlp();
|
||||
|
||||
fn decode(r: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let mut blockheader = Header {
|
||||
parent_hash: r.val_at(0)?,
|
||||
uncles_hash: r.val_at(1)?,
|
||||
@@ -283,7 +281,7 @@ impl Decodable for Header {
|
||||
bare_hash: RefCell::new(None),
|
||||
};
|
||||
|
||||
for i in 13..r.item_count() {
|
||||
for i in 13..r.item_count()? {
|
||||
blockheader.seal.push(r.at(i)?.as_raw().to_vec())
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
use super::test_common::*;
|
||||
use evm;
|
||||
use ethjson;
|
||||
use rlp::{UntrustedRlp, View};
|
||||
use rlp::UntrustedRlp;
|
||||
use transaction::{Action, UnverifiedTransaction};
|
||||
use ethstore::ethkey::public_to_address;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! This migration compresses the state db.
|
||||
|
||||
use util::migration::{SimpleMigration, Progress};
|
||||
use rlp::{Compressible, UntrustedRlp, View, RlpType};
|
||||
use rlp::{Compressible, UntrustedRlp, RlpType};
|
||||
|
||||
/// Compressing migration.
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -26,8 +26,7 @@ use util::migration::{Batch, Config, Error, Migration, SimpleMigration, Progress
|
||||
use util::sha3::Hashable;
|
||||
use std::sync::Arc;
|
||||
|
||||
use rlp::{decode, Rlp, RlpStream, View};
|
||||
|
||||
use rlp::{decode, Rlp, RlpStream};
|
||||
|
||||
// attempt to migrate a key, value pair. None if migration not possible.
|
||||
fn attempt_migrate(mut key_h: H256, val: &[u8]) -> Option<H256> {
|
||||
@@ -184,7 +183,7 @@ impl OverlayRecentV7 {
|
||||
}
|
||||
|
||||
// migrate all deleted keys.
|
||||
let mut deleted_keys: Vec<H256> = rlp.val_at(2);
|
||||
let mut deleted_keys: Vec<H256> = rlp.list_at(2);
|
||||
for old_key in &mut deleted_keys {
|
||||
if let Some(new) = self.migrated_keys.get(&*old_key) {
|
||||
*old_key = new.clone();
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
//! This migration consolidates all databases into single one using Column Families.
|
||||
|
||||
use rlp::{Rlp, RlpStream, View};
|
||||
use rlp::{Rlp, RlpStream};
|
||||
use util::kvdb::Database;
|
||||
use util::migration::{Batch, Config, Error, Migration, Progress};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -22,7 +22,7 @@ use snapshot::Error;
|
||||
|
||||
use util::{U256, H256, Bytes, HashDB, SHA3_EMPTY, SHA3_NULL_RLP};
|
||||
use util::trie::{TrieDB, Trie};
|
||||
use rlp::{RlpStream, UntrustedRlp, View};
|
||||
use rlp::{RlpStream, UntrustedRlp};
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
@@ -180,7 +180,7 @@ mod tests {
|
||||
|
||||
use util::sha3::{SHA3_EMPTY, SHA3_NULL_RLP};
|
||||
use util::{Address, H256, HashDB, DBValue};
|
||||
use rlp::{UntrustedRlp, View};
|
||||
use rlp::UntrustedRlp;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ use block::Block;
|
||||
use header::Header;
|
||||
|
||||
use views::BlockView;
|
||||
use rlp::{DecoderError, RlpStream, UntrustedRlp, View};
|
||||
use rlp::{DecoderError, RlpStream, UntrustedRlp};
|
||||
use util::{Bytes, Hashable, H256};
|
||||
use util::triehash::ordered_trie_root;
|
||||
|
||||
@@ -101,8 +101,8 @@ impl AbridgedBlock {
|
||||
header.set_timestamp(rlp.val_at(6)?);
|
||||
header.set_extra_data(rlp.val_at(7)?);
|
||||
|
||||
let transactions = rlp.val_at(8)?;
|
||||
let uncles: Vec<Header> = rlp.val_at(9)?;
|
||||
let transactions = rlp.list_at(8)?;
|
||||
let uncles: Vec<Header> = rlp.list_at(9)?;
|
||||
|
||||
header.set_transactions_root(ordered_trie_root(
|
||||
rlp.at(8)?.iter().map(|r| r.as_raw().to_owned())
|
||||
@@ -114,7 +114,7 @@ impl AbridgedBlock {
|
||||
header.set_uncles_hash(uncles_rlp.as_raw().sha3());
|
||||
|
||||
let mut seal_fields = Vec::new();
|
||||
for i in (HEADER_FIELDS + BLOCK_FIELDS)..rlp.item_count() {
|
||||
for i in (HEADER_FIELDS + BLOCK_FIELDS)..rlp.item_count()? {
|
||||
let seal_rlp = rlp.at(i)?;
|
||||
seal_fields.push(seal_rlp.as_raw().to_owned());
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
use util::Bytes;
|
||||
use util::hash::H256;
|
||||
use rlp::{self, Encodable, RlpStream, UntrustedRlp, View};
|
||||
use rlp::{self, Encodable, RlpStream, UntrustedRlp};
|
||||
|
||||
use super::ManifestData;
|
||||
|
||||
@@ -57,12 +57,10 @@ impl Encodable for ChunkInfo {
|
||||
}
|
||||
|
||||
impl rlp::Decodable for ChunkInfo {
|
||||
fn decode<D: rlp::Decoder>(decoder: &D) -> Result<Self, rlp::DecoderError> {
|
||||
let d = decoder.as_rlp();
|
||||
|
||||
let hash = d.val_at(0)?;
|
||||
let len = d.val_at(1)?;
|
||||
let off = d.val_at(2)?;
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, rlp::DecoderError> {
|
||||
let hash = rlp.val_at(0)?;
|
||||
let len = rlp.val_at(1)?;
|
||||
let off = rlp.val_at(2)?;
|
||||
Ok(ChunkInfo(hash, len, off))
|
||||
}
|
||||
}
|
||||
@@ -257,8 +255,8 @@ impl PackedReader {
|
||||
|
||||
let rlp = UntrustedRlp::new(&manifest_buf);
|
||||
|
||||
let state: Vec<ChunkInfo> = rlp.val_at(0)?;
|
||||
let blocks: Vec<ChunkInfo> = rlp.val_at(1)?;
|
||||
let state: Vec<ChunkInfo> = rlp.list_at(0)?;
|
||||
let blocks: Vec<ChunkInfo> = rlp.list_at(1)?;
|
||||
|
||||
let manifest = ManifestData {
|
||||
state_hashes: state.iter().map(|c| c.0).collect(),
|
||||
|
||||
@@ -37,7 +37,7 @@ use util::journaldb::{self, Algorithm, JournalDB};
|
||||
use util::kvdb::Database;
|
||||
use util::trie::{TrieDB, TrieDBMut, Trie, TrieMut};
|
||||
use util::sha3::SHA3_NULL_RLP;
|
||||
use rlp::{RlpStream, UntrustedRlp, View};
|
||||
use rlp::{RlpStream, UntrustedRlp};
|
||||
use bloom_journal::Bloom;
|
||||
|
||||
use self::block::AbridgedBlock;
|
||||
@@ -408,10 +408,10 @@ impl StateRebuilder {
|
||||
pub fn feed(&mut self, chunk: &[u8], flag: &AtomicBool) -> Result<(), ::error::Error> {
|
||||
let rlp = UntrustedRlp::new(chunk);
|
||||
let empty_rlp = StateAccount::new_basic(U256::zero(), U256::zero()).rlp();
|
||||
let mut pairs = Vec::with_capacity(rlp.item_count());
|
||||
let mut pairs = Vec::with_capacity(rlp.item_count()?);
|
||||
|
||||
// initialize the pairs vector with empty values so we have slots to write into.
|
||||
pairs.resize(rlp.item_count(), (H256::new(), Vec::new()));
|
||||
pairs.resize(rlp.item_count()?, (H256::new(), Vec::new()));
|
||||
|
||||
let status = rebuild_accounts(
|
||||
self.db.as_hashdb_mut(),
|
||||
@@ -601,7 +601,7 @@ impl BlockRebuilder {
|
||||
use util::triehash::ordered_trie_root;
|
||||
|
||||
let rlp = UntrustedRlp::new(chunk);
|
||||
let item_count = rlp.item_count();
|
||||
let item_count = rlp.item_count()?;
|
||||
let num_blocks = (item_count - 3) as u64;
|
||||
|
||||
trace!(target: "snapshot", "restoring block chunk with {} blocks.", item_count - 3);
|
||||
@@ -621,7 +621,7 @@ impl BlockRebuilder {
|
||||
let pair = rlp.at(idx)?;
|
||||
let abridged_rlp = pair.at(0)?.as_raw().to_owned();
|
||||
let abridged_block = AbridgedBlock::from_raw(abridged_rlp);
|
||||
let receipts: Vec<::receipt::Receipt> = pair.val_at(1)?;
|
||||
let receipts: Vec<::receipt::Receipt> = pair.list_at(1)?;
|
||||
let receipts_root = ordered_trie_root(
|
||||
pair.at(1)?.iter().map(|r| r.as_raw().to_owned())
|
||||
);
|
||||
|
||||
@@ -34,7 +34,7 @@ use super::genesis::Genesis;
|
||||
use super::seal::Generic as GenericSeal;
|
||||
use ethereum;
|
||||
use ethjson;
|
||||
use rlp::{Rlp, RlpStream, View};
|
||||
use rlp::{Rlp, RlpStream};
|
||||
|
||||
/// Parameters common to all engines.
|
||||
#[derive(Debug, PartialEq, Clone, Default)]
|
||||
|
||||
@@ -461,7 +461,7 @@ impl fmt::Debug for Account {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use rlp::{UntrustedRlp, RlpType, View, Compressible};
|
||||
use rlp::{UntrustedRlp, RlpType, Compressible};
|
||||
use util::*;
|
||||
use super::*;
|
||||
use account_db::*;
|
||||
|
||||
@@ -25,7 +25,6 @@ use types::filter::Filter;
|
||||
use util::*;
|
||||
use devtools::*;
|
||||
use miner::Miner;
|
||||
use rlp::View;
|
||||
use spec::Spec;
|
||||
use views::BlockView;
|
||||
use ethkey::{KeyPair, Secret};
|
||||
|
||||
@@ -60,8 +60,8 @@ impl Into<BloomGroup> for BlockTracesBloomGroup {
|
||||
}
|
||||
|
||||
impl Decodable for BlockTracesBloom {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
Decodable::decode(decoder).map(BlockTracesBloom)
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
LogBloom::decode(rlp).map(BlockTracesBloom)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ impl Encodable for BlockTracesBloom {
|
||||
}
|
||||
|
||||
impl Decodable for BlockTracesBloomGroup {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let blooms = Decodable::decode(decoder)?;
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let blooms = rlp.as_list()?;
|
||||
let group = BlockTracesBloomGroup {
|
||||
blooms: blooms
|
||||
};
|
||||
|
||||
@@ -43,8 +43,7 @@ impl Encodable for BasicAccount {
|
||||
}
|
||||
|
||||
impl Decodable for BasicAccount {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let rlp = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
Ok(BasicAccount {
|
||||
nonce: rlp.val_at(0)?,
|
||||
balance: rlp.val_at(1)?,
|
||||
|
||||
@@ -29,7 +29,7 @@ use transaction::UnverifiedTransaction;
|
||||
use views;
|
||||
|
||||
use util::{Address, Hashable, H256, H2048, U256, HeapSizeOf};
|
||||
use rlp::{Rlp, View};
|
||||
use rlp::Rlp;
|
||||
|
||||
/// Owning header view.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
||||
@@ -51,8 +51,8 @@ impl Encodable for CallType {
|
||||
}
|
||||
|
||||
impl Decodable for CallType {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
decoder.as_rlp().as_val().and_then(|v| Ok(match v {
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
rlp.as_val().and_then(|v| Ok(match v {
|
||||
0u32 => CallType::None,
|
||||
1 => CallType::Call,
|
||||
2 => CallType::CallCode,
|
||||
|
||||
@@ -47,12 +47,11 @@ impl Encodable for LogEntry {
|
||||
}
|
||||
|
||||
impl Decodable for LogEntry {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let entry = LogEntry {
|
||||
address: d.val_at(0)?,
|
||||
topics: d.val_at(1)?,
|
||||
data: d.val_at(2)?,
|
||||
address: rlp.val_at(0)?,
|
||||
topics: rlp.list_at(1)?,
|
||||
data: rlp.val_at(2)?,
|
||||
};
|
||||
Ok(entry)
|
||||
}
|
||||
|
||||
@@ -65,21 +65,20 @@ impl Encodable for Receipt {
|
||||
}
|
||||
|
||||
impl Decodable for Receipt {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
if d.item_count() == 3 {
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
if rlp.item_count()? == 3 {
|
||||
Ok(Receipt {
|
||||
state_root: None,
|
||||
gas_used: d.val_at(0)?,
|
||||
log_bloom: d.val_at(1)?,
|
||||
logs: d.val_at(2)?,
|
||||
gas_used: rlp.val_at(0)?,
|
||||
log_bloom: rlp.val_at(1)?,
|
||||
logs: rlp.list_at(2)?,
|
||||
})
|
||||
} else {
|
||||
Ok(Receipt {
|
||||
state_root: Some(d.val_at(0)?),
|
||||
gas_used: d.val_at(1)?,
|
||||
log_bloom: d.val_at(2)?,
|
||||
logs: d.val_at(3)?,
|
||||
state_root: Some(rlp.val_at(0)?),
|
||||
gas_used: rlp.val_at(1)?,
|
||||
log_bloom: rlp.val_at(2)?,
|
||||
logs: rlp.list_at(3)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ impl ManifestData {
|
||||
pub fn from_rlp(raw: &[u8]) -> Result<Self, DecoderError> {
|
||||
let decoder = UntrustedRlp::new(raw);
|
||||
|
||||
let state_hashes: Vec<H256> = decoder.val_at(0)?;
|
||||
let block_hashes: Vec<H256> = decoder.val_at(1)?;
|
||||
let state_hashes: Vec<H256> = decoder.list_at(0)?;
|
||||
let block_hashes: Vec<H256> = decoder.list_at(1)?;
|
||||
let state_root: H256 = decoder.val_at(2)?;
|
||||
let block_number: u64 = decoder.val_at(3)?;
|
||||
let block_hash: H256 = decoder.val_at(4)?;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Trace errors.
|
||||
|
||||
use std::fmt;
|
||||
use rlp::{Encodable, RlpStream, Decodable, Decoder, DecoderError, View};
|
||||
use rlp::{Encodable, RlpStream, Decodable, DecoderError, UntrustedRlp};
|
||||
use evm::Error as EvmError;
|
||||
|
||||
/// Trace evm errors.
|
||||
@@ -91,9 +91,9 @@ impl Encodable for Error {
|
||||
}
|
||||
|
||||
impl Decodable for Error {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
use self::Error::*;
|
||||
let value: u8 = decoder.as_rlp().as_val()?;
|
||||
let value: u8 = rlp.as_val()?;
|
||||
match value {
|
||||
0 => Ok(OutOfGas),
|
||||
1 => Ok(BadJumpDestination),
|
||||
|
||||
@@ -64,9 +64,8 @@ impl Encodable for FlatTrace {
|
||||
}
|
||||
|
||||
impl Decodable for FlatTrace {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
let v: Vec<usize> = d.val_at(3)?;
|
||||
fn decode(d: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let v: Vec<usize> = d.list_at(3)?;
|
||||
let res = FlatTrace {
|
||||
action: d.val_at(0)?,
|
||||
result: d.val_at(1)?,
|
||||
@@ -108,8 +107,8 @@ impl Encodable for FlatTransactionTraces {
|
||||
}
|
||||
|
||||
impl Decodable for FlatTransactionTraces {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
Ok(FlatTransactionTraces(Decodable::decode(decoder)?))
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
Ok(FlatTransactionTraces(rlp.as_list()?))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,8 +148,8 @@ impl Encodable for FlatBlockTraces {
|
||||
}
|
||||
|
||||
impl Decodable for FlatBlockTraces {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
Ok(FlatBlockTraces(Decodable::decode(decoder)?))
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
Ok(FlatBlockTraces(rlp.as_list()?))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,11 +45,10 @@ impl Encodable for CallResult {
|
||||
}
|
||||
|
||||
impl Decodable for CallResult {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let res = CallResult {
|
||||
gas_used: d.val_at(0)?,
|
||||
output: d.val_at(1)?,
|
||||
gas_used: rlp.val_at(0)?,
|
||||
output: rlp.val_at(1)?,
|
||||
};
|
||||
|
||||
Ok(res)
|
||||
@@ -78,12 +77,11 @@ impl Encodable for CreateResult {
|
||||
}
|
||||
|
||||
impl Decodable for CreateResult {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let res = CreateResult {
|
||||
gas_used: d.val_at(0)?,
|
||||
code: d.val_at(1)?,
|
||||
address: d.val_at(2)?,
|
||||
gas_used: rlp.val_at(0)?,
|
||||
code: rlp.val_at(1)?,
|
||||
address: rlp.val_at(2)?,
|
||||
};
|
||||
|
||||
Ok(res)
|
||||
@@ -141,15 +139,14 @@ impl Encodable for Call {
|
||||
}
|
||||
|
||||
impl Decodable for Call {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let res = Call {
|
||||
from: d.val_at(0)?,
|
||||
to: d.val_at(1)?,
|
||||
value: d.val_at(2)?,
|
||||
gas: d.val_at(3)?,
|
||||
input: d.val_at(4)?,
|
||||
call_type: d.val_at(5)?,
|
||||
from: rlp.val_at(0)?,
|
||||
to: rlp.val_at(1)?,
|
||||
value: rlp.val_at(2)?,
|
||||
gas: rlp.val_at(3)?,
|
||||
input: rlp.val_at(4)?,
|
||||
call_type: rlp.val_at(5)?,
|
||||
};
|
||||
|
||||
Ok(res)
|
||||
@@ -201,13 +198,12 @@ impl Encodable for Create {
|
||||
}
|
||||
|
||||
impl Decodable for Create {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let res = Create {
|
||||
from: d.val_at(0)?,
|
||||
value: d.val_at(1)?,
|
||||
gas: d.val_at(2)?,
|
||||
init: d.val_at(3)?,
|
||||
from: rlp.val_at(0)?,
|
||||
value: rlp.val_at(1)?,
|
||||
gas: rlp.val_at(2)?,
|
||||
init: rlp.val_at(3)?,
|
||||
};
|
||||
|
||||
Ok(res)
|
||||
@@ -252,12 +248,11 @@ impl Encodable for Suicide {
|
||||
}
|
||||
|
||||
impl Decodable for Suicide {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let res = Suicide {
|
||||
address: d.val_at(0)?,
|
||||
refund_address: d.val_at(1)?,
|
||||
balance: d.val_at(2)?,
|
||||
address: rlp.val_at(0)?,
|
||||
refund_address: rlp.val_at(1)?,
|
||||
balance: rlp.val_at(2)?,
|
||||
};
|
||||
|
||||
Ok(res)
|
||||
@@ -298,13 +293,12 @@ impl Encodable for Action {
|
||||
}
|
||||
|
||||
impl Decodable for Action {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
let action_type: u8 = d.val_at(0)?;
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let action_type: u8 = rlp.val_at(0)?;
|
||||
match action_type {
|
||||
0 => d.val_at(1).map(Action::Call),
|
||||
1 => d.val_at(1).map(Action::Create),
|
||||
2 => d.val_at(1).map(Action::Suicide),
|
||||
0 => rlp.val_at(1).map(Action::Call),
|
||||
1 => rlp.val_at(1).map(Action::Create),
|
||||
2 => rlp.val_at(1).map(Action::Suicide),
|
||||
_ => Err(DecoderError::Custom("Invalid action type.")),
|
||||
}
|
||||
}
|
||||
@@ -369,14 +363,13 @@ impl Encodable for Res {
|
||||
}
|
||||
|
||||
impl Decodable for Res {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
let action_type: u8 = d.val_at(0)?;
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let action_type: u8 = rlp.val_at(0)?;
|
||||
match action_type {
|
||||
0 => d.val_at(1).map(Res::Call),
|
||||
1 => d.val_at(1).map(Res::Create),
|
||||
2 => d.val_at(1).map(Res::FailedCall),
|
||||
3 => d.val_at(1).map(Res::FailedCreate),
|
||||
0 => rlp.val_at(1).map(Res::Call),
|
||||
1 => rlp.val_at(1).map(Res::Create),
|
||||
2 => rlp.val_at(1).map(Res::FailedCall),
|
||||
3 => rlp.val_at(1).map(Res::FailedCreate),
|
||||
4 => Ok(Res::None),
|
||||
_ => Err(DecoderError::Custom("Invalid result type.")),
|
||||
}
|
||||
@@ -420,11 +413,10 @@ impl Encodable for MemoryDiff {
|
||||
}
|
||||
|
||||
impl Decodable for MemoryDiff {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
Ok(MemoryDiff {
|
||||
offset: d.val_at(0)?,
|
||||
data: d.val_at(1)?,
|
||||
offset: rlp.val_at(0)?,
|
||||
data: rlp.val_at(1)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -448,11 +440,10 @@ impl Encodable for StorageDiff {
|
||||
}
|
||||
|
||||
impl Decodable for StorageDiff {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
Ok(StorageDiff {
|
||||
location: d.val_at(0)?,
|
||||
value: d.val_at(1)?,
|
||||
location: rlp.val_at(0)?,
|
||||
value: rlp.val_at(1)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -482,13 +473,12 @@ impl Encodable for VMExecutedOperation {
|
||||
}
|
||||
|
||||
impl Decodable for VMExecutedOperation {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
Ok(VMExecutedOperation {
|
||||
gas_used: d.val_at(0)?,
|
||||
stack_push: d.val_at(1)?,
|
||||
mem_diff: d.val_at(2)?,
|
||||
store_diff: d.val_at(3)?,
|
||||
gas_used: rlp.val_at(0)?,
|
||||
stack_push: rlp.list_at(1)?,
|
||||
mem_diff: rlp.val_at(2)?,
|
||||
store_diff: rlp.val_at(3)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -518,13 +508,12 @@ impl Encodable for VMOperation {
|
||||
}
|
||||
|
||||
impl Decodable for VMOperation {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let res = VMOperation {
|
||||
pc: d.val_at(0)?,
|
||||
instruction: d.val_at(1)?,
|
||||
gas_cost: d.val_at(2)?,
|
||||
executed: d.val_at(3)?,
|
||||
pc: rlp.val_at(0)?,
|
||||
instruction: rlp.val_at(1)?,
|
||||
gas_cost: rlp.val_at(2)?,
|
||||
executed: rlp.val_at(3)?,
|
||||
};
|
||||
|
||||
Ok(res)
|
||||
@@ -557,13 +546,12 @@ impl Encodable for VMTrace {
|
||||
}
|
||||
|
||||
impl Decodable for VMTrace {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let res = VMTrace {
|
||||
parent_step: d.val_at(0)?,
|
||||
code: d.val_at(1)?,
|
||||
operations: d.val_at(2)?,
|
||||
subs: d.val_at(3)?,
|
||||
parent_step: rlp.val_at(0)?,
|
||||
code: rlp.val_at(1)?,
|
||||
operations: rlp.list_at(2)?,
|
||||
subs: rlp.list_at(3)?,
|
||||
};
|
||||
|
||||
Ok(res)
|
||||
|
||||
@@ -42,8 +42,7 @@ impl Default for Action {
|
||||
}
|
||||
|
||||
impl Decodable for Action {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let rlp = decoder.as_rlp();
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
if rlp.is_empty() {
|
||||
Ok(Action::Create)
|
||||
} else {
|
||||
@@ -243,12 +242,11 @@ impl Deref for UnverifiedTransaction {
|
||||
}
|
||||
|
||||
impl Decodable for UnverifiedTransaction {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
if d.item_count() != 9 {
|
||||
fn decode(d: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
if d.item_count()? != 9 {
|
||||
return Err(DecoderError::RlpIncorrectListLen);
|
||||
}
|
||||
let hash = decoder.as_raw().sha3();
|
||||
let hash = d.as_raw().sha3();
|
||||
Ok(UnverifiedTransaction {
|
||||
unsigned: Transaction {
|
||||
nonce: d.val_at(0)?,
|
||||
|
||||
@@ -26,7 +26,7 @@ use engines::Engine;
|
||||
use error::{BlockError, Error};
|
||||
use blockchain::*;
|
||||
use header::{BlockNumber, Header};
|
||||
use rlp::{UntrustedRlp, View};
|
||||
use rlp::UntrustedRlp;
|
||||
use transaction::SignedTransaction;
|
||||
use views::BlockView;
|
||||
use time::get_time;
|
||||
@@ -101,7 +101,7 @@ pub fn verify_block_family(header: &Header, bytes: &[u8], engine: &Engine, bc: &
|
||||
verify_parent(&header, &parent)?;
|
||||
engine.verify_block_family(&header, &parent, Some(bytes))?;
|
||||
|
||||
let num_uncles = UntrustedRlp::new(bytes).at(2)?.item_count();
|
||||
let num_uncles = UntrustedRlp::new(bytes).at(2)?.item_count()?;
|
||||
if num_uncles != 0 {
|
||||
if num_uncles > engine.maximum_uncle_count() {
|
||||
return Err(From::from(BlockError::TooManyUncles(OutOfBounds { min: None, max: Some(engine.maximum_uncle_count()), found: num_uncles })));
|
||||
@@ -264,7 +264,6 @@ mod tests {
|
||||
use transaction::*;
|
||||
use tests::helpers::*;
|
||||
use types::log_entry::{LogEntry, LocalizedLogEntry};
|
||||
use rlp::View;
|
||||
use time::get_time;
|
||||
use encoded;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ use util::*;
|
||||
use header::*;
|
||||
use transaction::*;
|
||||
use super::{TransactionView, HeaderView};
|
||||
use rlp::{Rlp, View};
|
||||
use rlp::Rlp;
|
||||
|
||||
/// View onto block rlp.
|
||||
pub struct BlockView<'a> {
|
||||
@@ -69,7 +69,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Return List of transactions in given block.
|
||||
pub fn transactions(&self) -> Vec<UnverifiedTransaction> {
|
||||
self.rlp.val_at(1)
|
||||
self.rlp.list_at(1)
|
||||
}
|
||||
|
||||
/// Return List of transactions with additional localization info.
|
||||
@@ -125,7 +125,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Return list of uncles of given block.
|
||||
pub fn uncles(&self) -> Vec<Header> {
|
||||
self.rlp.val_at(2)
|
||||
self.rlp.list_at(2)
|
||||
}
|
||||
|
||||
/// Return number of uncles in given block, without deserializing them.
|
||||
|
||||
@@ -20,7 +20,7 @@ use util::*;
|
||||
use header::*;
|
||||
use transaction::*;
|
||||
use super::{TransactionView, HeaderView};
|
||||
use rlp::{Rlp, View};
|
||||
use rlp::Rlp;
|
||||
|
||||
/// View onto block rlp.
|
||||
pub struct BodyView<'a> {
|
||||
@@ -49,7 +49,7 @@ impl<'a> BodyView<'a> {
|
||||
|
||||
/// Return List of transactions in given block.
|
||||
pub fn transactions(&self) -> Vec<UnverifiedTransaction> {
|
||||
self.rlp.val_at(0)
|
||||
self.rlp.list_at(0)
|
||||
}
|
||||
|
||||
/// Return List of transactions with additional localization info.
|
||||
@@ -99,7 +99,7 @@ impl<'a> BodyView<'a> {
|
||||
|
||||
/// Return list of uncles of given block.
|
||||
pub fn uncles(&self) -> Vec<Header> {
|
||||
self.rlp.val_at(1)
|
||||
self.rlp.list_at(1)
|
||||
}
|
||||
|
||||
/// Return number of uncles in given block, without deserializing them.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! View onto block header rlp
|
||||
|
||||
use util::{U256, Bytes, Hashable, H256, Address, H2048};
|
||||
use rlp::{Rlp, View};
|
||||
use rlp::Rlp;
|
||||
use header::BlockNumber;
|
||||
|
||||
/// View onto block header rlp.
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! View onto transaction rlp
|
||||
use util::{U256, Bytes, Hashable, H256};
|
||||
use rlp::{Rlp, View};
|
||||
use rlp::Rlp;
|
||||
|
||||
/// View onto transaction rlp.
|
||||
pub struct TransactionView<'a> {
|
||||
|
||||
Reference in New Issue
Block a user