Skip to content

Commit 770ce83

Browse files
authored
Merge pull request #234 from zoedberg/revert_tmp_electrum_client_fix
revert electrum-client usage temporary fix
2 parents 13c119e + f8c9895 commit 770ce83

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

src/bucketd/processor.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::io::Write;
1414

1515
use bitcoin::{OutPoint, Txid};
1616
use commit_verify::{lnpbp4, CommitConceal, TaggedHash};
17-
use electrum_client::{Client as ElectrumClient, ConfigBuilder};
1817
use psbt::Psbt;
1918
use rgb::psbt::RgbExt;
2019
use rgb::schema::{OwnedRightType, TransitionType};
@@ -35,8 +34,6 @@ use crate::amplify::Wrapper;
3534
use crate::db::{self, StoreRpcExt};
3635
use crate::DaemonError;
3736

38-
const ELECTRUM_TIMEOUT: u8 = 4;
39-
4037
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display, Error, From)]
4138
#[display(doc_comments)]
4239
pub enum StashError {
@@ -130,15 +127,6 @@ pub enum FinalizeError {
130127
}
131128

132129
impl Runtime {
133-
fn _new_electrum_client(&self) -> Result<ElectrumClient, DaemonError> {
134-
let electrum_config = ConfigBuilder::new()
135-
.timeout(Some(ELECTRUM_TIMEOUT))
136-
.expect("cannot fail since socks5 is unset")
137-
.build();
138-
ElectrumClient::from_config(&self.electrum_url, electrum_config)
139-
.map_err(|e| DaemonError::ElectrumConnectivity(e.to_string()))
140-
}
141-
142130
/// Processes incoming transfer downloaded as a container locally
143131
pub(super) fn process_container(
144132
&mut self,
@@ -189,7 +177,7 @@ impl Runtime {
189177
trace!("Starting with contract state {:?}", state);
190178

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

195183
match status.validity() {

src/bucketd/service.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use amplify::num::u24;
1717
use bitcoin::secp256k1::rand::random;
1818
use bitcoin::{OutPoint, Txid};
1919
use commit_verify::ConsensusCommit;
20+
use electrum_client::{Client as ElectrumClient, ConfigBuilder};
2021
use internet2::addr::NodeAddr;
2122
use internet2::ZmqSocketType;
2223
use microservices::error::BootstrapError;
@@ -45,6 +46,8 @@ use crate::bus::{
4546
};
4647
use crate::{Config, DaemonError, LaunchError};
4748

49+
const ELECTRUM_TIMEOUT: u8 = 4;
50+
4851
pub fn run(config: Config) -> Result<(), BootstrapError<LaunchError>> {
4952
let storm_endpoint = config.storm_endpoint.clone();
5053
let rpc_endpoint = config.rpc_endpoint.clone();
@@ -82,7 +85,7 @@ pub fn run(config: Config) -> Result<(), BootstrapError<LaunchError>> {
8285
pub struct Runtime {
8386
id: DaemonId,
8487

85-
pub(crate) electrum_url: String,
88+
pub(crate) electrum: ElectrumClient,
8689

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

9699
let id = random();
97100

101+
let electrum_config = ConfigBuilder::new()
102+
.timeout(Some(ELECTRUM_TIMEOUT))
103+
.expect("cannot fail since socks5 is unset")
104+
.build();
105+
let electrum = ElectrumClient::from_config(&config.electrum_url, electrum_config)
106+
.map_err(|e| LaunchError::ElectrumConnectivity(e.to_string()))?;
107+
98108
info!("Bucket runtime started successfully");
99109

100110
Ok(Self {
101111
id,
102112
store,
103-
electrum_url: config.electrum_url,
113+
electrum,
104114
})
105115
}
106116
}

src/error.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub enum LaunchError {
2929
#[from]
3030
StoreConnection(ServerError<store_rpc::FailureCode>),
3131

32-
/// can't connect to electrum server
33-
ElectrumConnectivity,
32+
/// electrum connectivity error. Details: {0}
33+
ElectrumConnectivity(String),
3434
}
3535

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

74-
/// electrum connectivity error. Details: {0}
75-
ElectrumConnectivity(String),
76-
7774
/// the container which was requested to be processed is absent in sthe store
7875
NoContainer(ContainerId),
7976

@@ -101,7 +98,6 @@ impl From<DaemonError> for RpcMsg {
10198
DaemonError::BucketLauncher(_) => FailureCode::Launcher,
10299
DaemonError::Stash(_) => FailureCode::Stash,
103100
DaemonError::Finalize(_) => FailureCode::Finalize,
104-
DaemonError::ElectrumConnectivity(_) => FailureCode::ElectrumConnectivity,
105101
DaemonError::NoContainer(_) => FailureCode::Store,
106102
};
107103
RpcMsg::Failure(rpc::Failure {

0 commit comments

Comments
 (0)