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: eth_getLogs missing events from early return #1941

Merged
merged 5 commits into from
Nov 17, 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
8 changes: 6 additions & 2 deletions evmrpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestGetBlockReceipts(t *testing.T) {
// Query by block height
resObj := sendRequestGood(t, "getBlockReceipts", "0x2")
result := resObj["result"].([]interface{})
require.Equal(t, 6, len(result))
require.Equal(t, 5, len(result))
receipt1 := result[0].(map[string]interface{})
require.Equal(t, "0x2", receipt1["blockNumber"])
require.Equal(t, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", receipt1["transactionHash"])
Expand All @@ -91,10 +91,14 @@ func TestGetBlockReceipts(t *testing.T) {
require.Equal(t, "0x2", receipt3["blockNumber"])
require.Equal(t, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", receipt3["transactionHash"])

resObjSei := sendSeiRequestGood(t, "getBlockReceipts", "0x2")
result = resObjSei["result"].([]interface{})
require.Equal(t, 6, len(result))

// Query by block hash
resObj2 := sendRequestGood(t, "getBlockReceipts", "0x0000000000000000000000000000000000000000000000000000000000000002")
result = resObj2["result"].([]interface{})
require.Equal(t, 6, len(result))
require.Equal(t, 5, len(result))
receipt1 = result[0].(map[string]interface{})
require.Equal(t, "0x2", receipt1["blockNumber"])
require.Equal(t, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", receipt1["transactionHash"])
Expand Down
6 changes: 1 addition & 5 deletions evmrpc/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,9 @@ func (f *LogFetcher) FindLogsByBloom(height int64, filters [][]bloomIndexes) (re
ctx.Logger().Error(fmt.Sprintf("FindLogsByBloom: unable to find receipt for hash %s", hash.Hex()))
continue
}
// if includeShellReceipts is false, include receipts with synthetic logs but exclude shell tx receipts
if !f.includeSyntheticReceipts && receipt.TxType == ShellEVMTxType {
if !f.includeSyntheticReceipts && (receipt.TxType == ShellEVMTxType || receipt.EffectiveGasPrice == 0) {
continue
}
if !f.includeSyntheticReceipts && receipt.EffectiveGasPrice == 0 {
return
}
if len(receipt.LogsBloom) > 0 && MatchFilters(ethtypes.Bloom(receipt.LogsBloom), filters) {
res = append(res, keeper.GetLogsForTx(receipt)...)
}
Expand Down
33 changes: 26 additions & 7 deletions evmrpc/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ func getCommonFilterLogTests() []GetFilterLogTests {
wantLen: 4,
},
{
name: "filter by single topic with default range",
topics: [][]common.Hash{{common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111")}},
wantErr: false,
name: "filter by single topic with block range",
fromBlock: "0x8",
toBlock: "0x8",
topics: [][]common.Hash{{common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111")}},
wantErr: false,
check: func(t *testing.T, log map[string]interface{}) {
require.Equal(t, "0x1111111111111111111111111111111111111111111111111111111111111111", log["topics"].([]interface{})[0].(string))
},
Expand Down Expand Up @@ -192,7 +194,7 @@ func TestFilterGetLogs(t *testing.T) {
testFilterGetLogs(t, "eth", getCommonFilterLogTests())
}

func TestSeiFilterGetLogs(t *testing.T) {
func TestFilterSeiGetLogs(t *testing.T) {
// make sure we pass all the eth_ namespace tests
testFilterGetLogs(t, "sei", getCommonFilterLogTests())

Expand Down Expand Up @@ -221,10 +223,10 @@ func TestSeiFilterGetLogs(t *testing.T) {
})
}

func TestEthEndpointCanReturnSyntheticLogs(t *testing.T) {
func TestFilterEthEndpointCanReturnSyntheticLogs(t *testing.T) {
testFilterGetLogs(t, "eth", []GetFilterLogTests{
{
name: "filter by single topic with default range, exclude synethetic logs",
name: "filter by single topic with default range, still include synthetic logs",
topics: [][]common.Hash{{common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000234")}},
wantErr: false,
check: func(t *testing.T, log map[string]interface{}) {
Expand All @@ -235,6 +237,23 @@ func TestEthEndpointCanReturnSyntheticLogs(t *testing.T) {
})
}

func TestFilterEthEndpointReturnsNormalEvmLogEvenIfSyntheticLogIsInSameBlock(t *testing.T) {
testFilterGetLogs(t, "eth", []GetFilterLogTests{
{
name: "normal evm log is returned even if synthetic log is in the same block",
fromBlock: "0x64", // 100
toBlock: "0x64",
wantErr: false,
check: func(t *testing.T, log map[string]interface{}) {
// check that none of the events have the synthetic hash
syntheticHash := multiTxBlockSynthTx.Hash()
require.NotEqual(t, syntheticHash.Hex(), log["transactionHash"].(string))
},
wantLen: 2,
},
})
}

func testFilterGetLogs(t *testing.T, namespace string, tests []GetFilterLogTests) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -283,7 +302,7 @@ func TestFilterGetFilterLogs(t *testing.T) {

resObj = sendRequest(t, TestPort, "getFilterLogs", filterId)
logs := resObj["result"].([]interface{})
require.Equal(t, 7, len(logs))
require.Equal(t, 6, len(logs))
for _, log := range logs {
logObj := log.(map[string]interface{})
require.Equal(t, "0x2", logObj["blockNumber"].(string))
Expand Down
59 changes: 44 additions & 15 deletions evmrpc/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const TestBadPort = 7779
const MockHeight = 8
const MultiTxBlockHeight = 2
const DebugTraceMockHeight = 101
const SyntheticBlockHeight = 100

var DebugTraceHashHex = "0x1234567890123456789023456789012345678901234567890123456789000004"
var DebugTraceBlockHash = "BE17E0261E539CB7E9A91E123A6D794E0163D656FCF9B8EAC07823F7ED28512B"
Expand Down Expand Up @@ -167,6 +168,26 @@ func (c *MockClient) mockBlock(height int64) *coretypes.ResultBlock {
},
}
}
if height == SyntheticBlockHeight {
return &coretypes.ResultBlock{
BlockID: MockBlockID,
Block: &tmtypes.Block{
Header: mockBlockHeader(height),
Data: tmtypes.Data{
Txs: []tmtypes.Tx{
func() []byte {
bz, _ := Encoder(MultiTxBlockSynthTx)
return bz
}(),
func() []byte {
bz, _ := Encoder(MultiTxBlockTx1)
return bz
}(),
},
},
},
}
}
res := &coretypes.ResultBlock{
BlockID: MockBlockID,
Block: &tmtypes.Block{
Expand Down Expand Up @@ -576,7 +597,7 @@ func generateTxData() {
From: "0x1234567890123456789012345678901234567890",
To: "0x1234567890123456789012345678901234567890",
TransactionIndex: 0,
BlockNumber: 8,
BlockNumber: MockHeight,
TxType: 1,
ContractAddress: "0x1234567890123456789012345678901234567890",
CumulativeGasUsed: 123,
Expand Down Expand Up @@ -679,7 +700,8 @@ func setupLogs() {
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000123"),
},
}}}})
EVMKeeper.MockReceipt(Ctx, multiTxBlockTx1.Hash(), &types.Receipt{
CtxMultiTx := Ctx.WithBlockHeight(MultiTxBlockHeight)
EVMKeeper.MockReceipt(CtxMultiTx, multiTxBlockTx1.Hash(), &types.Receipt{
BlockNumber: MultiTxBlockHeight,
TransactionIndex: 1, // start at 1 bc 0 is the non-evm tx
TxHashHex: multiTxBlockTx1.Hash().Hex(),
Expand All @@ -700,7 +722,7 @@ func setupLogs() {
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000456"),
},
}}}})
EVMKeeper.MockReceipt(Ctx, multiTxBlockTx2.Hash(), &types.Receipt{
EVMKeeper.MockReceipt(CtxMultiTx, multiTxBlockTx2.Hash(), &types.Receipt{
BlockNumber: MultiTxBlockHeight,
TransactionIndex: 3,
TxHashHex: multiTxBlockTx2.Hash().Hex(),
Expand All @@ -718,7 +740,7 @@ func setupLogs() {
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000456"),
},
}}}})
EVMKeeper.MockReceipt(Ctx, multiTxBlockTx3.Hash(), &types.Receipt{
EVMKeeper.MockReceipt(CtxMultiTx, multiTxBlockTx3.Hash(), &types.Receipt{
BlockNumber: MultiTxBlockHeight,
TransactionIndex: 4,
TxHashHex: multiTxBlockTx3.Hash().Hex(),
Expand All @@ -736,9 +758,10 @@ func setupLogs() {
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000456"),
},
}}}})
EVMKeeper.MockReceipt(Ctx, multiTxBlockTx4.Hash(), &types.Receipt{
CtxMock := Ctx.WithBlockHeight(MockHeight)
EVMKeeper.MockReceipt(CtxMock, multiTxBlockTx4.Hash(), &types.Receipt{
BlockNumber: MockHeight,
TransactionIndex: 0,
TransactionIndex: 1,
TxHashHex: multiTxBlockTx4.Hash().Hex(),
LogsBloom: bloom4[:],
Logs: []*types.Log{{
Expand All @@ -755,26 +778,28 @@ func setupLogs() {
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000456"),
},
}}}})
EVMKeeper.MockReceipt(Ctx, multiTxBlockSynthTx.Hash(), &types.Receipt{
BlockNumber: MultiTxBlockHeight,
TransactionIndex: 5,
EVMKeeper.MockReceipt(CtxMock, multiTxBlockSynthTx.Hash(), &types.Receipt{
TxType: evmrpc.ShellEVMTxType,
BlockNumber: MockHeight,
TransactionIndex: 0,
TxHashHex: multiTxBlockSynthTx.Hash().Hex(),
LogsBloom: bloomSynth[:],
Logs: []*types.Log{{
Address: "0x1111111111111111111111111111111111111116",
Topics: []string{"0x0000000000000000000000000000000000000000000000000000000000000234", "0x0000000000000000000000000000000000000000000000000000000000000789"},
Synthetic: true,
}},
EffectiveGasPrice: 100,
EffectiveGasPrice: 0,
})
EVMKeeper.MockReceipt(Ctx, common.HexToHash(DebugTraceHashHex), &types.Receipt{
CtxDebugTrace := Ctx.WithBlockHeight(DebugTraceMockHeight)
EVMKeeper.MockReceipt(CtxDebugTrace, common.HexToHash(DebugTraceHashHex), &types.Receipt{
BlockNumber: DebugTraceMockHeight,
TransactionIndex: 0,
TxHashHex: DebugTraceHashHex,
})
txNonEvmBz, _ := Encoder(TxNonEvmWithSyntheticLog)
txNonEvmHash := sha256.Sum256(txNonEvmBz)
EVMKeeper.MockReceipt(Ctx, txNonEvmHash, &types.Receipt{
EVMKeeper.MockReceipt(CtxMultiTx, txNonEvmHash, &types.Receipt{
BlockNumber: MultiTxBlockHeight,
TransactionIndex: 1,
TxHashHex: common.Hash(txNonEvmHash).Hex(),
Expand All @@ -786,22 +811,26 @@ func setupLogs() {
}},
EffectiveGasPrice: 100,
})

// block 8
EVMKeeper.SetTxHashesOnHeight(Ctx, MultiTxBlockHeight, []common.Hash{
multiTxBlockTx1.Hash(),
multiTxBlockTx2.Hash(),
multiTxBlockTx3.Hash(),
})
EVMKeeper.SetBlockBloom(MultiTxCtx, []ethtypes.Bloom{bloom1, bloom2, bloom3})

// block 2
EVMKeeper.SetTxHashesOnHeight(Ctx, MockHeight, []common.Hash{
multiTxBlockTx4.Hash(),
multiTxBlockSynthTx.Hash(),
multiTxBlockTx4.Hash(),
})
bloomTx1 := ethtypes.CreateBloom(ethtypes.Receipts{&ethtypes.Receipt{Logs: []*ethtypes.Log{{
Address: common.HexToAddress("0x1111111111111111111111111111111111111111"),
Topics: []common.Hash{common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111"),
common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111112")},
}}}})
EVMKeeper.SetBlockBloom(MultiTxCtx, []ethtypes.Bloom{bloom1, bloom2, bloom3})
EVMKeeper.SetBlockBloom(Ctx, []ethtypes.Bloom{bloom4, bloomSynth, bloomTx1})
EVMKeeper.SetBlockBloom(Ctx, []ethtypes.Bloom{bloomSynth, bloom4, bloomTx1})
}

//nolint:deadcode
Expand Down
Loading