Skip to content

Commit d6617be

Browse files
committed
chore: trim some comments
1 parent a832792 commit d6617be

5 files changed

Lines changed: 36 additions & 56 deletions

File tree

l1/export_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import (
44
"context"
55
)
66

7-
// This file is compiled only with the test binary. It exposes
8-
// package-private surface to the external l1_test package, which is
9-
// where the L1 client tests live (separating them avoids a circular
10-
// import: l1 -> mocks -> l1).
7+
// Exposes package-private surface to the external l1_test package. The
8+
// tests live there to avoid a circular import: l1 -> mocks -> l1.
119

1210
// SetSettlement swaps the underlying settlement layer. Used by tests
1311
// that rebuild expectations across iterations on a single Client.

l1/geth_settlement.go

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,15 @@ const watchForwarderBuffer = 64
2828
// finalised block; used as the "block number" arg to HeaderByNumber.
2929
var gethFinalizedBlockNumber = new(big.Int).SetInt64(rpc.FinalizedBlockNumber.Int64())
3030

31-
// GethSettlement is the go-ethereum-backed implementation of
32-
// SettlementLayer. It wraps go-ethereum's ethclient plus the abigen-
33-
// generated StarknetFilterer to talk to the Starknet core L1 bridge.
31+
// GethSettlement is the go-ethereum-backed SettlementLayer, wrapping
32+
// ethclient plus the abigen StarknetFilterer to talk to the Starknet
33+
// core L1 bridge. It also satisfies rpccore.L1Client (via
34+
// TransactionReceipt), so node.go hands one instance to both the L1
35+
// sync loop and the RPC handlers.
3436
//
35-
// The same instance also satisfies rpccore.L1Client via
36-
// TransactionReceipt, so node.go can construct one client and hand it
37-
// to both the L1 sync loop and the RPC handlers.
38-
//
39-
// go-ethereum's rpc.Client transparently reconnects unary calls over
40-
// the WS transport, and any active subscription propagates the drop
41-
// via its Err() channel, which the upper-layer resubscribe loop in
42-
// l1.Client.watchL1StateUpdates already handles.
37+
// WS connection drops are recovered below this layer: rpc.Client
38+
// reconnects unary calls, and subscription drops surface on Err() for
39+
// l1.Client.watchL1StateUpdates to resubscribe.
4340
type GethSettlement struct {
4441
contractAddress eth.Address
4542
url string
@@ -94,19 +91,16 @@ type gethSettlementOptions struct {
9491
listener EventListener
9592
}
9693

97-
// WithSettlementListener sets the EventListener that fires OnL1Call for
98-
// every Ethereum RPC method. Defaults to a no-op SelectiveListener.
99-
//
100-
// The listener is supplied at construction because the field is read
101-
// unlocked from every RPC method, so it must not be mutated once the
102-
// settlement is handed off to a goroutine (i.e. l1.NewClient in node.go).
94+
// WithSettlementListener sets the EventListener that fires OnL1Call on
95+
// every Ethereum RPC method (default: no-op). Set at construction: the
96+
// listener field is read unlocked from every RPC method, so it must not
97+
// be mutated once the settlement is shared with a goroutine.
10398
func WithSettlementListener(l EventListener) GethSettlementOption {
10499
return func(o *gethSettlementOptions) { o.listener = l }
105100
}
106101

107-
// observe wraps an RPC call so OnL1Call fires on both success and
108-
// failure paths — error rates and latency under failure are as
109-
// interesting to monitor as success.
102+
// observe reports OnL1Call latency on return, on both success and
103+
// failure paths.
110104
func (s *GethSettlement) observe(method string) func() {
111105
t := time.Now()
112106
return func() { s.listener.OnL1Call(method, time.Since(t)) }
@@ -224,9 +218,8 @@ func stateUpdateFromGethContract(ev *contract.StarknetLogStateUpdate) *StateUpda
224218
}
225219
}
226220

227-
// gethReceiptToEth shallow-copies the fields of a geth receipt that juno
228-
// actually reads. Today only Logs is consumed, but every nested Log is
229-
// converted so the shape matches juno's own eth.Receipt type exactly.
221+
// gethReceiptToEth copies the receipt fields juno reads. Only Logs is
222+
// consumed today; a consumer needing other fields must extend this.
230223
func gethReceiptToEth(r *types.Receipt) *eth.Receipt {
231224
logs := make([]eth.Log, len(r.Logs))
232225
for i, l := range r.Logs {
@@ -248,12 +241,11 @@ func gethLogToEth(l *types.Log) eth.Log {
248241
}
249242
}
250243

251-
// forwardStateUpdates returns a subscription whose goroutine decodes each
252-
// contract.StarknetLogStateUpdate event into a neutral StateUpdate and
253-
// forwards it to sink, until the inner subscription errors or the caller
254-
// unsubscribes. The subscription lifecycle (once-only close, idempotent
255-
// Unsubscribe, error delivery, goroutine teardown) is handled by
256-
// event.NewSubscription; this only owns the type translation.
244+
// forwardStateUpdates returns a subscription that decodes each raw event
245+
// into a StateUpdate and forwards it to sink, until inner errors or the
246+
// caller unsubscribes. Lifecycle (close, Unsubscribe, error delivery,
247+
// teardown) is owned by event.NewSubscription; this adds only the type
248+
// translation and the stall-vs-quit select.
257249
func forwardStateUpdates(
258250
inner event.Subscription,
259251
raw <-chan *contract.StarknetLogStateUpdate,
@@ -278,8 +270,7 @@ func forwardStateUpdates(
278270
})
279271
}
280272

281-
// Compile-time assertions: GethSettlement satisfies both interfaces it
282-
// is intended to serve.
273+
// GethSettlement must satisfy both interfaces it serves.
283274
var (
284275
_ SettlementLayer = (*GethSettlement)(nil)
285276
_ rpccore.L1Client = (*GethSettlement)(nil)

l1/settlement.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ import (
77
"github.com/NethermindEth/juno/core/felt"
88
)
99

10-
// SettlementLayer is the interface l1.Client uses to follow the Ethereum
11-
// L1 chain Starknet settles to: reading heights, watching and replaying
12-
// LogStateUpdate events, and checking the chain id. GethSettlement is the
13-
// implementation today; a hand-rolled Ethereum client (to drop the
14-
// go-ethereum dependency) is intended to slot in behind this same
15-
// interface, which is why l1.Client depends on the interface rather than a
16-
// concrete client.
17-
//
18-
// Decoded events cross this boundary as StateUpdate, in juno's own types,
19-
// so no go-ethereum type — nor any implementation's internal types — leaks
20-
// into the L1 sync loop.
10+
// SettlementLayer is how l1.Client follows the Ethereum L1 chain Starknet
11+
// settles to: heights, LogStateUpdate events, and chain id. The interface
12+
// exists so a hand-rolled Ethereum client can later replace GethSettlement
13+
// (dropping the go-ethereum dependency) without touching l1.Client. Events
14+
// cross as StateUpdate in juno's own types, so no go-ethereum type leaks
15+
// into the sync loop.
2116
//
2217
//go:generate mockgen -destination=../mocks/mock_settlement_layer.go -package=mocks github.com/NethermindEth/juno/l1 SettlementLayer
2318
type SettlementLayer interface {

node/metrics.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,10 @@ func makeBlockchainMetrics() blockchain.EventListener {
264264
}
265265
}
266266

267-
// makeL1Metrics registers the L1 gauges that only need the chain reader
268-
// and returns the shared EventListener recording per-call latency. The
269-
// gauges that poll the settlement layer are registered separately by
270-
// registerL1SettlementMetrics, once the settlement exists — so the
271-
// listener can be attached at construction instead of via a setter.
267+
// makeL1Metrics registers the chain-reader gauges and returns the shared
268+
// EventListener. Settlement-polling gauges are registered separately by
269+
// registerL1SettlementMetrics so the listener can be attached at
270+
// construction rather than via a setter.
272271
func makeL1Metrics(bcReader blockchain.Reader) l1.EventListener {
273272
l2BlockFinalizedOnL1 := prometheus.NewGaugeFunc(prometheus.GaugeOpts{
274273
Namespace: "l1",

node/node.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,8 @@ func New(cfg *Config, version string, logLevel *log.Level) (*Node, error) {
621621
return nil, fmt.Errorf("ethereum node address not found; Use --disable-l1-verification flag if L1 verification is not required")
622622
}
623623

624-
// One EventListener is shared between the L1 client (which
625-
// fires OnNewL1Head) and the settlement (which fires OnL1Call
626-
// for every Ethereum RPC method). Metrics are registered only
627-
// when the node is built with --metrics; otherwise the default
628-
// no-op SelectiveListener is used.
624+
// One EventListener, shared by the L1 client (OnNewL1Head) and
625+
// the settlement (OnL1Call), wired only under --metrics.
629626
l1Opts := []l1.Option{}
630627
settlementOpts := []l1.GethSettlementOption{}
631628
if cfg.Metrics {

0 commit comments

Comments
 (0)