From ba8f442e63b3391cdb63cbe3f89e07988d8b2f69 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Fri, 7 Apr 2023 11:17:09 -0600 Subject: [PATCH] Make min query loop duration configurable (#1164) --- .../chains/cosmos/cosmos_chain_processor.go | 14 +++++-- relayer/chains/cosmos/provider.go | 39 ++++++++++--------- .../penumbra/penumbra_chain_processor.go | 7 +++- relayer/chains/penumbra/provider.go | 39 ++++++++++--------- relayer/channel.go | 2 +- 5 files changed, 57 insertions(+), 44 deletions(-) diff --git a/relayer/chains/cosmos/cosmos_chain_processor.go b/relayer/chains/cosmos/cosmos_chain_processor.go index 300666b63..1feb92124 100644 --- a/relayer/chains/cosmos/cosmos_chain_processor.go +++ b/relayer/chains/cosmos/cosmos_chain_processor.go @@ -193,9 +193,14 @@ type queryCyclePersistence struct { // The initialBlockHistory parameter determines how many historical blocks should be fetched and processed before continuing with current blocks. // ChainProcessors should obey the context and return upon context cancellation. func (ccp *CosmosChainProcessor) Run(ctx context.Context, initialBlockHistory uint64) error { + minQueryLoopDuration := ccp.chainProvider.PCfg.MinLoopDuration + if minQueryLoopDuration == 0 { + minQueryLoopDuration = defaultMinQueryLoopDuration + } + // this will be used for persistence across query cycle loop executions persistence := queryCyclePersistence{ - minQueryLoopDuration: defaultMinQueryLoopDuration, + minQueryLoopDuration: minQueryLoopDuration, lastBalanceUpdate: time.Unix(0, 0), balanceUpdateWaitDuration: defaultBalanceUpdateWaitDuration, } @@ -320,9 +325,10 @@ func (ccp *CosmosChainProcessor) queryCycle(ctx context.Context, persistence *qu persistence.latestHeight = status.SyncInfo.LatestBlockHeight ccp.chainProvider.setCometVersion(ccp.log, status.NodeInfo.Version) - ccp.log.Debug("Queried latest height", - zap.Int64("latest_height", persistence.latestHeight), - ) + // This debug log is very noisy, but is helpful when debugging new chains. + // ccp.log.Debug("Queried latest height", + // zap.Int64("latest_height", persistence.latestHeight), + // ) if ccp.metrics != nil { ccp.CollectMetrics(ctx, persistence) diff --git a/relayer/chains/cosmos/provider.go b/relayer/chains/cosmos/provider.go index f34ec5700..58d3ca47f 100644 --- a/relayer/chains/cosmos/provider.go +++ b/relayer/chains/cosmos/provider.go @@ -35,25 +35,26 @@ var ( const cometEncodingThreshold = "v0.37.0-alpha" type CosmosProviderConfig struct { - KeyDirectory string `json:"key-directory" yaml:"key-directory"` - Key string `json:"key" yaml:"key"` - ChainName string `json:"-" yaml:"-"` - ChainID string `json:"chain-id" yaml:"chain-id"` - RPCAddr string `json:"rpc-addr" yaml:"rpc-addr"` - AccountPrefix string `json:"account-prefix" yaml:"account-prefix"` - KeyringBackend string `json:"keyring-backend" yaml:"keyring-backend"` - GasAdjustment float64 `json:"gas-adjustment" yaml:"gas-adjustment"` - GasPrices string `json:"gas-prices" yaml:"gas-prices"` - MinGasAmount uint64 `json:"min-gas-amount" yaml:"min-gas-amount"` - Debug bool `json:"debug" yaml:"debug"` - Timeout string `json:"timeout" yaml:"timeout"` - BlockTimeout string `json:"block-timeout" yaml:"block-timeout"` - OutputFormat string `json:"output-format" yaml:"output-format"` - SignModeStr string `json:"sign-mode" yaml:"sign-mode"` - ExtraCodecs []string `json:"extra-codecs" yaml:"extra-codecs"` - Modules []module.AppModuleBasic `json:"-" yaml:"-"` - Slip44 *int `json:"coin-type" yaml:"coin-type"` - Broadcast provider.BroadcastMode `json:"broadcast-mode" yaml:"broadcast-mode"` + KeyDirectory string `json:"key-directory" yaml:"key-directory"` + Key string `json:"key" yaml:"key"` + ChainName string `json:"-" yaml:"-"` + ChainID string `json:"chain-id" yaml:"chain-id"` + RPCAddr string `json:"rpc-addr" yaml:"rpc-addr"` + AccountPrefix string `json:"account-prefix" yaml:"account-prefix"` + KeyringBackend string `json:"keyring-backend" yaml:"keyring-backend"` + GasAdjustment float64 `json:"gas-adjustment" yaml:"gas-adjustment"` + GasPrices string `json:"gas-prices" yaml:"gas-prices"` + MinGasAmount uint64 `json:"min-gas-amount" yaml:"min-gas-amount"` + Debug bool `json:"debug" yaml:"debug"` + Timeout string `json:"timeout" yaml:"timeout"` + BlockTimeout string `json:"block-timeout" yaml:"block-timeout"` + OutputFormat string `json:"output-format" yaml:"output-format"` + SignModeStr string `json:"sign-mode" yaml:"sign-mode"` + ExtraCodecs []string `json:"extra-codecs" yaml:"extra-codecs"` + Modules []module.AppModuleBasic `json:"-" yaml:"-"` + Slip44 *int `json:"coin-type" yaml:"coin-type"` + Broadcast provider.BroadcastMode `json:"broadcast-mode" yaml:"broadcast-mode"` + MinLoopDuration time.Duration `json:"min-loop-duration" yaml:"min-loop-duration"` } func (pc CosmosProviderConfig) Validate() error { diff --git a/relayer/chains/penumbra/penumbra_chain_processor.go b/relayer/chains/penumbra/penumbra_chain_processor.go index f1cc169a1..b140b87f5 100644 --- a/relayer/chains/penumbra/penumbra_chain_processor.go +++ b/relayer/chains/penumbra/penumbra_chain_processor.go @@ -154,9 +154,14 @@ type queryCyclePersistence struct { // The initialBlockHistory parameter determines how many historical blocks should be fetched and processed before continuing with current blocks. // ChainProcessors should obey the context and return upon context cancellation. func (pcp *PenumbraChainProcessor) Run(ctx context.Context, initialBlockHistory uint64) error { + minQueryLoopDuration := pcp.chainProvider.PCfg.MinLoopDuration + if minQueryLoopDuration == 0 { + minQueryLoopDuration = defaultMinQueryLoopDuration + } + // this will be used for persistence across query cycle loop executions persistence := queryCyclePersistence{ - minQueryLoopDuration: defaultMinQueryLoopDuration, + minQueryLoopDuration: minQueryLoopDuration, } // Infinite retry to get initial latest height diff --git a/relayer/chains/penumbra/provider.go b/relayer/chains/penumbra/provider.go index 604a9d7c2..25af1575a 100644 --- a/relayer/chains/penumbra/provider.go +++ b/relayer/chains/penumbra/provider.go @@ -37,25 +37,26 @@ var ( const cometEncodingThreshold = "v0.37.0-alpha" type PenumbraProviderConfig struct { - KeyDirectory string `json:"key-directory" yaml:"key-directory"` - Key string `json:"key" yaml:"key"` - ChainName string `json:"-" yaml:"-"` - ChainID string `json:"chain-id" yaml:"chain-id"` - RPCAddr string `json:"rpc-addr" yaml:"rpc-addr"` - AccountPrefix string `json:"account-prefix" yaml:"account-prefix"` - KeyringBackend string `json:"keyring-backend" yaml:"keyring-backend"` - GasAdjustment float64 `json:"gas-adjustment" yaml:"gas-adjustment"` - GasPrices string `json:"gas-prices" yaml:"gas-prices"` - MinGasAmount uint64 `json:"min-gas-amount" yaml:"min-gas-amount"` - Debug bool `json:"debug" yaml:"debug"` - Timeout string `json:"timeout" yaml:"timeout"` - BlockTimeout string `json:"block-timeout" yaml:"block-timeout"` - OutputFormat string `json:"output-format" yaml:"output-format"` - SignModeStr string `json:"sign-mode" yaml:"sign-mode"` - ExtraCodecs []string `json:"extra-codecs" yaml:"extra-codecs"` - Modules []module.AppModuleBasic `json:"-" yaml:"-"` - Slip44 int `json:"coin-type" yaml:"coin-type"` - Broadcast provider.BroadcastMode `json:"broadcast-mode" yaml:"broadcast-mode"` + KeyDirectory string `json:"key-directory" yaml:"key-directory"` + Key string `json:"key" yaml:"key"` + ChainName string `json:"-" yaml:"-"` + ChainID string `json:"chain-id" yaml:"chain-id"` + RPCAddr string `json:"rpc-addr" yaml:"rpc-addr"` + AccountPrefix string `json:"account-prefix" yaml:"account-prefix"` + KeyringBackend string `json:"keyring-backend" yaml:"keyring-backend"` + GasAdjustment float64 `json:"gas-adjustment" yaml:"gas-adjustment"` + GasPrices string `json:"gas-prices" yaml:"gas-prices"` + MinGasAmount uint64 `json:"min-gas-amount" yaml:"min-gas-amount"` + Debug bool `json:"debug" yaml:"debug"` + Timeout string `json:"timeout" yaml:"timeout"` + BlockTimeout string `json:"block-timeout" yaml:"block-timeout"` + OutputFormat string `json:"output-format" yaml:"output-format"` + SignModeStr string `json:"sign-mode" yaml:"sign-mode"` + ExtraCodecs []string `json:"extra-codecs" yaml:"extra-codecs"` + Modules []module.AppModuleBasic `json:"-" yaml:"-"` + Slip44 int `json:"coin-type" yaml:"coin-type"` + Broadcast provider.BroadcastMode `json:"broadcast-mode" yaml:"broadcast-mode"` + MinLoopDuration time.Duration `json:"min-loop-duration" yaml:"min-loop-duration"` } func (pc PenumbraProviderConfig) Validate() error { diff --git a/relayer/channel.go b/relayer/channel.go index 528e1d047..5274d405d 100644 --- a/relayer/channel.go +++ b/relayer/channel.go @@ -74,7 +74,7 @@ func (c *Chain) CreateOpenChannels( dst.chainProcessor(c.log, nil), ). WithPathProcessors(pp). - WithInitialBlockHistory(100). + WithInitialBlockHistory(0). WithMessageLifecycle(&processor.ChannelMessageLifecycle{ Initial: &processor.ChannelMessage{ ChainID: c.PathEnd.ChainID,