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

Commit 6654d02

Browse files
ascjones5chdn
authored andcommitted
[beta] Backports (#8624)
* Trace precompiled contracts when the transfer value is not zero (#8486) * Trace precompiled contracts when the transfer value is not zero * Add tests for precompiled CALL tracing * Use byzantium test machine for the new test * Add notes in comments on why we don't trace all precompileds * Use is_transferred instead of transferred * Return error if RLP size of transaction exceeds the limit (#8473) * Return error if RLP size of transaction exceeds the limit * Review comments fixed * RLP check moved to verifier, corresponding pool test added * Don't block sync when importing old blocks (#8530) * Alter IO queueing. * Don't require IoMessages to be Clone * Ancient blocks imported via IoChannel. * Get rid of private transactions io message. * Get rid of deadlock and fix disconnected handler. * Revert to old disconnect condition. * Fix tests. * Fix deadlock. * Refactoring `ethcore-sync` - Fixing warp-sync barrier (#8543) * Start dividing sync chain : first supplier method * WIP - updated chain sync supplier * Finish refactoring the Chain Sync Supplier * Create Chain Sync Requester * Add Propagator for Chain Sync * Add the Chain Sync Handler * Move tests from mod -> handler * Move tests to propagator * Refactor SyncRequester arguments * Refactoring peer fork header handler * Fix wrong highest block number in snapshot sync * Small refactor... * Address PR grumbles * Retry failed CI job * Fix tests * PR Grumbles * Handle socket address parsing errors (#8545) Unpack errors and check for io::ErrorKind::InvalidInput and return our own AddressParse error. Remove the foreign link to std::net::AddrParseError and add an `impl From` for that error. Test parsing properly. * Fix packet count when talking with PAR2 peers (#8555) * Support diferent packet counts in different protocol versions. * Fix light timeouts and eclipse protection. * Fix devp2p tests. * Fix whisper-cli compilation. * Fix compilation. * Fix ethcore-sync tests. * Revert "Fix light timeouts and eclipse protection." This reverts commit 06285ea. * Increase timeouts. * Add whisper CLI to the pipelines (#8578) * Add whisper CLI to the pipelines * Address todo, ref #8579 * Rename `whisper-cli binary` to `whisper` (#8579) * rename whisper-cli binary to whisper * fix tests * Remove manually added text to the errors (#8595) These messages were confusing for the users especially the help message. * Fix account list double 0x display (#8596) * Remove unused self import * Fix account list double 0x display * Fix BlockReward contract "arithmetic operation overflow" (#8611) * Fix BlockReward contract "arithmetic operation overflow" * Add docs on how execute_as_system works * Fix typo * Rlp decode returns Result (#8527) rlp::decode returns Result Make a best effort to handle decoding errors gracefully throughout the code, using `expect` where the value is guaranteed to be valid (and in other places where it makes sense). * Remove expect (#8536) * Remove expect and propagate rlp::DecoderErrors as TrieErrors * Decoding headers can fail (#8570) * rlp::decode returns Result * Fix journaldb to handle rlp::decode Result * Fix ethcore to work with rlp::decode returning Result * Light client handles rlp::decode returning Result * Fix tests in rlp_derive * Fix tests * Cleanup * cleanup * Allow panic rather than breaking out of iterator * Let decoding failures when reading from disk blow up * syntax * Fix the trivial grumbles * Fix failing tests * Make Account::from_rlp return Result * Syntx, sigh * Temp-fix for decoding failures * Header::decode returns Result Handle new return type throughout the code base. * Do not continue reading from the DB when a value could not be read * Fix tests * Handle header decoding in light_sync * Handling header decoding errors * Let the DecodeError bubble up unchanged * Remove redundant error conversion * fix compiler warning (#8590) * Attempt to fix intermittent test failures (#8584) Occasionally should_return_correct_nonces_when_dropped_because_of_limit fails, possibly because of multiple threads competing to finish. See CI logs here for an example: https://gitlab.parity.io/parity/parity/-/jobs/86738 * block_header can fail so return Result (#8581) * block_header can fail so return Result * Restore previous return type based on feedback * Fix failing doc tests running on non-code * Block::decode() returns Result (#8586) * Gitlab test script fixes (#8573) * Exclude /docs from modified files. * Ensure all references in the working tree are available * Remove duplicated line from test script
1 parent 885f45c commit 6654d02

File tree

106 files changed

+4484
-3675
lines changed

Some content is hidden

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

106 files changed

+4484
-3675
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,17 @@ const RECALCULATE_COSTS_INTERVAL: Duration = Duration::from_secs(60 * 60);
7575
// minimum interval between updates.
7676
const UPDATE_INTERVAL: Duration = Duration::from_millis(5000);
7777

78+
/// Packet count for PIP.
79+
const PACKET_COUNT_V1: u8 = 9;
80+
7881
/// Supported protocol versions.
79-
pub const PROTOCOL_VERSIONS: &'static [u8] = &[1];
82+
pub const PROTOCOL_VERSIONS: &'static [(u8, u8)] = &[
83+
(1, PACKET_COUNT_V1),
84+
];
8085

8186
/// Max protocol version.
8287
pub const MAX_PROTOCOL_VERSION: u8 = 1;
8388

84-
/// Packet count for PIP.
85-
pub const PACKET_COUNT: u8 = 9;
8689

8790
// packet ID definitions.
8891
mod packet {
@@ -111,9 +114,9 @@ mod packet {
111114
mod timeout {
112115
use std::time::Duration;
113116

114-
pub const HANDSHAKE: Duration = Duration::from_millis(2500);
115-
pub const ACKNOWLEDGE_UPDATE: Duration = Duration::from_millis(5000);
116-
pub const BASE: u64 = 1500; // base timeout for packet.
117+
pub const HANDSHAKE: Duration = Duration::from_millis(4_000);
118+
pub const ACKNOWLEDGE_UPDATE: Duration = Duration::from_millis(5_000);
119+
pub const BASE: u64 = 2_500; // base timeout for packet.
117120

118121
// timeouts per request within packet.
119122
pub const HEADERS: u64 = 250; // per header?
@@ -688,7 +691,7 @@ impl LightProtocol {
688691
Err(e) => { punish(*peer, io, e); return }
689692
};
690693

691-
if PROTOCOL_VERSIONS.iter().find(|x| **x == proto_version).is_none() {
694+
if PROTOCOL_VERSIONS.iter().find(|x| x.0 == proto_version).is_none() {
692695
punish(*peer, io, Error::UnsupportedProtocolVersion(proto_version));
693696
return;
694697
}

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)