From a35bec0003777e6c0c2ed3bf43171e54fb7d221a Mon Sep 17 00:00:00 2001 From: bruce-riley <96066700+bruce-riley@users.noreply.github.com> Date: Mon, 3 Jul 2023 10:12:52 -0500 Subject: [PATCH] Node: Make Terra Class watcher handle old blocks (#3159) --- node/pkg/watchers/cosmwasm/watcher.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/node/pkg/watchers/cosmwasm/watcher.go b/node/pkg/watchers/cosmwasm/watcher.go index f4ee02836..33bf1b81c 100644 --- a/node/pkg/watchers/cosmwasm/watcher.go +++ b/node/pkg/watchers/cosmwasm/watcher.go @@ -287,7 +287,22 @@ func (e *Watcher) Run(ctx context.Context) error { continue } - msgs := EventsToMessagePublications(e.contract, txHash, events.Array(), logger, e.chainID, e.contractAddressLogKey) + contractAddressLogKey := e.contractAddressLogKey + if e.chainID == vaa.ChainIDTerra { + // Terra Classic upgraded WASM versions starting at block 13215800. If this transaction is from before that, we need to use the old contract address format. + blockHeightStr := gjson.Get(txJSON, "tx_response.height") + if !blockHeightStr.Exists() { + logger.Error("failed to look up block height on old reobserved tx", zap.String("network", networkName), zap.String("txHash", txHash), zap.String("payload", txJSON)) + continue + } + blockHeight := blockHeightStr.Int() + if blockHeight < 13215800 { + logger.Info("doing look up of old tx", zap.String("network", networkName), zap.String("txHash", txHash), zap.Int64("blockHeight", blockHeight)) + contractAddressLogKey = "contract_address" + } + } + + msgs := EventsToMessagePublications(e.contract, txHash, events.Array(), logger, e.chainID, contractAddressLogKey) for _, msg := range msgs { e.msgC <- msg messagesConfirmed.WithLabelValues(networkName).Inc()