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

transaction: Sort txs by gas tip and then tx arrival time #2128

Merged
merged 6 commits into from May 13, 2024

Conversation

2dvorak
Copy link
Collaborator

@2dvorak 2dvorak commented Apr 4, 2024

Proposed changes

  • Currently, slice typed txlist is sorted by the arrival time (map typed txlist with address key is sorted by nonce). It is sorted when it's (1) block creation and (2) broadcasting the txlist. By this PR, the txs can be sorted by gas tip and then by arrival time.
  • Additionally, this PR (1) references current govParam in feeHistory api, (2) adds price heap of tx list at block creation, (3) and remove ordering validation logic when broadcasting txs. Since ordering validation is as time-consuming as sorting, this PR only sorts at the start of the broadcast and remove ordering validation in callee functions such as SortTransactions.

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Benchmark Time & Time by interval

BenchmarkSortTxsByPriceAndTime is used.

  • Benchmark Time
➜  types git:(2dvorak/tx-sort-by-fee) ✗ go test -bench=BenchmarkSortTxsByPriceAndTime -benchtime=10x
goos: darwin
goarch: arm64
pkg: github.com/klaytn/klaytn/blockchain/types
BenchmarkSortTxsByPriceAndTime20000-10                10          10464658 ns/op
BenchmarkSortTxsByPriceAndTime10000-10                10           4263929 ns/op
BenchmarkSortTxsByPriceAndTime100-10                  10             23067 ns/op
  • Time by interval
    Batch creation time: calculating time of each tx's effectiveGasTip.
    Sort Validation time: isSorted time
    Pure sorting time: sort.Sort time.
# size of txs: 20000
batch creation time: 4.785167ms
sort validation time : 1.291µs
pure sorting time: 5.390458ms
# size of txs: 10000
batch creation time: 2.04825ms
sort validation time: 916ns
pure sorting time: 2.189625ms
# size of txs: 100
batch creation time: 45.083µs
sort validation time: 750ns
pure sorting time: 22.583µs

@2dvorak 2dvorak self-assigned this Apr 4, 2024
@2dvorak 2dvorak removed their assignment Apr 22, 2024
@yoomee1313 yoomee1313 changed the title Sort Tx by their gas tip transaction: Sort block txs by gas tip and then tx arrival time Apr 25, 2024
@yoomee1313 yoomee1313 changed the title transaction: Sort block txs by gas tip and then tx arrival time transaction: Sort txs by gas tip and then tx arrival time Apr 25, 2024
@yoomee1313 yoomee1313 force-pushed the 2dvorak/tx-sort-by-fee branch 3 times, most recently from d78751b to 3cc381b Compare May 10, 2024 02:58
@blukat29
Copy link
Contributor

Hello, could you either (1) rebase against the latest dev or (2) git fetch --all && git cherry-pick 946bfe6? This will fix the CI failure.

@yoomee1313 yoomee1313 force-pushed the 2dvorak/tx-sort-by-fee branch 2 times, most recently from 4e79038 to 06cfc9d Compare May 10, 2024 07:15
@yoomee1313 yoomee1313 self-assigned this May 13, 2024
@blukat29 blukat29 merged commit 8a64d62 into klaytn:dev May 13, 2024
11 checks passed
@blukat29 blukat29 deleted the 2dvorak/tx-sort-by-fee branch May 13, 2024 02:17
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.

None yet

4 participants