@@ -10,7 +10,6 @@ use super::{
1010 temporal_safety:: TemporalSafety ,
1111 StateReport ,
1212} ;
13- use crate :: service:: { Endpoints , Reporter } ;
1413use crate :: swapd:: temporal_safety:: SWEEP_MONERO_THRESHOLD ;
1514use crate :: swapd:: Opts ;
1615use crate :: syncerd:: bitcoin_syncer:: p2wpkh_signed_tx_fee;
@@ -23,6 +22,10 @@ use crate::{
2322 bus:: { BusMsg , Outcome , ServiceBus } ,
2423 syncerd:: { HeightChanged , TransactionRetrieved , XmrAddressAddendum } ,
2524} ;
25+ use crate :: {
26+ service:: { Endpoints , Reporter } ,
27+ syncerd:: AddressTransaction ,
28+ } ;
2629use crate :: { CtlServer , Error , LogStyle , Service , ServiceConfig , ServiceId } ;
2730
2831use std:: time:: { Duration , SystemTime } ;
@@ -107,9 +110,7 @@ pub fn run(config: ServiceConfig, opts: Opts) -> Result<(), Error> {
107110 monero_height : 0 ,
108111 bitcoin_height : 0 ,
109112 confirmation_bound : 50000 ,
110- lock_tx_confs : None ,
111- cancel_tx_confs : None ,
112- buy_tx_confs : None ,
113+ last_tx_event : none ! ( ) ,
113114 network,
114115 bitcoin_syncer : ServiceId :: Syncer ( Blockchain :: Bitcoin , network) ,
115116 monero_syncer : ServiceId :: Syncer ( Blockchain :: Monero , network) ,
@@ -542,9 +543,23 @@ impl Runtime {
542543 self . temporal_safety . acc_finality ,
543544 endpoints,
544545 ) ;
546+
547+ // saving requests of interest for later replaying latest event
548+ if let Some ( txlabel) = self . syncer_state . tasks . watched_txs . get ( id) {
549+ self . syncer_state
550+ . last_tx_event
551+ . insert ( * txlabel, request. clone ( ) ) ;
552+ }
545553 }
546554
547- Event :: AddressTransaction ( _) => { }
555+ Event :: AddressTransaction ( AddressTransaction { id, .. } ) => {
556+ // saving requests of interest for later replaying latest event
557+ if let Some ( txlabel) = self . syncer_state . tasks . watched_addrs . get ( id) {
558+ self . syncer_state
559+ . last_tx_event
560+ . insert ( * txlabel, request. clone ( ) ) ;
561+ }
562+ }
548563
549564 Event :: SweepSuccess ( _) => { }
550565
@@ -596,19 +611,11 @@ impl Runtime {
596611 self . temporal_safety . arb_finality ,
597612 endpoints,
598613 ) ;
599- let txlabel = self . syncer_state . tasks . watched_txs . get ( id) ;
600614 // saving requests of interest for later replaying latest event
601- match txlabel {
602- Some ( & TxLabel :: Lock ) => {
603- self . syncer_state . lock_tx_confs = Some ( request. clone ( ) ) ;
604- }
605- Some ( & TxLabel :: Cancel ) => {
606- self . syncer_state . cancel_tx_confs = Some ( request. clone ( ) ) ;
607- }
608- Some ( & TxLabel :: Buy ) => {
609- self . syncer_state . buy_tx_confs = Some ( request. clone ( ) )
610- }
611- _ => { }
615+ if let Some ( txlabel) = self . syncer_state . tasks . watched_txs . get ( id) {
616+ self . syncer_state
617+ . last_tx_event
618+ . insert ( * txlabel, request. clone ( ) ) ;
612619 }
613620 }
614621
@@ -624,13 +631,27 @@ impl Runtime {
624631 self . temporal_safety . arb_finality ,
625632 endpoints,
626633 ) ;
634+ // saving requests of interest for later replaying latest event
635+ if let Some ( txlabel) = self . syncer_state . tasks . watched_txs . get ( id) {
636+ self . syncer_state
637+ . last_tx_event
638+ . insert ( * txlabel, request. clone ( ) ) ;
639+ }
627640 }
628641
629642 Event :: TransactionBroadcasted ( event) => {
630643 self . syncer_state . transaction_broadcasted ( event) ;
631644 }
632645
633- Event :: AddressTransaction ( _) => { }
646+ Event :: AddressTransaction ( AddressTransaction { id, .. } ) => {
647+ // saving requests of interest for later replaying latest event
648+ if let Some ( txlabel) = self . syncer_state . tasks . watched_addrs . get ( id) {
649+ self . syncer_state
650+ . last_tx_event
651+ . insert ( * txlabel, request. clone ( ) ) ;
652+ }
653+ self . log_debug ( event) ;
654+ }
634655
635656 Event :: TaskAborted ( event) => {
636657 self . log_debug ( event) ;
@@ -705,15 +726,9 @@ impl Runtime {
705726 if let Some ( peer_msg) = self . unhandled_peer_message . clone ( ) {
706727 self . handle_msg ( endpoints, source. clone ( ) , peer_msg) ?;
707728 }
708- // Replay confirmation events to ensure we immediately advance through states that can be skipped
709- if let Some ( buy_tx_confs_req) = self . syncer_state . buy_tx_confs . clone ( ) {
710- self . handle_sync ( endpoints, source. clone ( ) , buy_tx_confs_req) ?;
711- }
712- if let Some ( lock_tx_confs_req) = self . syncer_state . lock_tx_confs . clone ( ) {
713- self . handle_sync ( endpoints, source. clone ( ) , lock_tx_confs_req) ?;
714- }
715- if let Some ( cancel_tx_confs_req) = self . syncer_state . cancel_tx_confs . clone ( ) {
716- self . handle_sync ( endpoints, source, cancel_tx_confs_req) ?;
729+ // Replay syncer events to ensure we immediately advance through states that can be skipped
730+ for event in self . syncer_state . last_tx_event . clone ( ) . values ( ) {
731+ self . handle_sync ( endpoints, source. clone ( ) , event. clone ( ) ) ?;
717732 }
718733 } else if let BusMsg :: P2p ( peer_msg) = msg {
719734 self . unhandled_peer_message = Some ( peer_msg) ;
0 commit comments