Skip to content

Commit 6c85d8d

Browse files
committed
Merge branch 'main' into alex/2609_hints
* main: feat: use DA timestamp (#2939) chore: improve code comments clarity (#2943) build(deps): bump libp2p (#2937)
2 parents 4ecf0a0 + a406515 commit 6c85d8d

24 files changed

Lines changed: 509 additions & 631 deletions

File tree

.mockery.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,8 @@ packages:
8282
dir: ./pkg/da/jsonrpc/mocks
8383
pkgname: mocks
8484
filename: blob_module_mock.go
85+
HeaderModule:
86+
config:
87+
dir: ./pkg/da/jsonrpc/mocks
88+
pkgname: mocks
89+
filename: header_module_mock.go

apps/evm/go.mod

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ require (
5353
github.com/filecoin-project/go-clock v0.1.0 // indirect
5454
github.com/filecoin-project/go-jsonrpc v0.9.0 // indirect
5555
github.com/flynn/noise v1.1.0 // indirect
56-
github.com/francoispqt/gojay v1.2.13 // indirect
5756
github.com/fsnotify/fsnotify v1.9.0 // indirect
5857
github.com/go-kit/kit v0.13.0 // indirect
5958
github.com/go-logr/logr v1.4.3 // indirect
@@ -89,7 +88,7 @@ require (
8988
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
9089
github.com/libp2p/go-cidranger v1.1.0 // indirect
9190
github.com/libp2p/go-flow-metrics v0.3.0 // indirect
92-
github.com/libp2p/go-libp2p v0.45.0 // indirect
91+
github.com/libp2p/go-libp2p v0.46.0 // indirect
9392
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
9493
github.com/libp2p/go-libp2p-kad-dht v0.36.0 // indirect
9594
github.com/libp2p/go-libp2p-kbucket v0.8.0 // indirect
@@ -150,8 +149,8 @@ require (
150149
github.com/prometheus/client_model v0.6.2 // indirect
151150
github.com/prometheus/common v0.66.1 // indirect
152151
github.com/prometheus/procfs v0.17.0 // indirect
153-
github.com/quic-go/qpack v0.5.1 // indirect
154-
github.com/quic-go/quic-go v0.55.0 // indirect
152+
github.com/quic-go/qpack v0.6.0 // indirect
153+
github.com/quic-go/quic-go v0.57.1 // indirect
155154
github.com/quic-go/webtransport-go v0.9.0 // indirect
156155
github.com/rivo/uniseg v0.2.0 // indirect
157156
github.com/sagikazarmark/locafero v0.11.0 // indirect

apps/evm/go.sum

Lines changed: 6 additions & 134 deletions
Large diffs are not rendered by default.

apps/grpc/go.mod

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ require (
3939
github.com/filecoin-project/go-clock v0.1.0 // indirect
4040
github.com/filecoin-project/go-jsonrpc v0.9.0 // indirect
4141
github.com/flynn/noise v1.1.0 // indirect
42-
github.com/francoispqt/gojay v1.2.13 // indirect
4342
github.com/fsnotify/fsnotify v1.9.0 // indirect
4443
github.com/go-kit/kit v0.13.0 // indirect
4544
github.com/go-logr/logr v1.4.3 // indirect
@@ -69,7 +68,7 @@ require (
6968
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
7069
github.com/libp2p/go-cidranger v1.1.0 // indirect
7170
github.com/libp2p/go-flow-metrics v0.3.0 // indirect
72-
github.com/libp2p/go-libp2p v0.45.0 // indirect
71+
github.com/libp2p/go-libp2p v0.46.0 // indirect
7372
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
7473
github.com/libp2p/go-libp2p-kad-dht v0.36.0 // indirect
7574
github.com/libp2p/go-libp2p-kbucket v0.8.0 // indirect
@@ -128,8 +127,8 @@ require (
128127
github.com/prometheus/client_model v0.6.2 // indirect
129128
github.com/prometheus/common v0.66.1 // indirect
130129
github.com/prometheus/procfs v0.17.0 // indirect
131-
github.com/quic-go/qpack v0.5.1 // indirect
132-
github.com/quic-go/quic-go v0.55.0 // indirect
130+
github.com/quic-go/qpack v0.6.0 // indirect
131+
github.com/quic-go/quic-go v0.57.1 // indirect
133132
github.com/quic-go/webtransport-go v0.9.0 // indirect
134133
github.com/sagikazarmark/locafero v0.11.0 // indirect
135134
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect

apps/grpc/go.sum

Lines changed: 6 additions & 133 deletions
Large diffs are not rendered by default.

apps/testapp/go.mod

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ require (
3838
github.com/filecoin-project/go-clock v0.1.0 // indirect
3939
github.com/filecoin-project/go-jsonrpc v0.9.0 // indirect
4040
github.com/flynn/noise v1.1.0 // indirect
41-
github.com/francoispqt/gojay v1.2.13 // indirect
4241
github.com/fsnotify/fsnotify v1.9.0 // indirect
4342
github.com/go-kit/kit v0.13.0 // indirect
4443
github.com/go-logr/logr v1.4.3 // indirect
@@ -68,7 +67,7 @@ require (
6867
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
6968
github.com/libp2p/go-cidranger v1.1.0 // indirect
7069
github.com/libp2p/go-flow-metrics v0.3.0 // indirect
71-
github.com/libp2p/go-libp2p v0.45.0 // indirect
70+
github.com/libp2p/go-libp2p v0.46.0 // indirect
7271
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
7372
github.com/libp2p/go-libp2p-kad-dht v0.36.0 // indirect
7473
github.com/libp2p/go-libp2p-kbucket v0.8.0 // indirect
@@ -127,8 +126,8 @@ require (
127126
github.com/prometheus/client_model v0.6.2 // indirect
128127
github.com/prometheus/common v0.66.1 // indirect
129128
github.com/prometheus/procfs v0.17.0 // indirect
130-
github.com/quic-go/qpack v0.5.1 // indirect
131-
github.com/quic-go/quic-go v0.55.0 // indirect
129+
github.com/quic-go/qpack v0.6.0 // indirect
130+
github.com/quic-go/quic-go v0.57.1 // indirect
132131
github.com/quic-go/webtransport-go v0.9.0 // indirect
133132
github.com/sagikazarmark/locafero v0.11.0 // indirect
134133
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect

apps/testapp/go.sum

Lines changed: 6 additions & 133 deletions
Large diffs are not rendered by default.

block/internal/cache/pending_headers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
// - DA submission of multiple headers is atomic - it's impossible to submit only part of a batch
1818
//
1919
// lastSubmittedHeaderHeight is updated only after receiving confirmation from DA.
20-
// Worst case scenario is when headers was successfully submitted to DA, but confirmation was not received (e.g. node was
20+
// Worst case scenario is when headers were successfully submitted to DA, but confirmation was not received (e.g. node was
2121
// restarted, networking issue occurred). In this case headers are re-submitted to DA (it's extra cost).
2222
// evolve is able to skip duplicate headers so this shouldn't affect full nodes.
2323
// TODO(tzdybal): we shouldn't try to push all pending headers at once; this should depend on max blob size

block/internal/da/client.go

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type Config struct {
3030
// It is unexported; callers should use the exported Client interface.
3131
type client struct {
3232
blobAPI *blobrpc.BlobAPI
33+
headerAPI *blobrpc.HeaderAPI
3334
logger zerolog.Logger
3435
defaultTimeout time.Duration
3536
namespaceBz []byte
@@ -58,6 +59,7 @@ func NewClient(cfg Config) FullClient {
5859

5960
return &client{
6061
blobAPI: &cfg.DA.Blob,
62+
headerAPI: &cfg.DA.Header,
6163
logger: cfg.Logger.With().Str("component", "da_client").Logger(),
6264
defaultTimeout: cfg.DefaultTimeout,
6365
namespaceBz: datypes.NamespaceFromString(cfg.Namespace).Bytes(),
@@ -180,8 +182,22 @@ func (c *client) Submit(ctx context.Context, data [][]byte, _ float64, namespace
180182
}
181183
}
182184

185+
// getBlockTimestamp fetches the block timestamp from the DA layer header.
186+
func (c *client) getBlockTimestamp(ctx context.Context, height uint64) (time.Time, error) {
187+
headerCtx, cancel := context.WithTimeout(ctx, c.defaultTimeout)
188+
defer cancel()
189+
190+
header, err := c.headerAPI.GetByHeight(headerCtx, height)
191+
if err != nil {
192+
return time.Time{}, fmt.Errorf("failed to get header timestamp for block %d: %w", height, err)
193+
}
194+
195+
return header.Time(), nil
196+
}
197+
183198
// Retrieve retrieves blobs from the DA layer at the specified height and namespace.
184199
// It uses GetAll to fetch all blobs at once.
200+
// The timestamp is derived from the DA block header to ensure determinism.
185201
func (c *client) Retrieve(ctx context.Context, height uint64, namespace []byte) datypes.ResultRetrieve {
186202
ns, err := share.NewNamespaceFromBytes(namespace)
187203
if err != nil {
@@ -195,21 +211,29 @@ func (c *client) Retrieve(ctx context.Context, height uint64, namespace []byte)
195211
}
196212
}
197213

198-
getCtx, cancel := context.WithTimeout(ctx, c.defaultTimeout)
199-
defer cancel()
214+
blobCtx, blobCancel := context.WithTimeout(ctx, c.defaultTimeout)
215+
defer blobCancel()
200216

201-
blobs, err := c.blobAPI.GetAll(getCtx, height, []share.Namespace{ns})
217+
blobs, err := c.blobAPI.GetAll(blobCtx, height, []share.Namespace{ns})
202218
if err != nil {
203219
// Handle known errors by substring because RPC may wrap them.
204220
switch {
205221
case strings.Contains(err.Error(), datypes.ErrBlobNotFound.Error()):
206222
c.logger.Debug().Uint64("height", height).Msg("No blobs found at height")
223+
// Fetch block timestamp for deterministic responses using parent context
224+
blockTime, err := c.getBlockTimestamp(ctx, height)
225+
if err != nil {
226+
c.logger.Error().Uint64("height", height).Err(err).Msg("failed to get block timestamp")
227+
blockTime = time.Now()
228+
// TODO: we should retry fetching the timestamp. Current time may mess block time consistency for based sequencers.
229+
}
230+
207231
return datypes.ResultRetrieve{
208232
BaseResult: datypes.BaseResult{
209233
Code: datypes.StatusNotFound,
210234
Message: datypes.ErrBlobNotFound.Error(),
211235
Height: height,
212-
Timestamp: time.Now(),
236+
Timestamp: blockTime,
213237
},
214238
}
215239
case strings.Contains(err.Error(), datypes.ErrHeightFromFuture.Error()):
@@ -234,14 +258,22 @@ func (c *client) Retrieve(ctx context.Context, height uint64, namespace []byte)
234258
}
235259
}
236260

261+
// Fetch block timestamp for deterministic responses using parent context
262+
blockTime, err := c.getBlockTimestamp(ctx, height)
263+
if err != nil {
264+
c.logger.Error().Uint64("height", height).Err(err).Msg("failed to get block timestamp")
265+
blockTime = time.Now()
266+
// TODO: we should retry fetching the timestamp. Current time may mess block time consistency for based sequencers.
267+
}
268+
237269
if len(blobs) == 0 {
238270
c.logger.Debug().Uint64("height", height).Msg("No blobs found at height")
239271
return datypes.ResultRetrieve{
240272
BaseResult: datypes.BaseResult{
241273
Code: datypes.StatusNotFound,
242274
Message: datypes.ErrBlobNotFound.Error(),
243275
Height: height,
244-
Timestamp: time.Now(),
276+
Timestamp: blockTime,
245277
},
246278
}
247279
}
@@ -261,7 +293,7 @@ func (c *client) Retrieve(ctx context.Context, height uint64, namespace []byte)
261293
Code: datypes.StatusSuccess,
262294
Height: height,
263295
IDs: ids,
264-
Timestamp: time.Now(),
296+
Timestamp: blockTime,
265297
},
266298
Data: data,
267299
}

0 commit comments

Comments
 (0)