Skip to content

Commit

Permalink
multi: make custodian proof retrieval delay configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Nov 20, 2023
1 parent 62545c4 commit aa31e22
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
14 changes: 10 additions & 4 deletions itest/tapd_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ type tapdConfig struct {
}

type harnessOpts struct {
proofSendBackoffCfg *proof.BackoffCfg
proofReceiverAckTimeout *time.Duration
proofCourier proof.CourierHarness
addrAssetSyncerDisable bool
proofSendBackoffCfg *proof.BackoffCfg
proofReceiverAckTimeout *time.Duration
proofCourier proof.CourierHarness
custodianProofRetrievalDelay *time.Duration
addrAssetSyncerDisable bool
}

type harnessOption func(*harnessOpts)
Expand Down Expand Up @@ -223,6 +224,11 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
finalCfg.HashMailCourier = nil
}

// Set the custodian proof retrieval delay if it was specified.
if opts.custodianProofRetrievalDelay != nil {
finalCfg.CustodianProofRetrievalDelay = *opts.custodianProofRetrievalDelay
}

return &tapdHarness{
cfg: &cfg,
clientCfg: finalCfg,
Expand Down
6 changes: 6 additions & 0 deletions itest/test_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ type tapdHarnessParams struct {
// an ack from the proof receiver.
proofReceiverAckTimeout *time.Duration

// custodianProofRetrievalDelay is the time duration the custodian waits
// having identified an asset transfer on-chain and before retrieving
// the corresponding proof via the proof courier service.
custodianProofRetrievalDelay *time.Duration

// addrAssetSyncerDisable is a flag that determines if the address book
// will try and bootstrap unknown assets on address creation.
addrAssetSyncerDisable bool
Expand Down Expand Up @@ -371,6 +376,7 @@ func setupTapdHarness(t *testing.T, ht *harnessTest,
ho.proofSendBackoffCfg = params.proofSendBackoffCfg
ho.proofReceiverAckTimeout = params.proofReceiverAckTimeout
ho.proofCourier = selectedProofCourier
ho.custodianProofRetrievalDelay = params.custodianProofRetrievalDelay
ho.addrAssetSyncerDisable = params.addrAssetSyncerDisable
}

Expand Down
8 changes: 8 additions & 0 deletions tapcfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ const (
// universe queries. By default we'll allow 100 qps, with a max burst
// of 10 queries.
defaultUniverseQueriesBurst = 10

// defaultProofRetrievalDelay is the default time duration the custodian
// waits having identified an asset transfer on-chain and before
// retrieving the corresponding proof via the proof courier service.
defaultProofRetrievalDelay = 5 * time.Second
)

var (
Expand Down Expand Up @@ -301,6 +306,8 @@ type Config struct {
DefaultProofCourierAddr string `long:"proofcourieraddr" description:"Default proof courier service address."`
HashMailCourier *proof.HashMailCourierCfg `group:"proofcourier" namespace:"hashmailcourier"`

CustodianProofRetrievalDelay time.Duration `long:"custodianproofretrievaldelay" description:"The number of seconds the custodian waits after identifying an asset transfer on-chain and before retrieving the corresponding proof."`

ChainConf *ChainConfig
RpcConf *RpcConfig

Expand Down Expand Up @@ -384,6 +391,7 @@ func DefaultConfig() Config {
MaxBackoff: defaultProofTransferMaxBackoff,
},
},
CustodianProofRetrievalDelay: defaultProofRetrievalDelay,
Universe: &UniverseConfig{
SyncInterval: defaultUniverseSyncInterval,
UniverseQueriesPerSecond: rate.Limit(
Expand Down
13 changes: 7 additions & 6 deletions tapcfg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,13 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
GroupVerifier: tapgarden.GenGroupVerifier(
context.Background(), assetMintingStore,
),
AddrBook: addrBook,
ProofArchive: proofArchive,
ProofNotifier: assetStore,
ErrChan: mainErrChan,
ProofCourierCfg: proofCourierCfg,
ProofWatcher: reOrgWatcher,
AddrBook: addrBook,
ProofArchive: proofArchive,
ProofNotifier: assetStore,
ErrChan: mainErrChan,
ProofCourierCfg: proofCourierCfg,
ProofRetrievalDelay: cfg.CustodianProofRetrievalDelay,
ProofWatcher: reOrgWatcher,
},
),
ChainBridge: chainBridge,
Expand Down
11 changes: 6 additions & 5 deletions tapgarden/custodian.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import (
"github.com/lightningnetwork/lnd/lnrpc"
)

const (
defaultProofRetrievalDelay = 5 * time.Second
)

// CustodianConfig houses all the items that the Custodian needs to carry out
// its duties.
type CustodianConfig struct {
Expand Down Expand Up @@ -58,6 +54,11 @@ type CustodianConfig struct {
// service handles.
ProofCourierCfg *proof.CourierCfg

// ProofRetrievalDelay is the time duration the custodian waits having
// identified an asset transfer on-chain and before retrieving the
// corresponding proof via the proof courier service.
ProofRetrievalDelay time.Duration

// ProofWatcher is used to watch new proofs for their anchor transaction
// to be confirmed safely with a minimum number of confirmations.
ProofWatcher proof.Watcher
Expand Down Expand Up @@ -420,7 +421,7 @@ func (c *Custodian) inspectWalletTx(walletTx *lndclient.Transaction) error {
// the proof will very likely fail. We should expect
// retrieval success before this delay.
select {
case <-time.After(defaultProofRetrievalDelay):
case <-time.After(c.cfg.ProofRetrievalDelay):
case <-ctx.Done():
return
}
Expand Down

0 comments on commit aa31e22

Please sign in to comment.