Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for existing asset in db before attempting to insert a new asset. #687

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
ffranr marked this conversation as resolved.
Show resolved Hide resolved
}

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):
ffranr marked this conversation as resolved.
Show resolved Hide resolved
case <-ctx.Done():
return
}
Expand Down