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

Commit 51ba2f4

Browse files
committed
Merge branch 'master' into dp/chore/move-machine-to-own-crate
* master: Allow default block parameter to be blockHash (#10932) Enable sealing when engine is ready (#10938) Fix some warnings and typos. (#10941)
2 parents 2477cbd + 7227985 commit 51ba2f4

File tree

14 files changed

+153
-16
lines changed

14 files changed

+153
-16
lines changed

ethcore/src/client/client.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,10 @@ impl BlockChainClient for Client {
17641764
self.config.spec_name.clone()
17651765
}
17661766

1767+
fn chain(&self) -> Arc<BlockProvider> {
1768+
self.chain.read().clone()
1769+
}
1770+
17671771
fn set_spec_name(&self, new_spec_name: String) -> Result<(), ()> {
17681772
trace!(target: "mode", "Client::set_spec_name({:?})", new_spec_name);
17691773
if !self.enabled.load(AtomicOrdering::Relaxed) {

ethcore/src/client/test_client.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::str::FromStr;
2020
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrder};
2121
use std::sync::Arc;
2222
use std::collections::{HashMap, BTreeMap};
23+
use blockchain::BlockProvider;
2324
use std::mem;
2425

2526
use blockchain::{TreeRoute, BlockReceipts};
@@ -707,6 +708,10 @@ impl BlockChainClient for TestBlockChainClient {
707708
}
708709
}
709710

711+
fn chain(&self) -> Arc<BlockProvider> {
712+
unimplemented!()
713+
}
714+
710715
fn list_accounts(&self, _id: BlockId, _after: Option<&Address>, _count: u64) -> Option<Vec<Address>> {
711716
None
712717
}

ethcore/src/client/traits.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use std::collections::BTreeMap;
1818
use std::sync::Arc;
1919

20-
use blockchain::{BlockReceipts, TreeRoute};
20+
use blockchain::{BlockReceipts, TreeRoute, BlockProvider};
2121
use bytes::Bytes;
2222
use call_contract::{CallContract, RegistryInfo};
2323
use client_traits::BlockInfo;
@@ -219,6 +219,8 @@ pub trait BlockChainClient : Sync + Send + AccountData + BlockChain + CallContra
219219
.expect("code will return Some if given BlockId::Latest; qed")
220220
}
221221

222+
fn chain(&self) -> Arc<BlockProvider>;
223+
222224
/// Get block queue information.
223225
fn queue_info(&self) -> BlockQueueInfo;
224226

ethcore/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ extern crate rayon;
9898
extern crate rlp;
9999
extern crate parity_util_mem;
100100
extern crate parity_util_mem as malloc_size_of;
101+
#[cfg(any(test, feature = "test-helpers"))]
101102
extern crate rustc_hex;
102103
extern crate serde;
103104
extern crate state_db;

ethcore/src/miner/miner.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,10 @@ impl Miner {
863863
fn prepare_and_update_sealing<C: miner::BlockChainClient>(&self, chain: &C) {
864864
use miner::MinerService;
865865
match self.engine.sealing_state() {
866-
SealingState::Ready => self.update_sealing(chain),
866+
SealingState::Ready => {
867+
self.maybe_enable_sealing();
868+
self.update_sealing(chain)
869+
}
867870
SealingState::External => {
868871
// this calls `maybe_enable_sealing()`
869872
if self.prepare_pending_block(chain) == BlockPreparationStatus::NotPrepared {
@@ -1108,7 +1111,7 @@ impl miner::MinerService for Miner {
11081111
Eq(value) => tx_value == value,
11091112
GreaterThan(value) => tx_value > value,
11101113
LessThan(value) => tx_value < value,
1111-
// Will always occure on `Any`, other operators
1114+
// Will always occur on `Any`, other operators
11121115
// get handled during deserialization
11131116
_ => true,
11141117
}
@@ -1124,7 +1127,7 @@ impl miner::MinerService for Miner {
11241127
let sender = tx.signed().sender();
11251128
match filter.from {
11261129
Eq(value) => sender == value,
1127-
// Will always occure on `Any`, other operators
1130+
// Will always occur on `Any`, other operators
11281131
// get handled during deserialization
11291132
_ => true,
11301133
}
@@ -1137,7 +1140,7 @@ impl miner::MinerService for Miner {
11371140
match filter.to {
11381141
// Could apply to `Some(Address)` or `None` (for contract creation)
11391142
Eq(value) => receiver == value,
1140-
// Will always occure on `Any`, other operators
1143+
// Will always occur on `Any`, other operators
11411144
// get handled during deserialization
11421145
_ => true,
11431146
}

ethcore/wasm/src/runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl ::std::fmt::Display for Error {
128128
Error::AllocationFailed => write!(f, "Memory allocation failed (OOM)"),
129129
Error::BadUtf8 => write!(f, "String encoding is bad utf-8 sequence"),
130130
Error::GasLimit => write!(f, "Invocation resulted in gas limit violated"),
131-
Error::Log => write!(f, "Error occured while logging an event"),
131+
Error::Log => write!(f, "Error occurred while logging an event"),
132132
Error::InvalidSyscall => write!(f, "Invalid syscall signature encountered at runtime"),
133133
Error::Other => write!(f, "Other unspecified error"),
134134
Error::Unreachable => write!(f, "Unreachable instruction encountered"),

rpc/src/v1/helpers/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,3 +609,13 @@ pub fn require_experimental(allow_experimental_rpcs: bool, eip: &str) -> Result<
609609
})
610610
}
611611
}
612+
613+
/// returns an error for when require_canonical was specified and
614+
pub fn invalid_input() -> Error {
615+
Error {
616+
// UNSUPPORTED_REQUEST shares the same error code for EIP-1898
617+
code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST),
618+
message: "Invalid input".into(),
619+
data: None
620+
}
621+
}

rpc/src/v1/helpers/light_fetch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ where
264264
// (they don't have state) we can safely fallback to `Latest`.
265265
let id = match num.unwrap_or_default() {
266266
BlockNumber::Num(n) => BlockId::Number(n),
267+
BlockNumber::Hash { hash, .. } => BlockId::Hash(hash),
267268
BlockNumber::Earliest => BlockId::Earliest,
268269
BlockNumber::Latest => BlockId::Latest,
269270
BlockNumber::Pending => {

rpc/src/v1/impls/eth.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> EthClient<C, SN, S
244244

245245
BlockNumberOrId::Number(num) => {
246246
let id = match num {
247+
BlockNumber::Hash { hash, .. } => BlockId::Hash(hash),
247248
BlockNumber::Latest => BlockId::Latest,
248249
BlockNumber::Earliest => BlockId::Earliest,
249250
BlockNumber::Num(n) => BlockId::Number(n),
@@ -436,10 +437,10 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> EthClient<C, SN, S
436437

437438
fn get_state(&self, number: BlockNumber) -> StateOrBlock {
438439
match number {
440+
BlockNumber::Hash { hash, .. } => BlockId::Hash(hash).into(),
439441
BlockNumber::Num(num) => BlockId::Number(num).into(),
440442
BlockNumber::Earliest => BlockId::Earliest.into(),
441443
BlockNumber::Latest => BlockId::Latest.into(),
442-
443444
BlockNumber::Pending => {
444445
let info = self.client.chain_info();
445446

@@ -475,10 +476,22 @@ fn check_known<C>(client: &C, number: BlockNumber) -> Result<()> where C: BlockC
475476

476477
let id = match number {
477478
BlockNumber::Pending => return Ok(()),
478-
479479
BlockNumber::Num(n) => BlockId::Number(n),
480480
BlockNumber::Latest => BlockId::Latest,
481481
BlockNumber::Earliest => BlockId::Earliest,
482+
BlockNumber::Hash { hash, require_canonical } => {
483+
// block check takes precedence over canon check.
484+
match client.block_status(BlockId::Hash(hash.clone())) {
485+
BlockStatus::InChain => {},
486+
_ => return Err(errors::unknown_block()),
487+
};
488+
489+
if require_canonical && !client.chain().is_canon(&hash) {
490+
return Err(errors::invalid_input())
491+
}
492+
493+
return Ok(())
494+
}
482495
};
483496

484497
match client.block_status(id) {
@@ -592,6 +605,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
592605

593606
let num = num.unwrap_or_default();
594607
let id = match num {
608+
BlockNumber::Hash { hash, .. } => BlockId::Hash(hash),
595609
BlockNumber::Num(n) => BlockId::Number(n),
596610
BlockNumber::Earliest => BlockId::Earliest,
597611
BlockNumber::Latest => BlockId::Latest,
@@ -765,6 +779,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
765779

766780
fn transaction_by_block_number_and_index(&self, num: BlockNumber, index: Index) -> BoxFuture<Option<Transaction>> {
767781
let block_id = match num {
782+
BlockNumber::Hash { hash, .. } => PendingOrBlock::Block(BlockId::Hash(hash)),
768783
BlockNumber::Latest => PendingOrBlock::Block(BlockId::Latest),
769784
BlockNumber::Earliest => PendingOrBlock::Block(BlockId::Earliest),
770785
BlockNumber::Num(num) => PendingOrBlock::Block(BlockId::Number(num)),
@@ -801,6 +816,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
801816

802817
fn uncle_by_block_number_and_index(&self, num: BlockNumber, index: Index) -> BoxFuture<Option<RichBlock>> {
803818
let id = match num {
819+
BlockNumber::Hash { hash, .. } => PendingUncleId { id: PendingOrBlock::Block(BlockId::Hash(hash)), position: index.value() },
804820
BlockNumber::Latest => PendingUncleId { id: PendingOrBlock::Block(BlockId::Latest), position: index.value() },
805821
BlockNumber::Earliest => PendingUncleId { id: PendingOrBlock::Block(BlockId::Earliest), position: index.value() },
806822
BlockNumber::Num(num) => PendingUncleId { id: PendingOrBlock::Block(BlockId::Number(num)), position: index.value() },
@@ -917,6 +933,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
917933
let signed = try_bf!(fake_sign::sign_call(request));
918934

919935
let num = num.unwrap_or_default();
936+
try_bf!(check_known(&*self.client, num.clone()));
920937

921938
let (mut state, header) = if num == BlockNumber::Pending {
922939
let info = self.client.chain_info();
@@ -926,6 +943,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
926943
(state, header)
927944
} else {
928945
let id = match num {
946+
BlockNumber::Hash { hash, .. } => BlockId::Hash(hash),
929947
BlockNumber::Num(num) => BlockId::Number(num),
930948
BlockNumber::Earliest => BlockId::Earliest,
931949
BlockNumber::Latest => BlockId::Latest,
@@ -967,6 +985,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
967985
(state, header)
968986
} else {
969987
let id = match num {
988+
BlockNumber::Hash { hash, .. } => BlockId::Hash(hash),
970989
BlockNumber::Num(num) => BlockId::Number(num),
971990
BlockNumber::Earliest => BlockId::Earliest,
972991
BlockNumber::Latest => BlockId::Latest,

rpc/src/v1/impls/parity.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
350350
(header.encoded(), None)
351351
} else {
352352
let id = match number {
353+
BlockNumber::Hash { hash, .. } => BlockId::Hash(hash),
353354
BlockNumber::Num(num) => BlockId::Number(num),
354355
BlockNumber::Earliest => BlockId::Earliest,
355356
BlockNumber::Latest => BlockId::Latest,
@@ -381,6 +382,7 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
381382
.collect()
382383
))
383384
},
385+
BlockNumber::Hash { hash, .. } => BlockId::Hash(hash),
384386
BlockNumber::Num(num) => BlockId::Number(num),
385387
BlockNumber::Earliest => BlockId::Earliest,
386388
BlockNumber::Latest => BlockId::Latest,
@@ -412,6 +414,7 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
412414
(state, header)
413415
} else {
414416
let id = match num {
417+
BlockNumber::Hash { hash, .. } => BlockId::Hash(hash),
415418
BlockNumber::Num(num) => BlockId::Number(num),
416419
BlockNumber::Earliest => BlockId::Earliest,
417420
BlockNumber::Latest => BlockId::Latest,

0 commit comments

Comments
 (0)