Do not wrap transactions into Box in pool (#1069)
It makes code more complex and may require more memory allocations than needed.
This commit is contained in:
committed by
Ignotus Peverell
parent
54b06a6fcb
commit
3026429b05
@@ -12,24 +12,25 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use time::now_utc;
|
||||
use util::LOGGER;
|
||||
|
||||
use pool::TransactionPool;
|
||||
use pool::PoolConfig;
|
||||
use pool::TxSource;
|
||||
use pool::BlockChain;
|
||||
use pool::PoolConfig;
|
||||
use pool::TransactionPool;
|
||||
use pool::TxSource;
|
||||
|
||||
/// A process to monitor transactions in the stempool.
|
||||
/// With Dandelion, transaction can be broadcasted in stem or fluff phase.
|
||||
/// When sent in stem phase, the transaction is relayed to only node: the dandelion relay. In
|
||||
/// order to maintain reliability a timer is started for each transaction sent in stem phase.
|
||||
/// This function will monitor the stempool and test if the timer is expired for each transaction.
|
||||
/// In that case the transaction will be sent in fluff phase (to multiple peers) instead of
|
||||
/// When sent in stem phase, the transaction is relayed to only node: the
|
||||
/// dandelion relay. In order to maintain reliability a timer is started for
|
||||
/// each transaction sent in stem phase. This function will monitor the
|
||||
/// stempool and test if the timer is expired for each transaction. In that case
|
||||
/// the transaction will be sent in fluff phase (to multiple peers) instead of
|
||||
/// sending only to the peer relay.
|
||||
pub fn monitor_transactions<T>(
|
||||
config: PoolConfig,
|
||||
@@ -59,7 +60,7 @@ pub fn monitor_transactions<T>(
|
||||
let stem_transaction = stem_transactions.get(tx_hash).unwrap();
|
||||
let res = tx_pool.write().unwrap().add_to_memory_pool(
|
||||
source,
|
||||
*stem_transaction.clone(),
|
||||
stem_transaction.clone(),
|
||||
false,
|
||||
);
|
||||
|
||||
|
||||
@@ -15,29 +15,29 @@
|
||||
//! Build a block to mine: gathers transactions from the pool, assembles
|
||||
//! them into a block and returns it.
|
||||
|
||||
use std::thread;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use time;
|
||||
use std::time::Duration;
|
||||
use rand::{self, Rng};
|
||||
use itertools::Itertools;
|
||||
use rand::{self, Rng};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use time;
|
||||
|
||||
use core::ser::AsFixedBytes;
|
||||
use chain;
|
||||
use chain::types::BlockSums;
|
||||
use pool;
|
||||
use common::adapters::PoolToChainAdapter;
|
||||
use common::types::Error;
|
||||
use core::consensus;
|
||||
use core::core;
|
||||
use core::core::Transaction;
|
||||
use core::core::hash::Hashed;
|
||||
use core::ser;
|
||||
use core::ser::AsFixedBytes;
|
||||
use keychain::{Identifier, Keychain};
|
||||
use wallet;
|
||||
use wallet::BlockFees;
|
||||
use pool;
|
||||
use util;
|
||||
use util::LOGGER;
|
||||
use common::types::Error;
|
||||
use common::adapters::PoolToChainAdapter;
|
||||
use wallet;
|
||||
use wallet::BlockFees;
|
||||
|
||||
/// Serializer that outputs the pre-pow part of the header,
|
||||
/// including the nonce (last 8 bytes) that can be sent off
|
||||
@@ -158,11 +158,12 @@ fn build_block(
|
||||
let difficulty = consensus::next_difficulty(diff_iter).unwrap();
|
||||
|
||||
// extract current transaction from the pool
|
||||
let txs_box = tx_pool
|
||||
let txs = tx_pool
|
||||
.read()
|
||||
.unwrap()
|
||||
.prepare_mineable_transactions(max_tx);
|
||||
let txs: Vec<&Transaction> = txs_box.iter().map(|tx| tx.as_ref()).collect();
|
||||
|
||||
let txs: Vec<&Transaction> = txs.iter().collect();
|
||||
|
||||
// build the coinbase and the block itself
|
||||
let fees = txs.iter().map(|tx| tx.fee()).sum();
|
||||
|
||||
Reference in New Issue
Block a user