Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 72ad364

Browse files
committed
Merge branch 'master' into fix/issues/6972
* master: Decoding headers can fail (#8570) Refactoring `ethcore-sync` - Fixing warp-sync barrier (#8543) Remove State::replace_backend (#8569) Make trace-time publishable. (#8568) Don't block sync when importing old blocks (#8530) Trace precompiled contracts when the transfer value is not zero (#8486) Parity as a library (#8412) Rlp decode returns Result (#8527) Node table sorting according to last contact data (#8541) Keep all enacted blocks notify in order (#8524) ethcore, rpc, machine: refactor block reward application and tracing (#8490)
2 parents 940e4b9 + 842b75c commit 72ad364

File tree

108 files changed

+5329
-4151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+5329
-4151
lines changed

Cargo.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ ethcore-miner = { path = "miner" }
4040
ethcore-network = { path = "util/network" }
4141
ethcore-private-tx = { path = "ethcore/private-tx" }
4242
ethcore-service = { path = "ethcore/service" }
43-
ethcore-stratum = { path = "ethcore/stratum" }
4443
ethcore-sync = { path = "ethcore/sync" }
4544
ethcore-transaction = { path = "ethcore/transaction" }
4645
ethereum-types = "0.3"
@@ -108,6 +107,9 @@ slow-blocks = ["ethcore/slow-blocks"]
108107
secretstore = ["ethcore-secretstore"]
109108
final = ["parity-version/final"]
110109

110+
[lib]
111+
path = "parity/lib.rs"
112+
111113
[[bin]]
112114
path = "parity/main.rs"
113115
name = "parity"
@@ -130,6 +132,7 @@ members = [
130132
"ethstore/cli",
131133
"evmbin",
132134
"miner",
135+
"parity-clib",
133136
"transaction-pool",
134137
"whisper",
135138
"whisper/cli",

ethcore/light/src/client/header_chain.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,15 @@ impl HeaderChain {
228228
let decoded_header = spec.genesis_header();
229229

230230
let chain = if let Some(current) = db.get(col, CURRENT_KEY)? {
231-
let curr : BestAndLatest = ::rlp::decode(&current);
231+
let curr : BestAndLatest = ::rlp::decode(&current).expect("decoding db value failed");
232232

233233
let mut cur_number = curr.latest_num;
234234
let mut candidates = BTreeMap::new();
235235

236236
// load all era entries, referenced headers within them,
237237
// and live epoch proofs.
238238
while let Some(entry) = db.get(col, era_key(cur_number).as_bytes())? {
239-
let entry: Entry = ::rlp::decode(&entry);
239+
let entry: Entry = ::rlp::decode(&entry).expect("decoding db value failed");
240240
trace!(target: "chain", "loaded header chain entry for era {} with {} candidates",
241241
cur_number, entry.candidates.len());
242242

@@ -305,7 +305,7 @@ impl HeaderChain {
305305
batch.put(col, cht_key(cht_num as u64).as_bytes(), &::rlp::encode(cht_root));
306306
}
307307

308-
let decoded_header = hardcoded_sync.header.decode();
308+
let decoded_header = hardcoded_sync.header.decode()?;
309309
let decoded_header_num = decoded_header.number();
310310

311311
// write the block in the DB.
@@ -524,7 +524,10 @@ impl HeaderChain {
524524
None
525525
}
526526
Ok(None) => panic!("stored candidates always have corresponding headers; qed"),
527-
Ok(Some(header)) => Some((epoch_transition, ::rlp::decode(&header))),
527+
Ok(Some(header)) => Some((
528+
epoch_transition,
529+
::rlp::decode(&header).expect("decoding value from db failed")
530+
)),
528531
};
529532
}
530533
}
@@ -582,7 +585,7 @@ impl HeaderChain {
582585
bail!(ErrorKind::Database(msg.into()));
583586
};
584587

585-
let decoded = header.decode();
588+
let decoded = header.decode().expect("decoding db value failed");
586589

587590
let entry: Entry = {
588591
let bytes = self.db.get(self.col, era_key(h_num).as_bytes())?
@@ -591,7 +594,7 @@ impl HeaderChain {
591594
in an inconsistent state", h_num);
592595
ErrorKind::Database(msg.into())
593596
})?;
594-
::rlp::decode(&bytes)
597+
::rlp::decode(&bytes).expect("decoding db value failed")
595598
};
596599

597600
let total_difficulty = entry.candidates.iter()
@@ -604,9 +607,9 @@ impl HeaderChain {
604607
.total_difficulty;
605608

606609
break Ok(Some(SpecHardcodedSync {
607-
header: header,
608-
total_difficulty: total_difficulty,
609-
chts: chts,
610+
header,
611+
total_difficulty,
612+
chts,
610613
}));
611614
},
612615
None => {
@@ -742,7 +745,7 @@ impl HeaderChain {
742745
/// so including it within a CHT would be redundant.
743746
pub fn cht_root(&self, n: usize) -> Option<H256> {
744747
match self.db.get(self.col, cht_key(n as u64).as_bytes()) {
745-
Ok(val) => val.map(|x| ::rlp::decode(&x)),
748+
Ok(db_fetch) => db_fetch.map(|bytes| ::rlp::decode(&bytes).expect("decoding value from db failed")),
746749
Err(e) => {
747750
warn!(target: "chain", "Error reading from database: {}", e);
748751
None
@@ -793,7 +796,7 @@ impl HeaderChain {
793796
pub fn pending_transition(&self, hash: H256) -> Option<PendingEpochTransition> {
794797
let key = pending_transition_key(hash);
795798
match self.db.get(self.col, &*key) {
796-
Ok(val) => val.map(|x| ::rlp::decode(&x)),
799+
Ok(db_fetch) => db_fetch.map(|bytes| ::rlp::decode(&bytes).expect("decoding value from db failed")),
797800
Err(e) => {
798801
warn!(target: "chain", "Error reading from database: {}", e);
799802
None
@@ -812,7 +815,9 @@ impl HeaderChain {
812815

813816
for hdr in self.ancestry_iter(BlockId::Hash(parent_hash)) {
814817
if let Some(transition) = live_proofs.get(&hdr.hash()).cloned() {
815-
return Some((hdr.decode(), transition.proof))
818+
return hdr.decode().map(|decoded_hdr| {
819+
(decoded_hdr, transition.proof)
820+
}).ok();
816821
}
817822
}
818823

@@ -1192,7 +1197,7 @@ mod tests {
11921197

11931198
let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600))));
11941199

1195-
let chain = HeaderChain::new(db.clone(), None, &spec, cache, HardcodedSync::Allow).unwrap();
1200+
let chain = HeaderChain::new(db.clone(), None, &spec, cache, HardcodedSync::Allow).expect("failed to instantiate a new HeaderChain");
11961201

11971202
let mut parent_hash = genesis_header.hash();
11981203
let mut rolling_timestamp = genesis_header.timestamp();
@@ -1211,17 +1216,17 @@ mod tests {
12111216
parent_hash = header.hash();
12121217

12131218
let mut tx = db.transaction();
1214-
let pending = chain.insert(&mut tx, header, None).unwrap();
1219+
let pending = chain.insert(&mut tx, header, None).expect("failed inserting a transaction");
12151220
db.write(tx).unwrap();
12161221
chain.apply_pending(pending);
12171222

12181223
rolling_timestamp += 10;
12191224
}
12201225

1221-
let hardcoded_sync = chain.read_hardcoded_sync().unwrap().unwrap();
1226+
let hardcoded_sync = chain.read_hardcoded_sync().expect("failed reading hardcoded sync").expect("failed unwrapping hardcoded sync");
12221227
assert_eq!(hardcoded_sync.chts.len(), 3);
12231228
assert_eq!(hardcoded_sync.total_difficulty, total_difficulty);
1224-
let decoded: Header = hardcoded_sync.header.decode();
1229+
let decoded: Header = hardcoded_sync.header.decode().expect("decoding failed");
12251230
assert_eq!(decoded.number(), h_num);
12261231
}
12271232
}

ethcore/light/src/client/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<T: ChainDataFetcher> Client<T> {
318318

319319
let epoch_proof = self.engine.is_epoch_end(
320320
&verified_header,
321-
&|h| self.chain.block_header(BlockId::Hash(h)).map(|hdr| hdr.decode()),
321+
&|h| self.chain.block_header(BlockId::Hash(h)).and_then(|hdr| hdr.decode().ok()),
322322
&|h| self.chain.pending_transition(h),
323323
);
324324

@@ -426,7 +426,15 @@ impl<T: ChainDataFetcher> Client<T> {
426426
};
427427

428428
// Verify Block Family
429-
let verify_family_result = self.engine.verify_block_family(&verified_header, &parent_header.decode());
429+
430+
let verify_family_result = {
431+
parent_header.decode()
432+
.map_err(|dec_err| dec_err.into())
433+
.and_then(|decoded| {
434+
self.engine.verify_block_family(&verified_header, &decoded)
435+
})
436+
437+
};
430438
if let Err(e) = verify_family_result {
431439
warn!(target: "client", "Stage 3 block verification failed for #{} ({})\nError: {:?}",
432440
verified_header.number(), verified_header.hash(), e);

ethcore/light/src/net/request_credits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ mod tests {
407407
let costs = CostTable::default();
408408
let serialized = ::rlp::encode(&costs);
409409

410-
let new_costs: CostTable = ::rlp::decode(&*serialized);
410+
let new_costs: CostTable = ::rlp::decode(&*serialized).unwrap();
411411

412412
assert_eq!(costs, new_costs);
413413
}

ethcore/light/src/types/request/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ mod tests {
16421642
{
16431643
// check as single value.
16441644
let bytes = ::rlp::encode(&val);
1645-
let new_val: T = ::rlp::decode(&bytes);
1645+
let new_val: T = ::rlp::decode(&bytes).unwrap();
16461646
assert_eq!(val, new_val);
16471647

16481648
// check as list containing single value.

0 commit comments

Comments
 (0)