NODE/IBC: Allow for a separate block height URL (#3480)

This commit is contained in:
bruce-riley 2023-11-01 09:45:54 -05:00 committed by GitHub
parent d6a410d7b2
commit 3b17062869
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 12 deletions

View File

@ -139,9 +139,10 @@ var (
wormchainKeyPath *string
wormchainKeyPassPhrase *string
ibcWS *string
ibcLCD *string
ibcContract *string
ibcWS *string
ibcLCD *string
ibcBlockHeightURL *string
ibcContract *string
accountantContract *string
accountantWS *string
@ -304,6 +305,7 @@ func init() {
ibcWS = NodeCmd.Flags().String("ibcWS", "", "Websocket used to listen to the IBC receiver smart contract on wormchain")
ibcLCD = NodeCmd.Flags().String("ibcLCD", "", "Path to LCD service root for http calls")
ibcBlockHeightURL = NodeCmd.Flags().String("ibcBlockHeightURL", "", "Optional URL to query for the block height (generated from ibcWS if not specified)")
ibcContract = NodeCmd.Flags().String("ibcContract", "", "Address of the IBC smart contract on wormchain")
accountantWS = NodeCmd.Flags().String("accountantWS", "", "Websocket used to listen to the accountant smart contract on wormchain")
@ -840,6 +842,7 @@ func runNode(cmd *cobra.Command, args []string) {
rpcMap["celoRPC"] = *celoRPC
rpcMap["ethRPC"] = *ethRPC
rpcMap["fantomRPC"] = *fantomRPC
rpcMap["ibcBlockHeightURL"] = *ibcBlockHeightURL
rpcMap["ibcLCD"] = *ibcLCD
rpcMap["ibcWS"] = *ibcWS
rpcMap["karuraRPC"] = *karuraRPC
@ -1370,9 +1373,10 @@ func runNode(cmd *cobra.Command, args []string) {
var ibcWatcherConfig *node.IbcWatcherConfig = nil
if shouldStart(ibcWS) {
ibcWatcherConfig = &node.IbcWatcherConfig{
Websocket: *ibcWS,
Lcd: *ibcLCD,
Contract: *ibcContract,
Websocket: *ibcWS,
Lcd: *ibcLCD,
BlockHeightURL: *ibcBlockHeightURL,
Contract: *ibcContract,
}
}

View File

@ -260,9 +260,10 @@ func GuardianOptionStatusServer(statusAddr string) *GuardianOption {
}
type IbcWatcherConfig struct {
Websocket string
Lcd string
Contract string
Websocket string
Lcd string
BlockHeightURL string
Contract string
}
// GuardianOptionWatchers configues all normal watchers and all IBC watchers. They need to be all configured at the same time because they may depend on each other.
@ -421,7 +422,7 @@ func GuardianOptionWatchers(watcherConfigs []watchers.WatcherConfig, ibcWatcherC
if len(chainConfig) > 0 {
logger.Info("Starting IBC watcher")
readiness.RegisterComponent(common.ReadinessIBCSyncing)
g.runnablesWithScissors["ibcwatch"] = ibc.NewWatcher(ibcWatcherConfig.Websocket, ibcWatcherConfig.Lcd, ibcWatcherConfig.Contract, chainConfig).Run
g.runnablesWithScissors["ibcwatch"] = ibc.NewWatcher(ibcWatcherConfig.Websocket, ibcWatcherConfig.Lcd, ibcWatcherConfig.BlockHeightURL, ibcWatcherConfig.Contract, chainConfig).Run
} else {
return errors.New("although IBC is enabled, there are no chains for it to monitor")
}

View File

@ -98,6 +98,7 @@ type (
Watcher struct {
wsUrl string
lcdUrl string
blockHeightUrl string
contractAddress string
logger *zap.Logger
@ -128,6 +129,7 @@ type (
func NewWatcher(
wsUrl string,
lcdUrl string,
blockHeightUrl string,
contractAddress string,
chainConfig ChainConfig,
) *Watcher {
@ -162,6 +164,7 @@ func NewWatcher(
return &Watcher{
wsUrl: wsUrl,
lcdUrl: lcdUrl,
blockHeightUrl: blockHeightUrl,
contractAddress: contractAddress,
chainMap: chainMap,
channelIdToChainIdMap: make(map[string]vaa.ChainID),
@ -205,12 +208,17 @@ func (w *Watcher) Run(ctx context.Context) error {
zap.String("watcher_name", "ibc"),
zap.String("wsUrl", w.wsUrl),
zap.String("lcdUrl", w.lcdUrl),
zap.String("blockHeightUrl", w.blockHeightUrl),
zap.String("contractAddress", w.contractAddress),
)
errC := make(chan error)
blockHeightUrl := convertWsUrlToHttpUrl(w.wsUrl) + "/abci_info"
blockHeightUrl := w.blockHeightUrl
if blockHeightUrl == "" {
blockHeightUrl = convertWsUrlToHttpUrl(w.wsUrl)
}
blockHeightUrl = blockHeightUrl + "/abci_info"
w.logger.Info("creating watcher",
zap.String("wsUrl", w.wsUrl),
@ -350,8 +358,8 @@ func (w *Watcher) handleEvents(ctx context.Context, c *websocket.Conn) error {
// convertWsUrlToHttpUrl takes a string like "ws://wormchain:26657/websocket" and converts it to "http://wormchain:26657". This is
// used to query for the abci_info. That query doesn't work on the LCD. We have to do it on the websocket port, using an http URL.
func convertWsUrlToHttpUrl(url string) string {
//
url = strings.TrimPrefix(url, "ws://")
url = strings.TrimPrefix(url, "wss://")
url = strings.TrimSuffix(url, "/websocket")
return "http://" + url
}

View File

@ -218,6 +218,8 @@ func TestParseIbcAllChannelChainsQueryResults(t *testing.T) {
func TestConvertingWsUrlToHttpUrl(t *testing.T) {
assert.Equal(t, "http://wormchain:26657", convertWsUrlToHttpUrl("ws://wormchain:26657/websocket"))
assert.Equal(t, "http://wormchain:26657", convertWsUrlToHttpUrl("ws://wormchain:26657"))
assert.Equal(t, "http://wormchain:26657", convertWsUrlToHttpUrl("wss://wormchain:26657/websocket"))
assert.Equal(t, "http://wormchain:26657", convertWsUrlToHttpUrl("wss://wormchain:26657"))
assert.Equal(t, "http://wormchain:26657", convertWsUrlToHttpUrl("wormchain:26657"))
}