cfxcore/pos/mempool/core_mempool/
transaction.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8use diem_crypto::HashValue;
9use diem_types::{
10    account_address::AccountAddress,
11    transaction::{GovernanceRole, SignedTransaction},
12};
13use serde::{Deserialize, Serialize};
14use std::time::Duration;
15
16#[derive(Clone)]
17pub struct MempoolTransaction {
18    pub txn: SignedTransaction,
19    // System expiration time of the transaction. It should be removed from
20    // mempool by that time.
21    pub expiration_time: Duration,
22    pub ranking_score: u64,
23    pub timeline_state: TimelineState,
24    pub governance_role: GovernanceRole,
25}
26
27impl MempoolTransaction {
28    pub(crate) fn new(
29        txn: SignedTransaction, expiration_time: Duration, ranking_score: u64,
30        timeline_state: TimelineState, governance_role: GovernanceRole,
31    ) -> Self {
32        Self {
33            txn,
34            ranking_score,
35            expiration_time,
36            timeline_state,
37            governance_role,
38        }
39    }
40
41    pub(crate) fn get_hash(&self) -> HashValue { self.txn.hash() }
42
43    pub(crate) fn get_sender(&self) -> AccountAddress { self.txn.sender() }
44}
45
46#[derive(Clone, Copy, PartialEq, Eq, Debug, Deserialize, Hash, Serialize)]
47pub enum TimelineState {
48    // The transaction is ready for broadcast.
49    // Associated integer represents it's position in the log of such
50    // transactions.
51    Ready(u64),
52    // Transaction is not yet ready for broadcast, but it might change in a
53    // future.
54    NotReady,
55    // Transaction will never be qualified for broadcasting.
56    // Currently we don't broadcast transactions originated on other peers.
57    NonQualified,
58}