Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Finalized block event triggers tx maintanance #12305

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
4995ead
finalized block event triggers tx maintanance
michalkucharczyk Sep 20, 2022
339636e
tx-pool: enactment helper introduced
michalkucharczyk Sep 22, 2022
cce685b
tx-pool: ChainApi: added tree_route method
michalkucharczyk Sep 26, 2022
a7c8035
enactment logic implemented + tests
michalkucharczyk Sep 26, 2022
cd27bc5
Some additional tests
michalkucharczyk Sep 27, 2022
9090201
minor improvements
michalkucharczyk Sep 27, 2022
8479b64
trigger CI job
michalkucharczyk Sep 27, 2022
e86d1bb
Merge remote-tracking branch 'origin/master' into mku-finalized-event…
michalkucharczyk Sep 27, 2022
deb7eab
fix compilation errors
michalkucharczyk Sep 28, 2022
cff7bd8
formatting
michalkucharczyk Sep 28, 2022
69040e9
trait removed
michalkucharczyk Sep 28, 2022
e367ffd
implementation slightly simplified
michalkucharczyk Sep 28, 2022
eb0a3b0
get rid of Arc<> in EnactmentState return value
michalkucharczyk Sep 28, 2022
c78f904
minor improvement
michalkucharczyk Sep 28, 2022
0c89000
Apply suggestions from code review
michalkucharczyk Sep 30, 2022
e75b180
Apply suggestions from code review
michalkucharczyk Sep 30, 2022
3a7f433
comment updated + formatting
michalkucharczyk Sep 30, 2022
a285f57
Apply suggestions from code review
michalkucharczyk Oct 1, 2022
26f8d96
formatting
michalkucharczyk Oct 1, 2022
4826e06
Merge remote-tracking branch 'origin/master' into mku-finalized-event…
michalkucharczyk Oct 3, 2022
7d59e8d
finalization notification bug fix
michalkucharczyk Oct 3, 2022
d0cc123
added error message on tree_route failure
michalkucharczyk Oct 3, 2022
7d8f162
Merge remote-tracking branch 'origin/master' into mku-finalized-event…
michalkucharczyk Oct 4, 2022
57b9192
Apply suggestions from code review
michalkucharczyk Oct 4, 2022
1e3af7e
use provided tree_route in Finalized event
michalkucharczyk Oct 4, 2022
cfd7f63
Option removed from ChainApi::tree_route
michalkucharczyk Oct 4, 2022
637a7ab
doc added, test and logs improved
michalkucharczyk Oct 4, 2022
6bfceca
handle_enactment aligned with original implementation
michalkucharczyk Oct 4, 2022
80f5216
use async-await
andresilva Oct 4, 2022
79c6739
Apply suggestions from code review
michalkucharczyk Oct 4, 2022
d7de511
Apply suggestions from code review
michalkucharczyk Oct 4, 2022
29e31b3
formatting + warn->debug
michalkucharczyk Oct 4, 2022
4bebf96
compilation error fix
michalkucharczyk Oct 4, 2022
0ef2a75
enactment_state initializers added
michalkucharczyk Oct 5, 2022
3793021
enactment_state: Option removed
michalkucharczyk Oct 5, 2022
d0d3d54
Merge remote-tracking branch 'origin/master' into mku-finalized-event…
michalkucharczyk Oct 5, 2022
8d26c23
manual-seal: compilation & tests fix
michalkucharczyk Oct 5, 2022
937daab
manual-seal: tests fixed
michalkucharczyk Oct 5, 2022
fef7e86
tests cleanup
michalkucharczyk Oct 5, 2022
49e4b4c
another compilation error fixed
michalkucharczyk Oct 5, 2022
3f038b5
TreeRoute::new added
michalkucharczyk Oct 7, 2022
0b6b28b
get rid of pub hack
michalkucharczyk Oct 7, 2022
36fb53b
one more test added
michalkucharczyk Oct 7, 2022
7d081b6
Merge remote-tracking branch 'origin/mku-finalized-tx-maintenance-imp…
michalkucharczyk Oct 7, 2022
65c41f5
formatting
michalkucharczyk Oct 7, 2022
7519a1b
Merge remote-tracking branch 'origin/master' into mku-finalized-event…
michalkucharczyk Oct 7, 2022
8e74825
Merge remote-tracking branch 'origin/master' into mku-finalized-event…
michalkucharczyk Oct 7, 2022
763c51c
TreeRoute::new doc added + formatting
michalkucharczyk Oct 7, 2022
1b49dd1
Apply suggestions from code review
michalkucharczyk Oct 7, 2022
cf98315
(bool,Option) simplified to Option
michalkucharczyk Oct 7, 2022
7f35983
log message improved
michalkucharczyk Oct 7, 2022
f46d5b6
Merge remote-tracking branch 'origin/master' into mku-finalized-event…
michalkucharczyk Oct 10, 2022
32a9522
yet another review suggestions applied
michalkucharczyk Oct 10, 2022
64a2ec0
get rid of hash in handle_enactment
michalkucharczyk Oct 10, 2022
61f9b92
Apply suggestions from code review
michalkucharczyk Oct 11, 2022
df3eec6
Update client/transaction-pool/src/lib.rs
michalkucharczyk Oct 11, 2022
d35c651
minor corrections
michalkucharczyk Oct 11, 2022
649bbf3
EnactmentState moved to new file
michalkucharczyk Oct 11, 2022
dab0fc3
File header corrected
michalkucharczyk Oct 11, 2022
63072de
error formatting aligned with codebase
michalkucharczyk Oct 11, 2022
e6ba411
Apply suggestions from code review
michalkucharczyk Oct 11, 2022
fdc6bd5
remove commented code
andresilva Oct 11, 2022
6ae40f6
small nits
andresilva Oct 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 19 additions & 9 deletions client/consensus/manual-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,8 @@ pub async fn run_instant_seal_and_finalize<B, BI, CB, E, C, TP, SC, CIDP, P>(
mod tests {
use super::*;
use sc_basic_authorship::ProposerFactory;
use sc_client_api::BlockBackend;
use sc_consensus::ImportedAux;
use sc_transaction_pool::{BasicPool, Options, RevalidationType};
use sc_transaction_pool::{BasicPool, FullChainApi, Options, RevalidationType};
use sc_transaction_pool_api::{MaintainedTransactionPool, TransactionPool, TransactionSource};
use sp_inherents::InherentData;
use sp_runtime::generic::{BlockId, Digest, DigestItem};
Expand Down Expand Up @@ -359,6 +358,7 @@ mod tests {
let (client, select_chain) = builder.build_with_longest_chain();
let client = Arc::new(client);
let spawner = sp_core::testing::TaskExecutor::new();
let genesis_hash = client.header(&BlockId::Number(0)).unwrap().unwrap().hash();
let pool = Arc::new(BasicPool::with_revalidation_type(
Options::default(),
true.into(),
Expand All @@ -367,6 +367,8 @@ mod tests {
RevalidationType::Full,
spawner.clone(),
0,
genesis_hash,
genesis_hash,
));
let env = ProposerFactory::new(spawner.clone(), client.clone(), pool.clone(), None, None);
// this test checks that blocks are created as soon as transactions are imported into the
Expand Down Expand Up @@ -429,6 +431,7 @@ mod tests {
let (client, select_chain) = builder.build_with_longest_chain();
let client = Arc::new(client);
let spawner = sp_core::testing::TaskExecutor::new();
let genesis_hash = client.header(&BlockId::Number(0)).unwrap().unwrap().hash();
let pool = Arc::new(BasicPool::with_revalidation_type(
Options::default(),
true.into(),
Expand All @@ -437,6 +440,8 @@ mod tests {
RevalidationType::Full,
spawner.clone(),
0,
genesis_hash,
genesis_hash,
));
let env = ProposerFactory::new(spawner.clone(), client.clone(), pool.clone(), None, None);
// this test checks that blocks are created as soon as an engine command is sent over the
Expand Down Expand Up @@ -505,8 +510,13 @@ mod tests {
let builder = TestClientBuilder::new();
let (client, select_chain) = builder.build_with_longest_chain();
let client = Arc::new(client);
let pool_api = api();
let pool_api = Arc::new(FullChainApi::new(
client.clone(),
None,
&sp_core::testing::TaskExecutor::new(),
));
let spawner = sp_core::testing::TaskExecutor::new();
let genesis_hash = client.header(&BlockId::Number(0)).unwrap().unwrap().hash();
let pool = Arc::new(BasicPool::with_revalidation_type(
Options::default(),
true.into(),
Expand All @@ -515,6 +525,8 @@ mod tests {
RevalidationType::Full,
spawner.clone(),
0,
genesis_hash,
genesis_hash,
));
let env = ProposerFactory::new(spawner.clone(), client.clone(), pool.clone(), None, None);
// this test checks that blocks are created as soon as an engine command is sent over the
Expand Down Expand Up @@ -550,7 +562,6 @@ mod tests {
.await
.unwrap();
let created_block = rx.await.unwrap().unwrap();
pool_api.increment_nonce(Alice.into());

// assert that the background task returns ok
assert_eq!(
Expand All @@ -566,8 +577,7 @@ mod tests {
}
}
);
let block = client.block(&BlockId::Number(1)).unwrap().unwrap().block;
pool_api.add_block(block, true);

assert!(pool.submit_one(&BlockId::Number(1), SOURCE, uxt(Alice, 1)).await.is_ok());

let header = client.header(&BlockId::Number(1)).expect("db error").expect("imported above");
Expand All @@ -588,9 +598,6 @@ mod tests {
.await
.is_ok());
assert_matches::assert_matches!(rx1.await.expect("should be no error receiving"), Ok(_));
let block = client.block(&BlockId::Number(2)).unwrap().unwrap().block;
pool_api.add_block(block, true);
pool_api.increment_nonce(Alice.into());

assert!(pool.submit_one(&BlockId::Number(1), SOURCE, uxt(Bob, 0)).await.is_ok());
let (tx2, rx2) = futures::channel::oneshot::channel();
Expand All @@ -614,6 +621,7 @@ mod tests {
let (client, select_chain) = builder.build_with_longest_chain();
let client = Arc::new(client);
let spawner = sp_core::testing::TaskExecutor::new();
let genesis_hash = client.header(&BlockId::Number(0)).unwrap().unwrap().hash();
let pool = Arc::new(BasicPool::with_revalidation_type(
Options::default(),
true.into(),
Expand All @@ -622,6 +630,8 @@ mod tests {
RevalidationType::Full,
spawner.clone(),
0,
genesis_hash,
genesis_hash,
));
let env = ProposerFactory::new(spawner.clone(), client.clone(), pool.clone(), None, None);

Expand Down
1 change: 1 addition & 0 deletions client/transaction-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
async-trait = "0.1.57"
codec = { package = "parity-scale-codec", version = "3.0.0" }
futures = "0.3.21"
futures-timer = "3.0.2"
Expand Down
1 change: 1 addition & 0 deletions client/transaction-pool/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/paritytech/substrate/"
description = "Transaction pool client facing API."

[dependencies]
async-trait = "0.1.57"
futures = "0.3.21"
log = "0.4.17"
serde = { version = "1.0.136", features = ["derive"] }
Expand Down
4 changes: 3 additions & 1 deletion client/transaction-pool/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

pub mod error;

use async_trait::async_trait;
use futures::{Future, Stream};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use sp_runtime::{
Expand Down Expand Up @@ -298,9 +299,10 @@ pub enum ChainEvent<B: BlockT> {
}

/// Trait for transaction pool maintenance.
#[async_trait]
pub trait MaintainedTransactionPool: TransactionPool {
/// Perform maintenance
fn maintain(&self, event: ChainEvent<Self::Block>) -> Pin<Box<dyn Future<Output = ()> + Send>>;
async fn maintain(&self, event: ChainEvent<Self::Block>);
}

/// Transaction pool interface for submitting local transactions that exposes a
Expand Down
8 changes: 8 additions & 0 deletions client/transaction-pool/benches/basics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ impl ChainApi for TestApi {
) -> Result<Option<<Self::Block as BlockT>::Header>, Self::Error> {
Ok(None)
}

fn tree_route(
&self,
_from: <Self::Block as BlockT>::Hash,
_to: <Self::Block as BlockT>::Hash,
) -> Result<sp_blockchain::TreeRoute<Self::Block>, Self::Error> {
unimplemented!()
}
}

fn uxt(transfer: Transfer) -> Extrinsic {
Expand Down
30 changes: 24 additions & 6 deletions client/transaction-pool/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use std::{marker::PhantomData, pin::Pin, sync::Arc};
use prometheus_endpoint::Registry as PrometheusRegistry;
use sc_client_api::{blockchain::HeaderBackend, BlockBackend};
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_blockchain::{HeaderMetadata, TreeRoute};
use sp_core::traits::SpawnEssentialNamed;
use sp_runtime::{
generic::BlockId,
Expand Down Expand Up @@ -111,8 +112,11 @@ impl<Client, Block> FullChainApi<Client, Block> {
impl<Client, Block> graph::ChainApi for FullChainApi<Client, Block>
where
Block: BlockT,
Client:
ProvideRuntimeApi<Block> + BlockBackend<Block> + BlockIdTo<Block> + HeaderBackend<Block>,
Client: ProvideRuntimeApi<Block>
+ BlockBackend<Block>
+ BlockIdTo<Block>
+ HeaderBackend<Block>
+ HeaderMetadata<Block, Error = sp_blockchain::Error>,
Client: Send + Sync + 'static,
Client::Api: TaggedTransactionQueue<Block>,
{
Expand Down Expand Up @@ -190,6 +194,14 @@ where
) -> Result<Option<<Self::Block as BlockT>::Header>, Self::Error> {
self.client.header(*at).map_err(Into::into)
}

fn tree_route(
&self,
from: <Self::Block as BlockT>::Hash,
to: <Self::Block as BlockT>::Hash,
) -> Result<TreeRoute<Self::Block>, Self::Error> {
sp_blockchain::tree_route::<Block, Client>(&*self.client, from, to).map_err(Into::into)
}
}

/// Helper function to validate a transaction using a full chain API.
Expand All @@ -202,8 +214,11 @@ fn validate_transaction_blocking<Client, Block>(
) -> error::Result<TransactionValidity>
where
Block: BlockT,
Client:
ProvideRuntimeApi<Block> + BlockBackend<Block> + BlockIdTo<Block> + HeaderBackend<Block>,
Client: ProvideRuntimeApi<Block>
+ BlockBackend<Block>
+ BlockIdTo<Block>
+ HeaderBackend<Block>
+ HeaderMetadata<Block, Error = sp_blockchain::Error>,
Client: Send + Sync + 'static,
Client::Api: TaggedTransactionQueue<Block>,
{
Expand Down Expand Up @@ -264,8 +279,11 @@ where
impl<Client, Block> FullChainApi<Client, Block>
where
Block: BlockT,
Client:
ProvideRuntimeApi<Block> + BlockBackend<Block> + BlockIdTo<Block> + HeaderBackend<Block>,
Client: ProvideRuntimeApi<Block>
+ BlockBackend<Block>
+ BlockIdTo<Block>
+ HeaderBackend<Block>
+ HeaderMetadata<Block, Error = sp_blockchain::Error>,
Client: Send + Sync + 'static,
Client::Api: TaggedTransactionQueue<Block>,
{
Expand Down
Loading