Skip to content

Commit f4ff234

Browse files
committed
Minor improvements and cleanup; appease clippy
1 parent 82f7dd3 commit f4ff234

10 files changed

Lines changed: 51 additions & 16 deletions

File tree

mempool/src/error/ban_score.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl MempoolBanScore for Error {
5454
// Internal error
5555
Error::SubsystemCallError(_) => 0,
5656

57-
// A configuration error is not the peer's fault.
57+
// A configuration error is not peer's fault.
5858
Error::ConfigError(_) => 0,
5959
}
6060
}
@@ -71,7 +71,7 @@ impl MempoolBanScore for MempoolPolicyError {
7171

7272
// Don't punish the peer for this, because max cluster size is technically configurable
7373
// and the peer doesn't know the node's mempool configuration.
74-
MempoolPolicyError::TxSizeExceedsMaxClusterSize => 0,
74+
MempoolPolicyError::TxSizeExceedsMaxClusterSize { .. } => 0,
7575

7676
// Errors to do with transaction conflicts and replacements are not punished since the
7777
// peer may not be aware of all the transactions the node has in the mempool.

mempool/src/error/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ pub enum MempoolPolicyError {
9898
#[error("Transaction size exceeds the maximum block size")]
9999
TxSizeExceedsMaxBlockSize,
100100

101-
#[error("Transaction size exceeds the maximum cluster size")]
102-
TxSizeExceedsMaxClusterSize,
101+
#[error("Transaction size ({tx_size}) exceeds the maximum cluster size ({limit})")]
102+
TxSizeExceedsMaxClusterSize { tx_size: usize, limit: usize },
103103

104104
#[error(
105105
"Replacement transaction has fee lower than the original. Replacement fee is {replacement_fee:?}, original fee {original_fee:?}"

mempool/src/pool/tests/relatives.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ async fn test_relatives_and_cluster_tx_count_limit(#[case] seed: Seed) {
312312
assert_descendants(&mempool, &b5, &[]);
313313
}
314314

315-
// A non-orphan subtest with a bigger limit
315+
// A non-orphan subtest with a bigger limit
316316
{
317317
let mut mempool = create_mempool(5);
318318

@@ -388,7 +388,7 @@ async fn test_relatives_and_cluster_tx_count_limit(#[case] seed: Seed) {
388388
assert_descendants(&mempool, &b2, &[]);
389389
}
390390

391-
// A non-orphan subtest with the default limit. All txs will be added and form a single cluster.
391+
// A non-orphan subtest with the default limit. All txs will be added and form a single cluster.
392392
{
393393
let mut mempool = create_mempool(*MaxClusterTxCount::default());
394394

mempool/src/pool/tx_pool/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,10 @@ impl<M: MemoryUsageEstimator> TxPool<M> {
291291
let max_cluster_size = *self.mempool_config.max_cluster_size_bytes;
292292
ensure!(
293293
size <= max_cluster_size,
294-
MempoolPolicyError::TxSizeExceedsMaxClusterSize
294+
MempoolPolicyError::TxSizeExceedsMaxClusterSize {
295+
tx_size: size,
296+
limit: max_cluster_size
297+
}
295298
);
296299

297300
Ok(())

mempool/src/pool/tx_pool/store/mod.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ impl TxMempoolEntry {
851851
self.parents.iter().copied(),
852852
RelativesKind::Ancestors,
853853
|_| Ok::<_, MempoolStoreInvariantError>(()),
854+
Some(self.count_with_ancestors - 1),
854855
);
855856

856857
match result {
@@ -874,6 +875,7 @@ impl TxMempoolEntry {
874875
self.children.iter().copied(),
875876
RelativesKind::Descendants,
876877
|_| Ok::<_, MempoolStoreInvariantError>(()),
878+
Some(self.count_with_descendants - 1),
877879
);
878880

879881
match result {
@@ -891,9 +893,13 @@ impl TxMempoolEntry {
891893
///
892894
/// This function is mainly intended for testing purposes.
893895
pub fn collect_cluster(&self, store: &MempoolStore) -> Result<Cluster, MempoolPolicyError> {
894-
let cluster = collect_relatives(store, [*self.tx_id()], RelativesKind::Cluster, |_| {
895-
Ok::<_, MempoolPolicyError>(())
896-
})?;
896+
let cluster = collect_relatives(
897+
store,
898+
[*self.tx_id()],
899+
RelativesKind::Cluster,
900+
|_| Ok::<_, MempoolPolicyError>(()),
901+
Some(self.count_with_ancestors + self.count_with_descendants - 1),
902+
)?;
897903

898904
Ok(Cluster::new(cluster))
899905
}
@@ -940,6 +946,7 @@ impl TxMempoolEntryWithAncestors {
940946
|collected_size| {
941947
ensure_cluster_tx_count_limit(&store.mempool_config, 1 + collected_size)
942948
},
949+
None,
943950
)?);
944951
enforce_cluster_size_limit(store, &entry, &cluster)?;
945952

@@ -948,6 +955,7 @@ impl TxMempoolEntryWithAncestors {
948955
parents.iter().copied(),
949956
RelativesKind::Ancestors,
950957
|_| Ok::<_, MempoolPolicyError>(()),
958+
None,
951959
)?);
952960

953961
let ancestor_entries_iter = ancestors
@@ -995,17 +1003,26 @@ pub enum RelativesKind {
9951003
///
9961004
/// After each tx is added to the result, `on_new_tx_added` is called with the current size
9971005
/// of the result as the argument.
1006+
///
1007+
/// `expected_result_size`, if specified, is used to reserve the needed capacity in the result
1008+
/// to avoid redundant reallocations.
9981009
pub fn collect_relatives<E>(
9991010
store: &MempoolStore,
10001011
initial_tx_ids: impl IntoIterator<Item = Id<Transaction>>,
10011012
kind: RelativesKind,
10021013
mut on_new_tx_added: impl FnMut(/*cur_result_size:*/ usize) -> Result<(), E>,
1014+
expected_result_size: Option<usize>,
10031015
) -> Result<StoreHashSet<Id<Transaction>>, E>
10041016
where
10051017
E: From<MempoolStoreInvariantError>,
10061018
{
1007-
let mut stack = Vec::new();
1008-
let mut result = StoreHashSet::default();
1019+
let initial_tx_ids = initial_tx_ids.into_iter();
1020+
let initial_tx_ids_min_size_hint = initial_tx_ids.size_hint().0;
1021+
let expected_result_size = expected_result_size.unwrap_or(initial_tx_ids_min_size_hint);
1022+
1023+
let mut stack = Vec::with_capacity(initial_tx_ids_min_size_hint);
1024+
let mut result =
1025+
StoreHashSet::with_capacity_and_hasher(expected_result_size, Default::default());
10091026

10101027
let mut visit = |stack: &mut Vec<Id<Transaction>>, tx_id: &Id<Transaction>| -> Result<(), E> {
10111028
if result.insert(*tx_id) {

mempool/src/pool/tx_pool/tests/basic.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ async fn tx_bigger_than_cluster_size(#[case] seed: Seed) -> anyhow::Result<()> {
381381
)
382382
.add_output_n_times(outputs_count, &output)
383383
.build();
384+
let tx_size = tx.encoded_size();
384385
let mempool_config = MempoolConfig {
385386
min_tx_relay_fee_rate: TEST_MIN_TX_RELAY_FEE_RATE.into(),
386387
max_cluster_size_bytes: max_cluster_size.into(),
@@ -392,7 +393,11 @@ async fn tx_bigger_than_cluster_size(#[case] seed: Seed) -> anyhow::Result<()> {
392393

393394
assert_eq!(
394395
mempool.add_transaction_test(tx),
395-
Err(MempoolPolicyError::TxSizeExceedsMaxClusterSize.into())
396+
Err(MempoolPolicyError::TxSizeExceedsMaxClusterSize {
397+
tx_size,
398+
limit: max_cluster_size
399+
}
400+
.into())
396401
);
397402
mempool.store.assert_valid();
398403
Ok(())
@@ -1547,7 +1552,10 @@ async fn accepted_tx_size(
15471552
let result = mempool.add_transaction_test(transaction);
15481553

15491554
let expected_err = if use_cluster_size_limit {
1550-
MempoolPolicyError::TxSizeExceedsMaxClusterSize
1555+
MempoolPolicyError::TxSizeExceedsMaxClusterSize {
1556+
tx_size,
1557+
limit: max_cluster_size,
1558+
}
15511559
} else {
15521560
MempoolPolicyError::TxSizeExceedsMaxBlockSize
15531561
};

wallet/src/account/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ impl<K: AccountKeyChains> Account<K> {
976976
)
977977
}
978978

979+
#[allow(clippy::too_many_arguments)]
979980
pub fn create_order_tx(
980981
&mut self,
981982
db_tx: &mut impl WalletStorageWriteLocked,
@@ -1004,6 +1005,7 @@ impl<K: AccountKeyChains> Account<K> {
10041005
)
10051006
}
10061007

1008+
#[allow(clippy::too_many_arguments)]
10071009
pub fn create_conclude_order_tx(
10081010
&mut self,
10091011
db_tx: &mut impl WalletStorageWriteLocked,
@@ -1199,6 +1201,7 @@ impl<K: AccountKeyChains> Account<K> {
11991201
)
12001202
}
12011203

1204+
#[allow(clippy::too_many_arguments)]
12021205
pub fn create_spend_utxo_tx(
12031206
&mut self,
12041207
db_tx: &mut impl WalletStorageWriteLocked,
@@ -1398,6 +1401,7 @@ impl<K: AccountKeyChains> Account<K> {
13981401
Ok(request)
13991402
}
14001403

1404+
#[allow(clippy::too_many_arguments)]
14011405
pub fn mint_tokens(
14021406
&mut self,
14031407
db_tx: &mut impl WalletStorageWriteLocked,
@@ -1594,6 +1598,7 @@ impl<K: AccountKeyChains> Account<K> {
15941598
)
15951599
}
15961600

1601+
#[allow(clippy::too_many_arguments)]
15971602
fn make_change_token_transaction(
15981603
&mut self,
15991604
authority: Destination,

wallet/src/account/utxo_selector/output_group.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use super::UtxoSelectorError;
2424
/// This helps reduce privacy leaks resulting from address reuse.
2525
// TODO: at this moment, we always create a separate output group for each utxo, i.e. we don't have
2626
// by-destination grouping.
27-
// Note that in Bitcoin, transactions are not grouped unconditionally:
27+
// Note that in Bitcoin transactions are not grouped unconditionally:
2828
// *) They are grouped if either m_avoid_partial_spends or m_avoid_address_reuse is true (both are
2929
// false by default).
3030
// *) Otherwise, if m_max_aps_fee is non-negative (it's zero by default), then a second attempt

wallet/src/wallet/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ pub struct Wallet<B: storage::Backend + 'static, P: SignerProvider> {
329329
chain_config: Arc<ChainConfig>,
330330
// Note: unlike the chain config, the mempool config may potentially change, e.g. if the node
331331
// is restarted with different parameters. At this moment, node restart requires the wallet
332-
// to be restarted as well, so it's not an issue for now. But when we implement the automatic
332+
// to be restarted as well, so it's not an issue for now. But when we implement automatic
333333
// reconnection, the mempool config stored here should be updated each time we reconnect to
334334
// the node.
335335
mempool_config: Arc<MempoolConfig>,
@@ -899,6 +899,7 @@ where
899899
Ok(())
900900
}
901901

902+
#[allow(clippy::too_many_arguments)]
902903
pub async fn load_wallet<
903904
F: Fn(u32) -> WalletResult<()>,
904905
F2: AsyncFnOnce(StoreTxRo<B>) -> WalletResult<P>,

wallet/wallet-controller/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ where
519519
Ok(())
520520
}
521521

522+
#[allow(clippy::too_many_arguments)]
522523
pub async fn open_wallet(
523524
chain_config: Arc<ChainConfig>,
524525
mempool_config: Arc<MempoolConfig>,

0 commit comments

Comments
 (0)