-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The syncers get initiated once the Mempool Executors are spawned. One Syncer per Executor is started in order to sync the regular and control transactions separately. First the Syncer starts to discover which transaction hashes other nodes with a mempool have and compare those with what we have locally. Then we distribute those unknown hashes among the peers we know have those transactions and retrieve the actual transactions. Lastly for every received transaction we do a full verification which should add it to our local mempool if everything checks out.
- Loading branch information
Showing
9 changed files
with
749 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use std::sync::Arc; | ||
|
||
use nimiq_hash::Blake2bHash; | ||
use nimiq_network_interface::{ | ||
network::Network, | ||
request::{Handle, RequestCommon, RequestMarker}, | ||
}; | ||
use nimiq_serde::{Deserialize, Serialize}; | ||
use nimiq_transaction::Transaction; | ||
use parking_lot::RwLock; | ||
|
||
use crate::mempool_state::MempoolState; | ||
|
||
const MAX_REQUEST_RESPONSE_MEMPOOL_STATE: u32 = 1000; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub enum MempoolTransactionType { | ||
Control, | ||
Regular, | ||
} | ||
|
||
/// Request the current transaction hashes in the mempool. | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct RequestMempoolHashes { | ||
pub transaction_type: MempoolTransactionType, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct ResponseMempoolHashes { | ||
pub hashes: Vec<Blake2bHash>, | ||
} | ||
|
||
impl RequestCommon for RequestMempoolHashes { | ||
type Kind = RequestMarker; | ||
const TYPE_ID: u16 = 219; | ||
type Response = ResponseMempoolHashes; | ||
const MAX_REQUESTS: u32 = MAX_REQUEST_RESPONSE_MEMPOOL_STATE; | ||
} | ||
|
||
/// Request transactions in the mempool based on the provided hashes. | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct RequestMempoolTransactions { | ||
pub hashes: Vec<Blake2bHash>, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct ResponseMempoolTransactions { | ||
pub transactions: Vec<Transaction>, | ||
} | ||
|
||
impl RequestCommon for RequestMempoolTransactions { | ||
type Kind = RequestMarker; | ||
const TYPE_ID: u16 = 220; | ||
type Response = ResponseMempoolTransactions; | ||
const MAX_REQUESTS: u32 = MAX_REQUEST_RESPONSE_MEMPOOL_STATE; | ||
} | ||
|
||
impl<N: Network> Handle<N, Arc<RwLock<MempoolState>>> for RequestMempoolHashes { | ||
fn handle(&self, _: N::PeerId, context: &Arc<RwLock<MempoolState>>) -> ResponseMempoolHashes { | ||
let hashes: Vec<Blake2bHash> = match self.transaction_type { | ||
MempoolTransactionType::Regular => context | ||
.read() | ||
.regular_transactions | ||
.best_transactions | ||
.iter() | ||
.map(|txn| txn.0.clone()) | ||
.collect(), | ||
MempoolTransactionType::Control => context | ||
.read() | ||
.control_transactions | ||
.best_transactions | ||
.iter() | ||
.map(|txn| txn.0.clone()) | ||
.collect(), | ||
}; | ||
|
||
ResponseMempoolHashes { hashes } | ||
} | ||
} | ||
|
||
impl<N: Network> Handle<N, Arc<RwLock<MempoolState>>> for RequestMempoolTransactions { | ||
fn handle(&self, _: N::PeerId, _: &Arc<RwLock<MempoolState>>) -> ResponseMempoolTransactions { | ||
todo!() | ||
} | ||
} |
Oops, something went wrong.