mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
committed by
Gav Wood
parent
1f717763e2
commit
1c5d6d59a7
+11
-6
@@ -192,7 +192,16 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn duty_roster(&self, at: &CheckedId) -> Result<DutyRoster> {
|
fn duty_roster(&self, at: &CheckedId) -> Result<DutyRoster> {
|
||||||
with_runtime!(self, at, ::runtime::Parachains::calculate_duty_roster)
|
// duty roster can only be queried at the start of a block,
|
||||||
|
// so we create a dummy.
|
||||||
|
let id = at.block_id();
|
||||||
|
let parent_hash = self.block_hash_from_id(id)?.ok_or(ErrorKind::UnknownBlock(*id))?;
|
||||||
|
let number = self.block_number_from_id(id)?.ok_or(ErrorKind::UnknownBlock(*id))? + 1;
|
||||||
|
|
||||||
|
with_runtime!(self, at, || {
|
||||||
|
::runtime::System::initialise(&number, &parent_hash, &Default::default());
|
||||||
|
::runtime::Parachains::calculate_duty_roster()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timestamp(&self, at: &CheckedId) -> Result<Timestamp> {
|
fn timestamp(&self, at: &CheckedId) -> Result<Timestamp> {
|
||||||
@@ -203,7 +212,7 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>>
|
|||||||
with_runtime!(self, at, || ::runtime::Executive::execute_block(block))
|
with_runtime!(self, at, || ::runtime::Executive::execute_block(block))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index(&self, at: &Self::CheckedBlockId, account: AccountId) -> Result<Index> {
|
fn index(&self, at: &CheckedId, account: AccountId) -> Result<Index> {
|
||||||
with_runtime!(self, at, || ::runtime::System::account_index(account))
|
with_runtime!(self, at, || ::runtime::System::account_index(account))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,10 +390,6 @@ mod tests {
|
|||||||
|| {
|
|| {
|
||||||
let mut storage = genesis_config.build_externalities();
|
let mut storage = genesis_config.build_externalities();
|
||||||
let block = ::client::genesis::construct_genesis_block(&storage);
|
let block = ::client::genesis::construct_genesis_block(&storage);
|
||||||
with_externalities(&mut storage, ||
|
|
||||||
// TODO: use api.rs to dispatch instead
|
|
||||||
runtime::System::initialise_genesis_state(&block.header)
|
|
||||||
);
|
|
||||||
(substrate_primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
|
(substrate_primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
|
||||||
}
|
}
|
||||||
).unwrap()
|
).unwrap()
|
||||||
|
|||||||
@@ -16,8 +16,7 @@
|
|||||||
|
|
||||||
//! Errors that can occur during the consensus process.
|
//! Errors that can occur during the consensus process.
|
||||||
|
|
||||||
use primitives::block::HeaderHash;
|
use primitives::block::{HeaderHash, Number};
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
links {
|
links {
|
||||||
PolkadotApi(::polkadot_api::Error, ::polkadot_api::ErrorKind);
|
PolkadotApi(::polkadot_api::Error, ::polkadot_api::ErrorKind);
|
||||||
@@ -41,6 +40,10 @@ error_chain! {
|
|||||||
description("Proposal had wrong parent hash."),
|
description("Proposal had wrong parent hash."),
|
||||||
display("Proposal had wrong parent hash. Expected {:?}, got {:?}", expected, got),
|
display("Proposal had wrong parent hash. Expected {:?}, got {:?}", expected, got),
|
||||||
}
|
}
|
||||||
|
WrongNumber(expected: Number, got: Number) {
|
||||||
|
description("Proposal had wrong number."),
|
||||||
|
display("Proposal had wrong number. Expected {:?}, got {:?}", expected, got),
|
||||||
|
}
|
||||||
ProposalTooLarge(size: usize) {
|
ProposalTooLarge(size: usize) {
|
||||||
description("Proposal exceeded the maximum size."),
|
description("Proposal exceeded the maximum size."),
|
||||||
display(
|
display(
|
||||||
|
|||||||
@@ -575,7 +575,7 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> {
|
|||||||
let substrate_block = Slicable::decode(&mut polkadot_block.encode().as_slice())
|
let substrate_block = Slicable::decode(&mut polkadot_block.encode().as_slice())
|
||||||
.expect("polkadot blocks defined to serialize to substrate blocks correctly; qed");
|
.expect("polkadot blocks defined to serialize to substrate blocks correctly; qed");
|
||||||
|
|
||||||
assert!(evaluate_proposal(&substrate_block, &*self.client, current_timestamp(), &self.parent_hash, &self.parent_id).is_ok());
|
assert!(evaluate_proposal(&substrate_block, &*self.client, current_timestamp(), &self.parent_hash, self.parent_number, &self.parent_id).is_ok());
|
||||||
|
|
||||||
Ok(substrate_block)
|
Ok(substrate_block)
|
||||||
}
|
}
|
||||||
@@ -583,7 +583,7 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> {
|
|||||||
// TODO: certain kinds of errors here should lead to a misbehavior report.
|
// TODO: certain kinds of errors here should lead to a misbehavior report.
|
||||||
fn evaluate(&self, proposal: &SubstrateBlock) -> Result<bool, Error> {
|
fn evaluate(&self, proposal: &SubstrateBlock) -> Result<bool, Error> {
|
||||||
debug!(target: "bft", "evaluating block on top of parent ({}, {:?})", self.parent_number, self.parent_hash);
|
debug!(target: "bft", "evaluating block on top of parent ({}, {:?})", self.parent_number, self.parent_hash);
|
||||||
match evaluate_proposal(proposal, &*self.client, current_timestamp(), &self.parent_hash, &self.parent_id) {
|
match evaluate_proposal(proposal, &*self.client, current_timestamp(), &self.parent_hash, self.parent_number, &self.parent_id) {
|
||||||
Ok(x) => Ok(x),
|
Ok(x) => Ok(x),
|
||||||
Err(e) => match *e.kind() {
|
Err(e) => match *e.kind() {
|
||||||
ErrorKind::PolkadotApi(polkadot_api::ErrorKind::Executor(_)) => Ok(false),
|
ErrorKind::PolkadotApi(polkadot_api::ErrorKind::Executor(_)) => Ok(false),
|
||||||
@@ -656,6 +656,7 @@ fn evaluate_proposal<C: PolkadotApi>(
|
|||||||
client: &C,
|
client: &C,
|
||||||
now: Timestamp,
|
now: Timestamp,
|
||||||
parent_hash: &HeaderHash,
|
parent_hash: &HeaderHash,
|
||||||
|
parent_number: BlockNumber,
|
||||||
parent_id: &C::CheckedBlockId,
|
parent_id: &C::CheckedBlockId,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
const MAX_TIMESTAMP_DRIFT: Timestamp = 4;
|
const MAX_TIMESTAMP_DRIFT: Timestamp = 4;
|
||||||
@@ -677,9 +678,9 @@ fn evaluate_proposal<C: PolkadotApi>(
|
|||||||
bail!(ErrorKind::WrongParentHash(*parent_hash, proposal.header.parent_hash));
|
bail!(ErrorKind::WrongParentHash(*parent_hash, proposal.header.parent_hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
// no need to check number because
|
if proposal.header.number != parent_number + 1 {
|
||||||
// a) we assume the parent is valid.
|
bail!(ErrorKind::WrongNumber(parent_number + 1, proposal.header.number))
|
||||||
// b) the runtime checks that `proposal.parent_hash` == `block_hash(proposal.number - 1)`
|
}
|
||||||
|
|
||||||
let block_timestamp = proposal.timestamp();
|
let block_timestamp = proposal.timestamp();
|
||||||
|
|
||||||
|
|||||||
@@ -249,12 +249,13 @@ fn start_bft<F, C>(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let input = messages.select(hash, network.bft_messages(), authorities).map_err(|e| e.into());
|
let input = messages.select(hash, network.bft_messages(), authorities).map_err(|e| e.into());
|
||||||
let output = BftSink { network: network, parent_hash: hash.clone(), _e: Default::default() };
|
let output = BftSink { network: network, parent_hash: hash.clone(), _e: Default::default() };
|
||||||
match bft_service.build_upon(&header, input, output) {
|
match bft_service.build_upon(&header, input, output) {
|
||||||
Ok(Some(bft)) => handle.spawn(bft),
|
Ok(Some(bft)) => handle.spawn(bft),
|
||||||
Ok(None) => {},
|
Ok(None) => {},
|
||||||
Err(e) => debug!("BFT agreement error: {:?}", e),
|
Err(e) => debug!(target: "bft","BFT agreement error: {:?}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -258,11 +258,6 @@ impl Service {
|
|||||||
let prepare_genesis = || {
|
let prepare_genesis = || {
|
||||||
storage = genesis_config.build_externalities();
|
storage = genesis_config.build_externalities();
|
||||||
let block = genesis::construct_genesis_block(&storage);
|
let block = genesis::construct_genesis_block(&storage);
|
||||||
with_externalities(&mut storage, || {
|
|
||||||
// TODO: use api.rs to dispatch instead
|
|
||||||
polkadot_runtime::System::initialise_genesis_state(&block.header);
|
|
||||||
info!("Genesis header hash: {}", polkadot_runtime::System::block_hash(0));
|
|
||||||
});
|
|
||||||
(primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
|
(primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user