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 Jul 30, 2021
1 parent d60d154 commit eb259be
Show file tree
Hide file tree
Showing 22 changed files with 203 additions and 706 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 benches/benches/benchmarks/overall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn setup_chain(txs_size: usize) -> (Shared, ChainController) {
.unwrap();

let network = dummy_network(&shared);
pack.take_tx_pool_builder().start(network);
pack.take_tx_pool_builder().start(network).unwrap();

let chain_service = ChainService::new(shared.clone(), pack.take_proposal_table());
let chain_controller = chain_service.start(Some("ChainService"));
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/block_assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn start_chain(consensus: Option<Consensus>) -> (ChainController, Shared) {
.unwrap();

let network = dummy_network(&shared);
pack.take_tx_pool_builder().start(network);
pack.take_tx_pool_builder().start(network).unwrap();

let chain_service = ChainService::new(shared.clone(), pack.take_proposal_table());
let chain_controller = chain_service.start::<&str>(None);
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub(crate) fn start_chain(consensus: Option<Consensus>) -> (ChainController, Sha
.build()
.unwrap();
let network = dummy_network(&shared);
pack.take_tx_pool_builder().start(network);
pack.take_tx_pool_builder().start(network).unwrap();

let chain_service = ChainService::new(shared.clone(), pack.take_proposal_table());
let chain_controller = chain_service.start::<&str>(None);
Expand Down
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
21 changes: 8 additions & 13 deletions ckb-bin/src/subcommand/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ pub fn run(args: RunArgs, version: Version, async_handle: Handle) -> Result<(),
);

let tx_pool_builder = pack.take_tx_pool_builder();
tx_pool_builder.start(network_controller);
tx_pool_builder.start(network_controller).map_err(|err| {
eprintln!("TxPool Error: {}", err);
ExitCode::Failure
})?;

let exit_handler_clone = exit_handler.clone();
ctrlc::set_handler(move || {
Expand All @@ -63,18 +66,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(())
}
3 changes: 2 additions & 1 deletion rpc/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ fn setup_rpc_test_suite(height: u64) -> RpcTestSuite {
};

pack.take_tx_pool_builder()
.start(network_controller.clone());
.start(network_controller.clone())
.unwrap();

// Build chain, insert [1, height) blocks
let mut parent = always_success_consensus().genesis_block;
Expand Down
2 changes: 1 addition & 1 deletion sync/src/relayer/tests/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub(crate) fn build_chain(tip: BlockNumber) -> (Relayer, OutPoint) {
};

let network = dummy_network(&shared);
pack.take_tx_pool_builder().start(network);
pack.take_tx_pool_builder().start(network).unwrap();

let chain_controller = {
let chain_service = ChainService::new(shared.clone(), pack.take_proposal_table());
Expand Down
12 changes: 8 additions & 4 deletions test/src/specs/tx_pool/pool_persisted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ 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);
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
);

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);
}
}
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 eb259be

Please sign in to comment.