-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Conversation
It looks like @ordian signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
ethcore/light/src/client/mod.rs
Outdated
proof: proof, | ||
}); | ||
self.db.write_buffered(batch); | ||
Ok(()) | ||
} | ||
} | ||
|
||
/// An ungly borrow-checker workaround to allow iterating over a block and its ancestry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/ungly/ugly/ (?) – and also, was this meant to be a doc-comment?
ethcore/light/src/client/mod.rs
Outdated
fn restore_db(&self, new_db: &str, spec: &Spec, hs: HardcodedSync) -> Result<(), Error> { | ||
trace!(target: "snapshot", "Replacing light client database with {:?}", new_db); | ||
|
||
let _import_lock = self.import_lock.lock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why not try_lock_for()
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try_lock_for()
is a timed lock. What should we do if the timeout is reached? If try again, then this is no better than lock()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, perhaps exit with an error message?
}; | ||
match result { | ||
Ok(pending) => *self.pending.write() = Some(pending), | ||
// TODO: panic? abort snapshot sync? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not return error upstream and have?
fn insert_epoch_transition(… …) -> Result<…> {
if header.number() == 0 {
let td = self.chain.genesis_header().difficulty();
self.chain.insert_with_td(batch, header, td, Some(transition.proof))
} else {
self.chain.insert(batch, header, Some(transition.proof))
}
}
EDIT I see: the new trait wraps previous code that doesn't use Return
much. Is it worthwhile to change that perhaps, so that new code can use more idiomatic error handling?
86167a9
to
9afe71f
Compare
@@ -564,6 +510,67 @@ impl HeaderChain { | |||
Ok(pending) | |||
} | |||
|
|||
fn produce_next_cht_root( | |||
&self, from_era: u64, candidates: &mut BTreeMap<u64, Entry>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: each param should get its own line if there are too many for one line
self.cache.clone() | ||
} | ||
|
||
/// Get the database column. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be good to elaborate on what this column is used for
ethcore/light/src/client/mod.rs
Outdated
proof: proof, | ||
}); | ||
self.db.write_buffered(batch); | ||
Ok(()) | ||
} | ||
} | ||
|
||
// An ugly borrow-checker workaround to allow iterating over a block and its ancestry. | ||
/// An iterator over a block and its ancestry. | ||
pub struct AncestryIter<'a>(RwLockReadGuard<'a, HeaderChain>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this necessary?
ethcore/src/engines/mod.rs
Outdated
@@ -342,9 +342,15 @@ pub trait Engine<M: Machine>: Sync + Send { | |||
None | |||
} | |||
|
|||
/// Create a factory for restoring from snapshot chunks. | |||
/// Returning `None` indicates that this engine doesn't support restoring from a snapshot. | |||
fn snapshot_restoration(&self) -> Option<Box<RebuilderFactory>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be unified with SnapshotComponents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, basically it worked, although there are a couple of unresolved questions left as comments. Also it would be nice to have tests for this and reduce code duplication with the full chain.
} | ||
|
||
fn add_child(&self, _batch: &mut DBTransaction, _block_hash: H256, _child_hash: H256) { | ||
// TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we store this parent<->child relationship in the database similar to a full node
https://github.com/paritytech/parity/blob/0bed5976e368e948566f5a445f5fa17088674f3d/ethcore/src/blockchain/blockchain.rs#L934-L947?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, something like that
.expect("blocks are only inserted if parent is present; or this is the block we just added; qed"); | ||
let canon_pos = match entry.candidates.iter().position(|x| x.hash == canon_hash) { | ||
Some(pos) => pos, | ||
None => break, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about correctness here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not return an Err
?
Is this to be reviewed? "[WIP] [1/2]"? |
ethcore/light/Cargo.toml
Outdated
@@ -36,10 +36,13 @@ triehash = { path = "../../util/triehash" } | |||
kvdb = { path = "../../util/kvdb" } | |||
memory-cache = { path = "../../util/memory_cache" } | |||
error-chain = { version = "0.12", default-features = false } | |||
util-error = { path = "../../util/error" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was crate was removed in #9054, do you need it?
Please rebase/merge to master
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me modulo minor grumbles. Can't say I fully understand it all though.
ethcore/light/Cargo.toml
Outdated
@@ -36,10 +36,13 @@ triehash = { path = "../../util/triehash" } | |||
kvdb = { path = "../../util/kvdb" } | |||
memory-cache = { path = "../../util/memory_cache" } | |||
error-chain = { version = "0.12", default-features = false } | |||
util-error = { path = "../../util/error" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This crate was recently removed.
@@ -359,7 +360,7 @@ impl HeaderChain { | |||
header: Header, | |||
transition_proof: Option<Vec<u8>>, | |||
) -> Result<PendingChanges, BlockImportError> { | |||
self.insert_inner(transaction, header, None, transition_proof) | |||
self.insert_inner(transaction, header, None, transition_proof, false) | |||
} | |||
|
|||
/// Insert a pre-verified header, with a known total difficulty. Similary to `insert`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo here: s/Similary/Similar/ maybe?
.expect("blocks are only inserted if parent is present; or this is the block we just added; qed"); | ||
let canon_pos = match entry.candidates.iter().position(|x| x.hash == canon_hash) { | ||
Some(pos) => pos, | ||
None => break, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not return an Err
?
if let Some((epoch_transition, header)) = last_canonical_transition { | ||
let x = encode_canonical_transition(&header, &epoch_transition.proof); | ||
transaction.put_vec(self.col, LAST_CANONICAL_TRANSITION, x); | ||
if !dont_produce_cht { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a great fan of double-negatives like this. Would you consider flipping the boolean, so you'd have if produce_cht { … … }
?
&self, | ||
transaction: &mut DBTransaction, | ||
header: Header, | ||
total_difficulty: Option<U256>, | ||
transition_proof: Option<Vec<u8>>, | ||
dont_produce_cht: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned, flipping this bool would make it easier to read imo: product_cht
.
fn commit(&self); | ||
} | ||
|
||
/// A factory producing `Rebuilder` necessary for snapshot restoration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/producing Rebuilder
/producing a Rebuilder
/
|
||
/// A factory producing `Rebuilder` necessary for snapshot restoration. | ||
pub trait RebuilderFactory: Send { | ||
/// Create a rebuilder, which will have chunks fed into it in arbitrary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/rebuilder/Rebuilder
/
} | ||
|
||
/// Returns the largest group of peers with the same snapshot hash. | ||
/// If we already have manifest, prefer peers with that manifest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double spaces between "already" and "have"
let protocol_version: u8 = rlp.val_at(0)?; | ||
let network_id: u64 = rlp.val_at(1)?; | ||
let _difficulty: U256 = rlp.val_at(2)?; | ||
let _latest_hash: H256 = rlp.val_at(3)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why fetch these two if we don't need them? (and why bail on error?) Is it faster maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure that the status message that we receive from a full node is well formed.
parity/export_hardcoded_sync.rs
Outdated
cmd.compaction, | ||
cmd.wal, | ||
VMType::Interpreter, | ||
"".into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps annotate these hard-to-guess items to help future readers?
ethcore/light/src/client/mod.rs
Outdated
|
||
impl<'a> AncestryIter<'a> { | ||
/// Get an iterator over a block and its ancestry. | ||
pub fn iter(&'a self, start: BlockId) -> Box<Iterator<Item=encoded::Header> + 'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could even be impl Iterator
now
ethcore/light/src/client/service.rs
Outdated
struct ImportBlocks<T>(Arc<Client<T>>); | ||
impl<T> ClientIoHandler<T> { | ||
pub fn new(client: Arc<Client<T>>, snapshot: Arc<SnapshotService>) -> Self { | ||
Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
favor ClientIoHandler
|
||
fn insert_unordered_block( | ||
&self, batch: &mut DBTransaction, bytes: &[u8], _receipts: Vec<Receipt>, | ||
parent_td: Option<U256>, _is_best: bool, _is_ancient: bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
ethcore/sync/src/chain/mod.rs
Outdated
|
||
const STATUS_PACKET: u8 = 0x00; | ||
pub const STATUS_PACKET: u8 = 0x00; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document all the public constants. Also, why have these become public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because currently, the warp sync handshake packet uses it: https://github.com/paritytech/parity-ethereum/blob/7ad556346eed03cfea2999f7f9daf864de6489af/ethcore/sync/src/chain/mod.rs#L890-L910
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, pub(crate)
is enough for them.
ethcore/sync/src/light_sync/mod.rs
Outdated
@@ -275,6 +300,13 @@ impl<L: AsLightClient + Send + Sync> Handler for LightSync<L> { | |||
} | |||
|
|||
fn on_disconnect(&self, ctx: &EventContext, unfulfilled: &[ReqId]) { | |||
match *self.state.lock() { | |||
SyncState::Snapshot(_) => { | |||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extraneous braces
* 'master' of https://github.com/paritytech/parity: removed client error (openethereum#9253) Implement EIP-1052 (EXTCODEHASH) and fix several issues in state account cache (openethereum#9234) Improve Tracer documentation (openethereum#9237) Update Dockerfile (openethereum#9242) block cleanup (openethereum#9117) Increase the number of sessions. (openethereum#9203) add changelog for 1.11.8 stable and 2.0.1 beta (openethereum#9230) fix typo (openethereum#9232) Fix potential as_usize overflow when casting from U256 in miner (openethereum#9221) Allow old blocks from peers with lower difficulty (openethereum#9226) Removes duplicate libudev-dev from Dockerfile (openethereum#9220) snap: remove ssl dependencies from snapcraft definition (openethereum#9222) remove ssl from dockerfiles, closes openethereum#8880 (openethereum#9195) Insert PROOF messages for some cases in blockchain (openethereum#9141) [Chain] Add more bootnodes (openethereum#9174) ethcore: update bn version (openethereum#9217) deserialize block only once during verification (openethereum#9161) Simple build instruction fix (openethereum#9215) Added --tx-queue-no-early-reject flag to disable early tx queue rejects (openethereum#9143)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@@ -451,15 +453,23 @@ impl HeaderChain { | |||
// reorganize ancestors so canonical entries are first in their | |||
// respective candidates vectors. | |||
if is_new_best { | |||
let prove = "blocks are only inserted if parent is present; or this is the block we just added; qed"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make const
(and "proof" is a better name imo)
…rp_sync_on_light_client * 'master' of https://github.com/paritytech/parity: Propagate transactions for next 4 blocks. (openethereum#9265) decode block rlp less often (openethereum#9252) Fix eternalities tests can_create (missing parameter) (openethereum#9270) Update ref to `parity-common` and update `seek` behaviour (openethereum#9257) Comply EIP-86 with the new definition (openethereum#9140) Check if synced when using eth_getWork (openethereum#9193) (openethereum#9210)
Codecov Report
@@ Coverage Diff @@
## master #8723 +/- ##
==========================================
+ Coverage 68.72% 68.77% +0.05%
==========================================
Files 635 636 +1
Lines 90784 91288 +504
==========================================
+ Hits 62394 62787 +393
- Misses 28390 28501 +111
Continue to review full report at Codecov.
|
…rp_sync_on_light_client * 'master' of https://github.com/paritytech/parity: ethcore: add transition flag for transaction permission contract (openethereum#9275) Remove all dapp permissions related settings (openethereum#9120) Improve return data truncate logic (openethereum#9254) Update wasm-tests hash (openethereum#9295) Implement KIP4: create2 for wasm (openethereum#9277) Fix loop start value (openethereum#9285) Avoid using $HOME if not necessary (openethereum#9273) Fix path to parity.h (openethereum#9274)
…rp_sync_on_light_client * 'master' of https://github.com/paritytech/parity: Allow setting the panic hook with parity-clib (openethereum#9292) Prevent blockchain & miner racing when accessing pending block. (openethereum#9310) Docker alpine: use multi-stage concept (openethereum#9269) Update `log` -> 0.4, `env_logger` -> 0.5. (openethereum#9294) Update tobalaba.json (openethereum#9313) Allow tx pool to be Send (openethereum#9315) Fix codecov.io badge in README (openethereum#9327) Move ethereum-specific H256FastMap type to own crate (openethereum#9307) ethcore sync decodes rlp less often (openethereum#9264)
Has some conflicts and needs a 2nd review. |
What's the status of this? |
@5chdn the current implementation uses existing warp sync protocol ( |
Ok, let's just reopen this once we are continuing with this. |
Part of #6010.
This part doesn't include background old header sync.