Skip to content

Commit

Permalink
support sei network
Browse files Browse the repository at this point in the history
Victor Neznaykin committed Aug 25, 2024
1 parent 4b2a73e commit 0a96bfa
Showing 34 changed files with 386 additions and 12,169 deletions.
12 changes: 6 additions & 6 deletions client/grpc/block.go
Original file line number Diff line number Diff line change
@@ -3,12 +3,12 @@ package grpc
import (
"context"

cometbftcoretypes "github.com/cometbft/cometbft/rpc/core/types"
cometbfttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
tmcoretypes "github.com/tendermint/tendermint/rpc/coretypes"
tmtypes "github.com/tendermint/tendermint/types"
)

func (c *Client) Block(ctx context.Context, height int64) (*cometbftcoretypes.ResultBlock, error) {
func (c *Client) Block(ctx context.Context, height int64) (*tmcoretypes.ResultBlock, error) {
resp, err := c.TmsService.GetBlockByHeight(
ctx,
&tmservice.GetBlockByHeightRequest{
@@ -19,17 +19,17 @@ func (c *Client) Block(ctx context.Context, height int64) (*cometbftcoretypes.Re
return nil, err
}

block, err := cometbfttypes.BlockFromProto(resp.Block) // nolint:staticcheck
block, err := tmtypes.BlockFromProto(resp.Block) // nolint:staticcheck
if err != nil {
return nil, err
}

blockID, err := cometbfttypes.BlockIDFromProto(resp.BlockId)
blockID, err := tmtypes.BlockIDFromProto(resp.BlockId)
if err != nil {
return nil, err
}

return &cometbftcoretypes.ResultBlock{
return &tmcoretypes.ResultBlock{
Block: block,
BlockID: *blockID,
}, nil
29 changes: 16 additions & 13 deletions client/grpc/client.go
Original file line number Diff line number Diff line change
@@ -7,13 +7,10 @@ import (

"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/types/tx"
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/timeout"
"github.com/prometheus/client_golang/prometheus"
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/rs/zerolog"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

"github.com/bro-n-bro/spacebox-crawler/v2/adapter/storage/model"
)
@@ -46,28 +43,23 @@ func (c *Client) Start(ctx context.Context) error {

options := []grpc.DialOption{
grpc.WithBlock(),
grpc.WithChainUnaryInterceptor(timeout.UnaryClientInterceptor(c.cfg.Timeout)), // request timeout
grpc.WithChainUnaryInterceptor(timeoutUnaryClientInterceptor(c.cfg.Timeout)), // request timeout
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(c.cfg.MaxReceiveMessageSize)),
}

if c.cfg.MetricsEnabled {
cm := grpcprom.NewClientMetrics(
grpcprom.WithClientHandlingTimeHistogram())

prometheus.MustRegister(cm)

options = append(
options,
grpc.WithChainUnaryInterceptor(cm.UnaryClientInterceptor()),
grpc.WithChainStreamInterceptor(cm.StreamClientInterceptor()),
grpc.WithChainUnaryInterceptor(grpcprometheus.UnaryClientInterceptor),
grpc.WithChainStreamInterceptor(grpcprometheus.StreamClientInterceptor),
)
}

// Add required secure grpc option based on config parameter
if c.cfg.SecureConnection {
options = append(options, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) // nolint:gosec
} else {
options = append(options, grpc.WithTransportCredentials(insecure.NewCredentials()))
options = append(options, grpc.WithInsecure())
}

// Create a connection to the gRPC server.
@@ -91,3 +83,14 @@ func (c *Client) Start(ctx context.Context) error {
func (c *Client) Stop(_ context.Context) error { return c.conn.Close() }

func (c *Client) Conn() *grpc.ClientConn { return c.conn }

// timeoutUnaryClientInterceptor returns a new unary client interceptor that sets a timeout on the request context.
func timeoutUnaryClientInterceptor(timeout time.Duration) grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker,
opts ...grpc.CallOption) error {

timedCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
return invoker(timedCtx, method, req, reply, cc, opts...)
}
}
4 changes: 2 additions & 2 deletions client/grpc/tx.go
Original file line number Diff line number Diff line change
@@ -5,16 +5,16 @@ import (
"encoding/hex"
"time"

cometbfttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/types/tx"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/bro-n-bro/spacebox-crawler/v2/adapter/storage/model"
)

// Txs queries for all the transactions in a block. Transactions are returned
// in sdk.TxResponse format which internally contains a sdk.Tx. An error is
// returned if any query fails.
func (c *Client) Txs(ctx context.Context, height int64, txs cometbfttypes.Txs) ([]*tx.GetTxResponse, error) {
func (c *Client) Txs(ctx context.Context, height int64, txs tmtypes.Txs) ([]*tx.GetTxResponse, error) {
txResponses := make([]*tx.GetTxResponse, 0, len(txs))

for _, tmTx := range txs {
68 changes: 0 additions & 68 deletions client/grpc/validator.go

This file was deleted.

4 changes: 2 additions & 2 deletions client/rpc/block_results.go
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@ package rpc
import (
"context"

coretypes "github.com/cometbft/cometbft/rpc/core/types"
tmcoretypes "github.com/tendermint/tendermint/rpc/coretypes"
)

func (c *Client) GetBlockResults(ctx context.Context, height int64) (*coretypes.ResultBlockResults, error) {
func (c *Client) GetBlockResults(ctx context.Context, height int64) (*tmcoretypes.ResultBlockResults, error) {
ctx, cancel := context.WithTimeout(ctx, c.cfg.Timeout)
defer cancel()

23 changes: 0 additions & 23 deletions client/rpc/blocker.go

This file was deleted.

13 changes: 6 additions & 7 deletions client/rpc/client.go
Original file line number Diff line number Diff line change
@@ -4,16 +4,15 @@ import (
"context"
"net/http"

cometbftHttp "github.com/cometbft/cometbft/rpc/client/http"
jsonrpcclient "github.com/cometbft/cometbft/rpc/jsonrpc/client"
"github.com/prometheus/client_golang/prometheus/promhttp"
tmHttp "github.com/tendermint/tendermint/rpc/client/http"
jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
)

type Client struct {
*jsonrpcclient.WSClient
*cometbftHttp.WSEvents

RPCClient *cometbftHttp.HTTP
RPCClient *tmHttp.HTTP

cfg Config
}
@@ -22,7 +21,7 @@ func New(cfg Config) *Client {
return &Client{cfg: cfg}
}

func (c *Client) Start(_ context.Context) error {
func (c *Client) Start(ctx context.Context) error {
httpClient, err := jsonrpcclient.DefaultHTTPClient(c.cfg.Host)
if err != nil {
return err
@@ -37,12 +36,12 @@ func (c *Client) Start(_ context.Context) error {
)
}

c.RPCClient, err = cometbftHttp.NewWithClient(c.cfg.Host, "/websocket", httpClient)
c.RPCClient, err = tmHttp.NewWithClient(c.cfg.Host, httpClient)
if err != nil {
return err
}

if err = c.RPCClient.Start(); err != nil {
if err = c.RPCClient.Start(ctx); err != nil {
return err
}

8 changes: 4 additions & 4 deletions client/rpc/genesis.go
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@ import (
"context"
"encoding/base64"

"github.com/cometbft/cometbft/libs/json"
cometbfttypes "github.com/cometbft/cometbft/types"
"github.com/tendermint/tendermint/libs/json"
tmtypes "github.com/tendermint/tendermint/types"
"golang.org/x/sync/errgroup"
)

func (c *Client) Genesis(ctx context.Context) (*cometbfttypes.GenesisDoc, error) {
func (c *Client) Genesis(ctx context.Context) (*tmtypes.GenesisDoc, error) {
chunk, err := c.RPCClient.GenesisChunked(ctx, 0)
if err != nil {
return nil, err
@@ -49,7 +49,7 @@ func (c *Client) Genesis(ctx context.Context) (*cometbfttypes.GenesisDoc, error)
totalData = append(totalData, ch...)
}

var resp *cometbfttypes.GenesisDoc
var resp *tmtypes.GenesisDoc
if err = json.Unmarshal(totalData, &resp); err != nil {
return nil, err
}
4 changes: 2 additions & 2 deletions client/rpc/subscribe.go
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ package rpc
import (
"context"

cometbftcoretypes "github.com/cometbft/cometbft/rpc/core/types"
tmcoretypes "github.com/tendermint/tendermint/rpc/coretypes"
)

func (c *Client) SubscribeNewBlocks(ctx context.Context) (<-chan cometbftcoretypes.ResultEvent, error) {
func (c *Client) SubscribeNewBlocks(ctx context.Context) (<-chan tmcoretypes.ResultEvent, error) {
return c.RPCClient.Subscribe(ctx, "", "tm.event = 'NewBlock'")
}
19 changes: 0 additions & 19 deletions client/rpc/tx_results.go

This file was deleted.

139 changes: 53 additions & 86 deletions go.mod
Original file line number Diff line number Diff line change
@@ -3,95 +3,81 @@ module github.com/bro-n-bro/spacebox-crawler/v2
go 1.22.4

replace (
github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.47.15-ics-lsm

github.com/cosmos/interchain-security/v4 => github.com/cosmos/interchain-security/v4 v4.2.0-lsm

github.com/CosmWasm/wasmd => github.com/sei-protocol/sei-wasmd v0.2.4-0.20240816184629-eb6d20caf603
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.3.33
github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.9
github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.2
github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-22
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.3.8
golang.org/x/exp => golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)

require (
github.com/CosmWasm/wasmd v0.45.0
github.com/caarlos0/env/v6 v6.10.1
github.com/cometbft/cometbft v0.37.6
github.com/confluentinc/confluent-kafka-go/v2 v2.3.0
github.com/cosmos/cosmos-sdk v0.47.11
github.com/cosmos/gaia/v17 v17.2.0
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.4.0
github.com/cosmos/interchain-security/v4 v4.2.0
github.com/cosmos/ibc-go/v3 v3.0.0
github.com/globocom/mongo-go-prometheus v0.1.1
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.0
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1
github.com/gogo/protobuf v1.3.3
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/joho/godotenv v1.4.0
github.com/json-iterator/go v1.1.12
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/rs/zerolog v1.32.0
github.com/sei-protocol/sei-chain v0.0.38
github.com/tendermint/tendermint v0.37.0-dev
go.mongodb.org/mongo-driver v1.12.1
golang.org/x/crypto v0.21.0
golang.org/x/sync v0.6.0
golang.org/x/crypto v0.23.0
golang.org/x/sync v0.7.0
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de
google.golang.org/grpc v1.63.2
gopkg.in/yaml.v3 v3.0.1
)

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.36.0 // indirect
cosmossdk.io/api v0.3.1 // indirect
cosmossdk.io/core v0.6.1-0.20230309163709-87da587416ba // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/CosmWasm/wasmvm v1.5.1 // indirect
github.com/CosmWasm/wasmvm v1.5.4 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go v1.44.224 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect
github.com/cometbft/cometbft-db v0.12.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.1 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.21.0-alpha.1.0.20230904092046-df3db2d96583 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/creachadair/taskgroup v0.4.2 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v4 v4.2.0 // indirect
github.com/dgraph-io/badger/v3 v3.2103.2 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.9+incompatible // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/ethereum/go-ethereum v1.13.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
@@ -100,82 +86,67 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogo/gateway v1.1.0 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.4 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/go-uuid v1.0.1 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/golang-lru/v2 v2.0.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.14 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20210609091139-0a56a4bca00b // indirect
github.com/onsi/gomega v1.27.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/opencontainers/runc v1.1.12 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/petermattis/goid v0.0.0-20230518223814-80aa455d8761 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.0 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sei-protocol/sei-db v0.0.27-0.20240123064153-d6dfa112e760 // indirect
github.com/sei-protocol/sei-tm-db v0.0.5 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
@@ -185,10 +156,12 @@ require (
github.com/spf13/viper v1.18.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/btcd v0.1.1 // indirect
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/tendermint/tm-db v0.6.8-0.20220519162814-e24b96538a12 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
@@ -197,28 +170,22 @@ require (
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.9.0 // indirect
go.opentelemetry.io/otel/metric v1.22.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/api v0.162.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v1.1.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
1,088 changes: 237 additions & 851 deletions go.sum

Large diffs are not rendered by default.

52 changes: 19 additions & 33 deletions internal/app/app.go
Original file line number Diff line number Diff line change
@@ -16,35 +16,30 @@ import (
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/capability"
"github.com/cosmos/cosmos-sdk/x/consensus"
"github.com/cosmos/cosmos-sdk/x/crisis"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
"github.com/cosmos/cosmos-sdk/x/mint"
nftmodule "github.com/cosmos/cosmos-sdk/x/nft/module"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
gaia "github.com/cosmos/gaia/v17/x/metaprotocols"
ibcaccounts "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibccore "github.com/cosmos/ibc-go/v7/modules/core"
ibclightclient "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
interchainprovider "github.com/cosmos/interchain-security/v4/x/ccv/provider"
ibctransfer "github.com/cosmos/ibc-go/v3/modules/apps/transfer"
ibccore "github.com/cosmos/ibc-go/v3/modules/core"
ibclightclient "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/rs/zerolog"
seidex "github.com/sei-protocol/sei-chain/x/dex/types"
seiepoch "github.com/sei-protocol/sei-chain/x/epoch/types"
seievm "github.com/sei-protocol/sei-chain/x/evm/types"
seimint "github.com/sei-protocol/sei-chain/x/mint/types"
seioracle "github.com/sei-protocol/sei-chain/x/oracle/types"
seitokenfactory "github.com/sei-protocol/sei-chain/x/tokenfactory/types"

"github.com/bro-n-bro/spacebox-crawler/v2/adapter/storage"
"github.com/bro-n-bro/spacebox-crawler/v2/adapter/storage/model"
@@ -58,7 +53,6 @@ import (
healthchecker "github.com/bro-n-bro/spacebox-crawler/v2/pkg/health_checker"
ts "github.com/bro-n-bro/spacebox-crawler/v2/pkg/mapper/to_storage"
"github.com/bro-n-bro/spacebox-crawler/v2/pkg/worker"
liquiditytypes "github.com/bro-n-bro/spacebox-crawler/v2/types/liquidity"
)

const (
@@ -206,7 +200,7 @@ func MakeEncodingConfig() codec.Codec {
registry = cdc.NewInterfaceRegistry()
basicManager = module.NewBasicManager(
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
genutil.AppModuleBasic{},
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
@@ -219,23 +213,10 @@ func MakeEncodingConfig() codec.Codec {
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
authzmodule.AppModuleBasic{},
groupmodule.AppModuleBasic{},
vesting.AppModuleBasic{},
nftmodule.AppModuleBasic{},
consensus.AppModuleBasic{},
ibccore.AppModuleBasic{},
ibcfee.AppModuleBasic{},
ibcaccounts.AppModuleBasic{},
ibclightclient.AppModuleBasic{},
interchainprovider.AppModuleBasic{},
gaia.AppModuleBasic{},
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
},
),
ibctransfer.AppModuleBasic{},
gov.NewAppModuleBasic(),
)
)

@@ -244,9 +225,14 @@ func MakeEncodingConfig() codec.Codec {
//
basicManager.RegisterInterfaces(registry)
std.RegisterInterfaces(registry)
ibctransfertypes.RegisterInterfaces(registry)
cryptocodec.RegisterInterfaces(registry)
liquiditytypes.RegisterInterfaces(registry)
ibclightclient.RegisterInterfaces(registry)
seidex.RegisterInterfaces(registry)
seiepoch.RegisterInterfaces(registry)
seievm.RegisterInterfaces(registry)
seimint.RegisterInterfaces(registry)
seioracle.RegisterInterfaces(registry)
seitokenfactory.RegisterInterfaces(registry)

return codec.NewProtoCodec(registry)
}
16 changes: 6 additions & 10 deletions internal/rep/client.go
Original file line number Diff line number Diff line change
@@ -3,25 +3,21 @@ package rep
import (
"context"

cometbftcoretypes "github.com/cometbft/cometbft/rpc/core/types"
cometbfttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/types/tx"

"github.com/bro-n-bro/spacebox-crawler/v2/types"
tmcoretypes "github.com/tendermint/tendermint/rpc/coretypes"
tmtypes "github.com/tendermint/tendermint/types"
)

type (
GrpcClient interface {
Block(ctx context.Context, height int64) (*cometbftcoretypes.ResultBlock, error)
Validators(ctx context.Context, height int64) (*cometbftcoretypes.ResultValidators, error)
Block(ctx context.Context, height int64) (*tmcoretypes.ResultBlock, error)

Txs(ctx context.Context, height int64, txs cometbfttypes.Txs) ([]*tx.GetTxResponse, error)
Txs(ctx context.Context, height int64, txs tmtypes.Txs) ([]*tx.GetTxResponse, error)
}

RPCClient interface {
SubscribeNewBlocks(ctx context.Context) (<-chan cometbftcoretypes.ResultEvent, error)
Genesis(ctx context.Context) (*cometbfttypes.GenesisDoc, error)
SubscribeNewBlocks(ctx context.Context) (<-chan tmcoretypes.ResultEvent, error)
Genesis(ctx context.Context) (*tmtypes.GenesisDoc, error)
GetLastBlockHeight(ctx context.Context) (int64, error)
GetBlockEvents(ctx context.Context, height int64) (begin, end types.BlockerEvents, err error)
}
)
2 changes: 1 addition & 1 deletion modules/raw/block.go
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ import (
"fmt"
"time"

coretypes "github.com/cometbft/cometbft/rpc/core/types"
jsoniter "github.com/json-iterator/go"
coretypes "github.com/tendermint/tendermint/rpc/coretypes"

"github.com/bro-n-bro/spacebox-crawler/v2/types"
)
4 changes: 2 additions & 2 deletions modules/raw/genesis.go
Original file line number Diff line number Diff line change
@@ -5,11 +5,11 @@ import (
"encoding/json"
"fmt"

cometbfttypes "github.com/cometbft/cometbft/types"
jsoniter "github.com/json-iterator/go"
tmtypes "github.com/tendermint/tendermint/types"
)

func (m *Module) HandleGenesis(ctx context.Context, doc *cometbfttypes.GenesisDoc, _ map[string]json.RawMessage) error {
func (m *Module) HandleGenesis(ctx context.Context, doc *tmtypes.GenesisDoc, _ map[string]json.RawMessage) error {
rawGenesis := struct {
GenesisTime string `json:"genesis_time"`
ChainID string `json:"chain_id"`
6 changes: 4 additions & 2 deletions modules/raw/module.go
Original file line number Diff line number Diff line change
@@ -13,8 +13,10 @@ const (
)

var (
_ types.Module = &Module{}
_ types.BlockHandler = &Module{}
_ types.Module = &Module{}
_ types.BlockHandler = &Module{}
_ types.TransactionHandler = &Module{}
_ types.GenesisHandler = &Module{}
)

type Module struct {
2 changes: 1 addition & 1 deletion modules/raw/transaction.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import (
"fmt"
"sync"

"github.com/cosmos/gogoproto/jsonpb"
"github.com/gogo/protobuf/jsonpb"

"github.com/bro-n-bro/spacebox-crawler/v2/types"
)
26 changes: 3 additions & 23 deletions pkg/worker/modules.go
Original file line number Diff line number Diff line change
@@ -3,14 +3,9 @@ package worker
import "github.com/bro-n-bro/spacebox-crawler/v2/types"

var (
transactionHandlers []types.TransactionHandler
blockHandlers []types.BlockHandler
genesisHandlers []types.GenesisHandler
messageHandlers []types.MessageHandler
validatorsHandlers []types.ValidatorsHandler
beginBlockerHandlers []types.BeginBlockerHandler
endBlockerHandlers []types.EndBlockerHandler
recursiveMessagesHandlers []types.RecursiveMessagesHandler
transactionHandlers []types.TransactionHandler
blockHandlers []types.BlockHandler
genesisHandlers []types.GenesisHandler
)

// fillModules fills the module handlers.
@@ -25,20 +20,5 @@ func (w *Worker) fillModules() {
if gI, ok := module.(types.GenesisHandler); ok {
genesisHandlers = append(genesisHandlers, gI)
}
if mI, ok := module.(types.MessageHandler); ok {
messageHandlers = append(messageHandlers, mI)
}
if vI, ok := module.(types.ValidatorsHandler); ok {
validatorsHandlers = append(validatorsHandlers, vI)
}
if bbI, ok := module.(types.BeginBlockerHandler); ok {
beginBlockerHandlers = append(beginBlockerHandlers, bbI)
}
if ebI, ok := module.(types.EndBlockerHandler); ok {
endBlockerHandlers = append(endBlockerHandlers, ebI)
}
if rmI, ok := module.(types.RecursiveMessagesHandler); ok {
recursiveMessagesHandlers = append(recursiveMessagesHandlers, rmI)
}
}
}
193 changes: 4 additions & 189 deletions pkg/worker/process.go
Original file line number Diff line number Diff line change
@@ -5,28 +5,21 @@ import (
"encoding/json"
"errors"
"fmt"
"reflect"
"time"

cometbftcoreypes "github.com/cometbft/cometbft/rpc/core/types"
cometbfttypes "github.com/cometbft/cometbft/types"
codec "github.com/cosmos/cosmos-sdk/codec/types"
jsoniter "github.com/json-iterator/go"
tmcoreypes "github.com/tendermint/tendermint/rpc/coretypes"
tmtypes "github.com/tendermint/tendermint/types"
"golang.org/x/sync/errgroup"

"github.com/bro-n-bro/spacebox-crawler/v2/types"
)

const (
keyHeight = "height"
keyTxHash = "tx_hash"
keyModule = "module"
)

var (
errRecurringHandling = errors.New("cant handle recurring messages")
)

func (w *Worker) process(ctx context.Context, workerIndex int, recoverMode bool) {
var parsedCount int
defer w.wg.Done()
@@ -106,11 +99,7 @@ func (w *Worker) processHeight(ctx context.Context, workerIndex int, height int6

g, ctx2 := errgroup.WithContext(ctx)

var (
block *cometbftcoreypes.ResultBlock
vals *cometbftcoreypes.ResultValidators
beginBlockEvents, endBlockEvents types.BlockerEvents
)
var block *tmcoreypes.ResultBlock

g.Go(func() error {
var err error
@@ -127,38 +116,6 @@ func (w *Worker) processHeight(ctx context.Context, workerIndex int, height int6
return nil
})

g.Go(func() error {
var err error
_validatorsDur := time.Now()
if vals, err = w.grpcClient.Validators(ctx2, height); err != nil {
return fmt.Errorf("failed to get validators: %w", err)
}
w.log.Debug().
Int("worker_number", workerIndex).
Int64("block_height", height).
Dur("get_validators_dur", time.Since(_validatorsDur)).
Msg("Get validators info")

return nil
})

g.Go(func() error {
var err error
_blockEventsDur := time.Now()
beginBlockEvents, endBlockEvents, err = w.rpcClient.GetBlockEvents(ctx2, height)
if err != nil {
return fmt.Errorf("failed to get block events: %w", err)
}

w.log.Debug().
Int("worker_number", workerIndex).
Int64("block_height", height).
Dur("get_block_events_dur", time.Since(_blockEventsDur)).
Msg("get validators info")

return nil
})

if err := g.Wait(); err != nil {
w.log.Error().Int64(keyHeight, height).Err(err).Msg("processHeight error")
w.setErrorStatusWithLogging(ctx, height, err.Error())
@@ -183,11 +140,6 @@ func (w *Worker) processHeight(ctx context.Context, workerIndex int, height int6
txs := types.NewTxsFromTmTxs(txsRes, w.cdc)
g, ctx2 = errgroup.WithContext(ctx)

g.Go(func() error {
return w.withMetrics("validators", func() error {
return w.processValidators(ctx2, height, vals)
})
})
g.Go(func() error {
return w.withMetrics("block", func() error {
return w.processBlock(ctx2, types.NewBlockFromTmBlock(block, txs.TotalGas()))
@@ -198,21 +150,6 @@ func (w *Worker) processHeight(ctx context.Context, workerIndex int, height int6
return w.processTxs(ctx2, txs)
})
})
g.Go(func() error {
return w.withMetrics("messages", func() error {
return w.processMessages(ctx2, txs)
})
})
g.Go(func() error {
return w.withMetrics("beginblocker", func() error {
return w.processBeginBlockerEvents(ctx2, beginBlockEvents, height)
})
})
g.Go(func() error {
return w.withMetrics("endblocker", func() error {
return w.processEndBlockEvents(ctx2, endBlockEvents, height)
})
})

if err := g.Wait(); err != nil {
w.setErrorStatusWithLogging(ctx, height, err.Error())
@@ -224,7 +161,7 @@ func (w *Worker) processHeight(ctx context.Context, workerIndex int, height int6
}
}

func (w *Worker) processGenesis(ctx context.Context, genesis *cometbfttypes.GenesisDoc) error {
func (w *Worker) processGenesis(ctx context.Context, genesis *tmtypes.GenesisDoc) error {
var appState map[string]json.RawMessage
if err := jsoniter.Unmarshal(genesis.AppState, &appState); err != nil {
w.log.Err(err).Msg("error unmarshalling genesis doc")
@@ -256,22 +193,6 @@ func (w *Worker) processBlock(ctx context.Context, block *types.Block) error {
return nil
}

func (w *Worker) processValidators(ctx context.Context, height int64, vals *cometbftcoreypes.ResultValidators) error {
for _, m := range validatorsHandlers {
if err := m.HandleValidators(ctx, vals); err != nil {
w.log.Error().
Err(err).
Int64(keyHeight, height).
Str(keyModule, m.Name()).
Msg("HandleValidators error")

return err
}
}

return nil
}

func (w *Worker) processTxs(ctx context.Context, txs []*types.Tx) error {
for _, tx := range txs {
for _, m := range transactionHandlers {
@@ -289,109 +210,3 @@ func (w *Worker) processTxs(ctx context.Context, txs []*types.Tx) error {

return nil
}

func (w *Worker) processMessages(ctx context.Context, txs []*types.Tx) error {
for _, tx := range txs {
if !tx.Successful() { // skip message processing for failed transaction
continue
}

for i, msg := range tx.Body.Messages {
if err := w.processMessage(ctx, msg, tx, i); err != nil {
return err
}
}
}

return nil
}

func (w *Worker) processMessage(ctx context.Context, msg *codec.Any, tx *types.Tx, msgIndex int) error {
if msg == nil {
w.log.Warn().Int64(keyHeight, tx.Height).Str(keyTxHash, tx.TxHash).Msg("can't process nil message")

if err := w.storage.InsertErrorMessage(ctx, w.tsM.NewErrorMessage(tx.Height, "message is nil")); err != nil {
w.log.Error().
Err(err).
Int64(keyHeight, tx.Height).
Msgf("fail to insert error_message: %v", err)

return err
}

return nil
}

stdMsg, err := w.unpackMessage(ctx, tx.Height, msg)
if err != nil {
return err
}

// message is not supported. skip it
if stdMsg == nil || reflect.ValueOf(stdMsg).IsNil() {
return nil
}

for _, m := range messageHandlers {
if err = m.HandleMessage(ctx, msgIndex, stdMsg, tx); err != nil {
w.log.Error().
Err(err).
Int64(keyHeight, tx.Height).
Str(keyModule, m.Name()).
Msg("HandleMessage error")

return err
}
}

for _, m := range recursiveMessagesHandlers {
toProcess, err := m.HandleMessageRecursive(ctx, msgIndex, stdMsg, tx)
if err != nil {
w.log.Error().
Err(err).
Int64(keyHeight, tx.Height).
Str(keyModule, m.Name()).
Msg("HandleRecursiveMessage error")

return err
}

if len(toProcess) > 0 {
for _, toProcessMessage := range toProcess {
if err = w.processMessage(ctx, toProcessMessage, tx, msgIndex); err != nil {
w.log.Error().
Err(err).
Int64(keyHeight, tx.Height).
Str(keyModule, m.Name()).
Msg("HandleRecursiveMessage error")

return errors.Join(errRecurringHandling, err)
}
}
}
}

return nil
}

func (w *Worker) processBeginBlockerEvents(ctx context.Context, events types.BlockerEvents, height int64) error {
for _, m := range beginBlockerHandlers {
if err := m.HandleBeginBlocker(ctx, events, height); err != nil {
w.log.Error().Err(err).Str(keyModule, m.Name()).Msg("HandleBeginBlocker error")
return err
}
}

return nil
}

func (w *Worker) processEndBlockEvents(ctx context.Context, events types.BlockerEvents, height int64) error {
for _, m := range endBlockerHandlers {
if err := m.HandleEndBlocker(ctx, events, height); err != nil {
w.log.Error().Err(err).Str(keyModule, m.Name()).Msg("HandleEndBlocker error")
return err
}
}

return nil
}
13 changes: 8 additions & 5 deletions pkg/worker/queue.go
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ import (
"sync"
"time"

cometbftcoreypes "github.com/cometbft/cometbft/rpc/core/types"
cometbfttypes "github.com/cometbft/cometbft/types"
tmcoreypes "github.com/tendermint/tendermint/rpc/coretypes"
tmtypes "github.com/tendermint/tendermint/types"
)

func (w *Worker) enqueueHeight(ctx context.Context, wg *sync.WaitGroup, startHeight, stopHeight int64) {
@@ -33,7 +33,7 @@ func (w *Worker) enqueueHeight(ctx context.Context, wg *sync.WaitGroup, startHei
}
}

func (w *Worker) enqueueNewBlocks(ctx context.Context, eventCh <-chan cometbftcoreypes.ResultEvent) {
func (w *Worker) enqueueNewBlocks(ctx context.Context, eventCh <-chan tmcoreypes.ResultEvent) {
ctx, w.stopWsListener = context.WithCancel(ctx)
defer w.stopWsListener()
w.log.Info().Msg("listening for new block events")
@@ -44,9 +44,12 @@ func (w *Worker) enqueueNewBlocks(ctx context.Context, eventCh <-chan cometbftco
w.log.Info().Msg("stop new block listener")
return
case e := <-eventCh:
newBlock, ok := e.Data.(cometbfttypes.EventDataNewBlock)
newBlock, ok := e.Data.(tmtypes.LegacyEventDataNewBlock)
if !ok {
w.log.Warn().Msg("failed to cast ws event to EventDataNewBlock type")
w.log.Warn().
Type("type", e.Data).
Msg("failed to cast ws event to LegacyEventDataNewBlock type")

continue
}

28 changes: 0 additions & 28 deletions pkg/worker/utils.go
Original file line number Diff line number Diff line change
@@ -2,10 +2,7 @@ package worker

import (
"context"
"strings"

codec "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/pkg/errors"

"github.com/bro-n-bro/spacebox-crawler/v2/adapter/storage/model"
@@ -56,28 +53,3 @@ func (w *Worker) checkOrCreateBlockInStorage(ctx context.Context, height int64)
}
return nil
}

func (w *Worker) unpackMessage(ctx context.Context, height int64, msg *codec.Any) (stdMsg sdk.Msg, err error) {
if err = w.cdc.UnpackAny(msg, &stdMsg); err == nil {
return stdMsg, nil
}

if strings.HasPrefix(err.Error(), "no concrete type registered for type URL") {
w.log.Warn().Err(err).Int64(keyHeight, height).Msg("error while unpacking message")

if err = w.storage.InsertErrorMessage(ctx, w.tsM.NewErrorMessage(height, err.Error())); err != nil {
w.log.Error().
Err(err).
Int64(keyHeight, height).
Msg("fail to insert error_message")
return nil, err
}

// just skip unsupported message
return nil, nil
}

w.log.Error().Err(err).Msg("error while unpacking message")

return nil, err
}
13 changes: 0 additions & 13 deletions types/blocker_attribute.go

This file was deleted.

53 changes: 8 additions & 45 deletions types/cosmos.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package types

import (
"crypto/sha256"
"fmt"
"time"

cometbftcrypto "github.com/cometbft/cometbft/crypto"
cometbftcoretypes "github.com/cometbft/cometbft/rpc/core/types"
cometbfttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
"github.com/pkg/errors"
"golang.org/x/crypto/ripemd160" // nolint: staticcheck
tmcoretypes "github.com/tendermint/tendermint/rpc/coretypes"
tmtypes "github.com/tendermint/tendermint/types"
)

var (
@@ -35,13 +32,13 @@ type (
}

Block struct {
rb *cometbftcoretypes.ResultBlock
rb *tmcoretypes.ResultBlock

Timestamp time.Time
Hash string
ProposerAddress string
ValidatorPreCommits []ValidatorPreCommit
Evidence cometbfttypes.EvidenceData
Evidence tmtypes.EvidenceList
TxNum int
TotalGas uint64
Height int64
@@ -66,7 +63,7 @@ type (
)

func NewBlock(height int64, hash, proposerAddress string, txNum int, totalGas uint64, timestamp time.Time,
evidence cometbfttypes.EvidenceData) *Block {
evidence tmtypes.EvidenceList) *Block {

return &Block{
Height: height,
@@ -80,7 +77,7 @@ func NewBlock(height int64, hash, proposerAddress string, txNum int, totalGas ui
}

// NewBlockFromTmBlock builds a new Block instance from a given ResultBlock object
func NewBlockFromTmBlock(blk *cometbftcoretypes.ResultBlock, totalGas uint64) *Block {
func NewBlockFromTmBlock(blk *tmcoretypes.ResultBlock, totalGas uint64) *Block {
res := NewBlock(
blk.Block.Height,
blk.Block.Hash().String(),
@@ -100,7 +97,7 @@ func NewBlockFromTmBlock(blk *cometbftcoretypes.ResultBlock, totalGas uint64) *B
return res
}

func NewValidatorPreCommitsFromTmSignatures(sigs []cometbfttypes.CommitSig) []ValidatorPreCommit {
func NewValidatorPreCommitsFromTmSignatures(sigs []tmtypes.CommitSig) []ValidatorPreCommit {
res := make([]ValidatorPreCommit, 0, len(sigs))
for _, sig := range sigs {
if len(sig.Signature) == 0 {
@@ -140,45 +137,11 @@ func NewTxsFromTmTxs(txs []*sdktx.GetTxResponse, cdc codec.Codec) Txs {
return res
}

func NewValidatorsFromTmValidator(tmVals *cometbftcoretypes.ResultValidators) Validators {
res := make(Validators, 0, len(tmVals.Validators))
for _, val := range tmVals.Validators {
consAddr := sdk.ConsAddress(val.Address).String()
if consPubKey, err := ConvertValidatorPubKeyToBech32String(val.PubKey); err == nil {
// we need only valid validators
res = append(res, NewValidator(consAddr, consPubKey))
}
}

return res
}

// NewValidator allows to build a new Validator instance
func NewValidator(consAddr string, consPubKey string) *Validator {
return &Validator{
ConsAddr: consAddr,
ConsPubkey: consPubKey,
}
}

func ConvertAddressToBech32String(address cryptotypes.Address) (string, error) {
bech32Prefix := sdk.GetConfig().GetBech32AccountAddrPrefix()
return bech32.ConvertAndEncode(bech32Prefix, address)
}

// ConvertValidatorPubKeyToBech32String converts the given pubKey to Bech32 string
func ConvertValidatorPubKeyToBech32String(pubKey cometbftcrypto.PubKey) (string, error) {
bech32Prefix := sdk.GetConfig().GetBech32ConsensusPubPrefix()
return bech32.ConvertAndEncode(bech32Prefix, pubKey.Bytes())
}

func BytesToAddress(key []byte) cryptotypes.Address {
sha := sha256.Sum256(key)
hasherRIPEMD160 := ripemd160.New()
hasherRIPEMD160.Write(sha[:])
return hasherRIPEMD160.Sum(nil)
}

// TotalGas calculates and returns total used gas of all transactions
func (txs Txs) TotalGas() (totalGas uint64) {
for _, tx := range txs {
@@ -219,4 +182,4 @@ func (tx Tx) Successful() bool {
return tx.TxResponse.Code == 0
}

func (b Block) Raw() *cometbftcoretypes.ResultBlock { return b.rb }
func (b Block) Raw() *tmcoretypes.ResultBlock { return b.rb }
49 changes: 0 additions & 49 deletions types/liquidity/codec.go

This file was deleted.

21 changes: 0 additions & 21 deletions types/liquidity/errors.go

This file was deleted.

29 changes: 0 additions & 29 deletions types/liquidity/events.go

This file was deleted.

9 changes: 0 additions & 9 deletions types/liquidity/keys.go

This file was deleted.

3,411 changes: 0 additions & 3,411 deletions types/liquidity/liquidity.pb.go

This file was deleted.

199 changes: 0 additions & 199 deletions types/liquidity/msgs.go

This file was deleted.

24 changes: 0 additions & 24 deletions types/liquidity/params.go

This file was deleted.

4,910 changes: 0 additions & 4,910 deletions types/liquidity/query.pb.go

This file was deleted.

2,048 changes: 0 additions & 2,048 deletions types/liquidity/tx.pb.go

This file was deleted.

36 changes: 2 additions & 34 deletions types/module.go
Original file line number Diff line number Diff line change
@@ -4,10 +4,7 @@ import (
"context"
"encoding/json"

cometbftcoretypes "github.com/cometbft/cometbft/rpc/core/types"
cometbfttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
tmtypes "github.com/tendermint/tendermint/types"
)

type (
@@ -28,38 +25,9 @@ type (
HandleTx(ctx context.Context, tx *Tx) error
}

MessageHandler interface {
Module
// HandleMessage handles a single message of transaction.
HandleMessage(ctx context.Context, index int, msg sdk.Msg, tx *Tx) error
}

RecursiveMessagesHandler interface {
Module
HandleMessageRecursive(ctx context.Context, index int, msg sdk.Msg, tx *Tx) ([]*types.Any, error)
}

ValidatorsHandler interface {
Module
// HandleValidators handles of all validators in blockchain.
HandleValidators(ctx context.Context, vals *cometbftcoretypes.ResultValidators) error
}

GenesisHandler interface {
Module
// HandleGenesis handles a genesis state.
HandleGenesis(ctx context.Context, doc *cometbfttypes.GenesisDoc, appState map[string]json.RawMessage) error
}

BeginBlockerHandler interface {
Module
// HandleBeginBlocker handles of beginblocker events.
HandleBeginBlocker(ctx context.Context, eventsMap BlockerEvents, height int64) error
}

EndBlockerHandler interface {
Module
// HandleEndBlocker handles of endblocker events.
HandleEndBlocker(ctx context.Context, eventsMap BlockerEvents, height int64) error
HandleGenesis(ctx context.Context, doc *tmtypes.GenesisDoc, appState map[string]json.RawMessage) error
}
)

0 comments on commit 0a96bfa

Please sign in to comment.