-
Notifications
You must be signed in to change notification settings - Fork 21.6k
core/tracing: state journal wrapper #30441
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
Changes from 18 commits
8659e68
b4e0174
f670a7f
cf873c3
365b715
aac4024
dbe5f83
b87c4fe
702a42f
c915bed
838fc25
1cc58cf
3c58155
501f302
1a64297
1862333
6650000
d9de74e
d2ba76f
a2ca5f8
85a85d0
2754b41
92337d8
36b4194
efed5a6
ea92ef4
fbd1d19
0f005af
5e4d6b8
4d2fb0e
b37f2ac
a0f7cd6
87582a4
6e4d14c
553f023
be93d72
1dda30d
4acea3b
018df6b
60b2222
6c56ea5
f4cf2a5
7fb2688
3228063
95b82cf
de48d55
9cae376
bf51dde
459c50f
831524a
6f5e74b
bca2e2c
8a2230e
59a5022
4ba05e9
2795c0e
51720dc
4787f31
8a44029
eaacae4
93432fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ package tracing | |
|
|
||
| import ( | ||
| "math/big" | ||
| "reflect" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/core/types" | ||
|
|
@@ -42,6 +43,7 @@ type StateDB interface { | |
| GetBalance(common.Address) *uint256.Int | ||
| GetNonce(common.Address) uint64 | ||
| GetCode(common.Address) []byte | ||
| GetCodeHash(common.Address) common.Hash | ||
| GetState(common.Address, common.Hash) common.Hash | ||
| Exist(common.Address) bool | ||
| GetRefund() uint64 | ||
|
|
@@ -134,6 +136,9 @@ type ( | |
| // GenesisBlockHook is called when the genesis block is being processed. | ||
| GenesisBlockHook = func(genesis *types.Block, alloc types.GenesisAlloc) | ||
|
|
||
| // ReorgHook is called when a segment of the chain is reverted. | ||
| ReorgHook = func(reverted []*types.Block) | ||
|
||
|
|
||
| // OnSystemCallStartHook is called when a system call is about to be executed. Today, | ||
| // this hook is invoked when the EIP-4788 system call is about to be executed to set the | ||
| // beacon block root. | ||
|
|
@@ -143,7 +148,7 @@ type ( | |
| // | ||
| // Note that system call happens outside normal transaction execution, so the `OnTxStart/OnTxEnd` hooks | ||
| // will not be invoked. | ||
| OnSystemCallStartHook = func() | ||
| OnSystemCallStartHook = func(vm *VMContext) | ||
|
|
||
| // OnSystemCallEndHook is called when a system call has finished executing. Today, | ||
| // this hook is invoked when the EIP-4788 system call is about to be executed to set the | ||
|
|
@@ -168,6 +173,27 @@ type ( | |
|
|
||
| // LogHook is called when a log is emitted. | ||
| LogHook = func(log *types.Log) | ||
|
|
||
| // BalanceReadHook is called when EVM reads the balance of an account. | ||
| BalanceReadHook = func(addr common.Address, bal *big.Int) | ||
|
|
||
| // NonceReadHook is called when EVM reads the nonce of an account. | ||
| NonceReadHook = func(addr common.Address, nonce uint64) | ||
|
|
||
| // CodeReadHook is called when EVM reads the code of an account. | ||
| CodeReadHook = func(addr common.Address, code []byte) | ||
|
||
|
|
||
| // CodeSizeReadHook is called when EVM reads the code size of an account. | ||
| CodeSizeReadHook = func(addr common.Address, size int) | ||
|
|
||
| // CodeHashReadHook is called when EVM reads the code hash of an account. | ||
| CodeHashReadHook = func(addr common.Address, hash common.Hash) | ||
|
|
||
| // StorageReadHook is called when EVM reads a storage slot of an account. | ||
| StorageReadHook = func(addr common.Address, slot, value common.Hash) | ||
|
|
||
| // BlockHashReadHook is called when EVM reads the blockhash of a block. | ||
| BlockHashReadHook = func(blockNumber uint64, hash common.Hash) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use-case is to have access to the headers of hashes that are accessed by the EVM. Alternative would be if we added a GetHeaderByHash method somewhere. But getting the hash from OnOpcode is also tricky since the hash will be put on the stack after OnOpcode is invoked. |
||
| ) | ||
|
|
||
| type Hooks struct { | ||
|
|
@@ -186,6 +212,7 @@ type Hooks struct { | |
| OnBlockEnd BlockEndHook | ||
| OnSkippedBlock SkippedBlockHook | ||
| OnGenesisBlock GenesisBlockHook | ||
| OnReorg ReorgHook | ||
| OnSystemCallStart OnSystemCallStartHook | ||
| OnSystemCallEnd OnSystemCallEndHook | ||
| // State events | ||
|
|
@@ -194,6 +221,30 @@ type Hooks struct { | |
| OnCodeChange CodeChangeHook | ||
| OnStorageChange StorageChangeHook | ||
| OnLog LogHook | ||
| // State reads | ||
| OnBalanceRead BalanceReadHook | ||
| OnNonceRead NonceReadHook | ||
|
||
| OnCodeRead CodeReadHook | ||
| OnCodeSizeRead CodeSizeReadHook | ||
| OnCodeHashRead CodeHashReadHook | ||
| OnStorageRead StorageReadHook | ||
| // Block hash read | ||
| OnBlockHashRead BlockHashReadHook | ||
| } | ||
|
|
||
| // Copy creates a new Hooks instance with all implemented hooks copied from the original. | ||
| func (h *Hooks) Copy() *Hooks { | ||
|
||
| copied := &Hooks{} | ||
| srcValue := reflect.ValueOf(h).Elem() | ||
| dstValue := reflect.ValueOf(copied).Elem() | ||
|
|
||
| for i := 0; i < srcValue.NumField(); i++ { | ||
| field := srcValue.Field(i) | ||
| if !field.IsNil() { | ||
| dstValue.Field(i).Set(field) | ||
| } | ||
| } | ||
| return copied | ||
|
||
| } | ||
|
|
||
| // BalanceChangeReason is used to indicate the reason for a balance change, useful | ||
|
|
@@ -245,6 +296,9 @@ const ( | |
| // account within the same tx (captured at end of tx). | ||
| // Note it doesn't account for a self-destruct which appoints itself as recipient. | ||
| BalanceDecreaseSelfdestructBurn BalanceChangeReason = 14 | ||
|
|
||
| // BalanceChangeRevert is emitted when the balance is reverted back to a previous value due to call failure. | ||
s1na marked this conversation as resolved.
Show resolved
Hide resolved
s1na marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| BalanceChangeRevert BalanceChangeReason = 15 | ||
| ) | ||
|
|
||
| // GasChangeReason is used to indicate the reason for a gas change, useful | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here types block is very very heavy. You should at most pass headers and allow chain access to pull the blocks on demand (chain access in someconstructor, ha)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought what is the issue? it is a slice so passed by reference and the memory can be freed as soon as
OnReorgprocessing is done.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, this is annoying. So reorg in the blockchain at some point in the past used to collect blocks. Turned out that sometimes it became insanely heavy and we've switched so it operates on headers. I guess later someone refactored it back to operate on blocks again. This is an issue when you do setHead or any similar operation; of even if finality fails for a while and you have blocks reorging back and forth. It's very very bad to pull all the block in from disk IMO.
CC @holiman @rjl493456442 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I don't particularly recall switching from headers to blocks....