MCPcopy Create free account
hub / github.com/ethstorage/es-node / L1BlockRefByLabel

Function L1BlockRefByLabel

ethstorage/eth/heads.go:93–105  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
93func 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}

Callers 1

PollBlockChangesFunction · 0.85

Calls 4

InfoToL1BlockRefFunction · 0.85
HeaderByNumberMethod · 0.65
ContainsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected