Skip to content

Commit

Permalink
fix: Eth Tx Events Bloom Filter: fix slice modification bug and flaky…
Browse files Browse the repository at this point in the history
… test (filecoin-project#12203)

* fix the event bloom filter in eth tx receipts
  • Loading branch information
aarshkshah1992 authored Jul 10, 2024
1 parent daf678f commit 1a94bd2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# UNRELEASED

- https://github.com/filecoin-project/lotus/pull/12203: Fix slice modification bug in ETH Tx Events Bloom Filter

## ☢️ Upgrade Warnings ☢️

- This Lotus release includes some correctness improvements to the events subsystem, impacting RPC APIs including `GetActorEventsRaw`, `SubscribeActorEventsRaw`, `eth_getLogs` and the `eth` filter APIs. Part of these improvements involve an events database migration that may take some time to complete on nodes with extensive event databases. See [filecoin-project/lotus#12080](https://github.com/filecoin-project/lotus/pull/12080) for details.
Expand Down
17 changes: 11 additions & 6 deletions chain/types/ethtypes/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,24 @@ type EthBlock struct {
const EthBloomSize = 2048

var (
EmptyEthBloom = [EthBloomSize / 8]byte{}
FullEthBloom = [EthBloomSize / 8]byte{}
EmptyEthHash = EthHash{}
EmptyUncleHash = must.One(ParseEthHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")) // Keccak-256 of an RLP of an empty array
EmptyRootHash = must.One(ParseEthHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")) // Keccak-256 hash of the RLP of null
EmptyEthInt = EthUint64(0)
EmptyEthNonce = [8]byte{0, 0, 0, 0, 0, 0, 0, 0}
)

func init() {
for i := range FullEthBloom {
FullEthBloom[i] = 0xff
func NewEmptyEthBloom() []byte {
eb := [EthBloomSize / 8]byte{}
return eb[:]
}

func NewFullEthBloom() []byte {
fb := [EthBloomSize / 8]byte{}
for i := range fb {
fb[i] = 0xff
}
return fb[:]
}

func NewEthBlock(hasTransactions bool, tipsetLen int) EthBlock {
Expand All @@ -210,7 +215,7 @@ func NewEthBlock(hasTransactions bool, tipsetLen int) EthBlock {
TransactionsRoot: EmptyRootHash, // TransactionsRoot set to a hardcoded value which is used by some clients to determine if has no transactions.
ReceiptsRoot: EmptyEthHash,
Difficulty: EmptyEthInt,
LogsBloom: FullEthBloom[:],
LogsBloom: NewFullEthBloom(),
Extradata: []byte{},
MixHash: EmptyEthHash,
Nonce: EmptyEthNonce,
Expand Down
2 changes: 1 addition & 1 deletion itests/eth_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func TestTxReceiptBloom(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, th)

receipt, err := client.EthGetTransactionReceipt(ctx, *th)
receipt, err := client.EVM().WaitTransaction(ctx, *th)
require.NoError(t, err)
require.NotNil(t, receipt)
require.Len(t, receipt.Logs, 1)
Expand Down
2 changes: 1 addition & 1 deletion node/impl/full/eth_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func newEthTxReceipt(ctx context.Context, tx ethtypes.EthTx, lookup *api.MsgLook
BlockNumber: blockNumber,
Type: ethtypes.EthUint64(2),
Logs: []ethtypes.EthLog{}, // empty log array is compulsory when no logs, or libraries like ethers.js break
LogsBloom: ethtypes.EmptyEthBloom[:],
LogsBloom: ethtypes.NewEmptyEthBloom(),
}

if lookup.Receipt.ExitCode.IsSuccess() {
Expand Down

0 comments on commit 1a94bd2

Please sign in to comment.