Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Nov 5, 2024
1 parent 055d715 commit b6ddbc1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 46 deletions.
23 changes: 1 addition & 22 deletions evmrpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,30 +148,9 @@ func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.Block
return nil, err
}

if block == nil {
return nil, errors.New("could not retrieve block requested")
}

// Get all tx hashes for the block
height := block.Block.Header.Height
txHashes := []common.Hash{}
for i, tx := range block.Block.Data.Txs {
sdkTx, err := a.txConfig.TxDecoder()(tx)
if err != nil {
fmt.Printf("error decoding tx %d in block %d, skipping\n", i, height)
continue
}
if len(sdkTx.GetMsgs()) == 0 {
continue
}
if evmTx, ok := sdkTx.GetMsgs()[0].(*types.MsgEVMTransaction); ok {
if evmTx.IsAssociateTx() {
continue
}
ethtx, _ := evmTx.AsTransaction()
txHashes = append(txHashes, ethtx.Hash())
}
}
txHashes := getEvmTxHashesFromBlock(block, a.txConfig)
// Get tx receipts for all hashes in parallel
wg := sync.WaitGroup{}
mtx := sync.Mutex{}
Expand Down
25 changes: 1 addition & 24 deletions evmrpc/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
ethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/x/evm/keeper"
"github.com/sei-protocol/sei-chain/x/evm/types"
rpcclient "github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/coretypes"
tmtypes "github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -367,29 +366,7 @@ func (f *LogFetcher) FindLogsByBloom(height int64, filters [][]bloomIndexes) (re
return
}

if block == nil {
fmt.Printf("no block found when querying logs for height %d\n", height)
return
}
txHashes := []common.Hash{}
for i, tx := range block.Block.Data.Txs {
sdkTx, err := f.txConfig.TxDecoder()(tx)
if err != nil {
fmt.Printf("error decoding tx %d in block %d, skipping\n", i, height)
continue
}
if len(sdkTx.GetMsgs()) == 0 {
continue
}
if evmTx, ok := sdkTx.GetMsgs()[0].(*types.MsgEVMTransaction); ok {
if evmTx.IsAssociateTx() {
continue
}
ethtx, _ := evmTx.AsTransaction()
txHashes = append(txHashes, ethtx.Hash())
}
}
for _, hash := range txHashes {
for _, hash := range getEvmTxHashesFromBlock(block, f.txConfig) {
receipt, err := f.k.GetReceipt(ctx, hash)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("FindLogsByBloom: unable to find receipt for hash %s", hash.Hex()))
Expand Down
24 changes: 24 additions & 0 deletions evmrpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rpc"
"github.com/sei-protocol/sei-chain/utils/metrics"
"github.com/sei-protocol/sei-chain/x/evm/keeper"
"github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/tendermint/tendermint/libs/bytes"
rpcclient "github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/coretypes"
Expand Down Expand Up @@ -203,3 +205,25 @@ func shouldIncludeSynthetic(namespace string) bool {
}
return namespace == "sei"
}

func getEvmTxHashesFromBlock(block *coretypes.ResultBlock, txConfig client.TxConfig) []common.Hash {
txHashes := []common.Hash{}
for i, tx := range block.Block.Data.Txs {
sdkTx, err := txConfig.TxDecoder()(tx)
if err != nil {
fmt.Printf("error decoding tx %d in block %d, skipping\n", i, block.Block.Height)
continue
}
if len(sdkTx.GetMsgs()) == 0 {
continue
}
if evmTx, ok := sdkTx.GetMsgs()[0].(*types.MsgEVMTransaction); ok {
if evmTx.IsAssociateTx() {
continue
}
ethtx, _ := evmTx.AsTransaction()
txHashes = append(txHashes, ethtx.Hash())
}
}
return txHashes
}

0 comments on commit b6ddbc1

Please sign in to comment.