@@ -21,10 +21,6 @@ import (
21
21
"github.com/keep-network/keep-core/pkg/internal/byteutils"
22
22
)
23
23
24
- // TODO: Some problems with Electrum re-connect were detected while developing
25
- // integration tests: https://github.com/keep-network/keep-core/issues/3586.
26
- // Make sure the problem is resolved soon.
27
-
28
24
var (
29
25
supportedProtocolVersions = []string {"1.4" }
30
26
logger = log .Logger ("keep-electrum" )
@@ -93,7 +89,9 @@ func (c *Connection) GetTransaction(
93
89
// as Esplora/Electrs doesn't support verbose transactions.
94
90
// See: https://github.com/Blockstream/electrs/pull/36
95
91
return client .GetRawTransaction (ctx , txID )
96
- })
92
+ },
93
+ "GetRawTransaction" ,
94
+ )
97
95
if err != nil {
98
96
return nil , fmt .Errorf (
99
97
"failed to get raw transaction with ID [%s]: [%w]" ,
@@ -129,7 +127,9 @@ func (c *Connection) GetTransactionConfirmations(
129
127
// as Esplora/Electrs doesn't support verbose transactions.
130
128
// See: https://github.com/Blockstream/electrs/pull/36
131
129
return client .GetRawTransaction (ctx , txID )
132
- })
130
+ },
131
+ "GetRawTransaction" ,
132
+ )
133
133
if err != nil {
134
134
return 0 ,
135
135
fmt .Errorf (
@@ -178,7 +178,9 @@ txOutLoop:
178
178
client * electrum.Client ,
179
179
) ([]* electrum.GetMempoolResult , error ) {
180
180
return client .GetHistory (ctx , reversedScriptHashString )
181
- })
181
+ },
182
+ "GetHistory" ,
183
+ )
182
184
if err != nil {
183
185
// Don't return an error, but continue to the next TxOut entry.
184
186
txLogger .Errorf ("failed to get history for script hash: [%v]" , err )
@@ -243,7 +245,9 @@ func (c *Connection) BroadcastTransaction(
243
245
c ,
244
246
func (ctx context.Context , client * electrum.Client ) (string , error ) {
245
247
return client .BroadcastTransaction (ctx , rawTx )
246
- })
248
+ },
249
+ "BroadcastTransaction" ,
250
+ )
247
251
if err != nil {
248
252
return fmt .Errorf ("failed to broadcast the transaction: [%w]" , err )
249
253
}
@@ -265,7 +269,9 @@ func (c *Connection) GetLatestBlockHeight() (uint, error) {
265
269
}
266
270
tip := <- headersChan
267
271
return tip .Height , nil
268
- })
272
+ },
273
+ "SubscribeHeaders" ,
274
+ )
269
275
if err != nil {
270
276
return 0 , fmt .Errorf ("failed to subscribe for headers: [%w]" , err )
271
277
}
@@ -291,6 +297,7 @@ func (c *Connection) GetBlockHeader(
291
297
) (* electrum.GetBlockHeaderResult , error ) {
292
298
return client .GetBlockHeader (ctx , uint32 (blockHeight ), 0 )
293
299
},
300
+ "GetBlockHeader" ,
294
301
)
295
302
if err != nil {
296
303
return nil , fmt .Errorf ("failed to get block header: [%w]" , err )
@@ -325,6 +332,7 @@ func (c *Connection) GetTransactionMerkleProof(
325
332
uint32 (blockHeight ),
326
333
)
327
334
},
335
+ "GetMerkleProof" ,
328
336
)
329
337
if err != nil {
330
338
return nil , fmt .Errorf ("failed to get merkle proof: [%w]" , err )
@@ -434,7 +442,9 @@ func (c *Connection) getConfirmedScriptHistory(
434
442
client * electrum.Client ,
435
443
) ([]* electrum.GetMempoolResult , error ) {
436
444
return client .GetHistory (ctx , reversedScriptHashString )
437
- })
445
+ },
446
+ "GetHistory" ,
447
+ )
438
448
if err != nil {
439
449
return nil , fmt .Errorf (
440
450
"failed to get history for script [0x%x]: [%v]" ,
@@ -565,7 +575,9 @@ func (c *Connection) getScriptMempool(
565
575
client * electrum.Client ,
566
576
) ([]* electrum.GetMempoolResult , error ) {
567
577
return client .GetMempool (ctx , reversedScriptHashString )
568
- })
578
+ },
579
+ "GetMempool" ,
580
+ )
569
581
if err != nil {
570
582
return nil , fmt .Errorf (
571
583
"failed to get mempool for script [0x%x]: [%v]" ,
@@ -614,7 +626,9 @@ func (c *Connection) EstimateSatPerVByteFee(blocks uint32) (int64, error) {
614
626
// since version 1.4.2 of the protocol. We need to replace it
615
627
// somehow once it disappears from Electrum implementations.
616
628
return client .GetFee (ctx , blocks )
617
- })
629
+ },
630
+ "GetFee" ,
631
+ )
618
632
if err != nil {
619
633
return 0 , fmt .Errorf ("failed to get fee: [%v]" , err )
620
634
}
@@ -673,6 +687,7 @@ func (c *Connection) verifyServer() error {
673
687
}
674
688
return & Server {serverVersion , protocolVersion }, nil
675
689
},
690
+ "ServerVersion" ,
676
691
)
677
692
if err != nil {
678
693
return fmt .Errorf ("failed to get server version: [%w]" , err )
@@ -708,6 +723,7 @@ func (c *Connection) keepAlive() {
708
723
func (ctx context.Context , client * electrum.Client ) (interface {}, error ) {
709
724
return nil , client .Ping (ctx )
710
725
},
726
+ "Ping" ,
711
727
)
712
728
if err != nil {
713
729
logger .Errorf (
@@ -757,7 +773,11 @@ func connectWithRetry(
757
773
func requestWithRetry [K interface {}](
758
774
c * Connection ,
759
775
requestFn func (ctx context.Context , client * electrum.Client ) (K , error ),
776
+ requestName string ,
760
777
) (K , error ) {
778
+ startTime := time .Now ()
779
+ logger .Infof ("starting [%s] request to Electrum server" , requestName )
780
+
761
781
var result K
762
782
763
783
err := wrappers .DoWithDefaultRetry (
@@ -783,6 +803,19 @@ func requestWithRetry[K interface{}](
783
803
return nil
784
804
})
785
805
806
+ solveRequestOutcome := func (err error ) string {
807
+ if err != nil {
808
+ return fmt .Sprintf ("error: [%v]" , err )
809
+ }
810
+ return "success"
811
+ }
812
+
813
+ logger .Infof ("[%s] request to Electrum server completed with [%s] after [%s]" ,
814
+ requestName ,
815
+ solveRequestOutcome (err ),
816
+ time .Since (startTime ),
817
+ )
818
+
786
819
return result , err
787
820
}
788
821
0 commit comments