ethereumjs-monorepo icon indicating copy to clipboard operation
ethereumjs-monorepo copied to clipboard

Block: use trie.batch

Open ScottyPoi opened this issue 1 year ago • 2 comments

Follow-up to #3313 Continuing work towards optimizations in #3293

block.genTransactionsTrie()

Returns the txs trie root for array of TypedTransaction

This method is used during block building and block validation

An empty trie is contructed from a list of serialized transactions (with the tx index as key)

The root of this trie is the TransactionsTrieRoot of a block.

trie.batch()

The refactored trie.batch method in #3313 demonstrated up to 33% efficiency improvements over the naive for (tx of txs) {...} approach.

Changes:

block.genTransactionsTrieRoot() will now construct a trie from a batch input of serialized transactions.

    const batchOp: BatchDBOp[] = txs.map((tx, i) => {
      return {
        type: 'put',
        key: RLP.encode(i),
        value: tx.serialize(),
      }
    })
    await trie.batch(batchOp)

This should improve performance during block building and validation

TODO:

  • merge #3313
  • rebase
  • benchmark

ScottyPoi avatar Mar 13 '24 05:03 ScottyPoi

Codecov Report

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

Project coverage is 86.93%. Comparing base (a70312d) to head (9609f1e).

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 88.46% <100.00%> (+0.02%) :arrow_up:
blockchain 91.61% <ø> (ø)
client 84.85% <ø> (ø)
common 98.43% <ø> (ø)
devp2p 82.12% <ø> (ø)
ethash ∅ <ø> (∅)
evm 74.16% <ø> (ø)
genesis 99.98% <ø> (ø)
rlp ∅ <ø> (∅)
statemanager 77.00% <ø> (ø)
trie 89.72% <95.45%> (+0.40%) :arrow_up:
tx 95.08% <ø> (ø)
util 89.34% <ø> (ø)
vm 79.87% <ø> (ø)
wallet 88.35% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

codecov[bot] avatar Mar 13 '24 05:03 codecov[bot]

Cool that you even already started on this one 👍, also cool that this is separated into two PRs! 💯

Is this already "so ready" that I could test this in the client setup I had and see how it goes? Or does this need more work before?

holgerd77 avatar Mar 13 '24 13:03 holgerd77