Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into release/v0.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
omritoptix committed Aug 29, 2023
2 parents cc72cfb + 3e1ed62 commit 897ad27
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions da/avail/avail.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ func (c *DataAvailabilityLayerClient) broadcastTx(tx []byte) (uint64, error) {
c.logger.Info("Submitted batch to avail. Waiting for inclusion event")

defer sub.Unsubscribe()
timeout := time.After(c.txInclusionTimeout)

inclusionTimer := time.NewTimer(c.txInclusionTimeout)
defer inclusionTimer.Stop()

for {
select {
case <-c.ctx.Done():
Expand All @@ -378,13 +381,18 @@ func (c *DataAvailabilityLayerClient) broadcastTx(tx []byte) (uint64, error) {
return blockHeight, nil
} else if status.IsInBlock {
c.logger.Debug(fmt.Sprintf("Batch included inside a block with hash %v, waiting for finalization.", status.AsInBlock.Hex()))
inclusionTimer.Reset(c.txInclusionTimeout)
continue
} else {
c.logger.Debug("unsupported status, still waiting for inclusion", "status", status)
recievedStatus, err := status.MarshalJSON()
if err != nil {
return 0, fmt.Errorf("%s: %s", "failed to MarshalJSON of received status", err)
}
c.logger.Debug("unsupported status, still waiting for inclusion", "status", string(recievedStatus))
continue
}
case <-timeout:
return 0, fmt.Errorf("%w: %s", da.ErrTxBroadcastTimeout, err)
case <-inclusionTimer.C:
return 0, da.ErrTxBroadcastTimeout
}
}
}
Expand All @@ -402,9 +410,9 @@ func (c *DataAvailabilityLayerClient) CheckBatchAvailability(dataLayerHeight uin
// getHeightFromHash returns the block height from the block hash
func (c *DataAvailabilityLayerClient) getHeightFromHash(hash availtypes.Hash) (uint64, error) {
c.logger.Debug("Getting block height from hash", "hash", hash)
block, err := c.client.GetBlock(hash)
header, err := c.client.GetHeader(hash)
if err != nil {
return 0, fmt.Errorf("cannot get block by hash:%w", err)
}
return uint64(block.Block.Header.Number), nil
return uint64(header.Number), nil
}

0 comments on commit 897ad27

Please sign in to comment.