NODE/IBC: Allow for a separate block height URL (#3480)
This commit is contained in:
parent
d6a410d7b2
commit
3b17062869
|
@ -141,6 +141,7 @@ var (
|
|||
|
||||
ibcWS *string
|
||||
ibcLCD *string
|
||||
ibcBlockHeightURL *string
|
||||
ibcContract *string
|
||||
|
||||
accountantContract *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
|
||||
|
@ -1372,6 +1375,7 @@ func runNode(cmd *cobra.Command, args []string) {
|
|||
ibcWatcherConfig = &node.IbcWatcherConfig{
|
||||
Websocket: *ibcWS,
|
||||
Lcd: *ibcLCD,
|
||||
BlockHeightURL: *ibcBlockHeightURL,
|
||||
Contract: *ibcContract,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -262,6 +262,7 @@ func GuardianOptionStatusServer(statusAddr string) *GuardianOption {
|
|||
type IbcWatcherConfig struct {
|
||||
Websocket string
|
||||
Lcd string
|
||||
BlockHeightURL string
|
||||
Contract string
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue