-
Notifications
You must be signed in to change notification settings - Fork 219
/
pool.rs
686 lines (621 loc) · 24.4 KB
/
pool.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
//! Top-level Pool type, methods, and tests
extern crate rustc_hash;
extern crate slab;
use super::component::{commit_txs_scanner::CommitTxsScanner, TxEntry};
use crate::callback::Callbacks;
use crate::component::pool_map::{PoolEntry, PoolMap, Status};
use crate::component::recent_reject::RecentReject;
use crate::error::Reject;
use crate::pool_cell::PoolCell;
use ckb_app_config::TxPoolConfig;
use ckb_logger::{debug, error, warn};
use ckb_snapshot::Snapshot;
use ckb_store::ChainStore;
use ckb_types::core::tx_pool::PoolTxDetailInfo;
use ckb_types::core::CapacityError;
use ckb_types::packed::OutPoint;
use ckb_types::{
core::{
cell::{resolve_transaction, OverlayCellChecker, OverlayCellProvider, ResolvedTransaction},
tx_pool::{TxPoolEntryInfo, TxPoolIds},
Capacity, Cycle, TransactionView, UncleBlockView,
},
packed::{Byte32, ProposalShortId},
};
use lru::LruCache;
use std::collections::HashSet;
use std::sync::Arc;
const COMMITTED_HASH_CACHE_SIZE: usize = 100_000;
const MAX_REPLACEMENT_CANDIDATES: usize = 100;
/// Tx-pool implementation
pub struct TxPool {
pub(crate) config: TxPoolConfig,
pub(crate) pool_map: PoolMap,
/// cache for committed transactions hash
pub(crate) committed_txs_hash_cache: LruCache<ProposalShortId, Byte32>,
// sum of all tx_pool tx's virtual sizes.
pub(crate) total_tx_size: usize,
// sum of all tx_pool tx's cycles.
pub(crate) total_tx_cycles: Cycle,
/// storage snapshot reference
pub(crate) snapshot: Arc<Snapshot>,
/// record recent reject
pub recent_reject: Option<RecentReject>,
// expiration milliseconds,
pub(crate) expiry: u64,
}
impl TxPool {
/// Create new TxPool
pub fn new(config: TxPoolConfig, snapshot: Arc<Snapshot>) -> TxPool {
let recent_reject = Self::build_recent_reject(&config);
let expiry = config.expiry_hours as u64 * 60 * 60 * 1000;
TxPool {
pool_map: PoolMap::new(config.max_ancestors_count),
committed_txs_hash_cache: LruCache::new(COMMITTED_HASH_CACHE_SIZE),
total_tx_size: 0,
total_tx_cycles: 0,
config,
snapshot,
recent_reject,
expiry,
}
}
/// Tx-pool owned snapshot, it may not consistent with chain cause tx-pool update snapshot asynchronously
pub(crate) fn snapshot(&self) -> &Snapshot {
&self.snapshot
}
/// Makes a clone of the `Arc<Snapshot>`
pub(crate) fn cloned_snapshot(&self) -> Arc<Snapshot> {
Arc::clone(&self.snapshot)
}
fn get_by_status(&self, status: Status) -> Vec<&PoolEntry> {
self.pool_map.get_by_status(status)
}
/// Get tx-pool size
pub fn status_size(&self, status: Status) -> usize {
self.get_by_status(status).len()
}
/// Update size and cycles statics for add tx
pub fn update_statics_for_add_tx(&mut self, tx_size: usize, cycles: Cycle) {
self.total_tx_size += tx_size;
self.total_tx_cycles += cycles;
}
/// Check whether tx-pool enable RBF
pub fn enable_rbf(&self) -> bool {
self.config.min_rbf_rate > self.config.min_fee_rate
}
/// The least required fee rate to allow tx to be replaced
pub fn min_replace_fee(&self, tx: &TxEntry) -> Option<Capacity> {
if !self.enable_rbf() {
return None;
}
let entry = vec![self.get_pool_entry(&tx.proposal_short_id()).unwrap()];
self.calculate_min_replace_fee(&entry, tx.size)
}
/// min_replace_fee = sum(replaced_txs.fee) + extra_rbf_fee
fn calculate_min_replace_fee(&self, conflicts: &[&PoolEntry], size: usize) -> Option<Capacity> {
let extra_rbf_fee = self.config.min_rbf_rate.fee(size as u64);
let replaced_sum_fee = conflicts
.iter()
.map(|c| c.inner.fee)
.try_fold(Capacity::zero(), |acc, x| acc.safe_add(x));
let res = replaced_sum_fee.map_or(Err(CapacityError::Overflow), |sum| {
sum.safe_add(extra_rbf_fee)
});
if let Ok(res) = res {
Some(res)
} else {
let fees = conflicts.iter().map(|c| c.inner.fee).collect::<Vec<_>>();
error!(
"conflicts: {:?} replaced_sum_fee {:?} overflow by add {}",
conflicts.iter().map(|e| e.id.clone()).collect::<Vec<_>>(),
fees,
extra_rbf_fee
);
None
}
}
/// Update size and cycles statics for remove tx
/// cycles overflow is possible, currently obtaining cycles is not accurate
pub fn update_statics_for_remove_tx(&mut self, tx_size: usize, cycles: Cycle) {
let total_tx_size = self.total_tx_size.checked_sub(tx_size).unwrap_or_else(|| {
error!(
"total_tx_size {} overflown by sub {}",
self.total_tx_size, tx_size
);
0
});
let total_tx_cycles = self.total_tx_cycles.checked_sub(cycles).unwrap_or_else(|| {
error!(
"total_tx_cycles {} overflown by sub {}",
self.total_tx_cycles, cycles
);
0
});
self.total_tx_size = total_tx_size;
self.total_tx_cycles = total_tx_cycles;
}
/// Add tx with pending status
/// If did have this value present, false is returned.
pub(crate) fn add_pending(&mut self, entry: TxEntry) -> Result<bool, Reject> {
self.pool_map.add_entry(entry, Status::Pending)
}
/// Add tx which proposed but still uncommittable to gap
pub(crate) fn add_gap(&mut self, entry: TxEntry) -> Result<bool, Reject> {
self.pool_map.add_entry(entry, Status::Gap)
}
/// Add tx with proposed status
pub(crate) fn add_proposed(&mut self, entry: TxEntry) -> Result<bool, Reject> {
self.pool_map.add_entry(entry, Status::Proposed)
}
/// Returns true if the tx-pool contains a tx with specified id.
pub(crate) fn contains_proposal_id(&self, id: &ProposalShortId) -> bool {
self.pool_map.get_by_id(id).is_some()
}
pub(crate) fn set_entry_proposed(&mut self, short_id: &ProposalShortId) {
self.pool_map.set_entry(short_id, Status::Proposed)
}
pub(crate) fn set_entry_gap(&mut self, short_id: &ProposalShortId) {
self.pool_map.set_entry(short_id, Status::Gap)
}
/// Returns tx with cycles corresponding to the id.
pub(crate) fn get_tx_with_cycles(
&self,
id: &ProposalShortId,
) -> Option<(TransactionView, Cycle)> {
self.pool_map
.get_by_id(id)
.map(|entry| (entry.inner.transaction().clone(), entry.inner.cycles))
}
pub(crate) fn get_pool_entry(&self, id: &ProposalShortId) -> Option<&PoolEntry> {
self.pool_map.get_by_id(id)
}
pub(crate) fn get_tx_from_pool(&self, id: &ProposalShortId) -> Option<&TransactionView> {
self.pool_map
.get_by_id(id)
.map(|entry| entry.inner.transaction())
}
pub(crate) fn remove_committed_txs<'a>(
&mut self,
txs: impl Iterator<Item = &'a TransactionView>,
callbacks: &Callbacks,
detached_headers: &HashSet<Byte32>,
) {
for tx in txs {
let tx_hash = tx.hash();
debug!("try remove_committed_tx {}", tx_hash);
self.remove_committed_tx(tx, callbacks);
self.committed_txs_hash_cache
.put(tx.proposal_short_id(), tx_hash);
}
if !detached_headers.is_empty() {
self.resolve_conflict_header_dep(detached_headers, callbacks)
}
}
fn resolve_conflict_header_dep(
&mut self,
detached_headers: &HashSet<Byte32>,
callbacks: &Callbacks,
) {
for (entry, reject) in self.pool_map.resolve_conflict_header_dep(detached_headers) {
callbacks.call_reject(self, &entry, reject);
}
}
fn remove_committed_tx(&mut self, tx: &TransactionView, callbacks: &Callbacks) {
let short_id = tx.proposal_short_id();
if let Some(entry) = self.pool_map.remove_entry(&short_id) {
debug!("remove_committed_tx for {}", tx.hash());
callbacks.call_committed(self, &entry)
}
{
let conflicts = self.pool_map.resolve_conflict(tx);
for (entry, reject) in conflicts {
debug!(
"removed {} for commited: {}",
entry.transaction().hash(),
tx.hash()
);
callbacks.call_reject(self, &entry, reject);
}
}
}
// Expire all transaction (and their dependencies) in the pool.
pub(crate) fn remove_expired(&mut self, callbacks: &Callbacks) {
let now_ms = ckb_systemtime::unix_time_as_millis();
let removed: Vec<_> = self
.pool_map
.iter()
.filter(|&entry| self.expiry + entry.inner.timestamp < now_ms)
.map(|entry| entry.inner.clone())
.collect();
for entry in removed {
let tx_hash = entry.transaction().hash();
debug!("remove_expired {} timestamp({})", tx_hash, entry.timestamp);
self.pool_map.remove_entry(&entry.proposal_short_id());
let reject = Reject::Expiry(entry.timestamp);
callbacks.call_reject(self, &entry, reject);
}
}
// Remove transactions from the pool until total size <= size_limit.
pub(crate) fn limit_size(&mut self, callbacks: &Callbacks) {
while self.total_tx_size > self.config.max_tx_pool_size {
let next_evict_entry = || {
self.pool_map
.next_evict_entry(Status::Pending)
.or_else(|| self.pool_map.next_evict_entry(Status::Gap))
.or_else(|| self.pool_map.next_evict_entry(Status::Proposed))
};
if let Some(id) = next_evict_entry() {
let removed = self.pool_map.remove_entry_and_descendants(&id);
for entry in removed {
let tx_hash = entry.transaction().hash();
debug!(
"Removed by size limit {} timestamp({})",
tx_hash, entry.timestamp
);
let reject = Reject::Full(format!(
"the fee_rate for this transaction is: {}",
entry.fee_rate()
));
callbacks.call_reject(self, &entry, reject);
}
}
}
self.pool_map.entries.shrink_to_fit();
}
// remove transaction with detached proposal from gap and proposed
// try re-put to pending
pub(crate) fn remove_by_detached_proposal<'a>(
&mut self,
ids: impl Iterator<Item = &'a ProposalShortId>,
) {
for id in ids {
if let Some(e) = self.pool_map.get_by_id(id) {
let status = e.status;
if status == Status::Pending {
continue;
}
let mut entries = self.pool_map.remove_entry_and_descendants(id);
entries.sort_unstable_by_key(|entry| entry.ancestors_count);
for mut entry in entries {
let tx_hash = entry.transaction().hash();
entry.reset_statistic_state();
let ret = self.add_pending(entry);
debug!(
"remove_by_detached_proposal from {:?} {} add_pending {:?}",
status, tx_hash, ret
);
}
}
}
}
pub(crate) fn remove_tx(&mut self, id: &ProposalShortId) -> bool {
let entries = self.pool_map.remove_entry_and_descendants(id);
if !entries.is_empty() {
for entry in entries {
self.update_statics_for_remove_tx(entry.size, entry.cycles);
}
return true;
}
if let Some(entry) = self.pool_map.remove_entry(id) {
self.update_statics_for_remove_tx(entry.size, entry.cycles);
return true;
}
false
}
pub(crate) fn check_rtx_from_pool(&self, rtx: &ResolvedTransaction) -> Result<(), Reject> {
let snapshot = self.snapshot();
let pool_cell = PoolCell::new(&self.pool_map, false);
let checker = OverlayCellChecker::new(&pool_cell, snapshot);
let mut seen_inputs = HashSet::new();
rtx.check(&mut seen_inputs, &checker, snapshot)
.map_err(Reject::Resolve)
}
pub(crate) fn resolve_tx_from_pool(
&self,
tx: TransactionView,
rbf: bool,
) -> Result<Arc<ResolvedTransaction>, Reject> {
let snapshot = self.snapshot();
let pool_cell = PoolCell::new(&self.pool_map, rbf);
let provider = OverlayCellProvider::new(&pool_cell, snapshot);
let mut seen_inputs = HashSet::new();
resolve_transaction(tx, &mut seen_inputs, &provider, snapshot)
.map(Arc::new)
.map_err(Reject::Resolve)
}
pub(crate) fn gap_rtx(&mut self, short_id: &ProposalShortId) -> Result<(), Reject> {
match self.get_pool_entry(short_id) {
Some(entry) => {
let tx_hash = entry.inner.transaction().hash();
if entry.status == Status::Gap {
Err(Reject::Duplicated(tx_hash))
} else {
debug!("gap_rtx: {:?} => {:?}", tx_hash, short_id);
self.set_entry_gap(short_id);
Ok(())
}
}
None => Err(Reject::Malformed(
String::from("invalid short_id"),
Default::default(),
)),
}
}
pub(crate) fn proposed_rtx(&mut self, short_id: &ProposalShortId) -> Result<(), Reject> {
match self.get_pool_entry(short_id) {
Some(entry) => {
let tx_hash = entry.inner.transaction().hash();
if entry.status == Status::Proposed {
Err(Reject::Duplicated(tx_hash))
} else {
debug!("proposed_rtx: {:?} => {:?}", tx_hash, short_id);
self.set_entry_proposed(short_id);
Ok(())
}
}
None => Err(Reject::Malformed(
String::from("invalid short_id"),
Default::default(),
)),
}
}
/// Get to-be-proposal transactions that may be included in the next block.
pub(crate) fn get_proposals(
&self,
limit: usize,
exclusion: &HashSet<ProposalShortId>,
) -> HashSet<ProposalShortId> {
let mut proposals = HashSet::with_capacity(limit);
self.pool_map
.fill_proposals(limit, exclusion, &mut proposals, Status::Pending);
proposals
}
/// Returns tx from tx-pool or storage corresponding to the id.
pub(crate) fn get_tx_from_pool_or_store(
&self,
proposal_id: &ProposalShortId,
) -> Option<TransactionView> {
self.get_tx_from_pool(proposal_id).cloned().or_else(|| {
self.committed_txs_hash_cache
.peek(proposal_id)
.and_then(|tx_hash| self.snapshot().get_transaction(tx_hash).map(|(tx, _)| tx))
})
}
pub(crate) fn get_ids(&self) -> TxPoolIds {
let pending = self
.pool_map
.score_sorted_iter_by(vec![Status::Pending, Status::Gap])
.map(|entry| entry.transaction().hash())
.collect();
let proposed = self
.pool_map
.sorted_proposed_iter()
.map(|entry| entry.transaction().hash())
.collect();
TxPoolIds { pending, proposed }
}
pub(crate) fn get_all_entry_info(&self) -> TxPoolEntryInfo {
let pending = self
.pool_map
.score_sorted_iter_by(vec![Status::Pending, Status::Gap])
.map(|entry| (entry.transaction().hash(), entry.to_info()))
.collect();
let proposed = self
.pool_map
.sorted_proposed_iter()
.map(|entry| (entry.transaction().hash(), entry.to_info()))
.collect();
TxPoolEntryInfo { pending, proposed }
}
pub(crate) fn drain_all_transactions(&mut self) -> Vec<TransactionView> {
let mut txs = CommitTxsScanner::new(&self.pool_map)
.txs_to_commit(self.total_tx_size, self.total_tx_cycles)
.0
.into_iter()
.map(|tx_entry| tx_entry.into_transaction())
.collect::<Vec<_>>();
let mut pending = self
.pool_map
.entries
.remove_by_status(&Status::Pending)
.into_iter()
.map(|e| e.inner.into_transaction())
.collect::<Vec<_>>();
txs.append(&mut pending);
let mut gap = self
.pool_map
.entries
.remove_by_status(&Status::Gap)
.into_iter()
.map(|e| e.inner.into_transaction())
.collect::<Vec<_>>();
txs.append(&mut gap);
self.total_tx_size = 0;
self.total_tx_cycles = 0;
self.pool_map.clear();
txs
}
pub(crate) fn clear(&mut self, snapshot: Arc<Snapshot>) {
self.pool_map.clear();
self.snapshot = snapshot;
self.committed_txs_hash_cache = LruCache::new(COMMITTED_HASH_CACHE_SIZE);
self.total_tx_size = 0;
self.total_tx_cycles = 0;
}
pub(crate) fn package_proposals(
&self,
proposals_limit: u64,
uncles: &[UncleBlockView],
) -> HashSet<ProposalShortId> {
let uncle_proposals = uncles
.iter()
.flat_map(|u| u.data().proposals().into_iter())
.collect();
self.get_proposals(proposals_limit as usize, &uncle_proposals)
}
pub(crate) fn package_txs(
&self,
max_block_cycles: Cycle,
txs_size_limit: usize,
) -> (Vec<TxEntry>, usize, Cycle) {
let (entries, size, cycles) =
CommitTxsScanner::new(&self.pool_map).txs_to_commit(txs_size_limit, max_block_cycles);
if !entries.is_empty() {
ckb_logger::info!(
"[get_block_template] candidate txs count: {}, size: {}/{}, cycles:{}/{}",
entries.len(),
size,
txs_size_limit,
cycles,
max_block_cycles
);
}
(entries, size, cycles)
}
pub(crate) fn check_rbf(
&self,
snapshot: &Snapshot,
entry: &TxEntry,
) -> Result<HashSet<ProposalShortId>, Reject> {
assert!(self.enable_rbf());
let tx_inputs: Vec<OutPoint> = entry.transaction().input_pts_iter().collect();
let conflict_ids = self.pool_map.find_conflict_tx(entry.transaction());
if conflict_ids.is_empty() {
return Ok(conflict_ids);
}
let tx_cells_deps: Vec<OutPoint> = entry
.transaction()
.cell_deps_iter()
.map(|c| c.out_point())
.collect();
let short_id = entry.proposal_short_id();
// Rule #1, the node has enabled RBF, which is checked by caller
let conflicts = conflict_ids
.iter()
.filter_map(|id| self.get_pool_entry(id))
.collect::<Vec<_>>();
assert!(conflicts.len() == conflict_ids.len());
// Rule #4, new tx's fee need to higher than min_rbf_fee computed from the tx_pool configuration
// Rule #3, new tx's fee need to higher than conflicts, here we only check the root tx
let fee = entry.fee;
if let Some(min_replace_fee) = self.calculate_min_replace_fee(&conflicts, entry.size) {
if fee < min_replace_fee {
return Err(Reject::RBFRejected(format!(
"Tx's current fee is {}, expect it to >= {} to replace old txs",
fee, min_replace_fee,
)));
}
} else {
return Err(Reject::RBFRejected(
"calculate_min_replace_fee failed".to_string(),
));
}
// Rule #2, new tx don't contain any new unconfirmed inputs
let mut inputs = HashSet::new();
let mut outputs = HashSet::new();
for c in conflicts.iter() {
inputs.extend(c.inner.transaction().input_pts_iter());
outputs.extend(c.inner.transaction().output_pts_iter());
}
if tx_inputs
.iter()
.any(|pt| !inputs.contains(pt) && !snapshot.transaction_exists(&pt.tx_hash()))
{
return Err(Reject::RBFRejected(
"new Tx contains unconfirmed inputs".to_string(),
));
}
if tx_cells_deps.iter().any(|dep| outputs.contains(dep)) {
return Err(Reject::RBFRejected(
"new Tx contains cell deps from conflicts".to_string(),
));
}
// Rule #5, the replaced tx's descendants can not more than 100
// and the ancestor of the new tx don't have common set with the replaced tx's descendants
let mut replace_count: usize = 0;
let ancestors = self.pool_map.calc_ancestors(&short_id);
for conflict in conflicts.iter() {
let descendants = self.pool_map.calc_descendants(&conflict.id);
replace_count += descendants.len() + 1;
if replace_count > MAX_REPLACEMENT_CANDIDATES {
return Err(Reject::RBFRejected(format!(
"Tx conflict too many txs, conflict txs count: {}",
replace_count,
)));
}
if !descendants.is_disjoint(&ancestors) {
return Err(Reject::RBFRejected(
"Tx ancestors have common with conflict Tx descendants".to_string(),
));
}
let entries = descendants
.iter()
.filter_map(|id| self.get_pool_entry(id))
.collect::<Vec<_>>();
for entry in entries.iter() {
let hash = entry.inner.transaction().hash();
if tx_inputs.iter().any(|pt| pt.tx_hash() == hash) {
return Err(Reject::RBFRejected(
"new Tx contains inputs in descendants of to be replaced Tx".to_string(),
));
}
}
}
Ok(conflict_ids)
}
/// query the details of a transaction in the pool, only for trouble shooting
pub(crate) fn get_tx_detail(&self, id: &ProposalShortId) -> Option<PoolTxDetailInfo> {
if let Some(entry) = self.pool_map.get_by_id(id) {
let ids = self.get_ids();
let rank_in_pending = if entry.status == Status::Proposed {
0
} else {
let tx_hash = entry.inner.transaction().hash();
ids.pending
.iter()
.enumerate()
.find(|(_, hash)| &tx_hash == *hash)
.map(|r| r.0)
.unwrap_or_default()
+ 1
};
let res = PoolTxDetailInfo {
timestamp: entry.inner.timestamp,
entry_status: entry.status.to_string(),
pending_count: self.pool_map.pending_size(),
rank_in_pending,
proposed_count: ids.proposed.len(),
descendants_count: self.pool_map.calc_descendants(id).len(),
ancestors_count: self.pool_map.calc_ancestors(id).len(),
score_sortkey: entry.inner.as_score_key().to_string(),
};
Some(res)
} else {
None
}
}
fn build_recent_reject(config: &TxPoolConfig) -> Option<RecentReject> {
if !config.recent_reject.as_os_str().is_empty() {
let recent_reject_ttl =
u8::max(1, config.keep_rejected_tx_hashes_days) as i32 * 24 * 60 * 60;
match RecentReject::new(
&config.recent_reject,
config.keep_rejected_tx_hashes_count,
recent_reject_ttl,
) {
Ok(recent_reject) => Some(recent_reject),
Err(err) => {
error!(
"Failed to open the recent reject database {:?} {}",
config.recent_reject, err
);
None
}
}
} else {
warn!("Recent reject database is disabled!");
None
}
}
}