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
Produce block always on updated transaction pool state #5227
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
550602e
make sure return ready iterator once state is updated
NikVolf 2b881eb
update sc_basic_authorship tests
NikVolf 341a2fb
update node tests
NikVolf c831275
fix manual seal
NikVolf 7136bd3
actually fix service test
NikVolf 31ea82e
add tests
NikVolf c97e9d6
Update client/basic-authorship/src/basic_authorship.rs
NikVolf 532351d
helper function
NikVolf 4b3bd80
review suggestions
NikVolf bbf0b0a
warning and continue
NikVolf b08b6e5
add debug log
NikVolf 00c15b0
use futures::chennel::oneshot
NikVolf 3b01817
use declaration bound
NikVolf e7e5e76
no option for updated_at
NikVolf b109316
no allocation
NikVolf 8c53a14
ready_at / ready
NikVolf f941891
Merge remote-tracking branch 'origin/master' into nv-txpool-poll
NikVolf f5a5e0d
Update client/transaction-pool/src/lib.rs
NikVolf 335ba7d
Update client/transaction-pool/src/lib.rs
NikVolf 7bb7eff
Update client/transaction-pool/src/lib.rs
NikVolf a7c65be
Update client/transaction-pool/src/lib.rs
NikVolf 24be207
Update client/transaction-pool/src/lib.rs
NikVolf 65375b2
Update client/transaction-pool/src/lib.rs
NikVolf 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
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 |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ use sp_transaction_pool::{TransactionPool, InPoolTransaction}; | |
| use sc_telemetry::{telemetry, CONSENSUS_INFO}; | ||
| use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider}; | ||
| use sp_api::{ProvideRuntimeApi, ApiExt}; | ||
| use futures::prelude::*; | ||
| use futures::{executor, future, future::Either}; | ||
| use sp_blockchain::{HeaderBackend, ApplyExtrinsicFailed}; | ||
| use std::marker::PhantomData; | ||
|
|
||
|
|
@@ -210,7 +210,18 @@ impl<A, B, Block, C> ProposerInner<B, Block, C, A> | |
| let mut is_first = true; | ||
| let mut skipped = 0; | ||
| let mut unqueue_invalid = Vec::new(); | ||
| let pending_iterator = self.transaction_pool.ready(); | ||
| let pending_iterator = match executor::block_on(future::select( | ||
| self.transaction_pool.ready_at(self.parent_number), | ||
| futures_timer::Delay::new((deadline - (self.now)()) / 8), | ||
| )) { | ||
| Either::Left((iterator, _)) => iterator, | ||
| Either::Right(_) => { | ||
| log::warn!( | ||
| "Timeout fired waiting for transaction pool to be ready. Proceeding to block production anyway.", | ||
| ); | ||
| self.transaction_pool.ready() | ||
| } | ||
| }; | ||
|
|
||
| debug!("Attempting to push transactions from the pool."); | ||
| debug!("Pool status: {:?}", self.transaction_pool.status()); | ||
|
|
@@ -304,10 +315,12 @@ mod tests { | |
| prelude::*, | ||
| runtime::{Extrinsic, Transfer}, | ||
| }; | ||
| use sp_transaction_pool::{ChainEvent, MaintainedTransactionPool}; | ||
| use sc_transaction_pool::{BasicPool, FullChainApi}; | ||
| use sp_api::Core; | ||
| use backend::Backend; | ||
| use sp_blockchain::HeaderBackend; | ||
| use sp_runtime::traits::NumberFor; | ||
|
|
||
| fn extrinsic(nonce: u64) -> Extrinsic { | ||
| Transfer { | ||
|
|
@@ -318,6 +331,17 @@ mod tests { | |
| }.into_signed_tx() | ||
| } | ||
|
|
||
| fn chain_event<B: BlockT>(block_number: u64, header: B::Header) -> ChainEvent<B> | ||
| where NumberFor<B>: From<u64> | ||
| { | ||
| ChainEvent::NewBlock { | ||
| id: BlockId::Number(block_number.into()), | ||
| retracted: vec![], | ||
| is_new_best: true, | ||
| header: header, | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn should_cease_building_block_when_deadline_is_reached() { | ||
| // given | ||
|
|
@@ -330,16 +354,27 @@ mod tests { | |
| txpool.submit_at(&BlockId::number(0), vec![extrinsic(0), extrinsic(1)]) | ||
| ).unwrap(); | ||
|
|
||
| futures::executor::block_on( | ||
| txpool.maintain(chain_event( | ||
| 0, | ||
| client.header(&BlockId::Number(0u64)).expect("header get error").expect("there should be header") | ||
| )) | ||
| ); | ||
|
|
||
| let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone()); | ||
|
|
||
| let cell = Mutex::new(time::Instant::now()); | ||
| let cell = Mutex::new((false, time::Instant::now())); | ||
| let mut proposer = proposer_factory.init_with_now( | ||
| &client.header(&BlockId::number(0)).unwrap().unwrap(), | ||
| Box::new(move || { | ||
| let mut value = cell.lock(); | ||
| let old = *value; | ||
| if !value.0 { | ||
| value.0 = true; | ||
| return value.1; | ||
| } | ||
| let old = value.1; | ||
| let new = old + time::Duration::from_secs(2); | ||
| *value = new; | ||
| *value = (true, new); | ||
| old | ||
| }) | ||
| ); | ||
|
|
@@ -371,6 +406,13 @@ mod tests { | |
| txpool.submit_at(&BlockId::number(0), vec![extrinsic(0)]), | ||
| ).unwrap(); | ||
|
|
||
| futures::executor::block_on( | ||
| txpool.maintain(chain_event( | ||
| 0, | ||
| client.header(&BlockId::Number(0u64)).expect("header get error").expect("there should be header") | ||
| )) | ||
| ); | ||
|
|
||
| let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone()); | ||
|
|
||
| let mut proposer = proposer_factory.init_with_now( | ||
|
|
@@ -459,15 +501,26 @@ mod tests { | |
| block | ||
| }; | ||
|
|
||
| futures::executor::block_on( | ||
| txpool.maintain(chain_event( | ||
| 0, | ||
| client.header(&BlockId::Number(0u64)).expect("header get error").expect("there should be header") | ||
| )) | ||
| ); | ||
|
|
||
| // let's create one block and import it | ||
| let block = propose_block(&client, 0, 2, 7); | ||
| client.import(BlockOrigin::Own, block).unwrap(); | ||
|
|
||
| // now let's make sure that we can still make some progress | ||
| futures::executor::block_on( | ||
| txpool.maintain(chain_event( | ||
| 1, | ||
| client.header(&BlockId::Number(1)).expect("header get error").expect("there should be header") | ||
| )) | ||
| ); | ||
|
|
||
| // This is most likely incorrect, and caused by #5139 | ||
| let tx_remaining = 0; | ||
| let block = propose_block(&client, 1, 2, tx_remaining); | ||
| // now let's make sure that we can still make some progress | ||
| let block = propose_block(&client, 1, 2, 5); | ||
|
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. Why did we had before
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. There were 7 initially, and 2 was included in previous block |
||
| client.import(BlockOrigin::Own, block).unwrap(); | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.