Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #234 from zoedberg/revert_tmp_electrum_client_fix
Browse files Browse the repository at this point in the history
revert electrum-client usage temporary fix
  • Loading branch information
dr-orlovsky authored Dec 29, 2022
2 parents 13c119e + f8c9895 commit 770ce83
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
14 changes: 1 addition & 13 deletions src/bucketd/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::io::Write;

use bitcoin::{OutPoint, Txid};
use commit_verify::{lnpbp4, CommitConceal, TaggedHash};
use electrum_client::{Client as ElectrumClient, ConfigBuilder};
use psbt::Psbt;
use rgb::psbt::RgbExt;
use rgb::schema::{OwnedRightType, TransitionType};
Expand All @@ -35,8 +34,6 @@ use crate::amplify::Wrapper;
use crate::db::{self, StoreRpcExt};
use crate::DaemonError;

const ELECTRUM_TIMEOUT: u8 = 4;

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display, Error, From)]
#[display(doc_comments)]
pub enum StashError {
Expand Down Expand Up @@ -130,15 +127,6 @@ pub enum FinalizeError {
}

impl Runtime {
fn _new_electrum_client(&self) -> Result<ElectrumClient, DaemonError> {
let electrum_config = ConfigBuilder::new()
.timeout(Some(ELECTRUM_TIMEOUT))
.expect("cannot fail since socks5 is unset")
.build();
ElectrumClient::from_config(&self.electrum_url, electrum_config)
.map_err(|e| DaemonError::ElectrumConnectivity(e.to_string()))
}

/// Processes incoming transfer downloaded as a container locally
pub(super) fn process_container(
&mut self,
Expand Down Expand Up @@ -189,7 +177,7 @@ impl Runtime {
trace!("Starting with contract state {:?}", state);

debug!("Validating consignment {} for contract {}", id, contract_id);
let status = Validator::validate(&consignment, &self._new_electrum_client()?);
let status = Validator::validate(&consignment, &self.electrum);
info!("Consignment validation result is {}", status.validity());

match status.validity() {
Expand Down
14 changes: 12 additions & 2 deletions src/bucketd/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use amplify::num::u24;
use bitcoin::secp256k1::rand::random;
use bitcoin::{OutPoint, Txid};
use commit_verify::ConsensusCommit;
use electrum_client::{Client as ElectrumClient, ConfigBuilder};
use internet2::addr::NodeAddr;
use internet2::ZmqSocketType;
use microservices::error::BootstrapError;
Expand Down Expand Up @@ -45,6 +46,8 @@ use crate::bus::{
};
use crate::{Config, DaemonError, LaunchError};

const ELECTRUM_TIMEOUT: u8 = 4;

pub fn run(config: Config) -> Result<(), BootstrapError<LaunchError>> {
let storm_endpoint = config.storm_endpoint.clone();
let rpc_endpoint = config.rpc_endpoint.clone();
Expand Down Expand Up @@ -82,7 +85,7 @@ pub fn run(config: Config) -> Result<(), BootstrapError<LaunchError>> {
pub struct Runtime {
id: DaemonId,

pub(crate) electrum_url: String,
pub(crate) electrum: ElectrumClient,

pub(crate) store: store_rpc::Client,
}
Expand All @@ -95,12 +98,19 @@ impl Runtime {

let id = random();

let electrum_config = ConfigBuilder::new()
.timeout(Some(ELECTRUM_TIMEOUT))
.expect("cannot fail since socks5 is unset")
.build();
let electrum = ElectrumClient::from_config(&config.electrum_url, electrum_config)
.map_err(|e| LaunchError::ElectrumConnectivity(e.to_string()))?;

info!("Bucket runtime started successfully");

Ok(Self {
id,
store,
electrum_url: config.electrum_url,
electrum,
})
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub enum LaunchError {
#[from]
StoreConnection(ServerError<store_rpc::FailureCode>),

/// can't connect to electrum server
ElectrumConnectivity,
/// electrum connectivity error. Details: {0}
ElectrumConnectivity(String),
}

impl microservices::error::Error for LaunchError {}
Expand Down Expand Up @@ -71,9 +71,6 @@ pub(crate) enum DaemonError {
#[from(bp::dbc::anchor::Error)]
Finalize(FinalizeError),

/// electrum connectivity error. Details: {0}
ElectrumConnectivity(String),

/// the container which was requested to be processed is absent in sthe store
NoContainer(ContainerId),

Expand Down Expand Up @@ -101,7 +98,6 @@ impl From<DaemonError> for RpcMsg {
DaemonError::BucketLauncher(_) => FailureCode::Launcher,
DaemonError::Stash(_) => FailureCode::Stash,
DaemonError::Finalize(_) => FailureCode::Finalize,
DaemonError::ElectrumConnectivity(_) => FailureCode::ElectrumConnectivity,
DaemonError::NoContainer(_) => FailureCode::Store,
};
RpcMsg::Failure(rpc::Failure {
Expand Down

0 comments on commit 770ce83

Please sign in to comment.