-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0001-expose-block-commitments-api.patch
More file actions
648 lines (619 loc) · 22.8 KB
/
Copy path0001-expose-block-commitments-api.patch
File metadata and controls
648 lines (619 loc) · 22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
diff --git a/op-node/api/sequencer_commitment.go b/op-node/api/sequencer_commitment.go
new file mode 100644
index 0000000..d572294
--- /dev/null
+++ b/op-node/api/sequencer_commitment.go
@@ -0,0 +1,131 @@
+package api
+
+import (
+ "context"
+ "encoding/hex"
+ "encoding/json"
+ "fmt"
+ "net/http"
+
+ "github.com/ethereum/go-ethereum/log"
+)
+
+// Service defines the interface that the API layer uses to interact with the node
+type Service interface {
+ GetSequencerCommitment(ctx context.Context) (signatureBytes []byte, dataBytes []byte, err error)
+}
+
+// GossipAPI defines the RPC methods for interacting with gossip data
+type GossipAPI interface {
+ GetSequencerCommitment(ctx context.Context) (SequencerCommitment, error)
+ HTTPHandler() http.HandlerFunc
+}
+
+// SequencerCommitment matches the Rust struct format exactly
+type SequencerCommitment struct {
+ Data string `json:"data"` // "0x" prefixed hex string
+ Signature Signature `json:"signature"` // Changed to use hex strings
+}
+
+// Signature matches the Rust Signature struct format
+type Signature struct {
+ R string `json:"r"` // "0x" prefixed hex string
+ S string `json:"s"` // "0x" prefixed hex string
+ YParity string `json:"yParity"` // "0x0" or "0x1"
+}
+
+type gossipAPI struct {
+ service Service
+ log log.Logger
+}
+
+func NewGossipAPI(service Service) GossipAPI {
+ return &gossipAPI{
+ service: service,
+ log: log.New("api", "gossip"),
+ }
+}
+
+// GetSequencerCommitment implements the RPC method
+func (g *gossipAPI) GetSequencerCommitment(ctx context.Context) (SequencerCommitment, error) {
+ g.log.Info("GetSequencerCommitment called")
+ sig, data, err := g.service.GetSequencerCommitment(ctx)
+ if err != nil {
+ g.log.Error("Error getting sequencer commitment", "err", err)
+ return SequencerCommitment{}, err
+ }
+
+ g.log.Debug("Retrieved sequencer commitment",
+ "sig_len", len(sig),
+ "data_len", len(data))
+
+ // Convert data bytes to hex string - this is the full payload, not just a hash
+ dataHex := "0x" + hex.EncodeToString(data)
+
+ // Default values for empty signature
+ r := "0x"
+ s := "0x"
+ yParity := "0x0"
+
+ // Parse signature components (65 bytes: r[32] + s[32] + v[1]) if available
+ if len(sig) >= 65 {
+ r = "0x" + hex.EncodeToString(sig[:32])
+ s = "0x" + hex.EncodeToString(sig[32:64])
+ yParity = "0x" + hex.EncodeToString([]byte{sig[64]}) // v is the last byte
+ }
+
+ result := SequencerCommitment{
+ Data: dataHex,
+ Signature: Signature{
+ R: r,
+ S: s,
+ YParity: yParity,
+ },
+ }
+
+ g.log.Debug("Returning sequencer commitment",
+ "data_len", len(dataHex),
+ "r", result.Signature.R,
+ "s", result.Signature.S,
+ "v", result.Signature.YParity)
+
+ return result, nil
+}
+
+// HTTPHandler returns an http.HandlerFunc that handles the GetSequencerCommitment endpoint
+func (g *gossipAPI) HTTPHandler() http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ g.log.Info("Sequencer commitment HTTP endpoint called", "path", r.URL.Path)
+
+ if r.Method != http.MethodGet {
+ g.log.Error("Method not allowed", "method", r.Method)
+ http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
+ return
+ }
+
+ commitment, err := g.GetSequencerCommitment(r.Context())
+ if err != nil {
+ g.log.Error("Error getting sequencer commitment", "err", err)
+ http.Error(w, fmt.Sprintf("Error getting sequencer commitment: %v", err), http.StatusInternalServerError)
+ return
+ }
+
+ // Check if both signature and data are empty
+ if len(commitment.Data) <= 2 && commitment.Signature.R == "0x" && commitment.Signature.S == "0x" { // "0x" is the minimum length for hex values
+ g.log.Warn("No sequencer commitment data available yet")
+ http.Error(w, "No sequencer commitment data available yet", http.StatusNotFound)
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ responseData, err := json.Marshal(commitment)
+ if err != nil {
+ g.log.Error("Error marshaling commitment response", "err", err)
+ http.Error(w, "Internal server error", http.StatusInternalServerError)
+ return
+ }
+
+ g.log.Info("Returning sequencer commitment response", "length", len(responseData))
+ w.Write(responseData)
+ }
+}
diff --git a/op-node/config/config.go b/op-node/config/config.go
index 4aaa32c..e01c1fe 100644
--- a/op-node/config/config.go
+++ b/op-node/config/config.go
@@ -90,6 +90,9 @@ type Config struct {
// Experimental. Enables new opstack RPC namespace. Used by op-test-sequencer.
ExperimentalOPStackAPI bool
+
+ // GossipOnly mode runs only P2P gossip and exposes block commitments API, without requiring L2 engine
+ GossipOnly bool
}
// ConductorRPCFunc retrieves the endpoint. The RPC may not immediately be available.
@@ -120,8 +123,11 @@ func (cfg *Config) Check() error {
if err := cfg.L1.Check(); err != nil {
return fmt.Errorf("l1 endpoint config error: %w", err)
}
- if err := cfg.L2.Check(); err != nil {
- return fmt.Errorf("l2 endpoint config error: %w", err)
+ // Skip L2 check in gossip-only mode
+ if !cfg.GossipOnly {
+ if err := cfg.L2.Check(); err != nil {
+ return fmt.Errorf("l2 endpoint config error: %w", err)
+ }
}
if cfg.L1ChainConfig == nil {
return fmt.Errorf("missing L1ChainConfig")
diff --git a/op-node/flags/flags.go b/op-node/flags/flags.go
index 37d9b42..836cfd7 100644
--- a/op-node/flags/flags.go
+++ b/op-node/flags/flags.go
@@ -452,6 +452,13 @@ var (
EnvVars: prefixEnvVars("EXPERIMENTAL_SEQUENCER_API"),
Category: MiscCategory,
}
+ GossipOnlyMode = &cli.BoolFlag{
+ Name: "gossip-only",
+ Usage: "Run in gossip-only mode: only listen to P2P gossip and expose block commitments API, without requiring an L2 execution engine",
+ Required: false,
+ EnvVars: prefixEnvVars("GOSSIP_ONLY"),
+ Category: MiscCategory,
+ }
)
var requiredFlags = []cli.Flag{
@@ -508,6 +515,7 @@ var optionalFlags = []cli.Flag{
InteropDependencySet,
IgnoreMissingPectraBlobSchedule,
ExperimentalOPStackAPI,
+ GossipOnlyMode,
}
var DeprecatedFlags = []cli.Flag{
@@ -542,9 +550,15 @@ func init() {
}
func CheckRequired(ctx cliiface.Context) error {
+ gossipOnly := ctx.Bool(GossipOnlyMode.Name)
for _, f := range requiredFlags {
- if !ctx.IsSet(f.Names()[0]) {
- return fmt.Errorf("flag %s is required", f.Names()[0])
+ flagName := f.Names()[0]
+ // In gossip-only mode, L2 engine flags are not required
+ if gossipOnly && (flagName == L2EngineAddr.Name || flagName == L2EngineJWTSecret.Name) {
+ continue
+ }
+ if !ctx.IsSet(flagName) {
+ return fmt.Errorf("flag %s is required", flagName)
}
}
return opflags.CheckRequiredXor(ctx)
diff --git a/op-node/node/node.go b/op-node/node/node.go
index fadc303..5770b0b 100644
--- a/op-node/node/node.go
+++ b/op-node/node/node.go
@@ -11,6 +11,7 @@ import (
"time"
"github.com/hashicorp/go-multierror"
+ "github.com/libp2p/go-libp2p/core/peer"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
@@ -44,10 +45,23 @@ import (
opsigner "github.com/ethereum-optimism/optimism/op-service/signer"
"github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/prometheus/client_golang/prometheus"
+
+ "github.com/ethereum-optimism/optimism/op-node/api"
)
var ErrAlreadyClosed = errors.New("node is already closed")
+// noOpGossipIn is a no-op implementation of p2p.GossipIn for gossip-only mode
+// It receives gossip messages but does not process them (commitments are stored in the gossip layer)
+type noOpGossipIn struct {
+ log log.Logger
+}
+
+func (n *noOpGossipIn) OnUnsafeL2Payload(ctx context.Context, from peer.ID, msg *eth.ExecutionPayloadEnvelope) error {
+ n.log.Debug("Received unsafe payload in gossip-only mode (no-op)", "block", msg.ExecutionPayload.BlockNumber, "from", from)
+ return nil
+}
+
// L1Client is the interface that op-node uses to interact with L1.
// This allows wrapped or mocked clients to be used
type L1Client interface {
@@ -242,17 +256,26 @@ func (n *OpNode) init(ctx context.Context, cfg *config.Config, overrides Initial
}
// initL2 may use side effects to register interop subsystem to the node.EventSystem
- n.l2Source, n.interopSys, n.l2Driver, n.safeDB, err = initL2(ctx, cfg, n)
- if err != nil {
- return fmt.Errorf("failed to init L2: %w", err)
+ // Skip L2 initialization in gossip-only mode
+ if !cfg.GossipOnly {
+ n.l2Source, n.interopSys, n.l2Driver, n.safeDB, err = initL2(ctx, cfg, n)
+ if err != nil {
+ return fmt.Errorf("failed to init L2: %w", err)
+ }
+ } else {
+ n.log.Info("Running in gossip-only mode, skipping L2 engine initialization")
}
- n.l1HeadsSub, n.l1SafeSub, n.l1FinalizedSub, err = initL1Handlers(cfg, n)
- if err != nil {
- return fmt.Errorf("failed to init L1 Source: %w", err)
+ // Skip L1 handlers in gossip-only mode (but still need runtime config for P2P sequencer address)
+ if !cfg.GossipOnly {
+ n.l1HeadsSub, n.l1SafeSub, n.l1FinalizedSub, err = initL1Handlers(cfg, n)
+ if err != nil {
+ return fmt.Errorf("failed to init L1 Source: %w", err)
+ }
}
// initRuntimeConfig relies on side effects to set the runCfg, node.halted and call node.cancel if needed
+ // We need this even in gossip-only mode for P2P sequencer address validation
if err := initRuntimeConfig(ctx, cfg, n); err != nil {
return fmt.Errorf("failed to init the runtime config: %w", err)
}
@@ -611,6 +634,11 @@ func initL2(ctx context.Context, cfg *config.Config, node *OpNode) (*sources.Eng
}
func initRPCServer(cfg *config.Config, node *OpNode) (*oprpc.Server, error) {
+ // In gossip-only mode, create a minimal RPC server with only the commitment API
+ if cfg.GossipOnly {
+ return initGossipOnlyRPCServer(cfg, node)
+ }
+
server := newRPCServer(&cfg.RPC, &cfg.Rollup, cfg.DependencySet,
node.l2Source.L2Client, node.l2Driver, node.safeDB,
node.log, node.metrics, node.appVersion)
@@ -619,6 +647,12 @@ func initRPCServer(cfg *config.Config, node *OpNode) (*oprpc.Server, error) {
// which wraps the Handler and panics if the API can't be added.
panic(fmt.Errorf("invalid API: %w", err))
}
+
+ // Add sequencer commitment endpoint if P2P is enabled
+ if p2pNode := node.getP2PNodeIfEnabled(); p2pNode != nil {
+ addSequencerCommitmentEndpoint(server, node, node.log)
+ }
+
node.log.Info("Starting JSON-RPC server")
if err := server.Start(); err != nil {
return nil, fmt.Errorf("unable to start RPC server: %w", err)
@@ -710,12 +744,24 @@ func initP2P(cfg *config.Config, node *OpNode) (*p2p.NodeP2P, error) {
panic("p2p node already initialized")
}
if node.p2pEnabled() {
- if node.l2Driver.SyncDeriver == nil {
- panic("SyncDeriver must be initialized")
+ var rec p2p.GossipIn
+ var l2Chain p2p.L2Chain
+
+ if cfg.GossipOnly {
+ // In gossip-only mode, use a no-op receiver (commitments are stored in gossip layer)
+ rec = &noOpGossipIn{log: node.log}
+ l2Chain = nil
+ node.log.Info("Initializing P2P in gossip-only mode")
+ } else {
+ if node.l2Driver.SyncDeriver == nil {
+ panic("SyncDeriver must be initialized")
+ }
+ // embed syncDeriver and tracer(optional) to the blockReceiver to handle unsafe payloads via p2p
+ rec = p2p.NewBlockReceiver(node.log, node.metrics, node.l2Driver.SyncDeriver, node.cfg.Tracer)
+ l2Chain = node.l2Source
}
- // embed syncDeriver and tracer(optional) to the blockReceiver to handle unsafe payloads via p2p
- rec := p2p.NewBlockReceiver(node.log, node.metrics, node.l2Driver.SyncDeriver, node.cfg.Tracer)
- p2pNode, err := p2p.NewNodeP2P(node.resourcesCtx, &cfg.Rollup, node.log, cfg.P2P, rec, node.l2Source, node.runCfg, node.metrics, node.clock)
+
+ p2pNode, err := p2p.NewNodeP2P(node.resourcesCtx, &cfg.Rollup, node.log, cfg.P2P, rec, l2Chain, node.runCfg, node.metrics, node.clock)
if err != nil {
return nil, err
}
@@ -744,11 +790,16 @@ func (n *OpNode) Start(ctx context.Context) error {
return err
}
}
- n.log.Info("Starting execution engine driver")
- // start driving engine: sync blocks by deriving them from L1 and driving them into the engine
- if err := n.l2Driver.Start(); err != nil {
- n.log.Error("Could not start a rollup node", "err", err)
- return err
+ // Skip driver start in gossip-only mode
+ if n.l2Driver != nil {
+ n.log.Info("Starting execution engine driver")
+ // start driving engine: sync blocks by deriving them from L1 and driving them into the engine
+ if err := n.l2Driver.Start(); err != nil {
+ n.log.Error("Could not start a rollup node", "err", err)
+ return err
+ }
+ } else {
+ n.log.Info("Gossip-only mode: skipping execution engine driver")
}
log.Info("Rollup node started")
return nil
@@ -1006,3 +1057,45 @@ func (n *OpNode) SyncStatus() *eth.SyncStatus {
}
return n.l2Driver.StatusTracker.SyncStatus()
}
+
+// GetSequencerCommitment retrieves the latest sequencer commitment data from the p2p node
+func (n *OpNode) GetSequencerCommitment(ctx context.Context) ([]byte, []byte, error) {
+ if n.p2pNode == nil {
+ return nil, nil, errors.New("p2p node not initialized")
+ }
+
+ if n.p2pNode.GossipOut() == nil {
+ return nil, nil, errors.New("gossip not enabled")
+ }
+
+ if store, ok := n.p2pNode.GossipOut().(p2p.GossipDataStore); ok {
+ sig, data := store.GetLatestGossipData()
+ return sig, data, nil
+ }
+
+ return nil, nil, errors.New("p2p node does not support gossip data retrieval")
+}
+
+// Verify OpNode satisfies the api.Service interface
+var _ api.Service = (*OpNode)(nil)
+
+// initGossipOnlyRPCServer creates a minimal RPC server for gossip-only mode
+// that only exposes the sequencer commitment API endpoint
+func initGossipOnlyRPCServer(cfg *config.Config, node *OpNode) (*oprpc.Server, error) {
+ server := oprpc.NewServer(cfg.RPC.ListenAddr, cfg.RPC.ListenPort, node.appVersion,
+ oprpc.WithLogger(node.log),
+ oprpc.WithCORSHosts([]string{"*"}),
+ )
+
+ // Add sequencer commitment endpoint if P2P is enabled
+ if p2pNode := node.getP2PNodeIfEnabled(); p2pNode != nil {
+ addSequencerCommitmentEndpoint(server, node, node.log)
+ }
+
+ node.log.Info("Starting gossip-only RPC server")
+ if err := server.Start(); err != nil {
+ return nil, fmt.Errorf("unable to start RPC server: %w", err)
+ }
+ node.log.Info("Started gossip-only RPC server", "addr", server.Endpoint())
+ return server, nil
+}
diff --git a/op-node/node/server.go b/op-node/node/server.go
index d91a1b5..06f7f93 100644
--- a/op-node/node/server.go
+++ b/op-node/node/server.go
@@ -4,6 +4,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
+ "github.com/ethereum-optimism/optimism/op-node/api"
"github.com/ethereum-optimism/optimism/op-node/rollup"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
oprpc "github.com/ethereum-optimism/optimism/op-service/rpc"
@@ -17,10 +18,20 @@ func newRPCServer(rpcCfg *oprpc.CLIConfig, rollupCfg *rollup.Config, depSet deps
oprpc.WithCORSHosts([]string{"*"}), // CORS is not important on op-node, but we used to do this on the old op-node RPC server, so kept for compatibility.
oprpc.WithRPCRecorder(metrics.NewRecorder("main")),
)
- api := NewNodeAPI(rollupCfg, depSet, l2Client, dr, safeDB, log)
+ nodeAPI := NewNodeAPI(rollupCfg, depSet, l2Client, dr, safeDB, log)
server.AddAPI(rpc.API{
Namespace: "optimism",
- Service: api,
+ Service: nodeAPI,
})
return server
}
+
+// addSequencerCommitmentEndpoint adds the sequencer commitment HTTP endpoint to the server
+func addSequencerCommitmentEndpoint(server *oprpc.Server, node *OpNode, log log.Logger) {
+ // Create the gossip API service
+ gossipAPI := api.NewGossipAPI(node)
+
+ // Add the HTTP endpoint
+ server.AddHandler("/gossip_getSequencerCommitment", gossipAPI.HTTPHandler())
+ log.Info("Registered sequencer commitment API endpoint", "path", "/gossip_getSequencerCommitment")
+}
diff --git a/op-node/p2p/gossip.go b/op-node/p2p/gossip.go
index 3ac14c3..c6698e8 100644
--- a/op-node/p2p/gossip.go
+++ b/op-node/p2p/gossip.go
@@ -18,6 +18,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-node/rollup"
@@ -105,6 +106,12 @@ var msgBufPool = sync.Pool{New: func() any {
return &x
}}
+// Global variables for gossip store access
+var (
+ JoinedGossipOut GossipOut
+ gossipStoreMu sync.RWMutex
+)
+
// BuildMsgIdFn builds a generic message ID function for gossipsub that can handle compressed payloads,
// mirroring the eth2 p2p gossip spec.
func BuildMsgIdFn(cfg *rollup.Config) pubsub.MsgIdFunction {
@@ -432,10 +439,34 @@ func BuildBlocksValidator(log log.Logger, cfg *rollup.Config, runCfg GossipRunti
return pubsub.ValidationIgnore
}
+ // Debug: Print signature and payload bytes
+ log.Info("Gossip validation - signature and payload",
+ "signature", fmt.Sprintf("%x", signature),
+ "payload_bytes_length", len(payloadBytes),
+ "payload_bytes_hex", fmt.Sprintf("%x", payloadBytes[:min(100, len(payloadBytes))]), // First 100 bytes
+ "block_hash", payload.BlockHash.String(),
+ "block_number", payload.BlockNumber,
+ "timestamp", payload.Timestamp)
+
// mark it as seen. (note: with concurrent validation more than 5 blocks may be marked as seen still,
// but validator concurrency is limited anyway)
seen.markSeen(payload.BlockHash)
+ // Capture sequencer commitment data after successful validation
+ gossipStoreMu.RLock()
+ gossipStore := JoinedGossipOut
+ gossipStoreMu.RUnlock()
+
+ if gossipStore != nil {
+ log.Debug("Storing sequencer commitment",
+ "peer", id,
+ "sig_len", len(signature),
+ "payload_len", len(payloadBytes))
+ gossipStore.StoreLatestGossipData(signature[:], payloadBytes)
+ } else {
+ log.Debug("Cannot store sequencer commitment, gossip store not initialized")
+ }
+
// remember the decoded payload for later usage in topic subscriber.
message.ValidatorData = &envelope
return pubsub.ValidationAccept
@@ -474,8 +505,17 @@ type GossipTopicInfo interface {
BlocksTopicV4Peers() []peer.ID
}
+// GossipDataStore interface for storing and retrieving gossip data
+type GossipDataStore interface {
+ // Store the latest signature and payload data
+ StoreLatestGossipData(signature []byte, payload []byte)
+ // Get the latest signature and payload data
+ GetLatestGossipData() ([]byte, []byte)
+}
+
type GossipOut interface {
GossipTopicInfo
+ GossipDataStore
SignAndPublishL2Payload(ctx context.Context, msg *eth.ExecutionPayloadEnvelope, signer Signer) error
PublishSignedL2Payload(ctx context.Context, signedEnvelope *opsigner.SignedExecutionPayloadEnvelope) error
Close() error
@@ -505,6 +545,11 @@ type publisher struct {
// thus we have to stop it ourselves this way.
p2pCancel context.CancelFunc
+ // Add mutex to protect access to latest data
+ latestDataMu sync.RWMutex
+ latestSignatureBytes []byte
+ latestPayloadBytes []byte
+
blocksV1 *blockTopic
blocksV2 *blockTopic
blocksV3 *blockTopic
@@ -611,7 +656,67 @@ func (p *publisher) SignAndPublishL2Payload(ctx context.Context, envelope *eth.E
return p.publishRawSignedPayload(ctx, uint64(envelope.ExecutionPayload.Timestamp), data)
}
+func (p *publisher) StoreLatestGossipData(signature []byte, payload []byte) {
+ p.latestDataMu.Lock()
+ defer p.latestDataMu.Unlock()
+
+ // Don't store empty data
+ if len(signature) == 0 || len(payload) == 0 {
+ p.log.Debug("Ignoring attempt to store empty sequencer commitment data")
+ return
+ }
+
+ // Store only when we have valid data
+ sigCopy := make([]byte, len(signature))
+ copy(sigCopy, signature)
+
+ payloadCopy := make([]byte, len(payload))
+ copy(payloadCopy, payload)
+
+ p.latestSignatureBytes = sigCopy
+ p.latestPayloadBytes = payloadCopy
+
+ p.log.Debug("Successfully stored sequencer commitment data",
+ "sig_len", len(signature),
+ "payload_len", len(payload))
+}
+
+func (p *publisher) GetLatestGossipData() ([]byte, []byte) {
+ p.latestDataMu.RLock()
+ defer p.latestDataMu.RUnlock()
+
+ // Ensure we don't return nil slices which could cause serialization issues
+ if p.latestSignatureBytes == nil || len(p.latestSignatureBytes) == 0 {
+ p.log.Debug("No sequencer commitment data available yet")
+ return []byte{}, []byte{}
+ }
+
+ // Return copies of the data to avoid concurrent access issues
+ sigCopy := make([]byte, len(p.latestSignatureBytes))
+ copy(sigCopy, p.latestSignatureBytes)
+
+ payloadCopy := make([]byte, len(p.latestPayloadBytes))
+ copy(payloadCopy, p.latestPayloadBytes)
+
+ p.log.Debug("Returning sequencer commitment data",
+ "sig_len", len(sigCopy),
+ "payload_len", len(payloadCopy))
+
+ return sigCopy, payloadCopy
+}
+
func (p *publisher) publishRawSignedPayload(ctx context.Context, timestamp uint64, data []byte) error {
+ // Store the signature and payload hash for commitment API
+ signature := data[:65]
+ payload := data[65:]
+ payloadHash := crypto.Keccak256Hash(payload)
+ p.StoreLatestGossipData(signature, payload)
+ p.log.Info("Stored sequencer commitment from outgoing payload",
+ "hash", payloadHash.String(),
+ "sig_len", len(signature),
+ "payload_len", len(payload),
+ "timestamp", timestamp)
+
// compress the full message
// This also copies the data, freeing up the original buffer to go back into the pool
out := snappy.Encode(nil, data)
@@ -669,7 +774,7 @@ func JoinGossip(self peer.ID, ps *pubsub.PubSub, log log.Logger, cfg *rollup.Con
return nil, fmt.Errorf("failed to setup blocks v4 p2p: %w", err)
}
- return &publisher{
+ pub := &publisher{
log: log,
cfg: cfg,
p2pCancel: p2pCancel,
@@ -678,7 +783,14 @@ func JoinGossip(self peer.ID, ps *pubsub.PubSub, log log.Logger, cfg *rollup.Con
blocksV3: blocksV3,
blocksV4: blocksV4,
runCfg: runCfg,
- }, nil
+ }
+
+ // Set the global variable for gossip store access
+ gossipStoreMu.Lock()
+ JoinedGossipOut = pub
+ gossipStoreMu.Unlock()
+
+ return pub, nil
}
func newBlockTopic(ctx context.Context, topicId string, ps *pubsub.PubSub, log log.Logger, gossipIn GossipIn, validator pubsub.ValidatorEx) (*blockTopic, error) {
diff --git a/op-node/service.go b/op-node/service.go
index d590750..15c59a6 100644
--- a/op-node/service.go
+++ b/op-node/service.go
@@ -77,9 +77,13 @@ func NewConfig(ctx cliiface.Context, log log.Logger) (*config.Config, error) {
l1Endpoint := NewL1EndpointConfig(ctx)
- l2Endpoint, err := NewL2EndpointConfig(ctx, log)
- if err != nil {
- return nil, fmt.Errorf("failed to load l2 endpoints info: %w", err)
+ gossipOnly := ctx.Bool(flags.GossipOnlyMode.Name)
+ var l2Endpoint *config.L2EndpointConfig
+ if !gossipOnly {
+ l2Endpoint, err = NewL2EndpointConfig(ctx, log)
+ if err != nil {
+ return nil, fmt.Errorf("failed to load l2 endpoints info: %w", err)
+ }
}
syncConfig, err := NewSyncConfig(ctx, log)
@@ -131,6 +135,7 @@ func NewConfig(ctx cliiface.Context, log log.Logger) (*config.Config, error) {
FetchWithdrawalRootFromState: ctx.Bool(flags.FetchWithdrawalRootFromState.Name),
ExperimentalOPStackAPI: ctx.Bool(flags.ExperimentalOPStackAPI.Name),
+ GossipOnly: gossipOnly,
}
if err := cfg.LoadPersisted(log); err != nil {