Skip to content

Commit

Permalink
Update dependencies and refactor event handling
Browse files Browse the repository at this point in the history
Updated `cometbft` version in go.mod to `v0.38.10-inj-1`  Refactored `fetcher.go` to handle final block events
  • Loading branch information
billettc committed Aug 14, 2024
1 parent 3509f83 commit f97629c
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 223 deletions.
1 change: 1 addition & 0 deletions cosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22
toolchain go1.22.0

require google.golang.org/protobuf v1.33.0

require github.com/google/go-cmp v0.6.0 // indirect

replace github.com/jhump/protoreflect => github.com/streamingfast/protoreflect v0.0.0-20231205191344-4b629d20ce8d
74 changes: 0 additions & 74 deletions injective/conversion.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package injective

import (
"encoding/hex"
"fmt"
"reflect"
"strings"
"unicode/utf8"

abci "github.com/cometbft/cometbft/abci/types"
cometType "github.com/cometbft/cometbft/types"
cosmoProto "github.com/cosmos/gogoproto/proto"
pbcosmos "github.com/streamingfast/firehose-cosmos/cosmos/pb/sf/cosmos/type/v2"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -56,76 +50,8 @@ func protoFlip(origin cosmoProto.Message, target proto.Message) error {

err = UnmarshallerDiscardUnknown.Unmarshal(data, target)
if err != nil {
if e, ok := origin.(*abci.ResponseDeliverTx); ok {
fmt.Println("event data:", hex.EncodeToString(data))
fmt.Println("log:", e.Log)
fmt.Println("info:", e.Info)
}
return fmt.Errorf("unmashalling target object %T: %w", data, err)
}

return nil
}

func convertResponseDeliverTx(tx *abci.ResponseDeliverTx) (*pbcosmos.TxResults, error) {
events := make([]*pbcosmos.Event, len(tx.Events))
for i, _ := range events {
events[i] = &pbcosmos.Event{}
}
err := arrayProtoFlip(arrayToPointerArray(tx.Events), events)
if err != nil {
return nil, fmt.Errorf("converting events: %w", err)
}

fixedLog := strings.Map(fixUtf, tx.Log)

txResults := &pbcosmos.TxResults{
Code: tx.Code,
Data: tx.Data,
Log: fixedLog,
Info: tx.Info,
GasWanted: tx.GasWanted,
GasUsed: tx.GasUsed,
Events: events,
Codespace: tx.Codespace,
}

return txResults, nil
}

func convertDeliverTxs(txs []*abci.ResponseDeliverTx) ([]*pbcosmos.TxResults, error) {
txResults := make([]*pbcosmos.TxResults, len(txs))
for i, tx := range txs {
txResults[i], _ = convertResponseDeliverTx(tx)
}
return txResults, nil
}

func MisbehaviorsFromEvidences(evidences cometType.EvidenceList) ([]*pbcosmos.Misbehavior, error) {
var misbehaviors []*pbcosmos.Misbehavior
for _, e := range evidences {

abciMisbehavior := e.ABCI()

partials := make([]*pbcosmos.Misbehavior, len(abciMisbehavior))
for i, _ := range partials {
partials[i] = &pbcosmos.Misbehavior{}
}

err := arrayProtoFlip(arrayToPointerArray(abciMisbehavior), partials)
if err != nil {
return nil, fmt.Errorf("converting abci misbehavior: %w", err)
}

misbehaviors = append(misbehaviors, partials...)
}
return misbehaviors, nil
}

func fixUtf(r rune) rune {
if r == utf8.RuneError {
fmt.Println("found rune error")
return '�'
}
return r
}
4 changes: 2 additions & 2 deletions injective/devel/poller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ firecore start reader-node merger \
--common-auto-mem-limit-percent=90 \
--common-one-block-store-url=data/oneblock \
--common-merged-blocks-store-url=data/merged \
--common-first-streamable-block=1561500 \
--common-first-streamable-block=82019824 \
--reader-node-data-dir=data/oneblock \
--reader-node-working-dir=data/work \
--reader-node-readiness-max-latency=600s \
Expand All @@ -16,4 +16,4 @@ firecore start reader-node merger \
--reader-node-grpc-listen-addr=:9001 \
--reader-node-manager-api-addr=:8080 \
--reader-node-path=fireinjective \
--reader-node-arguments='injective fetch rpc 1561500 --state-dir data --block-fetch-batch-size=1 --endpoints $INJECTIVE_ENDPOINT'
--reader-node-arguments="injective fetch rpc 82019824 --state-dir data --block-fetch-batch-size=1 --endpoints $INJECTIVE_ENDPOINT"
68 changes: 66 additions & 2 deletions injective/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"encoding/hex"
"fmt"
"math"
"strings"
"time"
"unicode/utf8"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/proto/tendermint/types"
Expand Down Expand Up @@ -182,8 +184,7 @@ func convertBlockFromResponse(rpcBlock *ctypes.ResultBlock, rpcBlockResults *cty
return nil, fmt.Errorf("converting consensus param updates: %w", err)
}

finalEvents := rpcBlockResults.BeginBlockEvents
finalEvents = append(finalEvents, rpcBlockResults.EndBlockEvents...)
finalEvents := rpcBlockResults.FinalizeBlockEvents
events, err := convertEventsFromResponse(finalEvents)
if err != nil {
return nil, fmt.Errorf("converting events: %w", err)
Expand Down Expand Up @@ -269,3 +270,66 @@ func convertConsensusParamUpdatesFromResponse(consensusParamUpdates *types.Conse
}
return out, nil
}

func convertResponseDeliverTx(tx *abci.ExecTxResult) (*pbcosmos.TxResults, error) {
events := make([]*pbcosmos.Event, len(tx.Events))
for i, _ := range events {
events[i] = &pbcosmos.Event{}
}
err := arrayProtoFlip(arrayToPointerArray(tx.Events), events)
if err != nil {
return nil, fmt.Errorf("converting events: %w", err)
}

fixedLog := strings.Map(fixUtf, tx.Log)

txResults := &pbcosmos.TxResults{
Code: tx.Code,
Data: tx.Data,
Log: fixedLog,
Info: tx.Info,
GasWanted: tx.GasWanted,
GasUsed: tx.GasUsed,
Events: events,
Codespace: tx.Codespace,
}

return txResults, nil
}

func convertDeliverTxs(txs []*abci.ExecTxResult) ([]*pbcosmos.TxResults, error) {
txResults := make([]*pbcosmos.TxResults, len(txs))
for i, tx := range txs {
txResults[i], _ = convertResponseDeliverTx(tx)
}
return txResults, nil
}

func MisbehaviorsFromEvidences(evidences cometType.EvidenceList) ([]*pbcosmos.Misbehavior, error) {
var misbehaviors []*pbcosmos.Misbehavior
for _, e := range evidences {

abciMisbehavior := e.ABCI()

partials := make([]*pbcosmos.Misbehavior, len(abciMisbehavior))
for i, _ := range partials {
partials[i] = &pbcosmos.Misbehavior{}
}

err := arrayProtoFlip(arrayToPointerArray(abciMisbehavior), partials)
if err != nil {
return nil, fmt.Errorf("converting abci misbehavior: %w", err)
}

misbehaviors = append(misbehaviors, partials...)
}
return misbehaviors, nil
}

func fixUtf(r rune) rune {
if r == utf8.RuneError {
fmt.Println("found rune error")
return '�'
}
return r
}
18 changes: 4 additions & 14 deletions injective/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.2

replace (
github.com/bufbuild/protocompile => github.com/bufbuild/protocompile v0.4.0
github.com/cometbft/cometbft => github.com/InjectiveLabs/cometbft v0.37.2-inj
github.com/cometbft/cometbft => github.com/InjectiveLabs/cometbft v0.38.10-inj-1
github.com/streamingfast/firehose-cosmos/cosmos => ../cosmos
)

Expand Down Expand Up @@ -66,28 +66,23 @@ require (
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // 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/dgraph-io/badger/v4 v4.2.0 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/envoyproxy/go-control-plane v0.12.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/go-json-experiment/json v0.0.0-20231013223334-54c864be5b8d // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
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/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.0 // indirect
Expand All @@ -106,8 +101,8 @@ require (
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/v2 v2.19.0 // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/boxo v0.8.0 // indirect
Expand All @@ -116,8 +111,6 @@ require (
github.com/jhump/protoreflect v1.14.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/josephburnett/jd v1.7.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/kr/pretty v0.3.1 // indirect
Expand All @@ -129,15 +122,12 @@ require (
github.com/lithammer/dedent v1.1.0 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-ieproxy v0.0.1 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/minio/sha256-simd v1.0.0 // 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/mostynb/go-grpc-compression v1.1.17 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
Expand All @@ -148,6 +138,7 @@ require (
github.com/multiformats/go-multihash v0.2.1 // indirect
github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/openzipkin/zipkin-go v0.4.2 // indirect
github.com/paulbellamy/ratecounter v0.2.0 // indirect
Expand Down Expand Up @@ -183,7 +174,6 @@ require (
github.com/streamingfast/dmetering v0.0.0-20240409120340-b517f0225538 // indirect
github.com/streamingfast/dmetrics v0.0.0-20230919161904-206fa8ebd545 // indirect
github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839 // indirect
github.com/streamingfast/jsonpb v0.0.0-20210811021341-3670f0aa02d0 // indirect
github.com/streamingfast/opaque v0.0.0-20210811180740-0c01d37ea308 // indirect
github.com/streamingfast/pbgo v0.0.6-0.20240131193313-6b88bc7139db // indirect
github.com/streamingfast/sf-tracing v0.0.0-20240209202324-9daa52c71a52 // indirect
Expand Down Expand Up @@ -215,7 +205,7 @@ require (
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
Expand Down
Loading

0 comments on commit f97629c

Please sign in to comment.