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

Merge seiv2 into main #234

Merged
merged 27 commits into from
Apr 19, 2024
Merged

Merge seiv2 into main #234

merged 27 commits into from
Apr 19, 2024

Conversation

udpatil
Copy link
Contributor

@udpatil udpatil commented Apr 19, 2024

Describe your changes and provide context

This merges seiv2 into main

Testing performed to validate your change

TODO: don't squash and merge, do rebase + merge instead

codchen and others added 26 commits April 16, 2024 18:52
* Perf: Increase buffer size for pubsub server to boost performance (#167)

* Increase buffer size for pubsub server

* Add more timeout for test failure

* Add more timeout

* Fix test split scripts

* Fix test split

* Fix unit test

* Unit test

* Unit test

* [P2P] Optimize block pool requester retry and peer pick up logic (#170)

* P2P Improvements: Fix block sync reactor and block pool retry logic

* Revert "Add event data to result event (#165)" (#176)

This reverts commit 72bb29c.

* Fix block sync auto restart not working as expected (#175)

* Fix edge case for blocksync (#178)

* fix evm pending nonce

* fix test

* deflake a test

* de-flake test

* Revert "merge main"

This reverts commit 58b9424, reversing
changes made to 02d1478.

* consider keep-in-cache logic when removing from cache

* undo test tweaks

---------

Co-authored-by: Yiming Zang <[email protected]>
Co-authored-by: Jeremy Wei <[email protected]>
* Add metrics for mempool pending transaction size

* Add expired tx count metrics
* add mempool prioritization with evm nonce

* fix priority stability

* index fixes

* replace with binary search insert

* impl binary search
* debug duplicate evm tx

* add more logs

* add some \ns

* more logs

* fix swap check

* add-lockable-reap-by-gas

* add invariant checks

* fix invariant parenthesis

* fix log

* remove invalid invariant

* fix nonce ordering pain

* handle ordering of insert

* fix remove

* cleanup

* fix imports

* cleanup

* avoid getTransactionByHash(hash) panic due to index

* use Key() to compare instead of pointer
* prevent duplicates in mempool

* use timestamp in priority queue
* add logging for expired txs

* cleanup
* remove heapIndex to avoid nil scenario

* avoid returning nil in loop (mimic Peek)
* add heapIndex with safety check

* cleanup

* comment out for perf test

* add back perf improvement

* fix nil test

* Use write-lock in (*TxPriorityQueue).ReapMax funcs (#209)

ReapMaxBytesMaxGas and ReapMaxTxs funcs in TxPriorityQueue claim
> Transactions returned are not removed from the mempool transaction
> store or indexes.

However, they use a priority queue to accomplish the claim
> Transaction are retrieved in priority order.

This is accomplished by popping all items out of the whole heap, and
then pushing then back in sequentially. A copy of the heap cannot be
obtained otherwise. Both of the mentioned functions use a read-lock
(RLock) when doing this. This results in a potential scenario where
multiple executions of the ReapMax can be started in parallel, and
both would be popping items out of the priority queue.

In practice, this can be abused by executing the `unconfirmed_txs` RPC
call repeatedly. Based on our observations, running it multiple times
per millisecond results in multiple threads picking it up at the same
time. Such a scenario can be obtained via the WebSocket interface, and
spamming `unconfirmed_txs` calls there. The behavior that happens is a
`Panic in WSJSONRPC handler` when a queue item unexpectedly disappears
for `mempool.(*TxPriorityQueue).Swap`.
(`runtime error: index out of range [0] with length 0`)

This can additionally lead to a `CONSENSUS FAILURE!!!` if the race
condition occurs for `internal/consensus.(*State).finalizeCommit`
when it tries to do `mempool.(*TxPriorityQueue).RemoveTx`, but
the ReapMax has already removed all elements from the underlying
heap. (`runtime error: index out of range [-1]`)

This commit switches the lock type to a write-lock (Lock) to ensure
no parallel modifications take place. This commit additionally updates
the tests to allow parallel execution of the func calls in testing,
as to prevent regressions (in case someone wants to downgrade the locks
without considering the implications from the underlying heap usage).

---------

Co-authored-by: Valters Jansons <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Apr 19, 2024

Codecov Report

Attention: Patch coverage is 73.22404% with 147 lines in your changes are missing coverage. Please review.

Project coverage is 58.26%. Comparing base (febb306) to head (59da3e7).

❗ Current head 59da3e7 differs from pull request most recent head 8c8db19. Consider uploading reports for the commit 8c8db19 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #234      +/-   ##
==========================================
+ Coverage   57.87%   58.26%   +0.38%     
==========================================
  Files         249      249              
  Lines       34006    34441     +435     
==========================================
+ Hits        19681    20066     +385     
- Misses      12756    12790      +34     
- Partials     1569     1585      +16     
Files Coverage Δ
abci/types/types.go 18.18% <ø> (ø)
config/config.go 62.98% <100.00%> (+0.27%) ⬆️
config/toml.go 51.35% <ø> (ø)
node/node.go 58.39% <100.00%> (+0.07%) ⬆️
rpc/client/mock/abci.go 59.75% <100.00%> (ø)
internal/proxy/client.go 21.66% <0.00%> (ø)
abci/example/kvstore/kvstore.go 53.79% <0.00%> (ø)
abci/types/application.go 0.00% <0.00%> (ø)
abci/types/messages.go 4.76% <0.00%> (ø)
internal/rpc/core/mempool.go 0.00% <0.00%> (ø)
... and 5 more

... and 16 files with indirect coverage changes

@udpatil udpatil merged commit c027db5 into main Apr 19, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants