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

txpool: don't maintain the pool during major sync #13004

Merged
merged 19 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
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.

1 change: 1 addition & 0 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ mod tests {

futures::executor::block_on(service.transaction_pool().maintain(
ChainEvent::NewBestBlock { hash: parent_header.hash(), tree_route: None },
Arc::new(sp_consensus::NoNetwork),
));

let mut proposer_factory = sc_basic_authorship::ProposerFactory::new(
Expand Down
78 changes: 47 additions & 31 deletions client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,14 @@ mod tests {
.unwrap();

block_on(
txpool.maintain(chain_event(
client
.expect_header(client.info().genesis_hash)
.expect("there should be header"),
)),
txpool.maintain(
chain_event(
client
.expect_header(client.info().genesis_hash)
.expect("there should be header"),
),
Arc::new(sp_consensus::NoNetwork),
),
);

let mut proposer_factory =
Expand Down Expand Up @@ -708,11 +711,14 @@ mod tests {
block_on(txpool.submit_at(&BlockId::number(0), SOURCE, vec![extrinsic(0)])).unwrap();

block_on(
txpool.maintain(chain_event(
client
.expect_header(client.info().genesis_hash)
.expect("there should be header"),
)),
txpool.maintain(
chain_event(
client
.expect_header(client.info().genesis_hash)
.expect("there should be header"),
),
Arc::new(sp_consensus::NoNetwork),
),
);

let mut proposer_factory =
Expand Down Expand Up @@ -809,11 +815,14 @@ mod tests {
};

block_on(
txpool.maintain(chain_event(
client
.expect_header(client.info().genesis_hash)
.expect("there should be header"),
)),
txpool.maintain(
chain_event(
client
.expect_header(client.info().genesis_hash)
.expect("there should be header"),
),
Arc::new(sp_consensus::NoNetwork),
),
);
assert_eq!(txpool.ready().count(), 7);

Expand All @@ -822,11 +831,10 @@ mod tests {
let hashof1 = block.hash();
block_on(client.import(BlockOrigin::Own, block)).unwrap();

block_on(
txpool.maintain(chain_event(
client.expect_header(hashof1).expect("there should be header"),
)),
);
block_on(txpool.maintain(
chain_event(client.expect_header(hashof1).expect("there should be header")),
Arc::new(sp_consensus::NoNetwork),
));
assert_eq!(txpool.ready().count(), 5);

// now let's make sure that we can still make some progress
Expand Down Expand Up @@ -872,7 +880,9 @@ mod tests {

block_on(txpool.submit_at(&BlockId::number(0), SOURCE, extrinsics)).unwrap();

block_on(txpool.maintain(chain_event(genesis_header.clone())));
block_on(
txpool.maintain(chain_event(genesis_header.clone()), Arc::new(sp_consensus::NoNetwork)),
);

let mut proposer_factory =
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), None, None);
Expand Down Expand Up @@ -958,11 +968,14 @@ mod tests {
.unwrap();

block_on(
txpool.maintain(chain_event(
client
.expect_header(client.info().genesis_hash)
.expect("there should be header"),
)),
txpool.maintain(
chain_event(
client
.expect_header(client.info().genesis_hash)
.expect("there should be header"),
),
Arc::new(sp_consensus::NoNetwork),
),
);
assert_eq!(txpool.ready().count(), MAX_SKIPPED_TRANSACTIONS * 3);

Expand Down Expand Up @@ -1020,11 +1033,14 @@ mod tests {
.unwrap();

block_on(
txpool.maintain(chain_event(
client
.expect_header(client.info().genesis_hash)
.expect("there should be header"),
)),
txpool.maintain(
chain_event(
client
.expect_header(client.info().genesis_hash)
.expect("there should be header"),
),
Arc::new(sp_consensus::NoNetwork),
),
);
assert_eq!(txpool.ready().count(), MAX_SKIPPED_TRANSACTIONS * 2 + 2);

Expand Down
11 changes: 7 additions & 4 deletions client/consensus/manual-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,13 @@ mod tests {

let header = client.header(created_block.hash).expect("db error").expect("imported above");
assert_eq!(header.number, 1);
pool.maintain(sc_transaction_pool_api::ChainEvent::NewBestBlock {
hash: header.hash(),
tree_route: None,
})
pool.maintain(
sc_transaction_pool_api::ChainEvent::NewBestBlock {
hash: header.hash(),
tree_route: None,
},
Arc::new(sp_consensus::NoNetwork),
)
.await;

let (tx1, rx1) = futures::channel::oneshot::channel();
Expand Down
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
2 changes: 2 additions & 0 deletions client/transaction-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ futures = "0.3.21"
futures-timer = "3.0.2"
linked-hash-map = "0.5.4"
log = "0.4.17"
num-traits = "0.2.8"
parking_lot = "0.12.1"
serde = { version = "1.0.136", features = ["derive"] }
thiserror = "1.0.30"
Expand All @@ -28,6 +29,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
Loading