Account creations can happen before a transaction starts

This commit is contained in:
Matthieu Vachon 2023-12-05 10:32:00 -05:00
parent c36b44073f
commit a7f50134bd

View file

@ -761,6 +761,11 @@ func (f *Firehose) OnNewAccount(a common.Address) {
// transaction active. In that case, we do not track the account creation because // transaction active. In that case, we do not track the account creation because
// the "old" Firehose didn't but mainly because we don't have `AccountCreation` at // the "old" Firehose didn't but mainly because we don't have `AccountCreation` at
// the block level so what can we do... // the block level so what can we do...
// This fix was applied on Erigon branch after chain's comparison. I need to check
// with what the old patch was doing to write a meaningful comment here and ensure
// they got the logic right
f.blockOrdinal.Next()
return return
} }
@ -768,11 +773,18 @@ func (f *Firehose) OnNewAccount(a common.Address) {
return return
} }
activeCall := f.callStack.Peek() accountCreation := &pbeth.AccountCreation{
activeCall.AccountCreations = append(activeCall.AccountCreations, &pbeth.AccountCreation{
Account: a.Bytes(), Account: a.Bytes(),
Ordinal: f.blockOrdinal.Next(), Ordinal: f.blockOrdinal.Next(),
}) }
activeCall := f.callStack.Peek()
if activeCall == nil {
f.deferredCallState.accountCreations = append(f.deferredCallState.accountCreations, accountCreation)
return
}
activeCall.AccountCreations = append(activeCall.AccountCreations, accountCreation)
} }
func (f *Firehose) OnGasChange(old, new uint64, reason vm.GasChangeReason) { func (f *Firehose) OnGasChange(old, new uint64, reason vm.GasChangeReason) {
@ -1347,9 +1359,10 @@ func (s *CallStack) Peek() *pbeth.Call {
// that is recorded before the Call has been started. This happens on the "starting" // that is recorded before the Call has been started. This happens on the "starting"
// portion of the call/created. // portion of the call/created.
type DeferredCallState struct { type DeferredCallState struct {
balanceChanges []*pbeth.BalanceChange accountCreations []*pbeth.AccountCreation
gasChanges []*pbeth.GasChange balanceChanges []*pbeth.BalanceChange
nonceChanges []*pbeth.NonceChange gasChanges []*pbeth.GasChange
nonceChanges []*pbeth.NonceChange
} }
func NewDeferredCallState() *DeferredCallState { func NewDeferredCallState() *DeferredCallState {
@ -1366,6 +1379,7 @@ func (d *DeferredCallState) MaybePopulateCallAndReset(source string, call *pbeth
} }
// We must happen because it's populated at beginning of the call as well as at the very end // We must happen because it's populated at beginning of the call as well as at the very end
call.AccountCreations = append(call.AccountCreations, d.accountCreations...)
call.BalanceChanges = append(call.BalanceChanges, d.balanceChanges...) call.BalanceChanges = append(call.BalanceChanges, d.balanceChanges...)
call.GasChanges = append(call.GasChanges, d.gasChanges...) call.GasChanges = append(call.GasChanges, d.gasChanges...)
call.NonceChanges = append(call.NonceChanges, d.nonceChanges...) call.NonceChanges = append(call.NonceChanges, d.nonceChanges...)
@ -1376,10 +1390,11 @@ func (d *DeferredCallState) MaybePopulateCallAndReset(source string, call *pbeth
} }
func (d *DeferredCallState) IsEmpty() bool { func (d *DeferredCallState) IsEmpty() bool {
return len(d.balanceChanges) == 0 && len(d.gasChanges) == 0 && len(d.nonceChanges) == 0 return len(d.accountCreations) == 0 && len(d.balanceChanges) == 0 && len(d.gasChanges) == 0 && len(d.nonceChanges) == 0
} }
func (d *DeferredCallState) Reset() { func (d *DeferredCallState) Reset() {
d.accountCreations = nil
d.balanceChanges = nil d.balanceChanges = nil
d.gasChanges = nil d.gasChanges = nil
d.nonceChanges = nil d.nonceChanges = nil