mirror of
https://code.gri.mw/GUI/grim.git
synced 2026-07-19 13:19:39 +00:00
stratum: start/stop refactoring, add ability to disable stratum server without node restart
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
//! Build a block to mine: gathers transactions from the pool, assembles
|
||||
//! them into a block and returns it.
|
||||
|
||||
use std::panic::panic_any;
|
||||
use chrono::prelude::{DateTime, NaiveDateTime, Utc};
|
||||
use rand::{thread_rng, Rng};
|
||||
use serde_json::{json, Value};
|
||||
@@ -33,6 +34,7 @@ use grin_keychain::{ExtKeychain, Identifier, Keychain};
|
||||
use grin_servers::ServerTxPool;
|
||||
use log::{debug, error, trace, warn};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use crate::node::stratum::StratumStopState;
|
||||
|
||||
/// Fees in block to use for coinbase amount calculation
|
||||
/// (Duplicated from Grin wallet project)
|
||||
@@ -74,6 +76,7 @@ pub fn get_block(
|
||||
tx_pool: &ServerTxPool,
|
||||
key_id: Option<Identifier>,
|
||||
wallet_listener_url: Option<String>,
|
||||
stop_state: &Arc<StratumStopState>
|
||||
) -> (core::Block, BlockFees) {
|
||||
let wallet_retry_interval = 5;
|
||||
// get the latest chain state and build a block on top of it
|
||||
@@ -111,6 +114,11 @@ pub fn get_block(
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
}
|
||||
|
||||
// Stop attempts to build a block on stop.
|
||||
if stop_state.is_stopped() {
|
||||
panic_any("Stopped");
|
||||
}
|
||||
|
||||
result = build_block(chain, tx_pool, new_key_id, wallet_listener_url.clone());
|
||||
}
|
||||
return result.unwrap();
|
||||
@@ -141,7 +149,6 @@ fn build_block(
|
||||
// If this fails for *any* reason then fallback to an empty vec of txs.
|
||||
// This will allow us to mine an "empty" block if the txpool is in an
|
||||
// invalid (and unexpected) state.
|
||||
println!("12345 prepare_mineable_transactions");
|
||||
let txs = match tx_pool.read().prepare_mineable_transactions() {
|
||||
Ok(txs) => txs,
|
||||
Err(e) => {
|
||||
@@ -153,7 +160,6 @@ fn build_block(
|
||||
vec![]
|
||||
}
|
||||
};
|
||||
println!("12345 after prepare_mineable_transactions");
|
||||
|
||||
// build the coinbase and the block itself
|
||||
let fees = txs.iter().map(|tx| tx.fee()).sum();
|
||||
|
||||
Reference in New Issue
Block a user