From 820d55a532ba139da64755a21f140ca298a56425 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Wed, 25 Apr 2018 16:48:19 +0100 Subject: [PATCH] Change wallet retry strategy (and address stratum panic) (#1004) * remove complex retry from wallet client * remove complex retry from wallet client * move retry code to stratum --- servers/src/mining/mine_block.rs | 10 ++++++++- wallet/src/client.rs | 35 +++++--------------------------- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/servers/src/mining/mine_block.rs b/servers/src/mining/mine_block.rs index 56a8f1c5b..c822a4727 100644 --- a/servers/src/mining/mine_block.rs +++ b/servers/src/mining/mine_block.rs @@ -86,6 +86,7 @@ pub fn get_block( max_tx: u32, wallet_listener_url: Option, ) -> (core::Block, BlockFees) { + let wallet_retry_interval = 5; // get the latest chain state and build a block on top of it let mut result = build_block( chain, @@ -102,6 +103,14 @@ pub fn get_block( "Duplicate commit for potential coinbase detected. Trying next derivation." ); } + self::Error::Wallet(_) => { + error!( + LOGGER, + "Stratum server: Can't connect to wallet listener at {:?}; will retry", + wallet_listener_url.as_ref().unwrap() + ); + thread::sleep(Duration::from_secs(wallet_retry_interval)); + } ae => { warn!(LOGGER, "Error building new block: {:?}. Retrying.", ae); } @@ -227,7 +236,6 @@ fn get_coinbase( let url = format!("{}/v1/receive/coinbase", wallet_listener_url.as_str()); let res = wallet::client::create_coinbase(&url, &block_fees)?; - let out_bin = util::from_hex(res.output).unwrap(); let kern_bin = util::from_hex(res.kernel).unwrap(); let key_id_bin = util::from_hex(res.key_id).unwrap(); diff --git a/wallet/src/client.rs b/wallet/src/client.rs index 9ca21cdda..ac715cd45 100644 --- a/wallet/src/client.rs +++ b/wallet/src/client.rs @@ -12,17 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::time; -use std::ops::FnMut; - use futures::{Future, Stream}; use failure::ResultExt; use hyper; use hyper::{Method, Request}; use hyper::header::ContentType; use tokio_core::reactor; -use tokio_retry::Retry; -use tokio_retry::strategy::FibonacciBackoff; use serde_json; use types::*; @@ -32,36 +27,16 @@ use std::io; /// Call the wallet API to create a coinbase output for the given block_fees. /// Will retry based on default "retry forever with backoff" behavior. pub fn create_coinbase(url: &str, block_fees: &BlockFees) -> Result { - let mut has_error = false; - - retry_backoff_forever(|| { - let res = single_create_coinbase(&url, &block_fees); - if let Err(_) = res { - has_error = true; + match single_create_coinbase(&url, &block_fees) { + Err(e) => { error!( LOGGER, "Failed to get coinbase from {}. Run grin wallet listen", url ); + Err(e) } - if has_error { - error!(LOGGER, "Successfully received coinbase from {}", url); - } - res - }) -} - -/// Runs the specified function wrapped in some basic retry logic. -fn retry_backoff_forever(f: F) -> Result -where - F: FnMut() -> Result, -{ - let mut core = - reactor::Core::new().context(ErrorKind::GenericError("Could not create reactor"))?; - let retry_strategy = - FibonacciBackoff::from_millis(100).max_delay(time::Duration::from_secs(10)); - let retry_future = Retry::spawn(core.handle(), retry_strategy, f); - let res = core.run(retry_future).unwrap(); - Ok(res) + Ok(res) => Ok(res), + } } pub fn send_partial_tx(url: &str, partial_tx: &PartialTx, fluff: bool) -> Result {