Skip to content

Commit

Permalink
popmd: make BFG request timeout configurable (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuasing authored Oct 10, 2024
1 parent 06ca6ef commit 99d0038
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/bfgapi/bfgapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var (
DefaultPrivateURL = "ws://" + DefaultPrivateListen + RouteWebsocketPrivate
DefaultPublicURL = "ws://" + DefaultPublicListen + RouteWebsocketPublic
DefaultRequestLimit = 10000 // XXX this is a bandaid
DefaultRequestTimeout = 9 // XXX PNOOMA
DefaultRequestTimeout = 10 // XXX PNOOMA
)

type AccessPublicKey struct {
Expand Down
12 changes: 11 additions & 1 deletion cmd/popmd/popmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/juju/loggo"

Expand Down Expand Up @@ -45,10 +46,19 @@ var (
},
"POPM_BFG_URL": config.Config{
Value: &cfg.BFGWSURL,
DefaultValue: popm.NewDefaultConfig().BFGWSURL,
DefaultValue: cfg.BFGWSURL,
Help: "url for BFG (Bitcoin Finality Governor)",
Print: config.PrintAll,
},
"POPM_BFG_REQUEST_TIMEOUT": config.Config{
Value: &cfg.BFGRequestTimeout,
DefaultValue: cfg.BFGRequestTimeout,
Help: "request timeout for BFG (Bitcoin Finality Governor)",
Print: config.PrintAll,
Parse: func(envValue string) (any, error) {
return time.ParseDuration(envValue)
},
},
"POPM_BTC_CHAIN_NAME": config.Config{
Value: &cfg.BTCChainName,
DefaultValue: popm.NewDefaultConfig().BTCChainName,
Expand Down
10 changes: 10 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Config struct {
Help string // One line help
Print PrintMode // Print mode
Required bool // If true, error out with error
Parse func(envValue string) (any, error)
}

type CfgMap map[string]Config
Expand Down Expand Up @@ -58,6 +59,15 @@ func Parse(c CfgMap) error {
// Set v.Value to v.DefaultValue
reflect.ValueOf(v.Value).Elem().Set(reflect.ValueOf(v.DefaultValue))
} else {
if v.Parse != nil {
val, err := v.Parse(envValue)
if err != nil {
return fmt.Errorf("invalid value for %v: %v", k, err)
}
reflect.ValueOf(v.Value).Elem().Set(reflect.ValueOf(val))
return nil
}

switch reflect.TypeOf(v.Value).Elem().Kind() {
case reflect.Int, reflect.Int8, reflect.Int16,
reflect.Int32, reflect.Int64:
Expand Down
14 changes: 11 additions & 3 deletions service/popm/popm.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type Config struct {
// hexadecimal digits.
BTCPrivateKey string

BFGRequestTimeout time.Duration

LogLevel string

PrometheusListenAddress string
Expand All @@ -85,10 +87,13 @@ type Config struct {
StaticFee uint
}

const DefaultBFGRequestTimeout = 15 * time.Second

func NewDefaultConfig() *Config {
return &Config{
BFGWSURL: "http://localhost:8383/v1/ws/public",
BTCChainName: "testnet3",
BFGWSURL: "http://localhost:8383/v1/ws/public",
BFGRequestTimeout: DefaultBFGRequestTimeout,
BTCChainName: "testnet3",
}
}

Expand Down Expand Up @@ -138,12 +143,15 @@ func NewMiner(cfg *Config) (*Miner, error) {
if cfg == nil {
cfg = NewDefaultConfig()
}
if cfg.BFGRequestTimeout <= 0 {
cfg.BFGRequestTimeout = DefaultBFGRequestTimeout
}

m := &Miner{
cfg: cfg,
bfgCmdCh: make(chan bfgCmd, 10),
holdoffTimeout: 5 * time.Second,
requestTimeout: 5 * time.Second,
requestTimeout: cfg.BFGRequestTimeout,
mineNowCh: make(chan struct{}, 1),
l2Keystones: make(map[string]L2KeystoneProcessingContainer, l2KeystonesMaxSize),
}
Expand Down

0 comments on commit 99d0038

Please sign in to comment.