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

fix: Eth Tx Events Bloom Filter: fix slice modification bug and flaky test #12203

Merged
merged 4 commits into from
Jul 10, 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
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