Skip to content

Commit 525b436

Browse files
committed
Fix rpc retry shutdown during SIGINT & implement tabled for TxInfo
1 parent f6db735 commit 525b436

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

node/src/sync.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,17 @@ impl Spaced {
171171
return Err(e);
172172
}
173173
warn!("Restore: {} - retrying in 1s", e);
174-
std_wait(|| shutdown_signal.try_recv().is_ok(), Duration::from_secs(1));
174+
let mut wait_recv = shutdown.subscribe();
175+
std_wait(|| wait_recv.try_recv().is_ok(), Duration::from_secs(1));
175176
}
176177
// Even if we couldn't restore just attempt to re-sync
177178
let new_tip = self.chain.state.tip.read().expect("read").clone();
178179
fetcher.restart(new_tip, &receiver);
179180
}
180181
BlockEvent::Error(e) => {
181182
warn!("Fetcher: {} - retrying in 1s", e);
182-
std_wait(|| shutdown_signal.try_recv().is_ok(), Duration::from_secs(1));
183+
let mut wait_recv = shutdown.subscribe();
184+
std_wait(|| wait_recv.try_recv().is_ok(), Duration::from_secs(1));
183185
// Even if we couldn't restore just attempt to re-sync
184186
let new_tip = self.chain.state.tip.read().expect("read").clone();
185187
fetcher.restart(new_tip, &receiver);

node/src/wallets.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use log::{info, warn};
1010
use protocol::{bitcoin::Txid, constants::ChainAnchor, hasher::{KeyHasher, SpaceKey}, script::SpaceScript, slabel::SLabel, FullSpaceOut, SpaceOut};
1111
use serde::{Deserialize, Serialize};
1212
use serde_json::json;
13+
use tabled::Tabled;
1314
use tokio::{
1415
select,
1516
sync::{broadcast, mpsc, mpsc::Receiver, oneshot},
@@ -45,16 +46,37 @@ pub struct ListSpacesResponse {
4546
pub owned: Vec<FullSpaceOut>,
4647
}
4748

48-
#[derive(Debug, Clone, Serialize, Deserialize)]
49+
50+
#[derive(Tabled, Debug, Clone, Serialize, Deserialize)]
51+
#[tabled(rename_all = "UPPERCASE")]
4952
pub struct TxInfo {
5053
pub txid: Txid,
5154
pub confirmed: bool,
5255
pub sent: Amount,
5356
pub received: Amount,
57+
#[tabled(display_with = "display_fee")]
5458
pub fee: Option<Amount>,
59+
#[tabled(rename = "DETAILS", display_with = "display_events")]
5560
pub events: Vec<TxEvent>,
5661
}
5762

63+
fn display_fee(fee: &Option<Amount>) -> String {
64+
match fee {
65+
None => "--".to_string(),
66+
Some(fee) => fee.to_string()
67+
}
68+
}
69+
70+
fn display_events(events: &Vec<TxEvent>) -> String {
71+
events
72+
.iter()
73+
.map(|e|
74+
format!("{} {}",
75+
e.kind,
76+
e.space.as_ref().map(|s| s.clone()).unwrap_or("".to_string())))
77+
.collect::<Vec<String>>().join("\n")
78+
}
79+
5880
#[derive(Debug, Clone, Serialize, Deserialize)]
5981
pub struct WalletResponse {
6082
pub result: Vec<TxResponse>,
@@ -429,7 +451,7 @@ impl RpcWallet {
429451
mut state: LiveSnapshot,
430452
mut wallet: SpacesWallet,
431453
mut commands: Receiver<WalletCommand>,
432-
mut shutdown: broadcast::Receiver<()>,
454+
shutdown: broadcast::Sender<()>,
433455
num_workers: usize,
434456
) -> anyhow::Result<()> {
435457
let (fetcher, receiver) = BlockFetcher::new(source.clone(), num_workers);
@@ -442,11 +464,12 @@ impl RpcWallet {
442464
}
443465
};
444466

467+
let mut shutdown_recv = shutdown.subscribe();
445468
fetcher.start(wallet_tip);
446469
let mut synced_at_least_once = false;
447470
let mut last_mempool_check = Instant::now();
448471
loop {
449-
if shutdown.try_recv().is_ok() {
472+
if shutdown_recv.try_recv().is_ok() {
450473
info!("Shutting down wallet sync");
451474
break;
452475
}
@@ -542,7 +565,8 @@ impl RpcWallet {
542565
}
543566
BlockEvent::Error(e) => {
544567
warn!("Fetcher: {} - retrying in 1s", e);
545-
std_wait(|| shutdown.try_recv().is_ok(), Duration::from_secs(1));
568+
let mut wait_recv = shutdown.subscribe();
569+
std_wait(|| wait_recv.try_recv().is_ok(), Duration::from_secs(1));
546570
fetcher.restart(wallet_tip, &receiver);
547571
}
548572
}
@@ -1091,7 +1115,7 @@ impl RpcWallet {
10911115
let wallet_name = loaded.export.label.clone();
10921116
let wallet_chain = store.clone();
10931117
let rpc = rpc.clone();
1094-
let wallet_shutdown = shutdown.subscribe();
1118+
let wallet_shutdown = shutdown.clone();
10951119
let (tx, rx) = oneshot::channel();
10961120

10971121
std::thread::spawn(move || {

0 commit comments

Comments
 (0)