Skip to content

Commit 4648add

Browse files
authored
Merge pull request #2362 from CortexFoundation/dev
hashing fix
2 parents 69edca5 + 0cface1 commit 4648add

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+19131
-17920
lines changed

core/blockchain.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ var (
5757
headFinalizedBlockGauge = metrics.NewRegisteredGauge("chain/head/finalized", nil)
5858
headSafeBlockGauge = metrics.NewRegisteredGauge("chain/head/safe", nil)
5959

60-
chainInfoGauge = metrics.NewRegisteredGaugeInfo("chain/info", nil)
60+
chainInfoGauge = metrics.NewRegisteredGaugeInfo("chain/info", nil)
61+
chainMgaspsGauge = metrics.NewRegisteredGauge("chain/mgasps", nil)
6162

6263
accountReadTimer = metrics.NewRegisteredTimer("chain/account/reads", nil)
6364
accountHashTimer = metrics.NewRegisteredTimer("chain/account/hashes", nil)

core/types/block.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ import (
2525
"math/big"
2626
"reflect"
2727
"slices"
28-
"sync"
2928
"sync/atomic"
3029
"time"
3130

3231
"github.com/CortexFoundation/CortexTheseus/common"
3332
"github.com/CortexFoundation/CortexTheseus/common/hexutil"
34-
"github.com/CortexFoundation/CortexTheseus/crypto"
3533
"github.com/CortexFoundation/CortexTheseus/rlp"
3634
)
3735

@@ -167,20 +165,6 @@ func (h *Header) SanityCheck() error {
167165
return nil
168166
}
169167

170-
// hasherPool holds LegacyKeccak hashers.
171-
var hasherPool = sync.Pool{
172-
New: func() interface{} { return crypto.NewKeccakState() },
173-
}
174-
175-
func rlpHash(x any) (h common.Hash) {
176-
sha := hasherPool.Get().(crypto.KeccakState)
177-
defer hasherPool.Put(sha)
178-
sha.Reset()
179-
rlp.Encode(sha, x)
180-
sha.Read(h[:])
181-
return h
182-
}
183-
184168
// EmptyBody returns true if there is no additional 'body' to complete the header
185169
// that is: no transactions and no uncles.
186170
func (h *Header) EmptyBody() bool {

core/types/hashing.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ import (
2727
"github.com/CortexFoundation/CortexTheseus/rlp"
2828
)
2929

30+
// hasherPool holds LegacyKeccak256 hashers for rlpHash.
31+
var hasherPool = sync.Pool{
32+
New: func() interface{} { return crypto.NewKeccakState() },
33+
}
34+
3035
// encodeBufferPool holds temporary encoder buffers for DeriveSha and TX encoding.
3136
var encodeBufferPool = sync.Pool{
3237
New: func() interface{} { return new(bytes.Buffer) },
@@ -48,6 +53,16 @@ func getPooledBuffer(size uint64) ([]byte, *bytes.Buffer, error) {
4853
return b, buf, nil
4954
}
5055

56+
// rlpHash encodes x and hashes the encoded bytes.
57+
func rlpHash(x interface{}) (h common.Hash) {
58+
sha := hasherPool.Get().(crypto.KeccakState)
59+
defer hasherPool.Put(sha)
60+
sha.Reset()
61+
rlp.Encode(sha, x)
62+
sha.Read(h[:])
63+
return h
64+
}
65+
5166
// prefixedRlpHash writes the prefix into the hasher before rlp-encoding x.
5267
// It's used for typed transactions.
5368
func prefixedRlpHash(prefix byte, x interface{}) (h common.Hash) {

go.mod

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.6.1
77
github.com/CortexFoundation/inference v1.0.2-0.20230307032835-9197d586a4e8
88
github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
9-
github.com/CortexFoundation/torrentfs v1.0.69-0.20250426172722-0e7ce3e83e62
9+
github.com/CortexFoundation/torrentfs v1.0.69-0.20250506101620-39689adc3b78
1010
github.com/VictoriaMetrics/fastcache v1.12.2
1111
github.com/arsham/figurine v1.3.0
1212
github.com/aws/aws-sdk-go-v2 v1.36.3
@@ -25,7 +25,7 @@ require (
2525
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0
2626
github.com/dop251/goja v0.0.0-20250309171923-bcd7cc6bf64c
2727
github.com/ethereum/c-kzg-4844 v1.0.3
28-
github.com/ethereum/go-ethereum v1.15.10
28+
github.com/ethereum/go-ethereum v1.15.11
2929
github.com/ethereum/go-verkle v0.2.2
3030
github.com/ferranbt/fastssz v0.1.4
3131
github.com/fjl/gencodec v0.1.0
@@ -63,13 +63,13 @@ require (
6363
github.com/ucwong/color v1.10.1-0.20200624105241-fba1e010fe1e
6464
github.com/urfave/cli/v2 v2.27.6
6565
go.uber.org/automaxprocs v1.6.0
66-
golang.org/x/crypto v0.37.0
66+
golang.org/x/crypto v0.38.0
6767
golang.org/x/mobile v0.0.0-20201217150744-e6ae53a27f4f
68-
golang.org/x/sync v0.13.0
69-
golang.org/x/sys v0.32.0
70-
golang.org/x/text v0.24.0
68+
golang.org/x/sync v0.14.0
69+
golang.org/x/sys v0.33.0
70+
golang.org/x/text v0.25.0
7171
golang.org/x/time v0.11.0
72-
golang.org/x/tools v0.32.0
72+
golang.org/x/tools v0.33.0
7373
google.golang.org/protobuf v1.36.6
7474
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
7575
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce
@@ -100,8 +100,8 @@ require (
100100
github.com/anacrolix/mmsg v1.1.1 // indirect
101101
github.com/anacrolix/multiless v0.4.0 // indirect
102102
github.com/anacrolix/stm v0.5.0 // indirect
103-
github.com/anacrolix/sync v0.5.3 // indirect
104-
github.com/anacrolix/torrent v1.58.2-0.20250425050513-ddc29fedcde0 // indirect
103+
github.com/anacrolix/sync v0.5.4 // indirect
104+
github.com/anacrolix/torrent v1.58.2-0.20250506021736-1e3f1bf041ca // indirect
105105
github.com/anacrolix/upnp v0.1.4 // indirect
106106
github.com/anacrolix/utp v0.2.0 // indirect
107107
github.com/antlabs/stl v0.0.2 // indirect
@@ -132,7 +132,7 @@ require (
132132
github.com/charmbracelet/x/ansi v0.9.2 // indirect
133133
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
134134
github.com/charmbracelet/x/term v0.2.1 // indirect
135-
github.com/cockroachdb/errors v1.11.3 // indirect
135+
github.com/cockroachdb/errors v1.12.0 // indirect
136136
github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0 // indirect
137137
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 // indirect
138138
github.com/cockroachdb/redact v1.1.6 // indirect
@@ -163,7 +163,7 @@ require (
163163
github.com/google/btree v1.1.3 // indirect
164164
github.com/google/flatbuffers v25.2.10+incompatible // indirect
165165
github.com/google/go-querystring v1.1.0 // indirect
166-
github.com/google/pprof v0.0.0-20250423184734-337e5dd93bb4 // indirect
166+
github.com/google/pprof v0.0.0-20250501235452-c0086092b71a // indirect
167167
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
168168
github.com/huandu/xstrings v1.5.0 // indirect
169169
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf // indirect
@@ -244,14 +244,14 @@ require (
244244
go.opentelemetry.io/otel v1.35.0 // indirect
245245
go.opentelemetry.io/otel/metric v1.35.0 // indirect
246246
go.opentelemetry.io/otel/trace v1.35.0 // indirect
247-
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect
247+
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
248248
golang.org/x/mod v0.24.0 // indirect
249-
golang.org/x/net v0.39.0 // indirect
250-
golang.org/x/term v0.31.0 // indirect
249+
golang.org/x/net v0.40.0 // indirect
250+
golang.org/x/term v0.32.0 // indirect
251251
gopkg.in/yaml.v2 v2.4.0 // indirect
252252
gopkg.in/yaml.v3 v3.0.1 // indirect
253-
lukechampine.com/blake3 v1.4.0 // indirect
254-
modernc.org/libc v1.65.0 // indirect
253+
lukechampine.com/blake3 v1.4.1 // indirect
254+
modernc.org/libc v1.65.3 // indirect
255255
modernc.org/mathutil v1.7.1 // indirect
256256
modernc.org/memory v1.10.0 // indirect
257257
modernc.org/sqlite v1.37.0 // indirect

0 commit comments

Comments
 (0)