Skip to content

Commit

Permalink
Merge pull request #517 from DefiantLabs/patch/rpc-block-results-erro…
Browse files Browse the repository at this point in the history
…rs-and-osmosis-v21

Patch/rpc block results errors and osmosis v21
  • Loading branch information
pharr117 authored Jan 1, 2024
2 parents 51588a8 + 64cca4c commit f6a3b55
Show file tree
Hide file tree
Showing 30 changed files with 1,533 additions and 559 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: golangci-lint
on:
push:
branches:
- master
- main
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.55.2

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ run:
linters:
disable-all: true
enable:
- depguard
- dogsled
- exportloopref
- errcheck
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ repos:
# args: [-over=15]
- id: validate-toml
- id: no-go-testing
- id: golangci-lint
args: [--timeout,10m]
# - id: golangci-lint
# args: [--timeout,10m]
# - id: go-critic
# - id: go-unit-tests
- id: go-build
Expand Down
15 changes: 2 additions & 13 deletions cmd/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"log"
"net/http"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -444,15 +443,10 @@ func (idxr *Indexer) indexBlockEvents(wg *sync.WaitGroup, failedBlockHandler cor

config.Log.Infof("Indexing block events from block: %v to %v", startHeight, endHeight)

rpcClient := rpc.URIClient{
Address: idxr.cl.Config.RPCAddr,
Client: &http.Client{},
}

currentHeight := startHeight

for endHeight == -1 || currentHeight <= endHeight {
bresults, err := rpc.GetBlockResultWithRetry(rpcClient, currentHeight, idxr.cfg.Base.RequestRetryAttempts, idxr.cfg.Base.RequestRetryMaxWait)
bresults, err := rpc.GetBlockResultWithRetry(idxr.cl, currentHeight, idxr.cfg.Base.RequestRetryAttempts, idxr.cfg.Base.RequestRetryMaxWait)
if err != nil {
config.Log.Error(fmt.Sprintf("Error receiving block result for block %d", currentHeight), err)
failedBlockHandler(currentHeight, core.FailedBlockEventHandling, err)
Expand Down Expand Up @@ -565,15 +559,10 @@ func (idxr *Indexer) indexEpochEvents(wg *sync.WaitGroup, failedBlockHandler cor

config.Log.Infof("Indexing epoch events from epoch: %v to %v", epochsBetween[0].EpochNumber, epochsBetween[len(epochsBetween)-1].EpochNumber)

rpcClient := rpc.URIClient{
Address: idxr.cl.Config.RPCAddr,
Client: &http.Client{},
}

for _, epoch := range epochsBetween {
config.Log.Infof("Indexing epoch events for epoch %v at height %d", epoch.EpochNumber, epoch.StartHeight)

bresults, err := rpc.GetBlockResultWithRetry(rpcClient, int64(epoch.StartHeight), idxr.cfg.Base.RequestRetryAttempts, idxr.cfg.Base.RequestRetryMaxWait)
bresults, err := rpc.GetBlockResultWithRetry(idxr.cl, int64(epoch.StartHeight), idxr.cfg.Base.RequestRetryAttempts, idxr.cfg.Base.RequestRetryMaxWait)
if err != nil {
config.Log.Error(fmt.Sprintf("Error receiving block result for block %d", epoch.StartHeight), err)
failedBlockHandler(int64(epoch.StartHeight), core.FailedBlockEventHandling, err)
Expand Down
2 changes: 1 addition & 1 deletion config/lens_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config

import (
lensClient "github.com/DefiantLabs/lens/client"
ibcTypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
ibcTypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
)

func GetLensClient(conf lens) *lensClient.ChainClient {
Expand Down
2 changes: 1 addition & 1 deletion core/block_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/DefiantLabs/cosmos-tax-cli/config"
eventTypes "github.com/DefiantLabs/cosmos-tax-cli/cosmos/events"
"github.com/DefiantLabs/cosmos-tax-cli/cosmoshub"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions core/epoch_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
eventTypes "github.com/DefiantLabs/cosmos-tax-cli/cosmos/events"
osmosisTypes "github.com/DefiantLabs/cosmos-tax-cli/osmosis"
osmosisEpochTypes "github.com/DefiantLabs/cosmos-tax-cli/osmosis/epochs"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
)

var epochIdentifierEventTypeHandlers = map[string]map[string]map[string][]func() eventTypes.CosmosEvent{}
Expand All @@ -19,7 +19,7 @@ func ChainSpecificEpochIdentifierEventTypeHandlersBootstrap(chainID string) {
}
}

func ProcessRPCEpochEvents(blockResults *ctypes.ResultBlockResults, epochIdentifier string) ([]eventTypes.EventRelevantInformation, error) {
func ProcessRPCEpochEvents(blockResults *coretypes.ResultBlockResults, epochIdentifier string) ([]eventTypes.EventRelevantInformation, error) {
var taxableEvents []eventTypes.EventRelevantInformation

if handlers, ok := epochIdentifierEventTypeHandlers[epochIdentifier]; ok {
Expand Down
6 changes: 3 additions & 3 deletions core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import (
"github.com/DefiantLabs/cosmos-tax-cli/tendermint/modules/liquidity"
"github.com/DefiantLabs/cosmos-tax-cli/util"
"github.com/DefiantLabs/lens/client"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
cryptoTypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types"
cosmosTx "github.com/cosmos/cosmos-sdk/types/tx"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -398,7 +398,7 @@ func AnalyzeSwaps() {
if swap.TokenOut.Denom == "uosmo" && swap.TokenIn.Denom == "uosmo" {
amount := swap.TokenOut.Amount.Sub(swap.TokenIn.Amount)
if amount.GT(types.ZeroInt()) {
txProfit := amount.ToDec().Quo(types.NewDec(1000000)).MustFloat64()
txProfit := amount.ToLegacyDec().Quo(types.NewDec(1000000)).MustFloat64()
profit += txProfit
}

Expand All @@ -418,7 +418,7 @@ func ProcessTx(db *gorm.DB, tx txtypes.MergedTx) (txDBWapper dbTypes.TxDBWrapper
txTime, err = time.Parse(time.RFC3339, tx.TxResponse.TimeStamp)
if err != nil {
config.Log.Error("Error parsing tx timestamp.", err)
return
return txDBWapper, txTime, err
}

code := tx.TxResponse.Code
Expand Down
2 changes: 1 addition & 1 deletion cosmos/events/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package events

import (
"github.com/tendermint/tendermint/abci/types"
"github.com/cometbft/cometbft/abci/types"
)

type CosmosEvent interface {
Expand Down
5 changes: 3 additions & 2 deletions cosmos/modules/bank/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
txModule "github.com/DefiantLabs/cosmos-tax-cli/cosmos/modules/tx"
"github.com/DefiantLabs/cosmos-tax-cli/util"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
Expand Down Expand Up @@ -58,7 +59,7 @@ func (sf *WrapperMsgMultiSend) HandleMsg(msgType string, msg sdk.Msg, log *txMod

// Make sure the that the total amount sent matches the total amount received for each coin
// sum up input coins
sentMap := make(map[string]sdk.Int)
sentMap := make(map[string]math.Int)
for _, input := range sf.CosmosMsgMultiSend.Inputs {
for _, coin := range input.Coins {
if currentTotal, ok := sentMap[coin.Denom]; ok {
Expand All @@ -70,7 +71,7 @@ func (sf *WrapperMsgMultiSend) HandleMsg(msgType string, msg sdk.Msg, log *txMod
}

// sum up output coins
recievedMap := make(map[string]sdk.Int)
recievedMap := make(map[string]math.Int)
for _, output := range sf.CosmosMsgMultiSend.Outputs {
for _, coin := range output.Coins {
if currentTotal, ok := recievedMap[coin.Denom]; ok {
Expand Down
2 changes: 1 addition & 1 deletion cosmos/modules/denoms/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package denoms

import transfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
import transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"

type Pagination struct {
NextKey string `json:"next_key"`
Expand Down
2 changes: 1 addition & 1 deletion cosmos/modules/gov/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/DefiantLabs/cosmos-tax-cli/util"
stdTypes "github.com/cosmos/cosmos-sdk/types"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

const (
Expand Down
9 changes: 5 additions & 4 deletions cosmos/modules/ibc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"fmt"
"strings"

"cosmossdk.io/math"
parsingTypes "github.com/DefiantLabs/cosmos-tax-cli/cosmos/modules"
txModule "github.com/DefiantLabs/cosmos-tax-cli/cosmos/modules/tx"
"github.com/DefiantLabs/cosmos-tax-cli/util"
stdTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
chantypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
chantypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
)

const (
Expand Down Expand Up @@ -56,7 +57,7 @@ type WrapperMsgRecvPacket struct {
Sequence uint64
SenderAddress string
ReceiverAddress string
Amount stdTypes.Int
Amount math.Int
Denom string
}

Expand Down Expand Up @@ -134,7 +135,7 @@ type WrapperMsgAcknowledgement struct {
Sequence uint64
SenderAddress string
ReceiverAddress string
Amount stdTypes.Int
Amount math.Int
Denom string
AckType int
AckResult int
Expand Down
18 changes: 12 additions & 6 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ func IndexNewBlock(db *gorm.DB, blockHeight int64, blockTime time.Time, txs []Tx
return err
}

for _, transaction := range txs {
for _, tx := range txs {
transaction := tx
txOnly := Tx{
Hash: transaction.Tx.Hash,
Code: transaction.Tx.Code,
Expand All @@ -194,7 +195,8 @@ func IndexNewBlock(db *gorm.DB, blockHeight int64, blockTime time.Time, txs []Tx
return err
}

for _, fee := range transaction.Tx.Fees {
for _, feeL := range transaction.Tx.Fees {
fee := feeL
feeOnly := Fee{
TxID: txOnly.ID,
Amount: fee.Amount,
Expand Down Expand Up @@ -225,7 +227,8 @@ func IndexNewBlock(db *gorm.DB, blockHeight int64, blockTime time.Time, txs []Tx
}
}

for _, message := range transaction.Messages {
for _, msg := range transaction.Messages {
message := msg
if message.Message.MessageType.MessageType == "" {
config.Log.Fatal("Message type not getting to DB")
}
Expand All @@ -246,7 +249,8 @@ func IndexNewBlock(db *gorm.DB, blockHeight int64, blockTime time.Time, txs []Tx
return err
}

for _, taxableTx := range message.TaxableTxs {
for _, taxableTxL := range message.TaxableTxs {
taxableTx := taxableTxL
if len(taxableTx.SenderAddress.Address) > maxAddrLen || len(taxableTx.ReceiverAddress.Address) > maxAddrLen {
continue
}
Expand Down Expand Up @@ -316,15 +320,17 @@ func IndexNewBlock(db *gorm.DB, blockHeight int64, blockTime time.Time, txs []Tx

func UpsertDenoms(db *gorm.DB, denoms []DenomDBWrapper) error {
return db.Transaction(func(dbTransaction *gorm.DB) error {
for _, denom := range denoms {
for _, denomL := range denoms {
denom := denomL
if err := dbTransaction.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "base"}},
DoUpdates: clause.AssignmentColumns([]string{"symbol", "name"}),
}).Create(&denom.Denom).Error; err != nil {
return err
}

for _, denomUnit := range denom.DenomUnits {
for _, denomUnitL := range denom.DenomUnits {
denomUnit := denomUnitL
denomUnit.DenomUnit.Denom = denom.Denom

if err := dbTransaction.Clauses(clause.OnConflict{
Expand Down
3 changes: 2 additions & 1 deletion db/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ func createTaxableEvents(db *gorm.DB, events []TaxableEvent) error {
var chainPrev Chain
var blockPrev Block

for _, event := range events {
for _, eventL := range events {
event := eventL
if chainPrev.ChainID != event.Block.Chain.ChainID || event.Block.Chain.Name != chainPrev.Name {
if chainErr := dbTransaction.Where("chain_id = ?", event.Block.Chain.ChainID).FirstOrCreate(&event.Block.Chain).Error; chainErr != nil {
fmt.Printf("Error %s creating chain DB object.\n", chainErr)
Expand Down
Loading

0 comments on commit f6a3b55

Please sign in to comment.