Skip to content

Commit

Permalink
multi: create unique cfg for each proof courier
Browse files Browse the repository at this point in the history
With this commit we disentangle the configurations for the two proof
couriers, so we can configure them individually in a proper way.
  • Loading branch information
guggero committed Jan 3, 2024
1 parent a7c0510 commit 9cd7d53
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
31 changes: 21 additions & 10 deletions itest/tapd_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,19 @@ var (
"allow the postgres fixture to run in total. Needs "+
"to be increased for long-running tests.")

// defaultBackoffConfig is the default backoff config we'll use for
// sending proofs.
defaultBackoffConfig = proof.BackoffCfg{
// defaultHashmailBackoffConfig is the default backoff config we'll use
// for sending proofs with the hashmail courier.
defaultHashmailBackoffConfig = proof.BackoffCfg{
BackoffResetWait: time.Second,
NumTries: 5,
InitialBackoff: 300 * time.Millisecond,
MaxBackoff: 600 * time.Millisecond,
}

// defaultUniverseRpcBackoffConfig is the default backoff config we'll
// use for sending proofs with the universe RPC courier.
defaultUniverseRpcBackoffConfig = proof.BackoffCfg{
SkipInitDelay: true,
BackoffResetWait: time.Second,
NumTries: 5,
InitialBackoff: 300 * time.Millisecond,
Expand Down Expand Up @@ -209,9 +219,11 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
// Populate proof courier specific config fields.
//
// Use passed in backoff config or default config.
backoffCfg := defaultBackoffConfig
hashmailBackoffCfg := defaultHashmailBackoffConfig
universeRpcBackoffCfg := defaultUniverseRpcBackoffConfig
if opts.proofSendBackoffCfg != nil {
backoffCfg = *opts.proofSendBackoffCfg
hashmailBackoffCfg = *opts.proofSendBackoffCfg
universeRpcBackoffCfg = *opts.proofSendBackoffCfg
}

// Used passed in proof receiver ack timeout or default.
Expand All @@ -220,12 +232,12 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
receiverAckTimeout = *opts.proofReceiverAckTimeout
}

// TODO(ffranr): Disentangle the hashmail config from the universe RPC
// courier config. Right now, the universe courier takes the backoff
// config from the hashmail courier config.
finalCfg.HashMailCourier = &proof.HashMailCourierCfg{
ReceiverAckTimeout: receiverAckTimeout,
BackoffCfg: &backoffCfg,
BackoffCfg: &hashmailBackoffCfg,
}
finalCfg.UniverseRpcCourier = &proof.UniverseRpcCourierCfg{
BackoffCfg: &universeRpcBackoffCfg,
}

switch typedProofCourier := (opts.proofCourier).(type) {
Expand All @@ -243,7 +255,6 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,

default:
finalCfg.DefaultProofCourierAddr = ""
finalCfg.HashMailCourier = nil
}

ht.t.Logf("Using proof courier address: %v",
Expand Down
22 changes: 11 additions & 11 deletions proof/courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,6 @@ func (h *UniverseRpcCourierAddr) Url() *url.URL {
func (h *UniverseRpcCourierAddr) NewCourier(_ context.Context,
cfg *CourierCfg, recipient Recipient) (Courier, error) {

// Skip the initial delivery delay for the universe RPC courier.
// This courier skips the initial delay because it uses the backoff
// procedure for each proof within a proof file separately.
// Consequently, if we attempt to perform two consecutive send events
// which share the same proof lineage (matching ancestral proofs), the
// second send event will be delayed by the initial delay.
cfg.BackoffCfg.SkipInitDelay = true
backoffHandle := NewBackoffHandler(cfg.BackoffCfg, cfg.TransferLog)

// Ensure that the courier address is a universe RPC address.
Expand Down Expand Up @@ -557,10 +550,10 @@ func (e *BackoffExecError) Error() string {

// BackoffCfg configures the behaviour of the proof delivery backoff procedure.
type BackoffCfg struct {
// SkipInitDelay is a flag that indicates whether we should skip
// the initial delay before attempting to deliver the proof to the
// receiver.
SkipInitDelay bool
// SkipInitDelay is a flag that indicates whether we should skip the
// initial delay before attempting to deliver the proof to the receiver
// or receiving from the sender.
SkipInitDelay bool `long:"skipinitdelay" description:"Skip the initial delay before attempting to deliver the proof to the receiver or receiving from the sender."`

// BackoffResetWait is the amount of time we'll wait before
// resetting the backoff counter to its initial state.
Expand Down Expand Up @@ -1049,6 +1042,13 @@ func (h *HashMailCourier) SetSubscribers(
// proof.Courier interface.
var _ Courier = (*HashMailCourier)(nil)

// UniverseRpcCourierCfg is the config for the universe RPC proof courier.
type UniverseRpcCourierCfg struct {
// BackoffCfg configures the behaviour of the proof delivery
// functionality.
BackoffCfg *BackoffCfg
}

// UniverseRpcCourier is a universe RPC proof courier service handle. It
// implements the Courier interface.
type UniverseRpcCourier struct {
Expand Down
14 changes: 12 additions & 2 deletions tapcfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ type Config struct {
ReOrgSafeDepth int32 `long:"reorgsafedepth" description:"The number of confirmations we'll wait for before considering a transaction safely buried in the chain."`

// The following options are used to configure the proof courier.
DefaultProofCourierAddr string `long:"proofcourieraddr" description:"Default proof courier service address."`
HashMailCourier *proof.HashMailCourierCfg `group:"proofcourier" namespace:"hashmailcourier"`
DefaultProofCourierAddr string `long:"proofcourieraddr" description:"Default proof courier service address."`
HashMailCourier *proof.HashMailCourierCfg `group:"hashmailcourier" namespace:"hashmailcourier"`
UniverseRpcCourier *proof.UniverseRpcCourierCfg `group:"universerpccourier" namespace:"universerpccourier"`

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."`

Expand Down Expand Up @@ -391,6 +392,15 @@ func DefaultConfig() Config {
MaxBackoff: defaultProofTransferMaxBackoff,
},
},
UniverseRpcCourier: &proof.UniverseRpcCourierCfg{
BackoffCfg: &proof.BackoffCfg{
SkipInitDelay: true,
BackoffResetWait: defaultProofTransferBackoffResetWait,
NumTries: defaultProofTransferNumTries,
InitialBackoff: defaultProofTransferInitialBackoff,
MaxBackoff: defaultProofTransferMaxBackoff,
},
},
CustodianProofRetrievalDelay: defaultProofRetrievalDelay,
Universe: &UniverseConfig{
SyncInterval: defaultUniverseSyncInterval,
Expand Down

0 comments on commit 9cd7d53

Please sign in to comment.