Skip to content

Commit

Permalink
feat: thorchain upgrade v3.0.0 (#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladinlight authored Dec 13, 2024
1 parent 2f7d33c commit 5492cab
Show file tree
Hide file tree
Showing 28 changed files with 631 additions and 3,389 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ aliases:
api-memory-request: 1Gi
stateful-service-replicas: 2
service-name-1: daemon
service-image-1: registry.gitlab.com/thorchain/thornode:mainnet-2.137.3
service-image-1: registry.gitlab.com/thorchain/thornode:mainnet-3.0.0
service-cpu-limit-1: "2"
service-cpu-request-1: "1"
service-memory-limit-1: 16Gi
Expand All @@ -401,7 +401,7 @@ aliases:
service-memory-limit-2: 8Gi
service-storage-size-2: 400Gi
service-name-3: indexer
service-image-3: registry.gitlab.com/thorchain/midgard:2.26.0
service-image-3: registry.gitlab.com/thorchain/midgard:2.28.1
service-cpu-limit-3: "2"
service-cpu-request-3: "1"
service-memory-limit-3: 2Gi
Expand Down
2 changes: 1 addition & 1 deletion go/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.5 as builder
FROM golang:1.23.4 as builder

ARG COINSTACK

Expand Down
3 changes: 2 additions & 1 deletion go/build/Dockerfile.local
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM quay.io/goswagger/swagger:v0.31.0
FROM golang:1.23.4

RUN go install github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0
RUN go install github.com/cespare/reflex@latest

ENTRYPOINT ["reflex", "-s"]
2 changes: 1 addition & 1 deletion go/cmd/thorchain-v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/shapeshift/unchained/pkg/cosmos"
"github.com/shapeshift/unchained/pkg/metrics"

thortypes "gitlab.com/thorchain/thornode/x/thorchain/types"
thortypes "gitlab.com/thorchain/thornode/v3/x/thorchain/types"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion go/cmd/thorchain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/shapeshift/unchained/pkg/cosmos"
"github.com/shapeshift/unchained/pkg/metrics"

thortypes "gitlab.com/thorchain/thornode/x/thorchain/types"
thortypes "gitlab.com/thorchain/thornode/v3/x/thorchain/types"
)

var (
Expand Down Expand Up @@ -55,6 +55,7 @@ func main() {
Bech32PkPrefix: "thorpub",
Bech32ValPrefix: "thorv",
Bech32PkValPrefix: "thorvpub",
Denom: "rune",
Encoding: encoding,
LCDURL: conf.LCDURL,
RPCURL: conf.RPCURL,
Expand Down
9 changes: 4 additions & 5 deletions go/coinstacks/thorchain-v1/api/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"net/url"
"time"

tendermintjson "github.com/cometbft/cometbft/libs/json"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
tendermint "github.com/cometbft/cometbft/rpc/jsonrpc/client"
"github.com/cometbft/cometbft/types"
"github.com/pkg/errors"
"github.com/shapeshift/unchained/pkg/cosmos"
tendermintjson "github.com/tendermint/tendermint/libs/json"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
tendermint "github.com/tendermint/tendermint/rpc/jsonrpc/client"
"github.com/tendermint/tendermint/types"
)

const (
Expand Down Expand Up @@ -109,7 +109,6 @@ func (ws *WSClient) listen() {
for r := range ws.client.ResponsesCh {
if r.Error != nil {
// resubscribe if subscription is cancelled by the server for reason: client is not pulling messages fast enough
// experimental rpc config available to help mitigate this issue: https://github.com/tendermint/tendermint/blob/main/config/config.go#L373
if r.Error.Code == -32000 {
ws.reset()
continue
Expand Down
38 changes: 19 additions & 19 deletions go/coinstacks/thorchain/api/affiliateFees.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
"sync"
"time"

abci "github.com/cometbft/cometbft/abci/types"
cometbftjson "github.com/cometbft/cometbft/libs/json"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
cometbft "github.com/cometbft/cometbft/rpc/jsonrpc/client"
"github.com/cometbft/cometbft/types"
cometbfttypes "github.com/cometbft/cometbft/types"
"github.com/pkg/errors"
"github.com/shapeshift/unchained/pkg/cosmos"
"github.com/shapeshift/unchained/pkg/thorchain"
abci "github.com/tendermint/tendermint/abci/types"
tendermintjson "github.com/tendermint/tendermint/libs/json"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
tendermint "github.com/tendermint/tendermint/rpc/jsonrpc/client"
"github.com/tendermint/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -159,16 +159,16 @@ func (i *AffiliateFeeIndexer) listen() error {
return errors.Wrapf(err, "failed to parse WSURL: %s", i.conf.WSURL)
}

client, err := tendermint.NewWS(wsURL.String(), "/websocket")
client, err := cometbft.NewWS(wsURL.String(), "/websocket")
if err != nil {
return errors.Wrapf(err, "failed to create websocket client")
}

// use default dialer
client.Dialer = net.Dial

tendermint.MaxReconnectAttempts(10)(client)
tendermint.OnReconnect(func() {
cometbft.MaxReconnectAttempts(10)(client)
cometbft.OnReconnect(func() {
logger.Info("OnReconnect triggered: resubscribing")
_ = client.Subscribe(context.Background(), types.EventQueryNewBlockHeader.String())
})(client)
Expand All @@ -181,7 +181,7 @@ func (i *AffiliateFeeIndexer) listen() error {
return errors.Wrap(err, "failed to subscribe to newBlocks")
}

go func(client *tendermint.WSClient) {
go func(client *cometbft.WSClient) {
for r := range client.ResponsesCh {
if r.Error != nil {
if r.Error.Code == -32000 {
Expand All @@ -203,7 +203,7 @@ func (i *AffiliateFeeIndexer) listen() error {
}

result := &coretypes.ResultEvent{}
if err := tendermintjson.Unmarshal(r.Result, result); err != nil {
if err := cometbftjson.Unmarshal(r.Result, result); err != nil {
logger.Errorf("failed to unmarshal tx message: %v", err)
continue
}
Expand Down Expand Up @@ -235,7 +235,7 @@ func (i *AffiliateFeeIndexer) fetchBlocks(httpClient *cosmos.HTTPClient, affilia
}
}

func (i *AffiliateFeeIndexer) handleBlock(httpClient *cosmos.HTTPClient, block *tmtypes.Block, affiliateAddress string) {
func (i *AffiliateFeeIndexer) handleBlock(httpClient *cosmos.HTTPClient, block *cometbfttypes.Block, affiliateAddress string) {
blockResult, err := httpClient.BlockResults(int(block.Height))
if err != nil {
logger.Panicf("failed to handle block: %d: %+v", block.Height, err)
Expand All @@ -245,19 +245,19 @@ func (i *AffiliateFeeIndexer) handleBlock(httpClient *cosmos.HTTPClient, block *
Block: block,
}

i.processAffiliateFees(b, blockResult.EndBlockEvents, []string{affiliateAddress})
i.processAffiliateFees(b, blockResult.FinalizeBlockEvents, []string{affiliateAddress})
}

func (i *AffiliateFeeIndexer) handleNewBlockHeader(newBlockHeader types.EventDataNewBlockHeader) {
b := &thorchain.NewBlockHeader{
EventDataNewBlockHeader: newBlockHeader,
}
//b := &thorchain.NewBlockHeader{
// EventDataNewBlockHeader: newBlockHeader,
//}

i.processAffiliateFees(b, newBlockHeader.ResultEndBlock.Events, i.AffiliateAddresses)
//i.processAffiliateFees(b, newBlockHeader.ResultEndBlock.Events, i.AffiliateAddresses)
}

func (i *AffiliateFeeIndexer) processAffiliateFees(block thorchain.Block, endBlockEvents []abci.Event, affiliateAddresses []string) {
_, typedEvents, err := thorchain.ParseBlockEvents(endBlockEvents)
func (i *AffiliateFeeIndexer) processAffiliateFees(block thorchain.Block, blockEvents []abci.Event, affiliateAddresses []string) {
_, typedEvents, err := thorchain.ParseBlockEvents(blockEvents)
if err != nil {
logger.Panicf("failed to parse block events for block: %d: %+v", block.Height(), err)
}
Expand Down
4 changes: 2 additions & 2 deletions go/coinstacks/thorchain/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func New(httpClient *cosmos.HTTPClient, wsClient *cosmos.WSClient, blockService
handler: handler,
}

// runtime check to ensure Handler implements CoinSpecific functionality
// compile check to ensure Handler implements necessary interfaces
var _ api.BaseAPI = handler
var _ cosmos.CoinSpecificHandler = handler

// runtime check to ensure Handler implements CoinSpecificHandler
// runtime check to ensure Handler implements CoinSpecific functionality
if err := handler.ValidateCoinSpecific(handler); err != nil {
logger.Panicf("%+v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions go/coinstacks/thorchain/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package api
import (
"math/big"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/pkg/errors"
"github.com/shapeshift/unchained/pkg/api"
"github.com/shapeshift/unchained/pkg/cosmos"
"github.com/shapeshift/unchained/pkg/thorchain"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/types"
)

type Handler struct {
Expand All @@ -19,8 +19,8 @@ type Handler struct {
}

func (h *Handler) StartWebsocket() error {
h.WSClient.EndBlockEventHandler(func(eventCache map[string]interface{}, blockHeader types.Header, endBlockEvents []abci.Event, eventIndex int) (interface{}, []string, error) {
tx, err := thorchain.GetTxFromEndBlockEvents(eventCache, blockHeader, endBlockEvents, eventIndex, h.BlockService.Latest.Height, h.Denom)
h.WSClient.BlockEventHandler(func(eventCache map[string]interface{}, blockHeader types.Header, blockEvents []abci.Event, eventIndex int) (interface{}, []string, error) {
tx, err := thorchain.GetTxFromBlockEvents(eventCache, blockHeader, blockEvents, eventIndex, h.BlockService.Latest.Height, h.Denom)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to get txs from end block events")
}
Expand Down
2 changes: 0 additions & 2 deletions go/coinstacks/thorchain/daemon/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

set -e

apk add bash

export THOR_TENDERMINT_RPC_EXPERIMENTAL_SUBSCRIPTION_BUFFER_SIZE=5000
export THOR_TENDERMINT_RPC_EXPERIMENTAL_WEBSOCKET_WRITE_BUFFER_SIZE=5000

Expand Down
4 changes: 2 additions & 2 deletions go/coinstacks/thorchain/daemon/readiness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ source /tendermint.sh

BLOCK_HEIGHT_TOLERANCE=5

SYNCING=$(curl -sf http://localhost:1317/syncing) || exit 1
SYNCING=$(curl -sf http://localhost:1317/cosmos/base/tendermint/v1beta1/syncing) || exit 1
NET_INFO=$(curl -sf http://localhost:27147/net_info) || exit 1
STATUS=$(curl -sf http://localhost:27147/status) || exit 1

Expand All @@ -22,7 +22,7 @@ NUM_PEERS=$(echo $NET_INFO | jq -r '.result.n_peers')
status_curls=(
"curl -sf -m 3 https://rpc.ninerealms.com/status"
# referer header now required to avoid being blocked
#"curl -sf -m 3 -H \"Referer: https://app.thorswap.finance\" https://rpc.thorswap.net/status"
"curl -sf -m 3 -H \"Referer: https://app.thorswap.finance\" https://rpc.thorswap.net/status"
)

if [[ $IS_SYNCING == false && $CATCHING_UP == false ]]; then
Expand Down
4 changes: 2 additions & 2 deletions go/coinstacks/thorchain/indexer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"tendermint_url": "http://localhost:27147/websocket",
"thornode_url": "http://localhost:1317/thorchain",
"last_chain_backoff": "7s",
"fetch_batch_size": 100,
"parallelism": 4,
"fetch_batch_size": 10,
"parallelism": 2,
"read_timeout": "32s",
"fork_infos": [
{
Expand Down
Loading

0 comments on commit 5492cab

Please sign in to comment.