mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Improve wallet + node API Comms error logging (#2472)
* make wallet+node communication errors more verbose * rustfmt
This commit is contained in:
parent
dd1a24dcbc
commit
a97ab376cb
6 changed files with 61 additions and 35 deletions
|
@ -48,10 +48,15 @@ impl WalletCommAdapter for HTTPWalletCommAdapter {
|
||||||
let url = format!("{}/v1/wallet/foreign/receive_tx", dest);
|
let url = format!("{}/v1/wallet/foreign/receive_tx", dest);
|
||||||
debug!("Posting transaction slate to {}", url);
|
debug!("Posting transaction slate to {}", url);
|
||||||
|
|
||||||
let res = api::client::post(url.as_str(), None, slate).context(
|
let res = api::client::post(url.as_str(), None, slate);
|
||||||
ErrorKind::ClientCallback("Posting transaction slate (is recipient listening?)"),
|
match res {
|
||||||
)?;
|
Err(e) => {
|
||||||
Ok(res)
|
let report = format!("Posting transaction slate (is recipient listening?): {}", e);
|
||||||
|
error!("{}", report);
|
||||||
|
Err(ErrorKind::ClientCallback(report).into())
|
||||||
|
}
|
||||||
|
Ok(r) => Ok(r),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_tx_async(&self, _dest: &str, _slate: &Slate) -> Result<(), Error> {
|
fn send_tx_async(&self, _dest: &str, _slate: &Slate) -> Result<(), Error> {
|
||||||
|
|
|
@ -291,7 +291,11 @@ impl WalletCommAdapter for KeybaseWalletCommAdapter {
|
||||||
// Send original slate to recipient with the SLATE_NEW topic
|
// Send original slate to recipient with the SLATE_NEW topic
|
||||||
match send(slate, addr, SLATE_NEW, TTL) {
|
match send(slate, addr, SLATE_NEW, TTL) {
|
||||||
true => (),
|
true => (),
|
||||||
false => return Err(ErrorKind::ClientCallback("Posting transaction slate"))?,
|
false => {
|
||||||
|
return Err(ErrorKind::ClientCallback(
|
||||||
|
"Posting transaction slate".to_owned(),
|
||||||
|
))?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
info!(
|
info!(
|
||||||
"tx request has been sent to @{}, tx uuid: {}",
|
"tx request has been sent to @{}, tx uuid: {}",
|
||||||
|
@ -300,7 +304,11 @@ impl WalletCommAdapter for KeybaseWalletCommAdapter {
|
||||||
// Wait for response from recipient with SLATE_SIGNED topic
|
// Wait for response from recipient with SLATE_SIGNED topic
|
||||||
match poll(TTL as u64, addr) {
|
match poll(TTL as u64, addr) {
|
||||||
Some(slate) => return Ok(slate),
|
Some(slate) => return Ok(slate),
|
||||||
None => return Err(ErrorKind::ClientCallback("Receiving reply from recipient"))?,
|
None => {
|
||||||
|
return Err(ErrorKind::ClientCallback(
|
||||||
|
"Receiving reply from recipient".to_owned(),
|
||||||
|
))?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -365,7 +365,9 @@ where
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("unsupported payment method: {}", args.method);
|
error!("unsupported payment method: {}", args.method);
|
||||||
return Err(ErrorKind::ClientCallback("unsupported payment method"))?;
|
return Err(ErrorKind::ClientCallback(
|
||||||
|
"unsupported payment method".to_owned(),
|
||||||
|
))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
api.tx_lock_outputs(&slate, lock_fn)?;
|
api.tx_lock_outputs(&slate, lock_fn)?;
|
||||||
|
|
|
@ -93,7 +93,7 @@ pub enum ErrorKind {
|
||||||
|
|
||||||
/// API Error
|
/// API Error
|
||||||
#[fail(display = "Client Callback Error: {}", _0)]
|
#[fail(display = "Client Callback Error: {}", _0)]
|
||||||
ClientCallback(&'static str),
|
ClientCallback(String),
|
||||||
|
|
||||||
/// Secp Error
|
/// Secp Error
|
||||||
#[fail(display = "Secp error")]
|
#[fail(display = "Secp error")]
|
||||||
|
|
|
@ -69,9 +69,12 @@ impl NodeClient for HTTPNodeClient {
|
||||||
} else {
|
} else {
|
||||||
url = format!("{}/v1/pool/push", dest);
|
url = format!("{}/v1/pool/push", dest);
|
||||||
}
|
}
|
||||||
api::client::post_no_ret(url.as_str(), self.node_api_secret(), tx).context(
|
let res = api::client::post_no_ret(url.as_str(), self.node_api_secret(), tx);
|
||||||
libwallet::ErrorKind::ClientCallback("Posting transaction to node"),
|
if let Err(e) = res {
|
||||||
)?;
|
let report = format!("Posting transaction to node: {}", e);
|
||||||
|
error!("Post TX Error: {}", e);
|
||||||
|
return Err(libwallet::ErrorKind::ClientCallback(report).into());
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,10 +82,15 @@ impl NodeClient for HTTPNodeClient {
|
||||||
fn get_chain_height(&self) -> Result<u64, libwallet::Error> {
|
fn get_chain_height(&self) -> Result<u64, libwallet::Error> {
|
||||||
let addr = self.node_url();
|
let addr = self.node_url();
|
||||||
let url = format!("{}/v1/chain", addr);
|
let url = format!("{}/v1/chain", addr);
|
||||||
let res = api::client::get::<api::Tip>(url.as_str(), self.node_api_secret()).context(
|
let res = api::client::get::<api::Tip>(url.as_str(), self.node_api_secret());
|
||||||
libwallet::ErrorKind::ClientCallback("Getting chain height from node"),
|
match res {
|
||||||
)?;
|
Err(e) => {
|
||||||
Ok(res.height)
|
let report = format!("Getting chain height from node: {}", e);
|
||||||
|
error!("Get chain height error: {}", e);
|
||||||
|
Err(libwallet::ErrorKind::ClientCallback(report).into())
|
||||||
|
}
|
||||||
|
Ok(r) => Ok(r.height),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve outputs from node
|
/// Retrieve outputs from node
|
||||||
|
@ -116,8 +124,9 @@ impl NodeClient for HTTPNodeClient {
|
||||||
let results = match rt.block_on(task) {
|
let results = match rt.block_on(task) {
|
||||||
Ok(outputs) => outputs,
|
Ok(outputs) => outputs,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
let report = format!("Getting outputs by id: {}", e);
|
||||||
error!("Outputs by id failed: {}", e);
|
error!("Outputs by id failed: {}", e);
|
||||||
return Err(libwallet::ErrorKind::ClientCallback("Error from server"))?;
|
return Err(libwallet::ErrorKind::ClientCallback(report).into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -173,12 +182,11 @@ impl NodeClient for HTTPNodeClient {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// if we got anything other than 200 back from server, bye
|
// if we got anything other than 200 back from server, bye
|
||||||
error!(
|
error!(
|
||||||
"get_outputs_by_pmmr_index: unable to contact API {}. Error: {}",
|
"get_outputs_by_pmmr_index: error contacting {}. Error: {}",
|
||||||
addr, e
|
addr, e
|
||||||
);
|
);
|
||||||
Err(libwallet::ErrorKind::ClientCallback(
|
let report = format!("outputs by pmmr index: {}", e);
|
||||||
"unable to contact api",
|
Err(libwallet::ErrorKind::ClientCallback(report))?
|
||||||
))?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,15 +177,15 @@ where
|
||||||
fn post_tx(&mut self, m: WalletProxyMessage) -> Result<WalletProxyMessage, libwallet::Error> {
|
fn post_tx(&mut self, m: WalletProxyMessage) -> Result<WalletProxyMessage, libwallet::Error> {
|
||||||
let dest_wallet = self.wallets.get_mut(&m.sender_id).unwrap().1.clone();
|
let dest_wallet = self.wallets.get_mut(&m.sender_id).unwrap().1.clone();
|
||||||
let wrapper: TxWrapper = serde_json::from_str(&m.body).context(
|
let wrapper: TxWrapper = serde_json::from_str(&m.body).context(
|
||||||
libwallet::ErrorKind::ClientCallback("Error parsing TxWrapper"),
|
libwallet::ErrorKind::ClientCallback("Error parsing TxWrapper".to_owned()),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let tx_bin = util::from_hex(wrapper.tx_hex).context(
|
let tx_bin = util::from_hex(wrapper.tx_hex).context(
|
||||||
libwallet::ErrorKind::ClientCallback("Error parsing TxWrapper: tx_bin"),
|
libwallet::ErrorKind::ClientCallback("Error parsing TxWrapper: tx_bin".to_owned()),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let tx: Transaction = ser::deserialize(&mut &tx_bin[..]).context(
|
let tx: Transaction = ser::deserialize(&mut &tx_bin[..]).context(
|
||||||
libwallet::ErrorKind::ClientCallback("Error parsing TxWrapper: tx"),
|
libwallet::ErrorKind::ClientCallback("Error parsing TxWrapper: tx".to_owned()),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
super::award_block_to_wallet(&self.chain, vec![&tx], dest_wallet)?;
|
super::award_block_to_wallet(&self.chain, vec![&tx], dest_wallet)?;
|
||||||
|
@ -323,15 +323,16 @@ impl LocalWalletClient {
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
let p = self.proxy_tx.lock();
|
let p = self.proxy_tx.lock();
|
||||||
p.send(m)
|
p.send(m).context(libwallet::ErrorKind::ClientCallback(
|
||||||
.context(libwallet::ErrorKind::ClientCallback("Send TX Slate"))?;
|
"Send TX Slate".to_owned(),
|
||||||
|
))?;
|
||||||
}
|
}
|
||||||
let r = self.rx.lock();
|
let r = self.rx.lock();
|
||||||
let m = r.recv().unwrap();
|
let m = r.recv().unwrap();
|
||||||
trace!("Received send_tx_slate response: {:?}", m.clone());
|
trace!("Received send_tx_slate response: {:?}", m.clone());
|
||||||
Ok(
|
Ok(
|
||||||
serde_json::from_str(&m.body).context(libwallet::ErrorKind::ClientCallback(
|
serde_json::from_str(&m.body).context(libwallet::ErrorKind::ClientCallback(
|
||||||
"Parsing send_tx_slate response",
|
"Parsing send_tx_slate response".to_owned(),
|
||||||
))?,
|
))?,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -352,15 +353,16 @@ impl WalletCommAdapter for LocalWalletClient {
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
let p = self.proxy_tx.lock();
|
let p = self.proxy_tx.lock();
|
||||||
p.send(m)
|
p.send(m).context(libwallet::ErrorKind::ClientCallback(
|
||||||
.context(libwallet::ErrorKind::ClientCallback("Send TX Slate"))?;
|
"Send TX Slate".to_owned(),
|
||||||
|
))?;
|
||||||
}
|
}
|
||||||
let r = self.rx.lock();
|
let r = self.rx.lock();
|
||||||
let m = r.recv().unwrap();
|
let m = r.recv().unwrap();
|
||||||
trace!("Received send_tx_slate response: {:?}", m.clone());
|
trace!("Received send_tx_slate response: {:?}", m.clone());
|
||||||
Ok(
|
Ok(
|
||||||
serde_json::from_str(&m.body).context(libwallet::ErrorKind::ClientCallback(
|
serde_json::from_str(&m.body).context(libwallet::ErrorKind::ClientCallback(
|
||||||
"Parsing send_tx_slate response",
|
"Parsing send_tx_slate response".to_owned(),
|
||||||
))?,
|
))?,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -405,8 +407,9 @@ impl NodeClient for LocalWalletClient {
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
let p = self.proxy_tx.lock();
|
let p = self.proxy_tx.lock();
|
||||||
p.send(m)
|
p.send(m).context(libwallet::ErrorKind::ClientCallback(
|
||||||
.context(libwallet::ErrorKind::ClientCallback("post_tx send"))?;
|
"post_tx send".to_owned(),
|
||||||
|
))?;
|
||||||
}
|
}
|
||||||
let r = self.rx.lock();
|
let r = self.rx.lock();
|
||||||
let m = r.recv().unwrap();
|
let m = r.recv().unwrap();
|
||||||
|
@ -425,7 +428,7 @@ impl NodeClient for LocalWalletClient {
|
||||||
{
|
{
|
||||||
let p = self.proxy_tx.lock();
|
let p = self.proxy_tx.lock();
|
||||||
p.send(m).context(libwallet::ErrorKind::ClientCallback(
|
p.send(m).context(libwallet::ErrorKind::ClientCallback(
|
||||||
"Get chain height send",
|
"Get chain height send".to_owned(),
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
let r = self.rx.lock();
|
let r = self.rx.lock();
|
||||||
|
@ -434,7 +437,7 @@ impl NodeClient for LocalWalletClient {
|
||||||
Ok(m.body
|
Ok(m.body
|
||||||
.parse::<u64>()
|
.parse::<u64>()
|
||||||
.context(libwallet::ErrorKind::ClientCallback(
|
.context(libwallet::ErrorKind::ClientCallback(
|
||||||
"Parsing get_height response",
|
"Parsing get_height response".to_owned(),
|
||||||
))?)
|
))?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,7 +460,7 @@ impl NodeClient for LocalWalletClient {
|
||||||
{
|
{
|
||||||
let p = self.proxy_tx.lock();
|
let p = self.proxy_tx.lock();
|
||||||
p.send(m).context(libwallet::ErrorKind::ClientCallback(
|
p.send(m).context(libwallet::ErrorKind::ClientCallback(
|
||||||
"Get outputs from node send",
|
"Get outputs from node send".to_owned(),
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
let r = self.rx.lock();
|
let r = self.rx.lock();
|
||||||
|
@ -496,7 +499,7 @@ impl NodeClient for LocalWalletClient {
|
||||||
{
|
{
|
||||||
let p = self.proxy_tx.lock();
|
let p = self.proxy_tx.lock();
|
||||||
p.send(m).context(libwallet::ErrorKind::ClientCallback(
|
p.send(m).context(libwallet::ErrorKind::ClientCallback(
|
||||||
"Get outputs from node by PMMR index send",
|
"Get outputs from node by PMMR index send".to_owned(),
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue