core/state: fix bug about getting stable LogsHash result. (#33082)

Because the map iteration is unstable, we need to order logs by tx index
and keep the same order with receipts and their logs, so we can still
get the same `LogsHash` across runs.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
This commit is contained in:
maskpp 2025-11-07 11:00:20 +08:00 committed by GitHub
parent 15ff378a89
commit 6420ee3592
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22,6 +22,7 @@ import (
"fmt"
"maps"
"slices"
"sort"
"sync"
"sync/atomic"
"time"
@ -264,6 +265,9 @@ func (s *StateDB) Logs() []*types.Log {
for _, lgs := range s.logs {
logs = append(logs, lgs...)
}
sort.Slice(logs, func(i, j int) bool {
return logs[i].Index < logs[j].Index
})
return logs
}