L1BlockRefByLabel returns the [eth.L1BlockRef] for the given block label. Notice, we cannot cache a block reference by label because labels are not guaranteed to be unique.
(src *PollingClient, ctx context.Context, label rpc.BlockNumber)
| 91 | // L1BlockRefByLabel returns the [eth.L1BlockRef] for the given block label. |
| 92 | // Notice, we cannot cache a block reference by label because labels are not guaranteed to be unique. |
| 93 | func L1BlockRefByLabel(src *PollingClient, ctx context.Context, label rpc.BlockNumber) (L1BlockRef, error) { |
| 94 | head, err := src.HeaderByNumber(ctx, big.NewInt(label.Int64())) |
| 95 | if err != nil { |
| 96 | // Both geth and erigon like to serve non-standard errors for the safe and finalized heads, correct that. |
| 97 | // This happens when the chain just started and nothing is marked as safe/finalized yet. |
| 98 | if strings.Contains(err.Error(), "block not found") || strings.Contains(err.Error(), "Unknown block") { |
| 99 | err = ethereum.NotFound |
| 100 | } |
| 101 | return L1BlockRef{}, fmt.Errorf("failed to fetch head header: %w", err) |
| 102 | } |
| 103 | ref := InfoToL1BlockRef(head) |
| 104 | return ref, nil |
| 105 | } |
no test coverage detected