Compute serialized size on the fly
This commit is contained in:
parent
6734a01aa7
commit
5cf5641b9b
|
@ -26,10 +26,6 @@ pub struct VerifiedSet {
|
|||
/// The set of verified transactions in the mempool.
|
||||
transactions: VecDeque<UnminedTx>,
|
||||
|
||||
/// The total size of the transactions in the mempool if they were
|
||||
/// serialized.
|
||||
transactions_serialized_size: usize,
|
||||
|
||||
/// The set of spent out points by the verified transactions.
|
||||
spent_outpoints: HashSet<transparent::OutPoint>,
|
||||
|
||||
|
@ -54,6 +50,11 @@ impl VerifiedSet {
|
|||
self.transactions.len()
|
||||
}
|
||||
|
||||
/// Returns the total serialized size of the transactions in the set.
|
||||
pub fn transactions_serialized_size(&self) -> usize {
|
||||
self.transactions().map(|tx| tx.size).sum()
|
||||
}
|
||||
|
||||
/// Returns `true` if the set of verified transactions contains the transaction with the
|
||||
/// specified `id.
|
||||
pub fn contains(&self, id: &UnminedTxId) -> bool {
|
||||
|
@ -69,7 +70,6 @@ impl VerifiedSet {
|
|||
self.sprout_nullifiers.clear();
|
||||
self.sapling_nullifiers.clear();
|
||||
self.orchard_nullifiers.clear();
|
||||
self.transactions_serialized_size = 0;
|
||||
self.update_metrics();
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,6 @@ impl VerifiedSet {
|
|||
}
|
||||
|
||||
self.cache_outputs_from(&transaction.transaction);
|
||||
self.transactions_serialized_size += transaction.size;
|
||||
self.transactions.push_front(transaction);
|
||||
|
||||
self.update_metrics();
|
||||
|
@ -143,7 +142,6 @@ impl VerifiedSet {
|
|||
.remove(transaction_index)
|
||||
.expect("invalid transaction index");
|
||||
|
||||
self.transactions_serialized_size -= removed_tx.size;
|
||||
self.remove_outputs(&removed_tx);
|
||||
|
||||
self.update_metrics();
|
||||
|
@ -216,7 +214,7 @@ impl VerifiedSet {
|
|||
);
|
||||
metrics::gauge!(
|
||||
"zcash.mempool.size.bytes",
|
||||
self.transactions_serialized_size as _
|
||||
self.transactions_serialized_size() as _
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue