Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions ethcore/client-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ use trace::{
use common_types::data_format::DataFormat;
use vm::{LastHashes, Schedule};

use common_types::snapshot::Progress;

/// State information to be used during client query
pub enum StateOrBlock {
/// State to be used, may be pending
Expand Down Expand Up @@ -448,36 +446,6 @@ pub trait DatabaseRestore: Send + Sync {
fn restore_db(&self, new_db: &str) -> Result<(), EthcoreError>;
}

/// Snapshot related functionality
pub trait SnapshotClient: BlockChainClient + BlockInfo + DatabaseRestore + BlockChainReset {
/// Take a snapshot at the given block.
/// If the ID given is "latest", this will default to 1000 blocks behind.
fn take_snapshot<W: SnapshotWriter + Send>(
&self,
writer: W,
at: BlockId,
p: &Progress,
) -> Result<(), EthcoreError>;
}


// todo[dvdplm] move this back to snapshot once extracted from ethcore
/// Something which can write snapshots.
/// Writing the same chunk multiple times will lead to implementation-defined
/// behavior, and is not advised.
pub trait SnapshotWriter {
/// Write a compressed state chunk.
fn write_state_chunk(&mut self, hash: H256, chunk: &[u8]) -> std::io::Result<()>;

/// Write a compressed block chunk.
fn write_block_chunk(&mut self, hash: H256, chunk: &[u8]) -> std::io::Result<()>;

/// Complete writing. The manifest's chunk lists must be consistent
/// with the chunks written.
fn finish(self, manifest: common_types::snapshot::ManifestData) -> std::io::Result<()> where Self: Sized;
}


/// Represents what has to be handled by actor listening to chain events
pub trait ChainNotify: Send + Sync {
/// fires when chain has new blocks.
Expand Down
4 changes: 2 additions & 2 deletions ethcore/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ use blockchain::{BlockChainDB, BlockChainDBHandler};
use ethcore::client::{Client, ClientConfig};
use ethcore::miner::Miner;
use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
use snapshot::{SnapshotService as _SnapshotService};
use snapshot::{SnapshotService as _SnapshotService, SnapshotClient};
use spec::Spec;
use common_types::{
io_message::ClientIoMessage,
errors::{EthcoreError, SnapshotError},
snapshot::RestorationStatus,
};
use client_traits::{ImportBlock, SnapshotClient, Tick};
use client_traits::{ImportBlock, Tick};


use ethcore_private_tx::{self, Importer, Signer};
Expand Down
6 changes: 6 additions & 0 deletions ethcore/snapshot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ lazy_static = { version = "1.3" }
spec = { path = "../spec" }
tempdir = "0.3"
trie-standardmap = "0.15.0"
# Note[dvdplm]: Ensure the snapshot tests are included in the dependency tree, which in turn means that
# `cargo test --all` runs the tests.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unfortunate, but I didn't come up with something better

snapshot-tests = { path = "./snapshot-tests" }

[features]
test-helpers = []
44 changes: 44 additions & 0 deletions ethcore/snapshot/snapshot-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "snapshot-tests"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
accounts = { package = "ethcore-accounts", path = "../../../accounts" }
account-db = { path = "../../account-db" }
account-state = { path = "../../account-state" }
blockchain = { package = "ethcore-blockchain", path = "../../blockchain" }
bytes = { package = "parity-bytes", version = "0.1.0" }
client-traits = { path = "../../client-traits" }
common-types = { path = "../../types" }
engine = { path = "../../engine", features = ["test-helpers"] }
env_logger = "0.5"
ethcore = { path = "../..", features = ["test-helpers"] }
ethcore-db = { path = "../../db" }
ethcore-io = { path = "../../../util/io" }
ethereum-types = "0.6.0"
ethkey = { path = "../../../accounts/ethkey" }
ethtrie = { package = "patricia-trie-ethereum", path = "../../../util/patricia-trie-ethereum" }
hash-db = "0.15.0"
journaldb = { path = "../../../util/journaldb" }
keccak-hash = "0.2.0"
keccak-hasher = { path = "../../../util/keccak-hasher" }
kvdb = "0.1.0"
kvdb-rocksdb = { version = "0.1.3" }
log = "0.4.8"
parking_lot = "0.8.0"
rand = "0.6"
rand_xorshift = "0.1.1"
rlp = "0.4.2"
snappy = { package = "parity-snappy", version ="0.1.0" }
snapshot = { path = "../../snapshot", features = ["test-helpers"] }
spec = { path = "../../spec" }
tempdir = "0.3"
trie-db = "0.15.0"
trie-standardmap = "0.15.0"
ethabi = "8.0"
ethabi-contract = "8.0"
ethabi-derive = "8.0"
lazy_static = { version = "1.3" }
triehash = { package = "triehash-ethereum", version = "0.2", path = "../../../util/triehash-ethereum" }
89 changes: 89 additions & 0 deletions ethcore/snapshot/snapshot-tests/src/abridged_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.

// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

//! Tests for block RLP encoding

use snapshot::test_helpers::AbridgedBlock;

use bytes::Bytes;
use ethereum_types::{H256, U256, Address};
use common_types::{
transaction::{Action, Transaction},
block::Block,
view,
views::BlockView,
};

fn encode_block(b: &Block) -> Bytes {
b.rlp_bytes()
}

#[test]
fn empty_block_abridging() {
let b = Block::default();
let receipts_root = b.header.receipts_root().clone();
let encoded = encode_block(&b);

let abridged = AbridgedBlock::from_block_view(&view!(BlockView, &encoded));
assert_eq!(abridged.to_block(H256::zero(), 0, receipts_root).unwrap(), b);
}

#[test]
#[should_panic]
fn wrong_number() {
let b = Block::default();
let receipts_root = b.header.receipts_root().clone();
let encoded = encode_block(&b);

let abridged = AbridgedBlock::from_block_view(&view!(BlockView, &encoded));
assert_eq!(abridged.to_block(H256::zero(), 2, receipts_root).unwrap(), b);
}

#[test]
fn with_transactions() {
let mut b = Block::default();

let t1 = Transaction {
action: Action::Create,
nonce: U256::from(42),
gas_price: U256::from(3000),
gas: U256::from(50_000),
value: U256::from(1),
data: b"Hello!".to_vec()
}.fake_sign(Address::from_low_u64_be(0x69));

let t2 = Transaction {
action: Action::Create,
nonce: U256::from(88),
gas_price: U256::from(12345),
gas: U256::from(300000),
value: U256::from(1000000000),
data: "Eep!".into(),
}.fake_sign(Address::from_low_u64_be(0x55));

b.transactions.push(t1.into());
b.transactions.push(t2.into());

let receipts_root = b.header.receipts_root().clone();
b.header.set_transactions_root(triehash::ordered_trie_root(
b.transactions.iter().map(::rlp::encode)
));

let encoded = encode_block(&b);

let abridged = AbridgedBlock::from_block_view(&view!(BlockView, &encoded[..]));
assert_eq!(abridged.to_block(H256::zero(), 0, receipts_root).unwrap(), b);
}
Loading