Skip to content

Commit

Permalink
refactor: use TransactionVec to persist tx pool
Browse files Browse the repository at this point in the history
  • Loading branch information
quake committed Aug 4, 2021
1 parent d60d154 commit e453fd4
Show file tree
Hide file tree
Showing 21 changed files with 215 additions and 715 deletions.
83 changes: 0 additions & 83 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion ckb-bin/src/subcommand/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn replay(args: ReplayArgs, async_handle: Handle) -> Result<(), ExitCode> {
)?;
let (shared, _) = shared_builder
.consensus(args.consensus.clone())
.tx_pool_config(args.config.tx_pool)
.tx_pool_config(args.config.tx_pool.clone())
.build()?;

if !args.tmp_target.is_dir() {
Expand Down
16 changes: 4 additions & 12 deletions ckb-bin/src/subcommand/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,10 @@ pub fn run(args: RunArgs, version: Version, async_handle: Handle) -> Result<(),
exit_handler.wait_for_exit();

info!("Finishing work, please wait...");
shared.tx_pool_controller().save_pool().map_err(|err| {
eprintln!("TxPool Error: {}", err);
ExitCode::Failure
})?;
drop(rpc_server);
drop(network_controller);
shared
.tx_pool_controller()
.persist_tx_pool()
.map_err(|err| {
eprintln!("TxPool Error: {}", err);
ExitCode::Failure
})?
.map_err(|err| {
eprintln!("TxPool Error: {}", err);
ExitCode::Failure
})?;
Ok(())
}
2 changes: 1 addition & 1 deletion test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ lazy_static = "1.4.0"
byteorder = "1.3.1"
jsonrpc-core = "18.0"

[target.'cfg(target_os="linux")'.dependencies]
[target.'cfg(not(target_os="windows"))'.dependencies]
nix = "0.20.0"

# Prevent this from interfering with workspaces
Expand Down
2 changes: 1 addition & 1 deletion test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ fn all_specs() -> Vec<Box<dyn Spec>> {
Box::new(TemplateSizeLimit),
Box::new(PoolReconcile),
Box::new(PoolResurrect),
#[cfg(target_os = "linux")]
#[cfg(not(target_os = "windows"))]
Box::new(PoolPersisted),
Box::new(TransactionRelayBasic),
Box::new(TransactionRelayLowFeeRate),
Expand Down
2 changes: 1 addition & 1 deletion test/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ impl Node {
drop(self.guard.take())
}

#[cfg(target_os = "linux")]
#[cfg(not(target_os = "windows"))]
pub fn stop_gracefully(&mut self) {
if let Some(mut guard) = self.guard.take() {
if !guard.killed {
Expand Down
4 changes: 2 additions & 2 deletions test/src/specs/tx_pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod depend_tx_in_same_block;
mod descendant;
mod different_txs_with_same_input;
mod limit;
#[cfg(target_os = "linux")]
#[cfg(not(target_os = "windows"))]
mod pool_persisted;
mod pool_reconcile;
mod pool_resurrect;
Expand All @@ -29,7 +29,7 @@ pub use depend_tx_in_same_block::*;
pub use descendant::*;
pub use different_txs_with_same_input::*;
pub use limit::*;
#[cfg(target_os = "linux")]
#[cfg(not(target_os = "windows"))]
pub use pool_persisted::*;
pub use pool_reconcile::*;
pub use pool_resurrect::*;
Expand Down
34 changes: 22 additions & 12 deletions test/src/specs/tx_pool/pool_persisted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ impl Spec for PoolPersisted {
mine_until_out_bootstrap_period(node0);

info!("Generate 6 txs on node0");
let mut txs_hash1 = Vec::new();
let mut txs_hash2 = Vec::new();
let mut hash = node0.generate_transaction();
txs_hash1.push(hash.clone());

(0..5).for_each(|_| {
let tx = node0.new_transaction(hash.clone());
hash = node0.rpc_client().send_transaction(tx.data().into());
txs_hash1.push(hash.clone());
});

info!("Generate 1 more blocks on node0");
Expand All @@ -32,7 +28,6 @@ impl Spec for PoolPersisted {
(0..5).for_each(|_| {
let tx = node0.new_transaction(hash.clone());
hash = node0.rpc_client().send_transaction(tx.data().into());
txs_hash2.push(hash.clone());
});

info!("Generate 1 more blocks on node0");
Expand All @@ -50,12 +45,27 @@ impl Spec for PoolPersisted {

let tx_pool_info_reloaded = node0.get_tip_tx_pool_info();
info!("TxPool should be same as before");
assert_eq!(tx_pool_info_original, tx_pool_info_reloaded);

info!("Check the specific values of TxPool state");
node0.assert_tx_pool_size(txs_hash2.len() as u64, txs_hash1.len() as u64);
assert!(tx_pool_info_reloaded.total_tx_size.value() > 0);
assert!(tx_pool_info_reloaded.total_tx_cycles.value() > 0);
assert!(tx_pool_info_reloaded.last_txs_updated_at.value() > 0);
info!("tx_pool_info_original: {:?}", tx_pool_info_original);
info!("tx_pool_info_reloaded: {:?}", tx_pool_info_reloaded);
assert_eq!(
tx_pool_info_original.proposed,
tx_pool_info_reloaded.proposed
);
assert_eq!(
tx_pool_info_original.orphan,
tx_pool_info_reloaded.orphan
);
assert_eq!(
tx_pool_info_original.pending,
tx_pool_info_reloaded.pending
);
assert_eq!(
tx_pool_info_original.total_tx_size,
tx_pool_info_reloaded.total_tx_size
);
assert_eq!(
tx_pool_info_original.total_tx_cycles,
tx_pool_info_reloaded.total_tx_cycles
);
}
}
18 changes: 0 additions & 18 deletions tx-pool/build.rs

This file was deleted.

10 changes: 0 additions & 10 deletions tx-pool/schemas/persisted.mol

This file was deleted.

67 changes: 0 additions & 67 deletions tx-pool/schemas/referenced.mol

This file was deleted.

Loading

0 comments on commit e453fd4

Please sign in to comment.