Skip to content

Commit 2c98c5d

Browse files
committed
Implement localhead in fiber client
1 parent 135c128 commit 2c98c5d

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

block/internal/da/fiber/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type BlobEvent struct {
4848

4949
// DA is the interface for interacting with the Fiber data availability layer.
5050
type DA interface {
51+
Head(ctx context.Context) (uint64, error)
52+
5153
// Upload submits a blob under the given namespace to the DA network.
5254
// Returns after the blob is uploaded and the payment transaction is broadcast.
5355
// Does NOT wait for on-chain confirmation (see package doc for rationale).

block/internal/da/fiber_client.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,18 @@ func (c *fiberDAClient) Subscribe(ctx context.Context, namespace []byte, _ bool)
359359
return out, nil
360360
}
361361

362-
func (c *fiberDAClient) GetLatestDAHeight(context.Context) (uint64, error) {
363-
panic(fmt.Errorf("p2p should not be enabled"))
362+
// GetLatestDAHeight returns the latest height available on the DA layer by
363+
// querying the network head.
364+
func (c *fiberDAClient) GetLatestDAHeight(ctx context.Context) (uint64, error) {
365+
headCtx, cancel := context.WithTimeout(ctx, c.defaultTimeout)
366+
defer cancel()
367+
368+
heigth, err := c.fiber.Head(headCtx)
369+
if err != nil {
370+
return 0, fmt.Errorf("failed to get DA network head: %w", err)
371+
}
372+
373+
return heigth, nil
364374
}
365375

366376
func (c *fiberDAClient) GetProofs(_ context.Context, ids []datypes.ID, _ []byte) ([]datypes.Proof, error) {

block/internal/da/fibremock/mock.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ func NewMockDA(cfg MockDAConfig) *MockDA {
7474
}
7575
}
7676

77+
func (m *MockDA) Head(ctx context.Context) (uint64, error) {
78+
m.mu.RLock()
79+
defer m.mu.RUnlock()
80+
return m.height, nil
81+
}
82+
7783
// Upload stores the blob in memory and notifies listeners.
7884
func (m *MockDA) Upload(ctx context.Context, namespace []byte, data []byte) (fiber.UploadResult, error) {
7985
if len(data) == 0 {

0 commit comments

Comments
 (0)