This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Integrate transaction pool to the proposal logic #80
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
482a074
reshuffle consensus libraries
rphmeier 917b092
polkadot-useful type definitions for statement table
rphmeier 8e2fd3c
begin BftService
rphmeier 776cf13
Merge branch 'master' into rh-split-bft-table
rphmeier 6abfed4
primary selection logic
rphmeier fc18524
bft service implementation without I/O
rphmeier 017fd51
extract out `BlockImport` trait
rphmeier 25990ee
Merge branch 'master' into rh-split-bft-table
rphmeier c33c3ff
allow bft primitives to compile on wasm
rphmeier acab9a3
Block builder (substrate)
gavofyork 1830fa7
take polkadot-consensus down to the core.
rphmeier 767a9d9
test for preemption
rphmeier 7fc4b4d
fix test build
rphmeier 9acd3f9
Fix wasm build
gavofyork ca5900f
Bulid on any block
gavofyork d11cfe1
Test for block builder.
gavofyork b973ccc
Block import tests for client.
gavofyork ec61865
Tidy ups
gavofyork 23638cd
clean up block builder instantiation
rphmeier dda6d24
Merge branch 'rh-split-bft-table' into rh-justification-verification
rphmeier 340ce39
justification verification logic
rphmeier 170b0d1
JustifiedHeader and import
rphmeier 6a1a851
Propert block generation for tests
arkpar 1352765
network and tablerouter trait
rphmeier 2758503
use statement import to drive creation of further statements
rphmeier a1247bd
Fixed rpc tests
arkpar a1a19b6
custom error type for consensus
rphmeier 40a9496
create proposer
rphmeier 9e4f273
asynchronous proposal evaluation
rphmeier 673fc2c
Merge branch 'master' into rh-justification-verification
rphmeier 8636b77
Merge branch 'rh-justification-verification' into rh-polkadot-propose
rphmeier a5c09c8
inherent transactions in polkadot runtime
rphmeier 7b1a563
fix tests to match real polkadot block constraints
rphmeier 8d08573
implicitly generate inherent functions
rphmeier 2abbe6c
add inherent transaction functionality to block body
rphmeier 5bace3a
Merge branch 'master' into rh-polkadot-propose
rphmeier a87afa7
block builder logic for polkadot
rphmeier e891649
some tests for the polkadot API
rphmeier 5b3556c
avoid redundancy in native code compatibility check
rphmeier ad8a576
helper for extracting nonce
rphmeier 40b5e4c
transaction pool implementation
rphmeier 760aeff
transaction pool
rphmeier 198ff7b
integrate transaction pool with proposer
rphmeier 3d052fb
Merge branch 'master' into rh-transaction-pool
rphmeier fd8e624
indentation
rphmeier 8458389
kill storage keys module
rphmeier 81ff2ad
accept new transactions to replace old
rphmeier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ use polkadot_runtime::runtime; | |
| use polkadot_executor::Executor as LocalDispatch; | ||
| use substrate_executor::{NativeExecutionDispatch, NativeExecutor}; | ||
| use state_machine::OverlayedChanges; | ||
| use primitives::{AccountId, SessionKey, Timestamp}; | ||
| use primitives::{AccountId, SessionKey, Timestamp, TxOrder}; | ||
| use primitives::block::{Id as BlockId, Block, Header, Body}; | ||
| use primitives::transaction::UncheckedTransaction; | ||
| use primitives::parachain::DutyRoster; | ||
|
|
@@ -85,6 +85,7 @@ impl From<client::error::Error> for Error { | |
| } | ||
| } | ||
|
|
||
| /// A builder for blocks. | ||
| pub trait BlockBuilder: Sized { | ||
| /// Push a non-inherent transaction. | ||
| fn push_transaction(&mut self, transaction: UncheckedTransaction) -> Result<()>; | ||
|
|
@@ -93,40 +94,64 @@ pub trait BlockBuilder: Sized { | |
| fn bake(self) -> Block; | ||
| } | ||
|
|
||
| /// A checked block identifier. | ||
| pub trait CheckedBlockId: Clone { | ||
| /// Yield the underlying block ID. | ||
| fn block_id(&self) -> &BlockId; | ||
| } | ||
|
|
||
| /// Trait encapsulating the Polkadot API. | ||
| /// | ||
| /// All calls should fail when the exact runtime is unknown. | ||
| pub trait PolkadotApi { | ||
| /// A checked block ID. Used to avoid redundancy of code check. | ||
| type CheckedBlockId: CheckedBlockId; | ||
| /// The type used to build blocks. | ||
| type BlockBuilder: BlockBuilder; | ||
|
|
||
| /// Check whether requests at the given block ID can be served. | ||
| /// | ||
| /// It should not be possible to instantiate this type without going | ||
| /// through this function. | ||
| fn check_id(&self, id: BlockId) -> Result<Self::CheckedBlockId>; | ||
|
|
||
| /// Get session keys at a given block. | ||
| fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>>; | ||
| fn session_keys(&self, at: &Self::CheckedBlockId) -> Result<Vec<SessionKey>>; | ||
|
|
||
| /// Get validators at a given block. | ||
| fn validators(&self, at: &BlockId) -> Result<Vec<AccountId>>; | ||
| fn validators(&self, at: &Self::CheckedBlockId) -> Result<Vec<AccountId>>; | ||
|
|
||
| /// Get the authority duty roster at a block. | ||
| fn duty_roster(&self, at: &BlockId) -> Result<DutyRoster>; | ||
| fn duty_roster(&self, at: &Self::CheckedBlockId) -> Result<DutyRoster>; | ||
|
|
||
| /// Get the timestamp registered at a block. | ||
| fn timestamp(&self, at: &BlockId) -> Result<Timestamp>; | ||
| fn timestamp(&self, at: &Self::CheckedBlockId) -> Result<Timestamp>; | ||
|
|
||
| /// Get the nonce of an account at a block. | ||
| fn nonce(&self, at: &Self::CheckedBlockId, account: AccountId) -> Result<TxOrder>; | ||
|
|
||
|
|
||
| /// Evaluate a block and see if it gives an error. | ||
| fn evaluate_block(&self, at: &BlockId, block: Block) -> Result<()>; | ||
| fn evaluate_block(&self, at: &Self::CheckedBlockId, block: Block) -> Result<()>; | ||
|
|
||
| /// Create a block builder on top of the parent block. | ||
| fn build_block(&self, parent: &BlockId, timestamp: u64) -> Result<Self::BlockBuilder>; | ||
| fn build_block(&self, parent: &Self::CheckedBlockId, timestamp: u64) -> Result<Self::BlockBuilder>; | ||
| } | ||
|
|
||
| /// A checked block ID used for the substrate-client implementation of CheckedBlockId; | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub struct CheckedId(BlockId); | ||
|
|
||
| impl CheckedBlockId for CheckedId { | ||
| fn block_id(&self) -> &BlockId { | ||
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| // set up the necessary scaffolding to execute the runtime. | ||
| macro_rules! with_runtime { | ||
| ($client: ident, $at: expr, $exec: expr) => {{ | ||
| // bail if the code is not the same as the natively linked. | ||
| if $client.code_at($at)? != LocalDispatch::native_equivalent() { | ||
| bail!(ErrorKind::UnknownRuntime); | ||
| } | ||
|
|
||
| $client.state_at($at).map_err(Error::from).and_then(|state| { | ||
| $client.state_at($at.block_id()).map_err(Error::from).and_then(|state| { | ||
| let mut changes = Default::default(); | ||
| let mut ext = state_machine::Ext { | ||
| overlay: &mut changes, | ||
|
|
@@ -141,33 +166,44 @@ macro_rules! with_runtime { | |
| impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>> | ||
| where ::client::error::Error: From<<<B as Backend>::State as state_machine::backend::Backend>::Error> | ||
| { | ||
| type CheckedBlockId = CheckedId; | ||
| type BlockBuilder = ClientBlockBuilder<B::State>; | ||
|
|
||
| fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> { | ||
| fn check_id(&self, id: BlockId) -> Result<CheckedId> { | ||
| // bail if the code is not the same as the natively linked. | ||
| if self.code_at(&id)? != LocalDispatch::native_equivalent() { | ||
| bail!(ErrorKind::UnknownRuntime); | ||
| } | ||
|
|
||
| Ok(CheckedId(id)) | ||
| } | ||
|
|
||
| fn session_keys(&self, at: &CheckedId) -> Result<Vec<SessionKey>> { | ||
| with_runtime!(self, at, ::runtime::consensus::authorities) | ||
| } | ||
|
|
||
| fn validators(&self, at: &BlockId) -> Result<Vec<AccountId>> { | ||
| fn validators(&self, at: &CheckedId) -> Result<Vec<AccountId>> { | ||
| with_runtime!(self, at, ::runtime::session::validators) | ||
| } | ||
|
|
||
| fn duty_roster(&self, at: &BlockId) -> Result<DutyRoster> { | ||
| fn duty_roster(&self, at: &CheckedId) -> Result<DutyRoster> { | ||
| with_runtime!(self, at, ::runtime::parachains::calculate_duty_roster) | ||
| } | ||
|
|
||
| fn timestamp(&self, at: &BlockId) -> Result<Timestamp> { | ||
| fn timestamp(&self, at: &CheckedId) -> Result<Timestamp> { | ||
| with_runtime!(self, at, ::runtime::timestamp::get) | ||
| } | ||
|
|
||
| fn evaluate_block(&self, at: &BlockId, block: Block) -> Result<()> { | ||
| fn evaluate_block(&self, at: &CheckedId, block: Block) -> Result<()> { | ||
| with_runtime!(self, at, || ::runtime::system::internal::execute_block(block)) | ||
| } | ||
|
|
||
| fn build_block(&self, parent: &BlockId, timestamp: Timestamp) -> Result<Self::BlockBuilder> { | ||
| if self.code_at(parent)? != LocalDispatch::native_equivalent() { | ||
| bail!(ErrorKind::UnknownRuntime); | ||
| } | ||
| fn nonce(&self, at: &Self::CheckedBlockId, account: AccountId) -> Result<TxOrder> { | ||
| with_runtime!(self, at, || ::runtime::system::nonce(account)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what ever happened to the plan to allow typed dispatching into wasm? poc-2?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. filed an issue: paritytech/polkadot#83 |
||
| } | ||
|
|
||
| fn build_block(&self, parent: &CheckedId, timestamp: Timestamp) -> Result<Self::BlockBuilder> { | ||
| let parent = parent.block_id(); | ||
| let header = Header { | ||
| parent_hash: self.block_hash_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))?, | ||
| number: self.block_number_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))? + 1, | ||
|
|
@@ -316,23 +352,24 @@ mod tests { | |
| #[test] | ||
| fn gets_session_and_validator_keys() { | ||
| let client = client(); | ||
| assert_eq!(client.session_keys(&BlockId::Number(0)).unwrap(), validators()); | ||
| assert_eq!(client.validators(&BlockId::Number(0)).unwrap(), validators()); | ||
| let id = client.check_id(BlockId::Number(0)).unwrap(); | ||
| assert_eq!(client.session_keys(&id).unwrap(), validators()); | ||
| assert_eq!(client.validators(&id).unwrap(), validators()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn build_block() { | ||
| let client = client(); | ||
|
|
||
| let block_builder = client.build_block(&BlockId::Number(0), 1_000_000).unwrap(); | ||
| let id = client.check_id(BlockId::Number(0)).unwrap(); | ||
| let block_builder = client.build_block(&id, 1_000_000).unwrap(); | ||
| let block = block_builder.bake(); | ||
|
|
||
| assert_eq!(block.header.number, 1); | ||
| } | ||
|
|
||
| #[test] | ||
| fn cannot_build_block_on_unknown_parent() { | ||
| let client = client(); | ||
| assert!(client.build_block(&BlockId::Number(100), 1_000_000).is_err()); | ||
| fn fails_to_check_id_for_unknown_block() { | ||
| assert!(client().check_id(BlockId::Number(100)).is_err()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
worth making this implement
AsRef?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.
potentially, but it's more overhead to implement the trait for any types