From e8731404d0893dd1d9b61b1f3d4e7c4f93396010 Mon Sep 17 00:00:00 2001 From: maskpp Date: Sun, 2 Nov 2025 22:23:17 +0800 Subject: [PATCH] get stable LogsHash result --- core/state/statedb.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/state/statedb.go b/core/state/statedb.go index b770698255..2f0ddaf7ea 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -22,6 +22,7 @@ import ( "fmt" "maps" "slices" + "sort" "sync" "sync/atomic" "time" @@ -264,6 +265,10 @@ func (s *StateDB) Logs() []*types.Log { for _, lgs := range s.logs { logs = append(logs, lgs...) } + // Due to the map iteration is not stable, we need to sort the logs by TxIndex, then the LogsHash result is stable. + sort.Slice(logs, func(i, j int) bool { + return logs[i].TxIndex < logs[j].TxIndex + }) return logs }