1
0
Fork 0
forked from forks/go-ethereum
go-ethereum-modded-tocallarg/core
Marius van der Wijden b47e4d5b38
core/types: reduce allocs in transaction signing (#31258)
This PR roughly halves the number of allocations needed to compute the
sigHash for a transaction.

This sigHash is used whenever we recover a signature of a transaction,
so quite often. During a recent benchmark full syncing on Holesky,
roughly 2.8% of all allocations were happening here because the fields
from the transaction would be copied multiple times.

```
66168733  153175654 (flat, cum)  2.80% of Total
         .          .    368:func (s londonSigner) Hash(tx *Transaction) common.Hash {
         .          .    369:	if tx.Type() != DynamicFeeTxType {
         .          .    370:		return s.eip2930Signer.Hash(tx)
         .          .    371:	}
         .   19169966    372:	return prefixedRlpHash(
         .          .    373:		tx.Type(),
  26442187   26442187    374:		[]interface{}{
         .          .    375:			s.chainId,
   6848616    6848616    376:			tx.Nonce(),
         .   19694077    377:			tx.GasTipCap(),
         .   18956774    378:			tx.GasFeeCap(),
   6357089    6357089    379:			tx.Gas(),
         .   12321050    380:			tx.To(),
         .   16865054    381:			tx.Value(),
  13435187   13435187    382:			tx.Data(),
  13085654   13085654    383:			tx.AccessList(),
         .          .    384:		})
         .          .    385:}
```

This PR reduces the allocations and speeds up the computation of the
sigHash by ~22%, which is quite significantly given that this operation
involves a call to Keccak
```
// BenchmarkHash-8   	  440082	      2639 ns/op	     384 B/op	      13 allocs/op
// BenchmarkHash-8   	  493566	      2033 ns/op	     240 B/op	       6 allocs/op
```

```
Hash-8   2.691µ ± 8%   2.097µ ± 9%  -22.07% (p=0.000 n=10)
```

It also kinda cleans up stuff in my opinion, since the transaction
should itself know best how to compute the sighash




![Screenshot_2025-02-25_13-52-41](https://github.com/user-attachments/assets/e2b268aa-e137-417d-926b-f3619daef748)

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2025-03-19 14:21:40 +08:00
..
bloombits all: fix typos in comments (#29873) 2024-05-29 12:24:10 +02:00
filtermaps core/filtermaps: fixed indexer checkpoint initialization (#31419) 2025-03-18 13:46:23 +01:00
forkid params: add hoodi testnet definition (#31406) 2025-03-18 12:07:49 +01:00
rawdb params: add hoodi testnet definition (#31406) 2025-03-18 12:07:49 +01:00
state core/rawdb,state: add preimage miss metric (#31295) 2025-03-07 11:23:19 +01:00
stateless beacon, core, eth, miner: integrate witnesses into production Geth (#30069) 2024-09-20 16:43:42 +03:00
tracing core/tracing: stringer for gas and nonce change reasons (#31234) 2025-02-28 12:53:56 +01:00
txpool core/txpool, eth: add GetRLP to transaction pool (#31307) 2025-03-19 14:20:50 +08:00
types core/types: reduce allocs in transaction signing (#31258) 2025-03-19 14:21:40 +08:00
vm core/asm: delete assembler/disassembler (#31211) 2025-02-19 06:57:08 -07:00
.gitignore Renamed chain => core 2014-12-04 10:28:02 +01:00
bench_test.go all: nuke total difficulty (#30744) 2025-01-28 18:55:41 +01:00
block_validator.go core/types: create block's bloom by merging receipts' bloom (#31129) 2025-02-13 18:05:58 +01:00
block_validator_test.go all: remove TerminalTotalDifficultyPassed (#30609) 2024-10-23 08:26:18 +02:00
blockchain.go core: update blockProcFeed in insertChain (#31065) 2025-03-13 12:35:10 +01:00
blockchain_insert.go all: remove forkchoicer and reorgNeeded (#29179) 2024-09-04 15:03:06 +02:00
blockchain_reader.go all: nuke total difficulty (#30744) 2025-01-28 18:55:41 +01:00
blockchain_repair_test.go core, eth, node: break rawdb -> {leveldb, pebble} dependency (#30689) 2024-10-29 10:31:04 +02:00
blockchain_sethead_test.go core, eth, node: break rawdb -> {leveldb, pebble} dependency (#30689) 2024-10-29 10:31:04 +02:00
blockchain_snapshot_test.go core, eth, node: break rawdb -> {leveldb, pebble} dependency (#30689) 2024-10-29 10:31:04 +02:00
blockchain_test.go all: nuke total difficulty (#30744) 2025-01-28 18:55:41 +01:00
bloom_indexer.go core: preallocate batch size in bloomIndexer (#25289) 2022-08-03 17:02:09 +02:00
chain_indexer.go core, eth, ethstats: simplify chain head events (#30601) 2024-10-16 10:32:58 +03:00
chain_indexer_test.go all: improve some error strings (#29842) 2024-05-28 13:44:40 +02:00
chain_makers.go consensus/misc/eip4844: more changes for blob gas calculation (#31128) 2025-02-05 10:35:03 +01:00
chain_makers_test.go params,core: add max and target value to chain config (#31002) 2025-02-04 15:43:18 +01:00
dao_test.go all: remove forkchoicer and reorgNeeded (#29179) 2024-09-04 15:03:06 +02:00
error.go core: implement eip-7623 floor data gas (#30946) 2025-01-30 09:07:45 -07:00
events.go core, eth, ethstats: simplify chain head events (#30601) 2024-10-16 10:32:58 +03:00
evm.go params,core: add max and target value to chain config (#31002) 2025-02-04 15:43:18 +01:00
gaspool.go core, miner: revert block gas counter in case of invalid transaction (#26799) 2023-03-07 05:23:52 -05:00
gen_genesis.go core: go fmt (#29544) 2024-04-16 15:42:16 +03:00
genesis.go params: add hoodi testnet definition (#31406) 2025-03-18 12:07:49 +01:00
genesis_alloc.go params: add hoodi testnet definition (#31406) 2025-03-18 12:07:49 +01:00
genesis_test.go params: add hoodi testnet definition (#31406) 2025-03-18 12:07:49 +01:00
headerchain.go all: nuke total difficulty (#30744) 2025-01-28 18:55:41 +01:00
headerchain_test.go all: nuke total difficulty (#30744) 2025-01-28 18:55:41 +01:00
mkalloc.go accounts, cmd/geth, core: close opened files (#29598) 2024-04-30 15:47:21 +02:00
rlp_test.go core: move genesis alloc types to core/types (#29003) 2024-02-16 19:05:33 +01:00
sender_cacher.go core: use sync.Once for SenderCacher initialization (#31029) 2025-01-16 14:36:45 +01:00
state_prefetcher.go core: switch EVM tx context in ApplyMessage (#30809) 2024-11-29 15:39:42 +01:00
state_processor.go core: match on deposit contract log topic (#31317) 2025-03-05 11:04:24 +01:00
state_processor_test.go consensus/misc/eip4844: more changes for blob gas calculation (#31128) 2025-02-05 10:35:03 +01:00
state_transition.go core/vm: clean up EVM environmental structure (#31061) 2025-02-18 21:53:33 +08:00
stateless.go cmd/evm: improve block/state test runner (#30633) 2024-12-02 15:18:02 +01:00
txindexer.go all: update license comments and AUTHORS (#31133) 2025-02-05 23:01:17 +01:00
txindexer_test.go all: update license comments and AUTHORS (#31133) 2025-02-05 23:01:17 +01:00
types.go all: implement flat deposit requests encoding (#30425) 2024-10-09 12:24:58 +02:00
verkle_witness_test.go core/tracing: state journal wrapper (#30441) 2025-02-05 13:58:25 +01:00