Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
bad814f
txpool: don't maintain the pool during major sync
michalkucharczyk Dec 22, 2022
536df11
passing sync_oracle to maintain method
michalkucharczyk Dec 22, 2022
368653d
fixed: builder, txpool tests
michalkucharczyk Dec 22, 2022
b462bfc
Merge remote-tracking branch 'origin/master' into mku-txpool-avoid-cp…
michalkucharczyk Jan 10, 2023
f13c244
do not maintain tx-pool if node gone out of sync
michalkucharczyk Jan 10, 2023
8032569
EnactmentAction: all logic moved to EnactmentState
michalkucharczyk Jan 12, 2023
6149606
maintain guard logic moved directly to MaintainedTransactionPool
michalkucharczyk Jan 12, 2023
3b5ddc4
minor fixes
michalkucharczyk Jan 12, 2023
6fd64ff
EnactmentAction: all logic moved to EnactmentState (again)
michalkucharczyk Jan 12, 2023
f3487f0
SyncOracle fixes here and there
michalkucharczyk Jan 12, 2023
18e6aad
Merge remote-tracking branch 'origin/master' into mku-txpool-avoid-cp…
Jan 12, 2023
47f9fce
Update client/transaction-pool/src/enactment_state.rs
michalkucharczyk Jan 12, 2023
54cf4c0
Update client/transaction-pool/src/enactment_state.rs
michalkucharczyk Jan 12, 2023
d5261cc
sync_oracle removed
michalkucharczyk Jan 12, 2023
ed7fdf6
spelling + fmt + doc
michalkucharczyk Jan 12, 2023
c0f8d0f
Review suggestions applied
michalkucharczyk Jan 12, 2023
b12aee1
log::info -> debug
michalkucharczyk Jan 13, 2023
68e3192
Update client/transaction-pool/src/enactment_state.rs
michalkucharczyk Jan 13, 2023
05332a2
".git/.scripts/commands/fmt/fmt.sh"
Jan 16, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 7 additions & 1 deletion client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ pub trait SpawnTaskNetwork<Block: BlockT>:
sc_offchain::NetworkProvider
+ NetworkStateInfo
+ NetworkStatusProvider<Block>
+ sp_consensus::SyncOracle
+ Send
+ Sync
+ 'static
Expand All @@ -362,6 +363,7 @@ where
T: sc_offchain::NetworkProvider
+ NetworkStateInfo
+ NetworkStatusProvider<Block>
+ sp_consensus::SyncOracle
+ Send
+ Sync
+ 'static,
Expand Down Expand Up @@ -498,7 +500,11 @@ where
spawn_handle.spawn(
"txpool-notifications",
Some("transaction-pool"),
sc_transaction_pool::notification_future(client.clone(), transaction_pool.clone()),
sc_transaction_pool::notification_future(
client.clone(),
transaction_pool.clone(),
network.clone(),
),
);

spawn_handle.spawn(
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 @@ -28,6 +28,7 @@ sc-transaction-pool-api = { version = "4.0.0-dev", path = "./api" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }
sp-api = { version = "4.0.0-dev", path = "../../primitives/api" }
sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" }
sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" }
sp-core = { version = "7.0.0", path = "../../primitives/core" }
sp-runtime = { version = "7.0.0", path = "../../primitives/runtime" }
sp-tracing = { version = "6.0.0", path = "../../primitives/tracing" }
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 @@ -16,6 +16,7 @@ serde = { version = "1.0.136", features = ["derive"] }
thiserror = "1.0.30"
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../../primitives/runtime" }
sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" }

[dev-dependencies]
serde_json = "1.0"
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 @@ -307,7 +307,9 @@ pub enum ChainEvent<B: BlockT> {
#[async_trait]
pub trait MaintainedTransactionPool: TransactionPool {
/// Perform maintenance
async fn maintain(&self, event: ChainEvent<Self::Block>);
async fn maintain<SO>(&self, event: ChainEvent<Self::Block>, sync_oracle: Arc<SO>)
where
SO: sp_consensus::SyncOracle + std::marker::Send + std::marker::Sync + ?Sized;
}

/// Transaction pool interface for submitting local transactions that exposes a
Expand Down
7 changes: 5 additions & 2 deletions client/transaction-pool/src/enactment_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ where
pub fn force_update(&mut self, event: &ChainEvent<Block>) {
match event {
ChainEvent::NewBestBlock { hash, .. } => self.recent_best_block = *hash,
ChainEvent::Finalized { hash, .. } => self.recent_finalized_block = *hash,
ChainEvent::Finalized { hash, .. } => {
self.recent_best_block = *hash;
self.recent_finalized_block = *hash;
},
};
log::debug!(target: "txpool", "forced update: {:?}, {:?}", self.recent_best_block, self.recent_finalized_block);
}
Expand Down Expand Up @@ -608,6 +611,6 @@ mod enactment_state_tests {
let mut es = EnactmentState::new(a().hash, a().hash);

es.force_update(&ChainEvent::Finalized { hash: b1().hash, tree_route: Arc::from([]) });
assert_es_eq(&es, a(), b1());
assert_es_eq(&es, b1(), b1());
}
}
25 changes: 21 additions & 4 deletions client/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,11 @@ where
let pool = self.pool.clone();
let api = self.api.clone();

// do not process maintain txpool if node is out of sync
if tree_route.enacted().len() > 20 {
return
}

let (hash, block_number) = match tree_route.last() {
Some(HashAndNumber { hash, number }) => (hash, number),
None => {
Expand Down Expand Up @@ -721,7 +726,15 @@ where
Block: BlockT,
PoolApi: 'static + graph::ChainApi<Block = Block>,
{
async fn maintain(&self, event: ChainEvent<Self::Block>) {
async fn maintain<SO>(&self, event: ChainEvent<Self::Block>, sync_oracle: Arc<SO>)
where
SO: sp_consensus::SyncOracle + std::marker::Send + std::marker::Sync + ?Sized,
{
if sync_oracle.is_major_syncing() {
self.enactment_state.lock().force_update(&event);
return
}

let prev_finalized_block = self.enactment_state.lock().recent_finalized_block();
let compute_tree_route = |from, to| -> Result<TreeRoute<Block>, String> {
match self.api.tree_route(from, to) {
Expand Down Expand Up @@ -767,11 +780,15 @@ where
}

/// Inform the transaction pool about imported and finalized blocks.
pub async fn notification_future<Client, Pool, Block>(client: Arc<Client>, txpool: Arc<Pool>)
where
pub async fn notification_future<Client, Pool, Block, SyncOracle>(
client: Arc<Client>,
txpool: Arc<Pool>,
sync_oracle: Arc<SyncOracle>,
) where
Block: BlockT,
Client: sc_client_api::BlockchainEvents<Block>,
Pool: MaintainedTransactionPool<Block = Block>,
SyncOracle: sp_consensus::SyncOracle + std::marker::Sync + std::marker::Send + ?Sized,
{
let import_stream = client
.import_notification_stream()
Expand All @@ -780,6 +797,6 @@ where
let finality_stream = client.finality_notification_stream().map(Into::into).fuse();

futures::stream::select(import_stream, finality_stream)
.for_each(|evt| txpool.maintain(evt))
.for_each(|evt| txpool.maintain(evt, sync_oracle.clone()))
.await
}
Loading