Skip to content

Commit afd7495

Browse files
ffranrguggero
authored andcommitted
proof: add courier service connection timeout
This commit adds a configurable timeout to the initial connection attempt. The attempt is already blocking since we do make a call to the Info RPC method to verify the connection integrity. Both the connection and transfer steps are part of the backoff procedure, so failures in either step will trigger re-attempts.
1 parent bfb6607 commit afd7495

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

proof/courier.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,10 +1154,17 @@ func (h *HashMailCourier) SetSubscribers(
11541154
var _ Courier = (*HashMailCourier)(nil)
11551155

11561156
// UniverseRpcCourierCfg is the config for the universe RPC proof courier.
1157+
//
1158+
// nolint:lll
11571159
type UniverseRpcCourierCfg struct {
11581160
// BackoffCfg configures the behaviour of the proof delivery
11591161
// functionality.
11601162
BackoffCfg *BackoffCfg
1163+
1164+
// ServiceRequestTimeout defines the maximum duration we'll wait for
1165+
// a courier service to handle our outgoing request during a connection
1166+
// attempt, or when delivering or retrieving a proof.
1167+
ServiceRequestTimeout time.Duration `long:"servicerequestimeout" description:"The maximum duration we'll wait for a courier service to handle our outgoing request during a connection attempt, or when delivering or retrieving a proof."`
11611168
}
11621169

11631170
// UniverseRpcCourier is a universe RPC proof courier service handle. It
@@ -1356,18 +1363,29 @@ func (c *UniverseRpcCourier) DeliverProof(ctx context.Context,
13561363
deliverFunc := func() error {
13571364
// Connect to the courier service if a connection hasn't
13581365
// been established yet.
1359-
err := c.ensureConnect(ctx)
1366+
subCtx, subCtxCancel := context.WithTimeout(
1367+
ctx, c.cfg.ServiceRequestTimeout,
1368+
)
1369+
defer subCtxCancel()
1370+
1371+
err := c.ensureConnect(subCtx)
13601372
if err != nil {
13611373
return fmt.Errorf("unable to connect to "+
13621374
"courier service during delivery "+
13631375
"attempt: %w", err)
13641376
}
13651377

13661378
// Submit proof to courier.
1367-
_, err = c.client.InsertProof(ctx, &unirpc.AssetProof{
1379+
subCtx, subCtxCancel = context.WithTimeout(
1380+
ctx, c.cfg.ServiceRequestTimeout,
1381+
)
1382+
defer subCtxCancel()
1383+
1384+
assetProof := unirpc.AssetProof{
13681385
Key: &universeKey,
13691386
AssetLeaf: &assetLeaf,
1370-
})
1387+
}
1388+
_, err = c.client.InsertProof(subCtx, &assetProof)
13711389
if err != nil {
13721390
return fmt.Errorf("error inserting proof "+
13731391
"into universe courier service: %w",
@@ -1420,15 +1438,25 @@ func (c *UniverseRpcCourier) ReceiveProof(ctx context.Context,
14201438
receiveFunc := func() error {
14211439
// Connect to the courier service if a connection hasn't
14221440
// been established yet.
1423-
err := c.ensureConnect(ctx)
1441+
subCtx, subCtxCancel := context.WithTimeout(
1442+
ctx, c.cfg.ServiceRequestTimeout,
1443+
)
1444+
defer subCtxCancel()
1445+
1446+
err := c.ensureConnect(subCtx)
14241447
if err != nil {
14251448
return fmt.Errorf("unable to connect to "+
14261449
"universe RPC courier service during "+
14271450
"recieve attempt: %w", err)
14281451
}
14291452

14301453
// Retrieve proof from courier.
1431-
resp, err := c.client.QueryProof(ctx, &universeKey)
1454+
subCtx, subCtxCancel = context.WithTimeout(
1455+
ctx, c.cfg.ServiceRequestTimeout,
1456+
)
1457+
defer subCtxCancel()
1458+
1459+
resp, err := c.client.QueryProof(subCtx, &universeKey)
14321460
if err != nil {
14331461
return fmt.Errorf("error retrieving proof "+
14341462
"from universe courier service: %w",

sample-tapd.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@
6464
; {s, m, h}.
6565
; custodianproofretrievaldelay=5s
6666

67+
; The maximum duration we'll wait for a proof courier service to handle our
68+
; outgoing request during a connection attempt, or when delivering or retrieving
69+
; a proof.
70+
; universerpccourier.servicerequestimeout=5s
71+
6772
; Network to run on (mainnet, regtest, testnet, simnet, signet)
6873
; network=testnet
6974

0 commit comments

Comments
 (0)