Skip to content

Commit

Permalink
block: use trie.batch in genTransactionsTrieRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Mar 15, 2024
1 parent 3455a3a commit 9609f1e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/block/src/block.ts
Expand Up @@ -40,7 +40,7 @@ import type {
TxOptions,
TypedTransaction,
} from '@ethereumjs/tx'
import type { EthersProvider, WithdrawalBytes } from '@ethereumjs/util'
import type { BatchDBOp, EthersProvider, WithdrawalBytes } from '@ethereumjs/util'

/**
* An object that represents the block.
Expand Down Expand Up @@ -84,9 +84,14 @@ export class Block {
*/
public static async genTransactionsTrieRoot(txs: TypedTransaction[], emptyTrie?: Trie) {
const trie = emptyTrie ?? new Trie()
for (const [i, tx] of txs.entries()) {
await trie.put(RLP.encode(i), tx.serialize())
}
const batchOp: BatchDBOp[] = txs.map((tx, i) => {
return {
type: 'put',
key: RLP.encode(i),
value: tx.serialize(),
}
})
await trie.batch(batchOp)
return trie.root()
}

Expand Down

0 comments on commit 9609f1e

Please sign in to comment.