Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Fix] getLogs endpoint should check whether or not to include cosmos Txs based on namespace #1988

Merged
merged 9 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contracts/test/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,14 @@ async function instantiateWasm(codeId, adminAddr, label, args = {}, from=adminKe
return getEventAttribute(response, "instantiate", "_contract_address");
}

async function proposeCW20toERC20Upgrade(erc20Address, cw20Address, title="erc20-pointer", version=99, description="erc20 pointer",fees="20000usei", from=adminKeyName) {
async function proposeCW20toERC20Upgrade(erc20Address, cw20Address, title="erc20-pointer", version=99, description="erc20 pointer",fees="200000usei", from=adminKeyName) {
const command = `seid tx evm add-cw-erc20-pointer "${title}" "${description}" ${erc20Address} ${version} 200000000usei ${cw20Address} --from ${from} --fees ${fees} -y -o json --broadcast-mode=block`
const output = await execute(command);
const proposalId = getEventAttribute(JSON.parse(output), "submit_proposal", "proposal_id")
return await passProposal(proposalId)
}

async function passProposal(proposalId, desposit="200000000usei", fees="20000usei", from=adminKeyName) {
async function passProposal(proposalId, desposit="200000000usei", fees="200000usei", from=adminKeyName) {
if(await isDocker()) {
await executeOnAllNodes(`seid tx gov vote ${proposalId} yes --from node_admin -b block -y --fees ${fees}`)
} else {
Expand Down Expand Up @@ -379,7 +379,7 @@ async function registerPointerForERC721(erc721Address, fees="20000usei", from=ad
return getEventAttribute(response, "pointer_registered", "pointer_address")
}

async function registerPointerForERC1155(erc1155Address, fees="20000usei", from=adminKeyName) {
async function registerPointerForERC1155(erc1155Address, fees="200000usei", from=adminKeyName) {
const command = `seid tx evm register-cw-pointer ERC1155 ${erc1155Address} --from ${from} --fees ${fees} --broadcast-mode block -y -o json`
const output = await execute(command);
const response = JSON.parse(output)
Expand Down
12 changes: 10 additions & 2 deletions evmrpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ type BlockAPI struct {
}

func NewBlockAPI(tmClient rpcclient.Client, k *keeper.Keeper, ctxProvider func(int64) sdk.Context, txConfig client.TxConfig, connectionType ConnectionType, namespace string) *BlockAPI {
return &BlockAPI{tmClient: tmClient, keeper: k, ctxProvider: ctxProvider, txConfig: txConfig, connectionType: connectionType, includeShellReceipts: shouldIncludeSynthetic(namespace)}
return &BlockAPI{
tmClient: tmClient,
keeper: k,
ctxProvider: ctxProvider,
txConfig: txConfig,
connectionType: connectionType,
namespace: namespace,
includeShellReceipts: shouldIncludeSynthetic(namespace),
}
}

func (a *BlockAPI) GetBlockTransactionCountByNumber(ctx context.Context, number rpc.BlockNumber) (result *hexutil.Uint, returnErr error) {
Expand Down Expand Up @@ -150,7 +158,7 @@ func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.Block

// Get all tx hashes for the block
height := block.Block.Header.Height
txHashes := getEvmTxHashesFromBlock(block, a.txConfig)
txHashes := getTxHashesFromBlock(block, a.txConfig, shouldIncludeSynthetic(a.namespace))
// Get tx receipts for all hashes in parallel
wg := sync.WaitGroup{}
mtx := sync.Mutex{}
Expand Down
32 changes: 16 additions & 16 deletions evmrpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ func TestGetBlockReceipts(t *testing.T) {
// Query by block height
resObj := sendRequestGood(t, "getBlockReceipts", "0x2")
result := resObj["result"].([]interface{})
require.Equal(t, 5, len(result))
require.Equal(t, 3, len(result))
receipt1 := result[0].(map[string]interface{})
require.Equal(t, "0x2", receipt1["blockNumber"])
require.Equal(t, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", receipt1["transactionHash"])
require.Equal(t, multiTxBlockTx1.Hash().Hex(), receipt1["transactionHash"])
receipt2 := result[1].(map[string]interface{})
require.Equal(t, "0x2", receipt2["blockNumber"])
require.Equal(t, multiTxBlockTx1.Hash().Hex(), receipt2["transactionHash"])
require.Equal(t, multiTxBlockTx2.Hash().Hex(), receipt2["transactionHash"])
receipt3 := result[2].(map[string]interface{})
require.Equal(t, "0x2", receipt3["blockNumber"])
require.Equal(t, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", receipt3["transactionHash"])
require.Equal(t, multiTxBlockTx3.Hash().Hex(), receipt3["transactionHash"])

resObjSei := sendSeiRequestGood(t, "getBlockReceipts", "0x2")
result = resObjSei["result"].([]interface{})
Expand All @@ -98,21 +98,21 @@ func TestGetBlockReceipts(t *testing.T) {
// Query by block hash
resObj2 := sendRequestGood(t, "getBlockReceipts", "0x0000000000000000000000000000000000000000000000000000000000000002")
result = resObj2["result"].([]interface{})
require.Equal(t, 5, len(result))
require.Equal(t, 3, len(result))
receipt1 = result[0].(map[string]interface{})
require.Equal(t, "0x2", receipt1["blockNumber"])
require.Equal(t, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", receipt1["transactionHash"])
require.Equal(t, multiTxBlockTx1.Hash().Hex(), receipt1["transactionHash"])
receipt2 = result[1].(map[string]interface{})
require.Equal(t, "0x2", receipt2["blockNumber"])
require.Equal(t, multiTxBlockTx1.Hash().Hex(), receipt2["transactionHash"])
require.Equal(t, multiTxBlockTx2.Hash().Hex(), receipt2["transactionHash"])
receipt3 = result[2].(map[string]interface{})
require.Equal(t, "0x2", receipt3["blockNumber"])
require.Equal(t, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", receipt3["transactionHash"])
require.Equal(t, multiTxBlockTx3.Hash().Hex(), receipt3["transactionHash"])

// Query by tag latest => retrieves block 8
resObj3 := sendRequestGood(t, "getBlockReceipts", "latest")
result = resObj3["result"].([]interface{})
require.Equal(t, 2, len(result))
require.Equal(t, 1, len(result))
receipt1 = result[0].(map[string]interface{})
require.Equal(t, "0x8", receipt1["blockNumber"])
require.Equal(t, tx1.Hash().Hex(), receipt1["transactionHash"])
Expand Down Expand Up @@ -192,10 +192,10 @@ func TestEncodeTmBlock_EmptyTransactions(t *testing.T) {
block := &coretypes.ResultBlock{
BlockID: MockBlockID,
Block: &tmtypes.Block{
Header: mockBlockHeader(MockHeight),
Header: mockBlockHeader(MockHeight8),
Data: tmtypes.Data{},
LastCommit: &tmtypes.Commit{
Height: MockHeight - 1,
Height: MockHeight8 - 1,
},
},
}
Expand Down Expand Up @@ -228,15 +228,15 @@ func TestEncodeBankMsg(t *testing.T) {
resBlock := coretypes.ResultBlock{
BlockID: MockBlockID,
Block: &tmtypes.Block{
Header: mockBlockHeader(MockHeight),
Header: mockBlockHeader(MockHeight8),
Data: tmtypes.Data{
Txs: []tmtypes.Tx{func() []byte {
bz, _ := Encoder(tx)
return bz
}()},
},
LastCommit: &tmtypes.Commit{
Height: MockHeight - 1,
Height: MockHeight8 - 1,
},
},
}
Expand Down Expand Up @@ -282,12 +282,12 @@ func TestEncodeWasmExecuteMsg(t *testing.T) {
resBlock := coretypes.ResultBlock{
BlockID: MockBlockID,
Block: &tmtypes.Block{
Header: mockBlockHeader(MockHeight),
Header: mockBlockHeader(MockHeight8),
Data: tmtypes.Data{
Txs: []tmtypes.Tx{bz},
},
LastCommit: &tmtypes.Commit{
Height: MockHeight - 1,
Height: MockHeight8 - 1,
},
},
}
Expand All @@ -313,7 +313,7 @@ func TestEncodeWasmExecuteMsg(t *testing.T) {
to := common.Address(toSeiAddr)
require.Equal(t, &ethapi.RPCTransaction{
BlockHash: &bh,
BlockNumber: (*hexutil.Big)(big.NewInt(MockHeight)),
BlockNumber: (*hexutil.Big)(big.NewInt(MockHeight8)),
From: fromEvmAddr,
To: &to,
Input: []byte{1, 2, 3},
Expand Down
8 changes: 5 additions & 3 deletions evmrpc/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,13 @@

func (f *LogFetcher) FindLogsByBloom(block *coretypes.ResultBlock, filters [][]bloomIndexes) (res []*ethtypes.Log) {
ctx := f.ctxProvider(LatestCtxHeight)

for _, hash := range getEvmTxHashesFromBlock(block, f.txConfig) {
for _, hash := range getTxHashesFromBlock(block, f.txConfig, f.includeSyntheticReceipts) {
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()))
// ignore the error if receipt is not found when includeSyntheticReceipts is true
if !f.includeSyntheticReceipts {
ctx.Logger().Error(fmt.Sprintf("FindLogsByBloom: unable to find receipt for hash %s", hash.Hex()))
}

Check warning on line 415 in evmrpc/filter.go

View check run for this annotation

Codecov / codecov/patch

evmrpc/filter.go#L414-L415

Added lines #L414 - L415 were not covered by tests
continue
}
if !f.includeSyntheticReceipts && (receipt.TxType == ShellEVMTxType || receipt.EffectiveGasPrice == 0) {
Expand Down
23 changes: 9 additions & 14 deletions evmrpc/filter_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package evmrpc_test

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -200,8 +199,8 @@ func TestFilterSeiGetLogs(t *testing.T) {
testFilterGetLogs(t, "sei", []GetFilterLogTests{
{
name: "filter by single synthetic address",
fromBlock: "0x8",
toBlock: "0x8",
fromBlock: "0x64",
toBlock: "0x64",
addrs: []common.Address{common.HexToAddress("0x1111111111111111111111111111111111111116")},
wantErr: false,
check: func(t *testing.T, log map[string]interface{}) {
Expand All @@ -210,21 +209,18 @@ func TestFilterSeiGetLogs(t *testing.T) {
wantLen: 1,
},
{
name: "filter by single topic with default range, include synethetic logs",
topics: [][]common.Hash{{common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000234")}},
wantErr: false,
name: "filter by single topic, include synethetic logs",
topics: [][]common.Hash{{common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000234")}},
wantErr: false,
fromBlock: "0x64",
toBlock: "0x64",
check: func(t *testing.T, log map[string]interface{}) {
require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000234", log["topics"].([]interface{})[0].(string))
},
wantLen: 1,
},
})
}

func TestFilterEthEndpointCanReturnSyntheticLogs(t *testing.T) {
testFilterGetLogs(t, "eth", []GetFilterLogTests{
{
name: "filter by single topic with default range, still include synthetic logs",
name: "filter by single topic with default range, include synethetic logs",
topics: [][]common.Hash{{common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000234")}},
wantErr: false,
check: func(t *testing.T, log map[string]interface{}) {
Expand Down Expand Up @@ -255,7 +251,6 @@ func TestFilterEthEndpointReturnsNormalEvmLogEvenIfSyntheticLogIsInSameBlock(t *
func testFilterGetLogs(t *testing.T, namespace string, tests []GetFilterLogTests) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fmt.Println(tt.name)
filterCriteria := map[string]interface{}{
"address": tt.addrs,
"topics": tt.topics,
Expand Down Expand Up @@ -300,7 +295,7 @@ func TestFilterGetFilterLogs(t *testing.T) {

resObj = sendRequest(t, TestPort, "getFilterLogs", filterId)
logs := resObj["result"].([]interface{})
require.Equal(t, 6, len(logs))
require.Equal(t, 4, len(logs))
for _, log := range logs {
logObj := log.(map[string]interface{})
require.Equal(t, "0x2", logObj["blockNumber"].(string))
Expand Down
Loading
Loading