-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from nervosnetwork/quake/tcp-subscription
feat: index the pending txs in the ckb tx-pool
- Loading branch information
Showing
6 changed files
with
342 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod indexer; | ||
pub mod pool; | ||
pub mod service; | ||
pub mod store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use ckb_types::{core::TransactionView, packed::OutPoint}; | ||
use std::collections::HashSet; | ||
|
||
/// an overlay to index the pending txs in the ckb tx pool, | ||
/// currently only supports removals of dead cells from the pending txs | ||
pub struct Pool { | ||
dead_cells: HashSet<OutPoint>, | ||
} | ||
|
||
impl Pool { | ||
pub fn new() -> Self { | ||
Self { | ||
dead_cells: HashSet::new(), | ||
} | ||
} | ||
|
||
// the tx has been comitted in a block, it should be removed from pending dead cells | ||
pub fn transaction_commited(&mut self, tx: &TransactionView) { | ||
for input in tx.inputs() { | ||
self.dead_cells.remove(&input.previous_output()); | ||
} | ||
} | ||
|
||
// the tx has been rejected for some reason, it should be removed from pending dead cells | ||
pub fn transaction_rejected(&mut self, tx: &TransactionView) { | ||
for input in tx.inputs() { | ||
self.dead_cells.remove(&input.previous_output()); | ||
} | ||
} | ||
|
||
// a new tx is submitted to the pool, mark its inputs as dead cells | ||
pub fn new_transaction(&mut self, tx: &TransactionView) { | ||
for input in tx.inputs() { | ||
self.dead_cells.insert(input.previous_output()); | ||
} | ||
} | ||
|
||
pub fn is_consumed_by_pool_tx(&self, out_point: &OutPoint) -> bool { | ||
self.dead_cells.contains(out_point) | ||
} | ||
|
||
pub fn transactions_commited(&mut self, txs: &[TransactionView]) { | ||
for tx in txs { | ||
self.transaction_commited(tx); | ||
} | ||
} | ||
} |
Oops, something went wrong.