From 9e51e865382710ccb283e9f88d157b7cd08774f9 Mon Sep 17 00:00:00 2001 From: hashmap Date: Thu, 30 Apr 2020 17:41:49 +0200 Subject: [PATCH] Use generic types instead of trait objects in tx pool (#3308) Tx pool takes some parameters as trait objects. It's not an idiomatic Rust code, in this particular case we should use generic types. Trait object makes sense when we accept in runtime different concrete types which implement the trait as a value of the same field. It's not the case here. Trait objects come with a price - instead of method dispatch in compile time we have to accept runtime dispatch. My guess we did it to not clutter the code with type parameters, which is understandable but still suboptimal. --- api/src/foreign.rs | 21 ++++++--- api/src/foreign_rpc.rs | 9 +++- api/src/handlers.rs | 49 ++++++++++++++++----- api/src/handlers/pool_api.rs | 62 +++++++++++++++++++++------ pool/src/pool.rs | 22 ++++++---- pool/src/transaction_pool.rs | 32 +++++++++----- pool/tests/common.rs | 12 ++++-- servers/src/common/adapters.rs | 60 +++++++++++++++++++------- servers/src/grin/dandelion_monitor.rs | 21 +++++---- servers/src/grin/server.rs | 12 ++++-- servers/src/lib.rs | 2 +- servers/src/mining/mine_block.rs | 12 +++--- servers/src/mining/stratumserver.rs | 15 +++---- servers/src/mining/test_miner.rs | 14 +++--- 14 files changed, 239 insertions(+), 104 deletions(-) diff --git a/api/src/foreign.rs b/api/src/foreign.rs index 61e7cf98b..7836358c5 100644 --- a/api/src/foreign.rs +++ b/api/src/foreign.rs @@ -17,12 +17,13 @@ use crate::chain::{Chain, SyncState}; use crate::core::core::hash::Hash; use crate::core::core::transaction::Transaction; +use crate::core::core::verifier_cache::VerifierCache; use crate::handlers::blocks_api::{BlockHandler, HeaderHandler}; use crate::handlers::chain_api::{ChainHandler, KernelHandler, OutputHandler}; use crate::handlers::pool_api::PoolHandler; use crate::handlers::transactions_api::TxHashSetHandler; use crate::handlers::version_api::VersionHandler; -use crate::pool::{self, PoolEntry}; +use crate::pool::{self, BlockChain, PoolAdapter, PoolEntry}; use crate::rest::*; use crate::types::{ BlockHeaderPrintable, BlockPrintable, LocatedTxKernel, OutputListing, OutputPrintable, Tip, @@ -38,13 +39,23 @@ use std::sync::Weak; /// Methods in this API are intended to be 'single use'. /// -pub struct Foreign { +pub struct Foreign +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ pub chain: Weak, - pub tx_pool: Weak>, + pub tx_pool: Weak>>, pub sync_state: Weak, } -impl Foreign { +impl Foreign +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ /// Create a new API instance with the chain, transaction pool, peers and `sync_state`. All subsequent /// API calls will operate on this instance of node API. /// @@ -60,7 +71,7 @@ impl Foreign { pub fn new( chain: Weak, - tx_pool: Weak>, + tx_pool: Weak>>, sync_state: Weak, ) -> Self { Foreign { diff --git a/api/src/foreign_rpc.rs b/api/src/foreign_rpc.rs index 8020df941..f1401ba13 100644 --- a/api/src/foreign_rpc.rs +++ b/api/src/foreign_rpc.rs @@ -16,8 +16,10 @@ use crate::core::core::hash::Hash; use crate::core::core::transaction::Transaction; +use crate::core::core::verifier_cache::VerifierCache; use crate::foreign::Foreign; use crate::pool::PoolEntry; +use crate::pool::{BlockChain, PoolAdapter}; use crate::rest::ErrorKind; use crate::types::{ BlockHeaderPrintable, BlockPrintable, LocatedTxKernel, OutputListing, OutputPrintable, Tip, @@ -738,7 +740,12 @@ pub trait ForeignRpc: Sync + Send { fn push_transaction(&self, tx: Transaction, fluff: Option) -> Result<(), ErrorKind>; } -impl ForeignRpc for Foreign { +impl ForeignRpc for Foreign +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ fn get_header( &self, height: Option, diff --git a/api/src/handlers.rs b/api/src/handlers.rs index 8375bd4f1..4da29cb41 100644 --- a/api/src/handlers.rs +++ b/api/src/handlers.rs @@ -42,12 +42,14 @@ use crate::auth::{ }; use crate::chain; use crate::chain::{Chain, SyncState}; +use crate::core::core::verifier_cache::VerifierCache; use crate::foreign::Foreign; use crate::foreign_rpc::ForeignRpc; use crate::owner::Owner; use crate::owner_rpc::OwnerRpc; use crate::p2p; use crate::pool; +use crate::pool::{BlockChain, PoolAdapter}; use crate::rest::{ApiServer, Error, TLSConfig}; use crate::router::ResponseFuture; use crate::router::{Router, RouterError}; @@ -62,16 +64,21 @@ use std::sync::{Arc, Weak}; /// Listener version, providing same API but listening for requests on a /// port and wrapping the calls -pub fn node_apis( +pub fn node_apis( addr: &str, chain: Arc, - tx_pool: Arc>, + tx_pool: Arc>>, peers: Arc, sync_state: Arc, api_secret: Option, foreign_api_secret: Option, tls_config: Option, -) -> Result<(), Error> { +) -> Result<(), Error> +where + B: BlockChain + 'static, + P: PoolAdapter + 'static, + V: VerifierCache + 'static, +{ // Manually build router when getting rid of v1 //let mut router = Router::new(); let mut router = build_router( @@ -190,17 +197,27 @@ impl crate::router::Handler for OwnerAPIHandlerV2 { } /// V2 API Handler/Wrapper for foreign functions -pub struct ForeignAPIHandlerV2 { +pub struct ForeignAPIHandlerV2 +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ pub chain: Weak, - pub tx_pool: Weak>, + pub tx_pool: Weak>>, pub sync_state: Weak, } -impl ForeignAPIHandlerV2 { +impl ForeignAPIHandlerV2 +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ /// Create a new foreign API handler for GET methods pub fn new( chain: Weak, - tx_pool: Weak>, + tx_pool: Weak>>, sync_state: Weak, ) -> Self { ForeignAPIHandlerV2 { @@ -211,7 +228,12 @@ impl ForeignAPIHandlerV2 { } } -impl crate::router::Handler for ForeignAPIHandlerV2 { +impl crate::router::Handler for ForeignAPIHandlerV2 +where + B: BlockChain + 'static, + P: PoolAdapter + 'static, + V: VerifierCache + 'static, +{ fn post(&self, req: Request) -> ResponseFuture { let api = Foreign::new( self.chain.clone(), @@ -309,12 +331,17 @@ fn response>(status: StatusCode, text: T) -> Response { since = "4.0.0", note = "The V1 Node API will be removed in grin 5.0.0. Please migrate to the V2 API as soon as possible." )] -pub fn build_router( +pub fn build_router( chain: Arc, - tx_pool: Arc>, + tx_pool: Arc>>, peers: Arc, sync_state: Arc, -) -> Result { +) -> Result +where + B: BlockChain + 'static, + P: PoolAdapter + 'static, + V: VerifierCache + 'static, +{ let route_list = vec![ "get blocks".to_string(), "get headers".to_string(), diff --git a/api/src/handlers/pool_api.rs b/api/src/handlers/pool_api.rs index a869b3dc2..9f46e04e3 100644 --- a/api/src/handlers/pool_api.rs +++ b/api/src/handlers/pool_api.rs @@ -14,9 +14,10 @@ use super::utils::w; use crate::core::core::hash::Hashed; +use crate::core::core::verifier_cache::VerifierCache; use crate::core::core::Transaction; use crate::core::ser::{self, ProtocolVersion}; -use crate::pool::{self, PoolEntry}; +use crate::pool::{self, BlockChain, PoolAdapter, PoolEntry}; use crate::rest::*; use crate::router::{Handler, ResponseFuture}; use crate::types::*; @@ -29,11 +30,21 @@ use std::sync::Weak; /// Get basic information about the transaction pool. /// GET /v1/pool -pub struct PoolInfoHandler { - pub tx_pool: Weak>, +pub struct PoolInfoHandler +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ + pub tx_pool: Weak>>, } -impl Handler for PoolInfoHandler { +impl Handler for PoolInfoHandler +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ fn get(&self, _req: Request) -> ResponseFuture { let pool_arc = w_fut!(&self.tx_pool); let pool = pool_arc.read(); @@ -44,11 +55,21 @@ impl Handler for PoolInfoHandler { } } -pub struct PoolHandler { - pub tx_pool: Weak>, +pub struct PoolHandler +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ + pub tx_pool: Weak>>, } -impl PoolHandler { +impl PoolHandler +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ pub fn get_pool_size(&self) -> Result { let pool_arc = w(&self.tx_pool)?; let pool = pool_arc.read(); @@ -96,14 +117,24 @@ struct TxWrapper { /// Push new transaction to our local transaction pool. /// POST /v1/pool/push_tx -pub struct PoolPushHandler { - pub tx_pool: Weak>, +pub struct PoolPushHandler +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ + pub tx_pool: Weak>>, } -async fn update_pool( - pool: Weak>, +async fn update_pool( + pool: Weak>>, req: Request, -) -> Result<(), Error> { +) -> Result<(), Error> +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ let pool = w(&pool)?; let params = QueryParams::from(req.uri().query()); let fluff = params.get("fluff").is_some(); @@ -138,7 +169,12 @@ async fn update_pool( Ok(()) } -impl Handler for PoolPushHandler { +impl Handler for PoolPushHandler +where + B: BlockChain + 'static, + P: PoolAdapter + 'static, + V: VerifierCache + 'static, +{ fn post(&self, req: Request) -> ResponseFuture { let pool = self.tx_pool.clone(); Box::pin(async move { diff --git a/pool/src/pool.rs b/pool/src/pool.rs index 8a6d8f48f..d2ac8be5a 100644 --- a/pool/src/pool.rs +++ b/pool/src/pool.rs @@ -30,21 +30,25 @@ use std::cmp::Reverse; use std::collections::{HashMap, HashSet}; use std::sync::Arc; -pub struct Pool { +pub struct Pool +where + B: BlockChain, + V: VerifierCache, +{ /// Entries in the pool (tx + info + timer) in simple insertion order. pub entries: Vec, /// The blockchain - pub blockchain: Arc, - pub verifier_cache: Arc>, + pub blockchain: Arc, + pub verifier_cache: Arc>, pub name: String, } -impl Pool { - pub fn new( - chain: Arc, - verifier_cache: Arc>, - name: String, - ) -> Pool { +impl Pool +where + B: BlockChain, + V: VerifierCache + 'static, +{ + pub fn new(chain: Arc, verifier_cache: Arc>, name: String) -> Self { Pool { entries: vec![], blockchain: chain, diff --git a/pool/src/transaction_pool.rs b/pool/src/transaction_pool.rs index ffe24b5e5..24a9a9889 100644 --- a/pool/src/transaction_pool.rs +++ b/pool/src/transaction_pool.rs @@ -31,30 +31,40 @@ use std::collections::VecDeque; use std::sync::Arc; /// Transaction pool implementation. -pub struct TransactionPool { +pub struct TransactionPool +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache, +{ /// Pool Config pub config: PoolConfig, /// Our transaction pool. - pub txpool: Pool, + pub txpool: Pool, /// Our Dandelion "stempool". - pub stempool: Pool, + pub stempool: Pool, /// Cache of previous txs in case of a re-org. pub reorg_cache: Arc>>, /// The blockchain - pub blockchain: Arc, - pub verifier_cache: Arc>, + pub blockchain: Arc, + pub verifier_cache: Arc>, /// The pool adapter - pub adapter: Arc, + pub adapter: Arc

, } -impl TransactionPool { +impl TransactionPool +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ /// Create a new transaction pool pub fn new( config: PoolConfig, - chain: Arc, - verifier_cache: Arc>, - adapter: Arc, - ) -> TransactionPool { + chain: Arc, + verifier_cache: Arc>, + adapter: Arc

, + ) -> Self { TransactionPool { config, txpool: Pool::new(chain.clone(), verifier_cache.clone(), "txpool".to_string()), diff --git a/pool/tests/common.rs b/pool/tests/common.rs index ad7b94d45..37205bd10 100644 --- a/pool/tests/common.rs +++ b/pool/tests/common.rs @@ -148,10 +148,14 @@ impl BlockChain for ChainAdapter { } } -pub fn test_setup( - chain: Arc, - verifier_cache: Arc>, -) -> TransactionPool { +pub fn test_setup( + chain: Arc, + verifier_cache: Arc>, +) -> TransactionPool +where + B: BlockChain, + V: VerifierCache + 'static, +{ TransactionPool::new( PoolConfig { accept_fee_base: 0, diff --git a/servers/src/common/adapters.rs b/servers/src/common/adapters.rs index 8d1701069..a5d0c8183 100644 --- a/servers/src/common/adapters.rs +++ b/servers/src/common/adapters.rs @@ -36,7 +36,7 @@ use crate::core::pow::Difficulty; use crate::core::{core, global}; use crate::p2p; use crate::p2p::types::PeerInfo; -use crate::pool; +use crate::pool::{self, BlockChain, PoolAdapter}; use crate::util::OneTime; use chrono::prelude::*; use chrono::Duration; @@ -45,17 +45,27 @@ use rand::prelude::*; /// Implementation of the NetAdapter for the . Gets notified when new /// blocks and transactions are received and forwards to the chain and pool /// implementations. -pub struct NetToChainAdapter { +pub struct NetToChainAdapter +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ sync_state: Arc, chain: Weak, - tx_pool: Arc>, - verifier_cache: Arc>, + tx_pool: Arc>>, + verifier_cache: Arc>, peers: OneTime>, config: ServerConfig, hooks: Vec>, } -impl p2p::ChainAdapter for NetToChainAdapter { +impl p2p::ChainAdapter for NetToChainAdapter +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ fn total_difficulty(&self) -> Result { Ok(self.chain().head()?.total_difficulty) } @@ -464,16 +474,21 @@ impl p2p::ChainAdapter for NetToChainAdapter { } } -impl NetToChainAdapter { +impl NetToChainAdapter +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ /// Construct a new NetToChainAdapter instance pub fn new( sync_state: Arc, chain: Arc, - tx_pool: Arc>, - verifier_cache: Arc>, + tx_pool: Arc>>, + verifier_cache: Arc>, config: ServerConfig, hooks: Vec>, - ) -> NetToChainAdapter { + ) -> Self { NetToChainAdapter { sync_state, chain: Arc::downgrade(&chain), @@ -699,13 +714,23 @@ impl NetToChainAdapter { /// Implementation of the ChainAdapter for the network. Gets notified when the /// accepted a new block, asking the pool to update its state and /// the network to broadcast the block -pub struct ChainToPoolAndNetAdapter { - tx_pool: Arc>, +pub struct ChainToPoolAndNetAdapter +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ + tx_pool: Arc>>, peers: OneTime>, hooks: Vec>, } -impl ChainAdapter for ChainToPoolAndNetAdapter { +impl ChainAdapter for ChainToPoolAndNetAdapter +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ fn block_accepted(&self, b: &core::Block, status: BlockStatus, opts: Options) { // not broadcasting blocks received through sync if !opts.contains(chain::Options::SYNC) { @@ -749,12 +774,17 @@ impl ChainAdapter for ChainToPoolAndNetAdapter { } } -impl ChainToPoolAndNetAdapter { +impl ChainToPoolAndNetAdapter +where + B: BlockChain, + P: PoolAdapter, + V: VerifierCache + 'static, +{ /// Construct a ChainToPoolAndNetAdapter instance. pub fn new( - tx_pool: Arc>, + tx_pool: Arc>>, hooks: Vec>, - ) -> ChainToPoolAndNetAdapter { + ) -> Self { ChainToPoolAndNetAdapter { tx_pool, peers: OneTime::new(), diff --git a/servers/src/grin/dandelion_monitor.rs b/servers/src/grin/dandelion_monitor.rs index 90cd5a9fd..5f6937990 100644 --- a/servers/src/grin/dandelion_monitor.rs +++ b/servers/src/grin/dandelion_monitor.rs @@ -22,8 +22,9 @@ use crate::common::adapters::DandelionAdapter; use crate::core::core::hash::Hashed; use crate::core::core::transaction; use crate::core::core::verifier_cache::VerifierCache; -use crate::pool::{DandelionConfig, Pool, PoolEntry, PoolError, TransactionPool, TxSource}; -use crate::util::{RwLock, StopState}; +use crate::pool::{BlockChain, DandelionConfig, Pool, PoolEntry, PoolError, TxSource}; +use crate::util::StopState; +use crate::{ServerTxPool, ServerVerifierCache}; /// A process to monitor transactions in the stempool. /// With Dandelion, transaction can be broadcasted in stem or fluff phase. @@ -35,9 +36,9 @@ use crate::util::{RwLock, StopState}; /// sending only to the peer relay. pub fn monitor_transactions( dandelion_config: DandelionConfig, - tx_pool: Arc>, + tx_pool: ServerTxPool, adapter: Arc, - verifier_cache: Arc>, + verifier_cache: ServerVerifierCache, stop_state: Arc, ) -> std::io::Result> { debug!("Started Dandelion transaction monitor."); @@ -90,7 +91,11 @@ pub fn monitor_transactions( // Query the pool for transactions older than the cutoff. // Used for both periodic fluffing and handling expired embargo timer. -fn select_txs_cutoff(pool: &Pool, cutoff_secs: u16) -> Vec { +fn select_txs_cutoff(pool: &Pool, cutoff_secs: u16) -> Vec +where + B: BlockChain, + V: VerifierCache, +{ let cutoff = Utc::now().timestamp() - cutoff_secs as i64; pool.entries .iter() @@ -101,9 +106,9 @@ fn select_txs_cutoff(pool: &Pool, cutoff_secs: u16) -> Vec { fn process_fluff_phase( dandelion_config: &DandelionConfig, - tx_pool: &Arc>, + tx_pool: &ServerTxPool, adapter: &Arc, - verifier_cache: &Arc>, + verifier_cache: &ServerVerifierCache, ) -> Result<(), PoolError> { // Take a write lock on the txpool for the duration of this processing. let mut tx_pool = tx_pool.write(); @@ -153,7 +158,7 @@ fn process_fluff_phase( fn process_expired_entries( dandelion_config: &DandelionConfig, - tx_pool: &Arc>, + tx_pool: &ServerTxPool, ) -> Result<(), PoolError> { // Take a write lock on the txpool for the duration of this processing. let mut tx_pool = tx_pool.write(); diff --git a/servers/src/grin/server.rs b/servers/src/grin/server.rs index adfd6f6dc..ce55084cd 100644 --- a/servers/src/grin/server.rs +++ b/servers/src/grin/server.rs @@ -41,7 +41,7 @@ use crate::common::stats::{ }; use crate::common::types::{Error, ServerConfig, StratumServerConfig}; use crate::core::core::hash::Hashed; -use crate::core::core::verifier_cache::{LruVerifierCache, VerifierCache}; +use crate::core::core::verifier_cache::LruVerifierCache; use crate::core::ser::ProtocolVersion; use crate::core::{consensus, genesis, global, pow}; use crate::grin::{dandelion_monitor, seed, sync}; @@ -54,6 +54,12 @@ use crate::util::file::get_first_line; use crate::util::{RwLock, StopState}; use grin_util::logger::LogEntry; +/// Arcified thread-safe TransactionPool with type parameters used by server components +pub type ServerTxPool = + Arc>>; +/// Arcified thread-safe LruVerifierCache +pub type ServerVerifierCache = Arc>; + /// Grin server holding internal structures. pub struct Server { /// server config @@ -63,10 +69,10 @@ pub struct Server { /// data store access pub chain: Arc, /// in-memory transaction pool - pub tx_pool: Arc>, + pub tx_pool: ServerTxPool, /// Shared cache for verification results when /// verifying rangeproof and kernel signatures. - verifier_cache: Arc>, + verifier_cache: ServerVerifierCache, /// Whether we're currently syncing pub sync_state: Arc, /// To be passed around to collect stats and info diff --git a/servers/src/lib.rs b/servers/src/lib.rs index eaa443c2b..be3d6a30a 100644 --- a/servers/src/lib.rs +++ b/servers/src/lib.rs @@ -41,4 +41,4 @@ mod mining; pub use crate::common::stats::{DiffBlock, PeerStats, ServerStats, StratumStats, WorkerStats}; pub use crate::common::types::{ServerConfig, StratumServerConfig}; -pub use crate::grin::server::Server; +pub use crate::grin::server::{Server, ServerTxPool, ServerVerifierCache}; diff --git a/servers/src/mining/mine_block.rs b/servers/src/mining/mine_block.rs index fea2359ea..a68443f57 100644 --- a/servers/src/mining/mine_block.rs +++ b/servers/src/mining/mine_block.rs @@ -15,7 +15,6 @@ //! Build a block to mine: gathers transactions from the pool, assembles //! them into a block and returns it. -use crate::util::RwLock; use chrono::prelude::{DateTime, NaiveDateTime, Utc}; use rand::{thread_rng, Rng}; use serde_json::{json, Value}; @@ -26,13 +25,12 @@ use std::time::Duration; use crate::api; use crate::chain; use crate::common::types::Error; -use crate::core::core::verifier_cache::VerifierCache; use crate::core::core::{Output, TxKernel}; use crate::core::libtx::secp_ser; use crate::core::libtx::ProofBuilder; use crate::core::{consensus, core, global}; use crate::keychain::{ExtKeychain, Identifier, Keychain}; -use crate::pool; +use crate::{ServerTxPool, ServerVerifierCache}; /// Fees in block to use for coinbase amount calculation /// (Duplicated from Grin wallet project) @@ -71,8 +69,8 @@ pub struct CbData { // Warning: This call does not return until/unless a new block can be built pub fn get_block( chain: &Arc, - tx_pool: &Arc>, - verifier_cache: Arc>, + tx_pool: &ServerTxPool, + verifier_cache: ServerVerifierCache, key_id: Option, wallet_listener_url: Option, ) -> (core::Block, BlockFees) { @@ -133,8 +131,8 @@ pub fn get_block( /// transactions from the pool. fn build_block( chain: &Arc, - tx_pool: &Arc>, - verifier_cache: Arc>, + tx_pool: &ServerTxPool, + verifier_cache: ServerVerifierCache, key_id: Option, wallet_listener_url: Option, ) -> Result<(core::Block, BlockFees), Error> { diff --git a/servers/src/mining/stratumserver.rs b/servers/src/mining/stratumserver.rs index 3cd83f18e..48fdd3bc1 100644 --- a/servers/src/mining/stratumserver.rs +++ b/servers/src/mining/stratumserver.rs @@ -36,13 +36,12 @@ use crate::chain::{self, SyncState}; use crate::common::stats::{StratumStats, WorkerStats}; use crate::common::types::StratumServerConfig; use crate::core::core::hash::Hashed; -use crate::core::core::verifier_cache::VerifierCache; use crate::core::core::Block; use crate::core::{pow, ser}; use crate::keychain; use crate::mining::mine_block; -use crate::pool; use crate::util::ToHex; +use crate::{ServerTxPool, ServerVerifierCache}; type Tx = mpsc::UnboundedSender; @@ -523,8 +522,8 @@ impl Handler { pub fn run( &self, config: &StratumServerConfig, - tx_pool: &Arc>, - verifier_cache: Arc>, + tx_pool: &ServerTxPool, + verifier_cache: ServerVerifierCache, ) { debug!("Run main loop"); let mut deadline: i64 = 0; @@ -803,8 +802,8 @@ pub struct StratumServer { id: String, config: StratumServerConfig, chain: Arc, - tx_pool: Arc>, - verifier_cache: Arc>, + pub tx_pool: ServerTxPool, + verifier_cache: ServerVerifierCache, sync_state: Arc, stratum_stats: Arc>, } @@ -814,8 +813,8 @@ impl StratumServer { pub fn new( config: StratumServerConfig, chain: Arc, - tx_pool: Arc>, - verifier_cache: Arc>, + tx_pool: ServerTxPool, + verifier_cache: ServerVerifierCache, stratum_stats: Arc>, ) -> StratumServer { StratumServer { diff --git a/servers/src/mining/test_miner.rs b/servers/src/mining/test_miner.rs index 582888270..3135b6b27 100644 --- a/servers/src/mining/test_miner.rs +++ b/servers/src/mining/test_miner.rs @@ -17,19 +17,17 @@ //! header with its proof-of-work. Any valid mined blocks are submitted to the //! network. -use crate::util::RwLock; use chrono::prelude::Utc; use std::sync::Arc; use crate::chain; use crate::common::types::StratumServerConfig; use crate::core::core::hash::{Hash, Hashed}; -use crate::core::core::verifier_cache::VerifierCache; use crate::core::core::{Block, BlockHeader}; use crate::core::global; use crate::mining::mine_block; -use crate::pool; use crate::util::StopState; +use crate::{ServerTxPool, ServerVerifierCache}; use grin_chain::SyncState; use std::thread; use std::time::Duration; @@ -37,8 +35,8 @@ use std::time::Duration; pub struct Miner { config: StratumServerConfig, chain: Arc, - tx_pool: Arc>, - verifier_cache: Arc>, + tx_pool: ServerTxPool, + verifier_cache: ServerVerifierCache, stop_state: Arc, sync_state: Arc, // Just to hold the port we're on, so this miner can be identified @@ -47,13 +45,13 @@ pub struct Miner { } impl Miner { - /// Creates a new Miner. Needs references to the chain state and its + // Creates a new Miner. Needs references to the chain state and its /// storage. pub fn new( config: StratumServerConfig, chain: Arc, - tx_pool: Arc>, - verifier_cache: Arc>, + tx_pool: ServerTxPool, + verifier_cache: ServerVerifierCache, stop_state: Arc, sync_state: Arc, ) -> Miner {