Skip to content

Commit

Permalink
tapcfg: make the universe proof courier the default
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Oct 11, 2023
1 parent df0670e commit 68b5b9a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 28 deletions.
22 changes: 15 additions & 7 deletions tapcfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ const (
// proofs for asynchronous sends.
fallbackHashMailAddr = "mailbox.terminal.lightning.today:443"

// fallbackUniverseAddr is the fallback address we'll use to deliver
// proofs for asynchronous sends.
fallbackUniverseAddr = defaultMainnetFederationServer

// DatabaseBackendSqlite is the name of the SQLite database backend.
DatabaseBackendSqlite = "sqlite"

Expand Down Expand Up @@ -155,6 +159,12 @@ var (
defaultDataDir, defaultNetwork, defaultSqliteDatabaseFileName,
)

// defaultProofCourierAddr is the default proof courier address URI
// we'll use to deliver proofs for asynchronous sends.
defaultProofCourierAddr = fmt.Sprintf(
"%s://%s", proof.UniverseRpcCourierType, fallbackUniverseAddr,
)

// minimalCompatibleVersion is the minimum version and build tags
// required in lnd to run tapd.
minimalCompatibleVersion = &verrpc.Version{
Expand Down Expand Up @@ -335,13 +345,11 @@ func DefaultConfig() Config {
Port: 5432,
MaxOpenConnections: 10,
},
LogWriter: build.NewRotatingLogWriter(),
Prometheus: monitoring.DefaultPrometheusConfig(),
BatchMintingInterval: defaultBatchMintingInterval,
ReOrgSafeDepth: defaultReOrgSafeDepth,
DefaultProofCourierAddr: fmt.Sprintf(
"%s://%s", proof.HashmailCourierType, fallbackHashMailAddr,
),
LogWriter: build.NewRotatingLogWriter(),
Prometheus: monitoring.DefaultPrometheusConfig(),
BatchMintingInterval: defaultBatchMintingInterval,
ReOrgSafeDepth: defaultReOrgSafeDepth,
DefaultProofCourierAddr: defaultProofCourierAddr,
HashMailCourier: &proof.HashMailCourierCfg{
ReceiverAckTimeout: defaultProofTransferReceiverAckTimeout,
BackoffCfg: &proof.BackoffCfg{
Expand Down
64 changes: 43 additions & 21 deletions tapcfg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type databaseBackend interface {
// genServerConfig generates a server config from the given tapd config.
//
// NOTE: The RPCConfig and SignalInterceptor fields must be set by the caller
// after genereting the server config.
// after generating the server config.
func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
lndServices *lndclient.LndServices,
mainErrChan chan<- error) (*tap.Config, error) {
Expand Down Expand Up @@ -161,6 +161,47 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
assetStore, proofFileStore,
)

federationMembers := cfg.Universe.FederationServers
switch cfg.ChainConf.Network {
case "mainnet":
cfgLogger.Infof("Configuring %v as initial Universe "+
"federation server", defaultMainnetFederationServer)

federationMembers = append(
federationMembers, defaultMainnetFederationServer,
)

case "testnet":
cfgLogger.Infof("Configuring %v as initial Universe "+
"federation server", defaultTestnetFederationServer)

federationMembers = append(
federationMembers, defaultTestnetFederationServer,
)

// For testnet, we need to overwrite the default universe proof
// courier address to use the testnet server.
if cfg.DefaultProofCourierAddr == defaultProofCourierAddr {
cfg.DefaultProofCourierAddr = fmt.Sprintf(
"%s://%s", proof.UniverseRpcCourierType,
fallbackUniverseAddr,
)
}

default:
// For any other network, such as regtest, we can't use a
// universe proof courier by default, as we don't know what
// server to pick. So if there is no explicit value set, we fall
// back to using the hashmail courier, which works in all cases.
if cfg.DefaultProofCourierAddr == defaultProofCourierAddr {
cfg.DefaultProofCourierAddr = fmt.Sprintf(
"%s://%s", proof.HashmailCourierType,
fallbackHashMailAddr,
)
}

}

// If no default proof courier address is set, use the fallback hashmail
// address.
fallbackHashmailCourierAddr := fmt.Sprintf(
Expand All @@ -185,10 +226,10 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
}
}

var proofCourierCfg *proof.CourierCfg
// TODO(ffranr): This logic is leftover for integration tests which
// do not yet enable a proof courier. Remove once all integration tests
// support a proof courier.
var proofCourierCfg *proof.CourierCfg
if cfg.HashMailCourier != nil {
proofCourierCfg = &proof.CourierCfg{
ReceiverAckTimeout: cfg.HashMailCourier.ReceiverAckTimeout,
Expand Down Expand Up @@ -234,25 +275,6 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
SyncBatchSize: defaultUniverseSyncBatchSize,
})

federationMembers := cfg.Universe.FederationServers
switch cfg.ChainConf.Network {
case "mainnet":
cfgLogger.Infof("Configuring %v as initial Universe "+
"federation server", defaultMainnetFederationServer)

federationMembers = append(
federationMembers, defaultMainnetFederationServer,
)

case "testnet":
cfgLogger.Infof("Configuring %v as initial Universe "+
"federation server", defaultTestnetFederationServer)

federationMembers = append(
federationMembers, defaultTestnetFederationServer,
)
}

runtimeID := prand.Int63() // nolint:gosec
universeFederation := universe.NewFederationEnvoy(
universe.FederationConfig{
Expand Down

0 comments on commit 68b5b9a

Please sign in to comment.