Skip to content

Commit ab86fbf

Browse files
authored
Merge pull request #2381 from CortexFoundation/dev
avoid copying blobs for marshaling
2 parents 06b53fe + 0238972 commit ab86fbf

77 files changed

Lines changed: 18543 additions & 573 deletions

Some content is hidden

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

crypto/kzg4844/kzg4844.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (b *Blob) UnmarshalJSON(input []byte) error {
4545
}
4646

4747
// MarshalText returns the hex representation of b.
48-
func (b Blob) MarshalText() ([]byte, error) {
48+
func (b *Blob) MarshalText() ([]byte, error) {
4949
return hexutil.Bytes(b[:]).MarshalText()
5050
}
5151

ctxc/backend.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package ctxc
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"math/big"
2324
"runtime"
@@ -61,6 +62,26 @@ import (
6162
"github.com/CortexFoundation/torrentfs"
6263
)
6364

65+
const (
66+
// This is the fairness knob for the discovery mixer. When looking for peers, we'll
67+
// wait this long for a single source of candidates before moving on and trying other
68+
// sources. If this timeout expires, the source will be skipped in this round, but it
69+
// will continue to fetch in the background and will have a chance with a new timeout
70+
// in the next rounds, giving it overall more time but a proportionally smaller share.
71+
// We expect a normal source to produce ~10 candidates per second.
72+
discmixTimeout = 100 * time.Millisecond
73+
74+
// discoveryPrefetchBuffer is the number of peers to pre-fetch from a discovery
75+
// source. It is useful to avoid the negative effects of potential longer timeouts
76+
// in the discovery, keeping dial progress while waiting for the next batch of
77+
// candidates.
78+
discoveryPrefetchBuffer = 32
79+
80+
// maxParallelENRRequests is the maximum number of parallel ENR requests that can be
81+
// performed by a disc/v4 source.
82+
maxParallelENRRequests = 16
83+
)
84+
6485
// Cortex implements the Cortex full node service.
6586
type Cortex struct {
6687
config *Config
@@ -168,7 +189,7 @@ func New(stack *node.Node, config *Config) (*Cortex, error) {
168189
bloomRequests: make(chan chan *bloombits.Retrieval),
169190
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms),
170191
p2pServer: stack.Server(),
171-
discmix: enode.NewFairMix(0),
192+
discmix: enode.NewFairMix(discmixTimeout),
172193
shutdownTracker: shutdowncheck.NewShutdownTracker(chainDb),
173194
}
174195

@@ -710,10 +731,27 @@ func (s *Cortex) setupDiscovery() error {
710731
s.discmix.AddSource(iter)
711732
}
712733

734+
// Add DHT nodes from discv4.
735+
if s.p2pServer.DiscoveryV4() != nil {
736+
iter := s.p2pServer.DiscoveryV4().RandomNodes()
737+
resolverFunc := func(ctx context.Context, enr *enode.Node) *enode.Node {
738+
// RequestENR does not yet support context. It will simply time out.
739+
// If the ENR can't be resolved, RequestENR will return nil. We don't
740+
// care about the specific error here, so we ignore it.
741+
nn, _ := s.p2pServer.DiscoveryV4().RequestENR(enr)
742+
return nn
743+
}
744+
iter = enode.AsyncFilter(iter, resolverFunc, maxParallelENRRequests)
745+
iter = enode.Filter(iter, NewNodeFilter(s.blockchain))
746+
iter = enode.NewBufferIter(iter, discoveryPrefetchBuffer)
747+
s.discmix.AddSource(iter)
748+
}
749+
713750
// Add DHT nodes from discv5.
714751
if s.p2pServer.DiscoveryV5() != nil {
715752
filter := NewNodeFilter(s.blockchain)
716753
iter := enode.Filter(s.p2pServer.DiscoveryV5().RandomNodes(), filter)
754+
iter = enode.NewBufferIter(iter, discoveryPrefetchBuffer)
717755
s.discmix.AddSource(iter)
718756
}
719757

go.mod

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
module github.com/CortexFoundation/CortexTheseus
22

3-
go 1.24.3
3+
go 1.24.4
44

55
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.20250515103356-dcc757b78082
9+
github.com/CortexFoundation/torrentfs v1.0.69-0.20250607180142-c06c58e629b5
1010
github.com/VictoriaMetrics/fastcache v1.12.5
1111
github.com/arsham/figurine v1.3.0
1212
github.com/aws/aws-sdk-go-v2 v1.36.3
13-
github.com/aws/aws-sdk-go-v2/config v1.29.14
14-
github.com/aws/aws-sdk-go-v2/credentials v1.17.67
15-
github.com/aws/aws-sdk-go-v2/service/route53 v1.51.1
13+
github.com/aws/aws-sdk-go-v2/config v1.29.15
14+
github.com/aws/aws-sdk-go-v2/credentials v1.17.68
15+
github.com/aws/aws-sdk-go-v2/service/route53 v1.52.0
1616
github.com/cespare/cp v1.1.1
1717
github.com/charmbracelet/bubbletea v1.3.5
1818
github.com/cloudflare/cloudflare-go v0.115.0
@@ -62,13 +62,13 @@ require (
6262
github.com/ucwong/color v1.10.1-0.20200624105241-fba1e010fe1e
6363
github.com/urfave/cli/v2 v2.27.6
6464
go.uber.org/automaxprocs v1.6.0
65-
golang.org/x/crypto v0.38.0
65+
golang.org/x/crypto v0.39.0
6666
golang.org/x/mobile v0.0.0-20201217150744-e6ae53a27f4f
67-
golang.org/x/sync v0.14.0
67+
golang.org/x/sync v0.15.0
6868
golang.org/x/sys v0.33.0
69-
golang.org/x/text v0.25.0
70-
golang.org/x/time v0.11.0
71-
golang.org/x/tools v0.33.0
69+
golang.org/x/text v0.26.0
70+
golang.org/x/time v0.12.0
71+
golang.org/x/tools v0.34.0
7272
google.golang.org/protobuf v1.36.6
7373
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
7474
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce
@@ -115,7 +115,7 @@ require (
115115
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 // indirect
116116
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 // indirect
117117
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 // indirect
118-
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19 // indirect
118+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.20 // indirect
119119
github.com/aws/smithy-go v1.22.3 // indirect
120120
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
121121
github.com/bahlo/generic-list-go v0.2.0 // indirect
@@ -140,7 +140,7 @@ require (
140140
github.com/consensys/bavard v0.1.30 // indirect
141141
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
142142
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
143-
github.com/dgraph-io/badger/v4 v4.7.1-0.20250514104548-674c0a729e03 // indirect
143+
github.com/dgraph-io/badger/v4 v4.7.1-0.20250601174320-4f557a74bbf7 // indirect
144144
github.com/dgraph-io/ristretto/v2 v2.2.0 // indirect
145145
github.com/dlclark/regexp2 v1.11.5 // indirect
146146
github.com/dustin/go-humanize v1.0.1 // 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-20250602020802-c6617b811d0e // indirect
166+
github.com/google/pprof v0.0.0-20250607225305-033d6d78b36a // 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
@@ -189,7 +189,7 @@ require (
189189
github.com/nutsdb/nutsdb v1.0.4 // indirect
190190
github.com/oapi-codegen/runtime v1.1.1 // indirect
191191
github.com/olekukonko/errors v1.1.0 // indirect
192-
github.com/olekukonko/ll v0.0.8 // indirect
192+
github.com/olekukonko/ll v0.0.9 // indirect
193193
github.com/otiai10/copy v1.14.1 // indirect
194194
github.com/otiai10/mint v1.6.3 // indirect
195195
github.com/pion/datachannel v1.5.10 // indirect
@@ -201,10 +201,10 @@ require (
201201
github.com/pion/mdns/v2 v2.0.7 // indirect
202202
github.com/pion/randutil v0.1.0 // indirect
203203
github.com/pion/rtcp v1.2.15 // indirect
204-
github.com/pion/rtp v1.8.17 // indirect
204+
github.com/pion/rtp v1.8.18 // indirect
205205
github.com/pion/sctp v1.8.39 // indirect
206206
github.com/pion/sdp/v3 v3.0.13 // indirect
207-
github.com/pion/srtp/v3 v3.0.4 // indirect
207+
github.com/pion/srtp/v3 v3.0.5 // indirect
208208
github.com/pion/stun/v3 v3.0.0 // indirect
209209
github.com/pion/transport/v2 v2.2.10 // indirect
210210
github.com/pion/transport/v3 v3.0.7 // indirect
@@ -225,14 +225,14 @@ require (
225225
github.com/russross/blackfriday/v2 v2.1.0 // indirect
226226
github.com/spaolacci/murmur3 v1.1.0 // indirect
227227
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 // indirect
228-
github.com/supranational/blst v0.3.14 // indirect
228+
github.com/supranational/blst v0.3.15 // indirect
229229
github.com/tidwall/btree v1.7.0 // indirect
230230
github.com/tidwall/hashmap v1.8.1 // indirect
231231
github.com/tklauser/go-sysconf v0.3.15 // indirect
232232
github.com/tklauser/numcpus v0.10.0 // indirect
233233
github.com/ucwong/filecache v1.0.6-0.20230405163841-810d53ced4bd // indirect
234234
github.com/ucwong/go-ttlmap v1.0.2-0.20221020173635-331e7ddde2bb // indirect
235-
github.com/ucwong/golang-kv v1.0.24-0.20250515102819-a6b899554118 // indirect
235+
github.com/ucwong/golang-kv v1.0.24-0.20250606215932-9b6cb1d9814d // indirect
236236
github.com/ucwong/shard v1.0.1-0.20250426172507-f1db2901f62c // indirect
237237
github.com/wlynxg/anet v0.0.5 // indirect
238238
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
@@ -246,14 +246,14 @@ require (
246246
go.opentelemetry.io/otel v1.36.0 // indirect
247247
go.opentelemetry.io/otel/metric v1.36.0 // indirect
248248
go.opentelemetry.io/otel/trace v1.36.0 // indirect
249-
golang.org/x/exp v0.0.0-20250531010427-b6e5de432a8b // indirect
250-
golang.org/x/mod v0.24.0 // indirect
251-
golang.org/x/net v0.40.0 // indirect
249+
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 // indirect
250+
golang.org/x/mod v0.25.0 // indirect
251+
golang.org/x/net v0.41.0 // indirect
252252
golang.org/x/term v0.32.0 // indirect
253253
gopkg.in/yaml.v2 v2.4.0 // indirect
254254
gopkg.in/yaml.v3 v3.0.1 // indirect
255255
lukechampine.com/blake3 v1.4.1 // indirect
256-
modernc.org/libc v1.65.8 // indirect
256+
modernc.org/libc v1.65.10 // indirect
257257
modernc.org/mathutil v1.7.1 // indirect
258258
modernc.org/memory v1.11.0 // indirect
259259
modernc.org/sqlite v1.37.1 // indirect

0 commit comments

Comments
 (0)