Skip to content

Commit

Permalink
fix cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
gusin13 committed Dec 16, 2024
1 parent 8050bb2 commit 7c3a688
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 53 deletions.
52 changes: 46 additions & 6 deletions e2etest/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
bbn "github.com/babylonlabs-io/babylon/types"
btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
queuecli "github.com/babylonlabs-io/staking-queue-client/client"
queuecfg "github.com/babylonlabs-io/staking-queue-client/config"
"github.com/babylonlabs-io/staking-queue-client/queuemngr"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
Expand All @@ -36,6 +37,7 @@ import (
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
pv "github.com/cosmos/relayer/v2/relayer/provider"

"github.com/stretchr/testify/require"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -70,7 +72,7 @@ func StartManager(t *testing.T, numMatureOutputsInWallet uint32, epochInterval u
passphrase := "pass"
_ = btcHandler.CreateWallet("default", passphrase)

cfg := DefaultStakingIndexerConfig()
cfg := TestConfig(t)

cfg.BTC.RPCHost = fmt.Sprintf("127.0.0.1:%s", bitcoind.GetPort("18443/tcp"))

Expand Down Expand Up @@ -227,12 +229,50 @@ func tempDir(t *testing.T) (string, error) {
return tempPath, err
}

func DefaultStakingIndexerConfig() *config.Config {
defaultConfig := config.DefaultConfig()
defaultConfig.Queue.QueueProcessingTimeout = time.Duration(500) * time.Second
defaultConfig.Queue.ReQueueDelayTime = time.Duration(300) * time.Second
func TestConfig(t *testing.T) *config.Config {
// TODO: ideally this should be setup through config-test.yaml
cfg := &config.Config{
BTC: config.BTCConfig{
RPCHost: "127.0.0.1:18443",
RPCUser: "user",
RPCPass: "pass",
BlockPollingInterval: 30 * time.Second,
TxPollingInterval: 30 * time.Second,
BlockCacheSize: 20 * 1024 * 1024, // 20 MB
MaxRetryTimes: 5,
RetryInterval: 500 * time.Millisecond,
NetParams: "regtest",
},
Db: config.DbConfig{
Address: "mongodb://localhost:27019/?replicaSet=RS&directConnection=true",
Username: "root",
Password: "example",
DbName: "babylon-staking-indexer",
},
BBN: config.BBNConfig{
RPCAddr: "http://localhost:26657",
Timeout: 20 * time.Second,
MaxRetryTimes: 3,
RetryInterval: 1 * time.Second,
},
Poller: config.PollerConfig{
ParamPollingInterval: 1 * time.Second,
ExpiryCheckerPollingInterval: 1 * time.Second,
ExpiredDelegationsLimit: 1000,
},
Queue: *queuecfg.DefaultQueueConfig(),
Metrics: config.MetricsConfig{
Host: "0.0.0.0",
Port: 2112,
},
}
cfg.Queue.QueueProcessingTimeout = time.Duration(50) * time.Second
cfg.Queue.ReQueueDelayTime = time.Duration(100) * time.Second

err := cfg.Validate()
require.NoError(t, err)

return defaultConfig
return cfg
}

// RetrieveTransactionFromMempool fetches transactions from the mempool for the given hashes
Expand Down
47 changes: 0 additions & 47 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"fmt"
"os"
"strings"
"time"

bbncfg "github.com/babylonlabs-io/babylon/client/config"
queue "github.com/babylonlabs-io/staking-queue-client/config"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -83,48 +81,3 @@ func New(cfgFile string) (*Config, error) {

return &cfg, nil
}

func DefaultConfig() *Config {
bbnCfg := bbncfg.DefaultBabylonConfig()
cfg := &Config{
BTC: BTCConfig{
RPCHost: "127.0.0.1:18443",
RPCUser: "user",
RPCPass: "pass",
BlockPollingInterval: 30 * time.Second,
TxPollingInterval: 30 * time.Second,
BlockCacheSize: 20 * 1024 * 1024, // 20 MB
MaxRetryTimes: 5,
RetryInterval: 500 * time.Millisecond,
NetParams: "regtest",
},
Db: DbConfig{
Address: "mongodb://localhost:27019/?replicaSet=RS&directConnection=true",
Username: "root",
Password: "example",
DbName: "babylon-staking-indexer",
},
BBN: BBNConfig{
RPCAddr: bbnCfg.RPCAddr,
Timeout: bbnCfg.Timeout,
MaxRetryTimes: 3,
RetryInterval: 1 * time.Second,
},
Poller: PollerConfig{
ParamPollingInterval: 1 * time.Second,
ExpiryCheckerPollingInterval: 1 * time.Second,
ExpiredDelegationsLimit: 1000,
},
Queue: *queue.DefaultQueueConfig(),
Metrics: MetricsConfig{
Host: "0.0.0.0",
Port: 2112,
},
}

if err := cfg.Validate(); err != nil {
panic(err)
}

return cfg
}

0 comments on commit 7c3a688

Please sign in to comment.