Skip to content

Commit 3a07d54

Browse files
committed
f Headers: use _subscribe over _pop, clear queue regularly
1 parent 7668515 commit 3a07d54

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

lightning-transaction-sync/src/electrum.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ where
8888
let mut num_confirmed = 0;
8989
let mut num_unconfirmed = 0;
9090

91+
// Clear any header notifications we might have gotten to keep the queue count low.
92+
while let Some(_) = self.client.block_headers_pop()? {}
93+
9194
let tip_notification = self.client.block_headers_subscribe()?;
9295
let mut tip_header = tip_notification.header;
9396
let mut tip_height = tip_notification.height as u32;
@@ -109,11 +112,12 @@ where
109112
Ok(unconfirmed_txs) => {
110113
// Double-check the tip hash. If it changed, a reorg happened since
111114
// we started syncing and we need to restart last-minute.
112-
if let Some(notification) = self.client.block_headers_pop()? {
113-
let check_tip_hash = notification.header.block_hash();
115+
{
116+
let check_notification = self.client.block_headers_subscribe()?;
117+
let check_tip_hash = check_notification.header.block_hash();
114118
if check_tip_hash != tip_header.block_hash() {
115-
tip_header = notification.header;
116-
tip_height = notification.height as u32;
119+
tip_header = check_notification.header;
120+
tip_height = check_notification.height as u32;
117121

118122
log_debug!(self.logger,
119123
"Encountered inconsistency during transaction sync, restarting.");
@@ -148,11 +152,16 @@ where
148152
Ok(confirmed_txs) => {
149153
// Double-check the tip hash. If it changed, a reorg happened since
150154
// we started syncing and we need to restart last-minute.
151-
if let Some(notification) = self.client.block_headers_pop()? {
152-
let check_tip_hash = notification.header.block_hash();
155+
{
156+
let check_notification = self.client.block_headers_subscribe()?;
157+
let check_tip_hash = check_notification.header.block_hash();
153158
if check_tip_hash != tip_header.block_hash() {
154-
tip_header = notification.header;
155-
tip_height = notification.height as u32;
159+
tip_header = check_notification.header;
160+
tip_height = check_notification.height as u32;
161+
162+
log_debug!(self.logger,
163+
"Encountered inconsistency during transaction sync, restarting.");
164+
sync_state.pending_sync = true;
156165
continue;
157166
}
158167
}

0 commit comments

Comments
 (0)