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 Alvarez
parent 873432c4e3
commit e72b1457ed

View file

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