forked from kaspanet/rusty-kaspa
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace by fee on mempool (kaspanet#499)
* Replace by fee on mempool with tests * Add a custom RemovalReason -- ReplacedByFee * Let `MinerManager` handle replace by fee (RBF) for RPC and P2P * Refines success conditions and process of RBF policies * Add an RPC `submit_transaction_replacement` method * fix fmt * Fix CLI Build WASM32 error * Avoid breaking wRPC * Extend some tests coverage to all priority, orphan & RBF policy combinations * Let RBF fail early or at least before checking transaction scripts in consensus * Cleaning * More cleaning * Use contextual instead of compute mass in RBF eviction rule * Avoid collision with another PR * Avoid collision with another PR (2) * Extended test coverage of RBF * Extended test coverage of RBF (2) * Rename `TransactionBatchValidationArgs` to `TransactionValidationBatchArgs` * Add comments * Assert instead of condition * Add an `RbfPolicy` parameter to mining manager tx validate_and_insert_... fns * Infer RBF policy from unorphaned transaction * Apply the RBF policy to all orphan-related cases * In Rbf allowed mode, check feerate threshold vs all double spends (i.e., compare to the max) * Minor hashset optimization * Rename: fee_per_mass -> feerate * Use rbf policy arg for post processing step as well * Renames and comments * Relaxation: fail gracefully if rbf replaced tx is missing (also fixes an edge case where mempool duplication resulted in this scenario) * Tx id is appended by the caller anyway --------- Co-authored-by: Tiram <[email protected]> Co-authored-by: Michael Sutton <[email protected]>
- Loading branch information
1 parent
6a56461
commit 56c19c9
Showing
44 changed files
with
1,455 additions
and
308 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::collections::HashMap; | ||
|
||
use crate::tx::TransactionId; | ||
|
||
/// A struct provided to consensus for transaction validation processing calls | ||
#[derive(Clone, Debug, Default)] | ||
pub struct TransactionValidationArgs { | ||
/// Optional fee/mass threshold above which a bound transaction in not rejected | ||
pub feerate_threshold: Option<f64>, | ||
} | ||
|
||
impl TransactionValidationArgs { | ||
pub fn new(feerate_threshold: Option<f64>) -> Self { | ||
Self { feerate_threshold } | ||
} | ||
} | ||
|
||
/// A struct provided to consensus for transactions validation batch processing calls | ||
pub struct TransactionValidationBatchArgs { | ||
tx_args: HashMap<TransactionId, TransactionValidationArgs>, | ||
} | ||
|
||
impl TransactionValidationBatchArgs { | ||
const DEFAULT_ARGS: TransactionValidationArgs = TransactionValidationArgs { feerate_threshold: None }; | ||
|
||
pub fn new() -> Self { | ||
Self { tx_args: HashMap::new() } | ||
} | ||
|
||
/// Set some fee/mass threshold for transaction `transaction_id`. | ||
pub fn set_feerate_threshold(&mut self, transaction_id: TransactionId, feerate_threshold: f64) { | ||
self.tx_args | ||
.entry(transaction_id) | ||
.and_modify(|x| x.feerate_threshold = Some(feerate_threshold)) | ||
.or_insert(TransactionValidationArgs::new(Some(feerate_threshold))); | ||
} | ||
|
||
pub fn get(&self, transaction_id: &TransactionId) -> &TransactionValidationArgs { | ||
self.tx_args.get(transaction_id).unwrap_or(&Self::DEFAULT_ARGS) | ||
} | ||
} | ||
|
||
impl Default for TransactionValidationBatchArgs { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
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
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
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
Oops, something went wrong.