-
Notifications
You must be signed in to change notification settings - Fork 107
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
Utilize BalanceChangeReason in tracing #375
base: master
Are you sure you want to change the base?
Conversation
…e with balanceChangeReason
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.
LGTM
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.
One change request, two others are just questions.
eth/tracers/native/call.go
Outdated
@@ -50,6 +50,7 @@ type callFrame struct { | |||
// Arbitrum: we add these here due to the tracer returning the top frame | |||
BeforeEVMTransfers *[]arbitrumTransfer `json:"beforeEVMTransfers,omitempty"` | |||
AfterEVMTransfers *[]arbitrumTransfer `json:"afterEVMTransfers,omitempty"` | |||
BalanceChanges *[]balanceChange `json:"balanceChanges,omitempty"` |
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.
what's the motivation for adding these here?
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 added balanceChanges
right after beforeEVMTransfers
and afterEVMTransfers
to show all the balance changes step-by-step that happened when a tx gets executed, leading to a trace something like
{
"beforeEVMTransfers": [
{
"purpose": "purchase of gas for execution of a transaction",
"from": "0x26E554a8acF9003b83495c7f45F06edCB803d4e3",
"to": null,
"value": "0x0"
}
],
"afterEVMTransfers": [
{
"purpose": "refund for unused gas at the end of execution",
"from": null,
"to": "0x26E554a8acF9003b83495c7f45F06edCB803d4e3",
"value": "0x0"
},
{
"purpose": "fee collection by network fee account",
"from": null,
"to": "0x0000000000000000000000000000000000000000",
"value": "0x6260d337500"
},
{
"purpose": "fee collection for L1 posting",
"from": null,
"to": "0xa4B00000000000000000000000000000000000F6",
"value": "0x68e6df69800"
}
],
"balanceChanges": [
{
"addr": "0x26E554a8acF9003b83495c7f45F06edCB803d4e3",
"prev": "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7",
"new": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffc46535f7",
"reason": "balance decrease due to transfer via a call"
},
{
"addr": "0x0000000000000000000000000000000000000064",
"prev": "0x0",
"new": "0x3b9aca00",
"reason": "balance increase due to transfer via a call"
},
{
"addr": "0x0000000000000000000000000000000000000064",
"prev": "0x3b9aca00",
"new": "0x0",
"reason": "balance decrease due to withdrawal to L1"
},
{
"addr": "0x0000000000000000000000000000000000000000",
"prev": "0x0",
"new": "0x6260d337500",
"reason": "balance increase due to fee collection by network fee account"
},
{
"addr": "0xa4B00000000000000000000000000000000000F6",
"prev": "0x0",
"new": "0x68e6df69800",
"reason": "balance increase due to fee collection for L1 posting"
}
],
...
}
Let me know if I got it wrong
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 don't think it's "wrong", but we should try to only change geth code when there is a strong customer-affecting motivation to do so, and I don't think there is one here.
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.
Oh got it! I've reverted the changes
core/tracing/hooks.go
Outdated
) | ||
|
||
func (b BalanceChangeReason) String(prev, new *big.Int) string { |
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.
What's the motivation for the new strings? Are they formatted after anything 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.
The thing is geth itself doesn't use BalanceChangeReason
type for anything meaningful (as of 1.14.0) i.e in any of the tracing code, but gives us the freedom to decide how and where we use it.
They aren't formatted after anything standard but gives the reason for the balance change itself, which I thought we could use in tracing, let me know if I got it wrong.
For example geth's current master uses BalanceChangeReason
this way https://github.com/ethereum/go-ethereum/blob/6d3d252a5ece0687dcaaf197e0bfc03466161ff1/eth/tracers/live/supply.go#L191-L208
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.
earlier in the purpose
field of beforeEVMTransfers
and afterEVMTransfers
we had single word strings like feeCollection
, tip
etc.. but now we could have a more descriptive reasons with the String() impl like in the above comment
...
...{ "beforeEVMTransfers": [ { "purpose": "purchase of gas for execution of a transaction", "from": "0x26E554a8acF9003b83495c7f45F06edCB803d4e3", "to": null, "value": "0x0" } ], "afterEVMTransfers": [ { "purpose": "refund for unused gas at the end of execution", "from": null, "to": "0x26E554a8acF9003b83495c7f45F06edCB803d4e3", "value": "0x0" },
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 am not sure, but I guess someone is already parsing the exiting short srings.
If they are - this change would hurt them, and I rather avoid it.
We could still have a "String" function but have it return the old string to avoid compatibility errors.
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.
Changed the String()
to be backwards compatible
This PR enables usage of
BalanceChangeReason
type in tracing, such as inCaptureArbitrumTransfer
and also to trace balance changes themself usingjsTracer
.We replace the string in
purpose
field of bothbeforeEVMTransfers
andafterEVMTransfers
with the reasoning derived fromtracing.BalanceChangeReason
, the strings themself are kept the same to maintain backwards compatibility.We added following balanceChangeReasons-
Corresponding nitro PR- OffchainLabs/nitro#2789
Part of NIT-2943