-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmempool_interface.rs
More file actions
124 lines (101 loc) · 5.18 KB
/
Copy pathmempool_interface.rs
File metadata and controls
124 lines (101 loc) · 5.18 KB
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
// Copyright (c) 2022-2023 RBB S.r.l
// opensource@mintlayer.org
// SPDX-License-Identifier: MIT
// Licensed under the MIT License;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{collections::BTreeSet, num::NonZeroUsize, sync::Arc};
use common::{
chain::{GenBlock, SignedTransaction, Transaction},
primitives::Id,
};
use mempool_types::TransactionDuplicateStatus;
use crate::{
AncestorScore, FeeRate, MempoolConfig, MempoolMaxSize, TxOptions, TxStatus,
error::{BlockConstructionError, Error},
event::MempoolEvent,
tx_accumulator::{PackingStrategy, TransactionAccumulator},
tx_origin::{LocalTxOrigin, RemoteTxOrigin},
};
pub trait MempoolInterface: Send + Sync {
/// Add a transaction from remote peer to mempool
fn add_transaction_remote(
&mut self,
tx: SignedTransaction,
origin: RemoteTxOrigin,
options: TxOptions,
) -> Result<TxStatus, Error>;
/// Add a local transaction
fn add_transaction_local(
&mut self,
tx: SignedTransaction,
origin: LocalTxOrigin,
options: TxOptions,
) -> Result<TransactionDuplicateStatus, Error>;
/// Get all transactions from mempool, in the insertion order.
fn get_all_in_insertion_order(&self) -> Vec<SignedTransaction>;
/// Get a specific transaction from the main mempool (non-orphan)
fn transaction(&self, id: &Id<Transaction>) -> Option<SignedTransaction>;
/// Get a specific transaction from the orphan pool
fn orphan_transaction(&self, id: &Id<Transaction>) -> Option<SignedTransaction>;
/// Check given transaction is contained in the main mempool (non-orphan)
fn contains_transaction(&self, tx: &Id<Transaction>) -> bool;
/// Check given transaction is contained in the main mempool (non-orphan)
fn contains_orphan_transaction(&self, tx: &Id<Transaction>) -> bool;
/// Best block ID according to mempool. May be temporarily out of sync with chainstate.
fn best_block_id(&self) -> Id<GenBlock>;
/// Return the mempool config.
fn config(&self) -> &MempoolConfig;
/// Collect transactions by putting them in given accumulator.
/// Returns the accumulator with the collected transactions.
/// Ok(None) is returned on recoverable errors, such as if
/// the tip changed before collecting transactions started.
fn collect_txs(
&self,
tx_accumulator: Box<dyn TransactionAccumulator + Send>,
transaction_ids: Vec<Id<Transaction>>,
packing_strategy: PackingStrategy,
) -> Result<Option<Box<dyn TransactionAccumulator>>, BlockConstructionError>;
/// Return at most `tx_count` transaction ids from `tx_ids`, ordering them by "ancestor score" and ancestry:
/// transactions with better score will come first and ancestors will come before their descendants.
///
/// All transactions in `tx_ids` must be present in the mempool before the call.
fn get_best_tx_ids_by_score_and_ancestry(
&self,
tx_ids: &BTreeSet<Id<Transaction>>,
tx_count: usize,
) -> Result<Vec<Id<Transaction>>, Error>;
/// Subscribe to events emitted by mempool subsystem
fn subscribe_to_subsystem_events(&mut self, handler: Arc<dyn Fn(MempoolEvent) + Send + Sync>);
/// Subscribe to broadcast mempool events
fn subscribe_to_rpc_events(&mut self) -> utils_networking::broadcaster::Receiver<MempoolEvent>;
/// Get current memory usage
fn memory_usage(&self) -> usize;
/// Get the maximum allowed mempool size, as in, the maximum total byte-size of all transactions in the mempool.
fn get_size_limit(&self) -> MempoolMaxSize;
/// Set the allowed size limit for the total of all transactions in the mempool.
fn set_size_limit(&mut self, max_size: MempoolMaxSize) -> Result<(), Error>;
/// Get the fee rate such that it would put the new transaction in the top X MB of the mempool
/// making it less likely to get rejected or trimmed in the case the mempool is full
fn get_fee_rate(&self, in_top_x_mb: usize) -> FeeRate;
/// Get the fee rate at multiple uniformly distributed points along the mempool's transactions
fn get_fee_rate_points(&self, num_points: NonZeroUsize)
-> Result<Vec<(usize, FeeRate)>, Error>;
/// Get the "ancestor score" of the specified transaction (the bigger the score, the more lucrative
/// the transaction is for inclusion in a block).
///
/// This is mainly intended for testing purposes.
fn get_tx_score(&self, tx_id: &Id<Transaction>) -> Result<Option<AncestorScore>, Error>;
/// Notify mempool given peer has disconnected
fn notify_peer_disconnected(&mut self, peer_id: p2p_types::PeerId);
/// Notify mempool about given chainstate event
fn notify_chainstate_event(&mut self, event: chainstate::ChainstateEvent);
}