Skip to content

Commit c551dfb

Browse files
committed
fix(electrum)!: Change into_tx_graph to take a u64
for its `seen_at` time. And only insert a seen_at time for transactions that have no anchors, as updating the last seen for already confirmed txs would cause needless database writes.
1 parent c9dd821 commit c551dfb

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

crates/electrum/src/electrum_ext.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ impl RelevantTxids {
4040
pub fn into_tx_graph(
4141
self,
4242
client: &Client,
43-
seen_at: Option<u64>,
43+
seen_at: u64,
4444
missing: Vec<Txid>,
4545
) -> Result<TxGraph<ConfirmationHeightAnchor>, Error> {
4646
let new_txs = client.batch_transaction_get(&missing)?;
4747
let mut graph = TxGraph::<ConfirmationHeightAnchor>::new(new_txs);
4848
for (txid, anchors) in self.0 {
49-
if let Some(seen_at) = seen_at {
49+
if anchors.is_empty() {
5050
let _ = graph.insert_seen_at(txid, seen_at);
5151
}
5252
for anchor in anchors {
@@ -67,7 +67,7 @@ impl RelevantTxids {
6767
pub fn into_confirmation_time_tx_graph(
6868
self,
6969
client: &Client,
70-
seen_at: Option<u64>,
70+
seen_at: u64,
7171
missing: Vec<Txid>,
7272
) -> Result<TxGraph<ConfirmationTimeHeightAnchor>, Error> {
7373
let graph = self.into_tx_graph(client, seen_at, missing)?;

crates/electrum/tests/test_electrum.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn scan_detects_confirmed_tx() -> Result<()> {
6868
} = client.sync(recv_chain.tip(), [spk_to_track], None, None, 5)?;
6969

7070
let missing = relevant_txids.missing_full_txs(recv_graph.graph());
71-
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, None, missing)?;
71+
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, 0, missing)?;
7272
let _ = recv_chain
7373
.apply_update(chain_update)
7474
.map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?;
@@ -134,7 +134,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> Result<()> {
134134
} = client.sync(recv_chain.tip(), [spk_to_track.clone()], None, None, 5)?;
135135

136136
let missing = relevant_txids.missing_full_txs(recv_graph.graph());
137-
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, None, missing)?;
137+
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, 0, missing)?;
138138
let _ = recv_chain
139139
.apply_update(chain_update)
140140
.map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?;
@@ -164,8 +164,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> Result<()> {
164164
} = client.sync(recv_chain.tip(), [spk_to_track.clone()], None, None, 5)?;
165165

166166
let missing = relevant_txids.missing_full_txs(recv_graph.graph());
167-
let graph_update =
168-
relevant_txids.into_confirmation_time_tx_graph(&client, None, missing)?;
167+
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, 1, missing)?;
169168
let _ = recv_chain
170169
.apply_update(chain_update)
171170
.map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?;

example-crates/example_electrum/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ fn main() -> anyhow::Result<()> {
304304
.expect("must get time")
305305
.as_secs();
306306

307-
let graph_update = relevant_txids.into_tx_graph(&client, Some(now), missing_txids)?;
307+
let graph_update = relevant_txids.into_tx_graph(&client, now, missing_txids)?;
308308

309309
let db_changeset = {
310310
let mut chain = chain.lock().unwrap();

example-crates/wallet_electrum/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ fn main() -> Result<(), anyhow::Error> {
6666
println!();
6767

6868
let missing = relevant_txids.missing_full_txs(wallet.as_ref());
69-
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, None, missing)?;
69+
let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
70+
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, now, missing)?;
7071

7172
let wallet_update = Update {
7273
last_active_indices: keychain_update,

0 commit comments

Comments
 (0)