-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Duplicating blacklisting feature for TxPool from
0.22.4
(#1748)
Duplicates the FuelLabs/fuel-core#1743 for the `master` --------- Co-authored-by: Brandon Kite <[email protected]>
- Loading branch information
Showing
7 changed files
with
460 additions
and
38 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,104 @@ | ||
//! Clap configuration related to consensus parameters | ||
use fuel_core::txpool::types::ContractId; | ||
use fuel_core_types::{ | ||
fuel_tx::{ | ||
Address, | ||
UtxoId, | ||
}, | ||
fuel_types::Nonce, | ||
}; | ||
|
||
#[derive(Debug, Clone, clap::Args)] | ||
pub struct TxPoolArgs { | ||
/// The max time to live of the transaction inside of the `TxPool`. | ||
#[clap(long = "tx-pool-ttl", default_value = "5m", env)] | ||
pub tx_pool_ttl: humantime::Duration, | ||
|
||
/// The max number of transactions that the `TxPool` can simultaneously store. | ||
#[clap(long = "tx-max-number", default_value = "4064", env)] | ||
pub tx_max_number: usize, | ||
|
||
/// The max depth of the dependent transactions that supported by the `TxPool`. | ||
#[clap(long = "tx-max-depth", default_value = "10", env)] | ||
pub tx_max_depth: usize, | ||
|
||
/// The maximum number of active subscriptions that supported by the `TxPool`. | ||
#[clap(long = "tx-number-active-subscriptions", default_value = "4064", env)] | ||
pub tx_number_active_subscriptions: usize, | ||
|
||
/// The list of banned addresses ignored by the `TxPool`. | ||
#[clap(long = "tx-blacklist-addresses", value_delimiter = ',', env)] | ||
pub tx_blacklist_addresses: Vec<Address>, | ||
|
||
/// The list of banned coins ignored by the `TxPool`. | ||
#[clap(long = "tx-blacklist-coins", value_delimiter = ',', env)] | ||
pub tx_blacklist_coins: Vec<UtxoId>, | ||
|
||
/// The list of banned messages ignored by the `TxPool`. | ||
#[clap(long = "tx-blacklist-messages", value_delimiter = ',', env)] | ||
pub tx_blacklist_messages: Vec<Nonce>, | ||
|
||
/// The list of banned contracts ignored by the `TxPool`. | ||
#[clap(long = "tx-blacklist-contracts", value_delimiter = ',', env)] | ||
pub tx_blacklist_contracts: Vec<ContractId>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use clap::Parser; | ||
use fuel_core::txpool::config::BlackList; | ||
use test_case::test_case; | ||
|
||
#[derive(Debug, Clone, Parser)] | ||
pub struct Command { | ||
#[clap(flatten)] | ||
tx_pool: TxPoolArgs, | ||
} | ||
|
||
fn blacklist( | ||
a: Vec<Address>, | ||
c: Vec<UtxoId>, | ||
m: Vec<Nonce>, | ||
ct: Vec<ContractId>, | ||
) -> BlackList { | ||
BlackList::new(a, c, m, ct) | ||
} | ||
|
||
#[test_case(&[""] => Ok(blacklist(vec![], vec![], vec![], vec![])); "defaults works")] | ||
#[test_case(&["", "--tx-blacklist-addresses=\ | ||
0x0000000000000000000000000000000000000000000000000000000000000000,\ | ||
0101010101010101010101010101010101010101010101010101010101010101" | ||
] | ||
=> Ok(blacklist(vec![[0; 32].into(), [1; 32].into()], vec![], vec![], vec![])); "addresses works")] | ||
#[test_case(&["", "--tx-blacklist-coins=\ | ||
0x000000000000000000000000000000000000000000000000000000000000000002,\ | ||
010101010101010101010101010101010101010101010101010101010101010103" | ||
] | ||
=> Ok(blacklist(vec![], vec![UtxoId::new([0; 32].into(), 2), UtxoId::new([1; 32].into(), 3)], vec![], vec![])); "coins works")] | ||
#[test_case(&["", "--tx-blacklist-messages=\ | ||
0x0000000000000000000000000000000000000000000000000000000000000000,\ | ||
0101010101010101010101010101010101010101010101010101010101010101" | ||
] | ||
=> Ok(blacklist(vec![], vec![], vec![[0; 32].into(), [1; 32].into()], vec![])); "messages works")] | ||
#[test_case(&["", "--tx-blacklist-contracts=\ | ||
0x0000000000000000000000000000000000000000000000000000000000000000,\ | ||
0101010101010101010101010101010101010101010101010101010101010101" | ||
] | ||
=> Ok(blacklist(vec![], vec![], vec![], vec![[0; 32].into(), [1; 32].into()])); "contracts works")] | ||
fn parse(args: &[&str]) -> Result<BlackList, String> { | ||
let command: Command = | ||
Command::try_parse_from(args).map_err(|e| e.to_string())?; | ||
let args = command.tx_pool; | ||
|
||
let blacklist = blacklist( | ||
args.tx_blacklist_addresses, | ||
args.tx_blacklist_coins, | ||
args.tx_blacklist_messages, | ||
args.tx_blacklist_contracts, | ||
); | ||
|
||
Ok(blacklist) | ||
} | ||
} |
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.