Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate the pool in the state machine
- Loading branch information
1 parent
5058aba
commit 3b74071
Showing
3 changed files
with
137 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use ledger::{ | ||
transaction_pool::{ | ||
diff::{BestTipDiff, DiffVerified}, | ||
ApplyDecision, | ||
RevalidateKind::EntirePool, | ||
}, | ||
Account, BaseLedger, Mask, | ||
}; | ||
|
||
enum TransactionPoolAction { | ||
BestTipChanged { | ||
best_tip: Mask, | ||
}, | ||
ApplyVerifiedDiff { | ||
diff: DiffVerified, | ||
is_sender_local: bool, | ||
}, | ||
ApplyTransitionFrontierDiff { | ||
best_tip: Mask, | ||
diff: BestTipDiff, | ||
}, | ||
// Rebroadcast locally generated pool items every 10 minutes. Do so for 50 | ||
// minutes - at most 5 rebroadcasts - before giving up. | ||
Rebroadcast, | ||
} | ||
|
||
impl redux::EnablingCondition<crate::State> for TransactionPoolAction { | ||
fn is_enabled(&self, state: &crate::State, time: redux::Timestamp) -> bool { | ||
true | ||
} | ||
} | ||
|
||
pub struct TransactionPoolState { | ||
pool: ledger::transaction_pool::TransactionPool, | ||
} | ||
|
||
type TransactionPoolActionWithMetaRef<'a> = redux::ActionWithMeta<&'a TransactionPoolAction>; | ||
|
||
impl TransactionPoolState { | ||
pub fn reducer(&mut self, action: TransactionPoolActionWithMetaRef<'_>) { | ||
use TransactionPoolAction::*; | ||
|
||
let (action, meta) = action.split(); | ||
match action { | ||
BestTipChanged { best_tip } => { | ||
self.pool.on_new_best_tip(best_tip.clone()); | ||
} | ||
ApplyVerifiedDiff { | ||
diff, | ||
is_sender_local, | ||
} => match self.pool.unsafe_apply(diff, *is_sender_local) { | ||
Ok((ApplyDecision::Accept, accepted, rejected)) => todo!(), | ||
Ok((ApplyDecision::Reject, accepted, rejected)) => todo!(), | ||
Err(_) => todo!(), | ||
}, | ||
ApplyTransitionFrontierDiff { best_tip, diff } => { | ||
self.pool | ||
.handle_transition_frontier_diff(diff, best_tip.clone()); | ||
} | ||
Rebroadcast => todo!(), | ||
} | ||
} | ||
} |