-
Notifications
You must be signed in to change notification settings - Fork 20.3k
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
core,eth: implement tx-level hooks for tracers #24510
Merged
+83
−40
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5138feb
core,eth: add empty tx logger hooks
s1na cd7d184
core,eth: add initial and remaining gas to tx hooks
s1na 45e6a7b
store tx gasLimit in js tracer
s1na d7fc0aa
use gasLimit to compute intrinsic cost for js tracer
s1na 48937ff
re-use rules in transitiondb
s1na cbb23c8
rm logs
s1na a76d5ac
rm logs
s1na 6cfef9f
Mv some fields from Start to TxStart
s1na 02b4741
simplify sender lookup in prestate tracer
s1na d3ae492
mv env to TxStart
s1na 34303bf
Revert "mv env to TxStart"
s1na 47913aa
Revert "simplify sender lookup in prestate tracer"
s1na 507f6b4
Revert "Mv some fields from Start to TxStart"
s1na a59d257
fix intrinsic gas for prestate tracer
s1na 3f09581
add comments
s1na b7d6ba0
refactor
s1na a167f7e
fix test case
s1na 5bffbc0
simplify consumedGas calc in prestate tracer
s1na File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ import ( | |
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/core" | ||
"github.com/ethereum/go-ethereum/core/vm" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/eth/tracers" | ||
|
@@ -47,6 +46,7 @@ type prestateTracer struct { | |
prestate prestate | ||
create bool | ||
to common.Address | ||
gasLimit uint64 // Amount of gas bought for the whole tx | ||
interrupt uint32 // Atomic flag to signal execution interruption | ||
reason error // Textual reason for the interruption | ||
} | ||
|
@@ -63,14 +63,6 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo | |
t.create = create | ||
t.to = to | ||
|
||
// Compute intrinsic gas | ||
isHomestead := env.ChainConfig().IsHomestead(env.Context.BlockNumber) | ||
isIstanbul := env.ChainConfig().IsIstanbul(env.Context.BlockNumber) | ||
intrinsicGas, err := core.IntrinsicGas(input, nil, create, isHomestead, isIstanbul) | ||
if err != nil { | ||
return | ||
} | ||
|
||
t.lookupAccount(from) | ||
t.lookupAccount(to) | ||
|
||
|
@@ -82,6 +74,7 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo | |
// The sender balance is after reducing: value, gasLimit, intrinsicGas. | ||
// We need to re-add them to get the pre-tx balance. | ||
fromBal := hexutil.MustDecodeBig(t.prestate[from].Balance) | ||
intrinsicGas := t.gasLimit - gas | ||
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 consumedGas is always equivalent to 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. Right, I was doing |
||
gasPrice := env.TxContext.GasPrice | ||
consumedGas := new(big.Int).Mul( | ||
gasPrice, | ||
|
@@ -145,6 +138,12 @@ func (t *prestateTracer) CaptureEnter(typ vm.OpCode, from common.Address, to com | |
func (t *prestateTracer) CaptureExit(output []byte, gasUsed uint64, err error) { | ||
} | ||
|
||
func (t *prestateTracer) CaptureTxStart(gasLimit uint64) { | ||
t.gasLimit = gasLimit | ||
} | ||
|
||
func (t *prestateTracer) CaptureTxEnd(restGas uint64) {} | ||
|
||
// GetResult returns the json-encoded nested list of call traces, and any | ||
// error arising from the encoding or forceful termination (via `Stop`). | ||
func (t *prestateTracer) GetResult() (json.RawMessage, error) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Well, I guess one thing though. A tracer/logger which implements this, but not others -- wouldn't they also want to tx hash and index?
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 had a look and the right now the only tracer taking this info is jsTracer and that through its constructor (which makes it a bit special).
Do you think it'll be useful to add this info to the logger interface? One advantage I can see it would make the js tracer a bit more standard.
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.
Well, I do think it would "make sense" to include it here and now: if we're adding tx level hooks, we should also provide the basic tx info. However, I now looked into it a bit more, and the hash/index is not information which we have readily available in
state_transition.go
at this point, so maybe it's more hassle than it's worth... ?