-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[SharovBot] fix Amsterdam signer support and BAL non-determinism #19434
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 all commits
766a434
02770f2
5229c8c
adc53f6
b45cdd2
bc63db8
b75f952
6bce0c8
7673b16
c526c0b
c84ec12
f7e2459
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 |
|---|---|---|
|
|
@@ -1551,6 +1551,20 @@ func (sdb *IntraBlockState) getStateObject(addr accounts.Address, recordRead boo | |
| obj := newObject(sdb, addr, account, account) | ||
| if code != nil { | ||
| obj.code = code | ||
| // When code is loaded from the version map (written by a prior tx), | ||
| // synchronise the stateObject's CodeHash with the actual code. | ||
| // refreshVersionedAccount above may not have updated the account's | ||
| // CodeHash because the base-reader version (sdb.Version()) makes the | ||
| // version check (cversion.TxIndex > readVersion.TxIndex) fail for | ||
| // entries from earlier transactions. Without this fix, the stale | ||
| // CodeHash causes the "revert to original" optimisation in SetCode | ||
| // to incorrectly delete code writes when clearing a delegation that | ||
| // was set by a prior transaction in the same block. | ||
| codeHash := accounts.InternCodeHash(crypto.Keccak256Hash(code)) | ||
| if codeHash != obj.data.CodeHash { | ||
| obj.data.CodeHash = codeHash | ||
| obj.original.CodeHash = codeHash | ||
| } | ||
| } | ||
| sdb.setStateObject(addr, obj) | ||
| return obj, nil | ||
|
|
@@ -2360,6 +2374,23 @@ func (sdb *IntraBlockState) VersionedWrites(checkDirty bool) VersionedWrites { | |
| // Apply entries in a given write set to StateDB. Note that this function does not change MVHashMap nor write set | ||
| // of the current StateDB. | ||
| func (sdb *IntraBlockState) ApplyVersionedWrites(writes VersionedWrites) error { | ||
| // Sort writes by (Address, Path, Key) to ensure deterministic processing | ||
| // order. VersionedWrites come from WriteSet map iteration (Go maps have | ||
| // non-deterministic order). Processing order matters because some paths | ||
| // (CodePath, SelfDestructPath) call GetOrNewStateObject which triggers a | ||
| // read from the stateReader. If a BalancePath write for the same address | ||
| // has already been processed, the state object is already loaded and no | ||
| // read occurs; otherwise an extra read is recorded. Different reads | ||
| // produce different EIP-7928 BAL hashes. | ||
|
Comment on lines
+2377
to
+2384
|
||
| sort.Slice(writes, func(i, j int) bool { | ||
| if c := writes[i].Address.Cmp(writes[j].Address); c != 0 { | ||
| return c < 0 | ||
| } | ||
| if writes[i].Path != writes[j].Path { | ||
| return writes[i].Path < writes[j].Path | ||
| } | ||
| return writes[i].Key.Cmp(writes[j].Key) < 0 | ||
| }) | ||
| for i := range writes { | ||
| path := writes[i].Path | ||
| val := writes[i].Val | ||
|
|
||
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.
Computing
Keccak256Hash(code)here can be expensive for large contract code, and this path may be hit frequently in parallel execution when prior-tx code updates are loaded from the version map. Consider using the version map’s existingCodeHashPathvalue (when present) to syncCodeHashinstead of hashing the full bytecode, falling back to hashing only if the hash entry is unavailable.