NODE/IBC: Allow for a separate block height URL (#3480)
This commit is contained in:
parent
d6a410d7b2
commit
3b17062869
|
@ -139,9 +139,10 @@ var (
|
||||||
wormchainKeyPath *string
|
wormchainKeyPath *string
|
||||||
wormchainKeyPassPhrase *string
|
wormchainKeyPassPhrase *string
|
||||||
|
|
||||||
ibcWS *string
|
ibcWS *string
|
||||||
ibcLCD *string
|
ibcLCD *string
|
||||||
ibcContract *string
|
ibcBlockHeightURL *string
|
||||||
|
ibcContract *string
|
||||||
|
|
||||||
accountantContract *string
|
accountantContract *string
|
||||||
accountantWS *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")
|
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")
|
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")
|
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")
|
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["celoRPC"] = *celoRPC
|
||||||
rpcMap["ethRPC"] = *ethRPC
|
rpcMap["ethRPC"] = *ethRPC
|
||||||
rpcMap["fantomRPC"] = *fantomRPC
|
rpcMap["fantomRPC"] = *fantomRPC
|
||||||
|
rpcMap["ibcBlockHeightURL"] = *ibcBlockHeightURL
|
||||||
rpcMap["ibcLCD"] = *ibcLCD
|
rpcMap["ibcLCD"] = *ibcLCD
|
||||||
rpcMap["ibcWS"] = *ibcWS
|
rpcMap["ibcWS"] = *ibcWS
|
||||||
rpcMap["karuraRPC"] = *karuraRPC
|
rpcMap["karuraRPC"] = *karuraRPC
|
||||||
|
@ -1370,9 +1373,10 @@ func runNode(cmd *cobra.Command, args []string) {
|
||||||
var ibcWatcherConfig *node.IbcWatcherConfig = nil
|
var ibcWatcherConfig *node.IbcWatcherConfig = nil
|
||||||
if shouldStart(ibcWS) {
|
if shouldStart(ibcWS) {
|
||||||
ibcWatcherConfig = &node.IbcWatcherConfig{
|
ibcWatcherConfig = &node.IbcWatcherConfig{
|
||||||
Websocket: *ibcWS,
|
Websocket: *ibcWS,
|
||||||
Lcd: *ibcLCD,
|
Lcd: *ibcLCD,
|
||||||
Contract: *ibcContract,
|
BlockHeightURL: *ibcBlockHeightURL,
|
||||||
|
Contract: *ibcContract,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,9 +260,10 @@ func GuardianOptionStatusServer(statusAddr string) *GuardianOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
type IbcWatcherConfig struct {
|
type IbcWatcherConfig struct {
|
||||||
Websocket string
|
Websocket string
|
||||||
Lcd string
|
Lcd string
|
||||||
Contract 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.
|
// 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 {
|
if len(chainConfig) > 0 {
|
||||||
logger.Info("Starting IBC watcher")
|
logger.Info("Starting IBC watcher")
|
||||||
readiness.RegisterComponent(common.ReadinessIBCSyncing)
|
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 {
|
} else {
|
||||||
return errors.New("although IBC is enabled, there are no chains for it to monitor")
|
return errors.New("although IBC is enabled, there are no chains for it to monitor")
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,7 @@ type (
|
||||||
Watcher struct {
|
Watcher struct {
|
||||||
wsUrl string
|
wsUrl string
|
||||||
lcdUrl string
|
lcdUrl string
|
||||||
|
blockHeightUrl string
|
||||||
contractAddress string
|
contractAddress string
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
|
|
||||||
|
@ -128,6 +129,7 @@ type (
|
||||||
func NewWatcher(
|
func NewWatcher(
|
||||||
wsUrl string,
|
wsUrl string,
|
||||||
lcdUrl string,
|
lcdUrl string,
|
||||||
|
blockHeightUrl string,
|
||||||
contractAddress string,
|
contractAddress string,
|
||||||
chainConfig ChainConfig,
|
chainConfig ChainConfig,
|
||||||
) *Watcher {
|
) *Watcher {
|
||||||
|
@ -162,6 +164,7 @@ func NewWatcher(
|
||||||
return &Watcher{
|
return &Watcher{
|
||||||
wsUrl: wsUrl,
|
wsUrl: wsUrl,
|
||||||
lcdUrl: lcdUrl,
|
lcdUrl: lcdUrl,
|
||||||
|
blockHeightUrl: blockHeightUrl,
|
||||||
contractAddress: contractAddress,
|
contractAddress: contractAddress,
|
||||||
chainMap: chainMap,
|
chainMap: chainMap,
|
||||||
channelIdToChainIdMap: make(map[string]vaa.ChainID),
|
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("watcher_name", "ibc"),
|
||||||
zap.String("wsUrl", w.wsUrl),
|
zap.String("wsUrl", w.wsUrl),
|
||||||
zap.String("lcdUrl", w.lcdUrl),
|
zap.String("lcdUrl", w.lcdUrl),
|
||||||
|
zap.String("blockHeightUrl", w.blockHeightUrl),
|
||||||
zap.String("contractAddress", w.contractAddress),
|
zap.String("contractAddress", w.contractAddress),
|
||||||
)
|
)
|
||||||
|
|
||||||
errC := make(chan error)
|
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",
|
w.logger.Info("creating watcher",
|
||||||
zap.String("wsUrl", w.wsUrl),
|
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
|
// 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.
|
// 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 {
|
func convertWsUrlToHttpUrl(url string) string {
|
||||||
//
|
|
||||||
url = strings.TrimPrefix(url, "ws://")
|
url = strings.TrimPrefix(url, "ws://")
|
||||||
|
url = strings.TrimPrefix(url, "wss://")
|
||||||
url = strings.TrimSuffix(url, "/websocket")
|
url = strings.TrimSuffix(url, "/websocket")
|
||||||
return "http://" + url
|
return "http://" + url
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,6 +218,8 @@ func TestParseIbcAllChannelChainsQueryResults(t *testing.T) {
|
||||||
func TestConvertingWsUrlToHttpUrl(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/websocket"))
|
||||||
assert.Equal(t, "http://wormchain:26657", convertWsUrlToHttpUrl("ws://wormchain:26657"))
|
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"))
|
assert.Equal(t, "http://wormchain:26657", convertWsUrlToHttpUrl("wormchain:26657"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue