Skip to content

Commit 2f95706

Browse files
Add helpers to expose TargetBlobs chain config
Rollups may want to use these to dynamically adjust blobs posted after BPO forks.
1 parent e03d97a commit 2f95706

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

consensus/misc/eip4844/eip4844.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,30 @@ func LatestMaxBlobsPerBlock(cfg *params.ChainConfig) int {
200200
return bcfg.Max
201201
}
202202

203+
// TargetBlobsPerBlock returns the target blobs per block for a block at the given timestamp.
204+
func TargetBlobsPerBlock(cfg *params.ChainConfig, time uint64) int {
205+
blobConfig := latestBlobConfig(cfg, time)
206+
if blobConfig == nil {
207+
return 0
208+
}
209+
return blobConfig.Target
210+
}
211+
212+
// TargetBlobGasPerBlock returns the target blob gas that can be spent in a block at the given timestamp.
213+
func TargetBlobGasPerBlock(cfg *params.ChainConfig, time uint64) uint64 {
214+
return uint64(TargetBlobsPerBlock(cfg, time)) * params.BlobTxBlobGasPerBlob
215+
}
216+
217+
// LatestTargetBlobsPerBlock returns the latest target blobs per block defined by the
218+
// configuration, regardless of the currently active fork.
219+
func LatestTargetBlobsPerBlock(cfg *params.ChainConfig) int {
220+
bcfg := latestBlobConfig(cfg, math.MaxUint64)
221+
if bcfg == nil {
222+
return 0
223+
}
224+
return bcfg.Target
225+
}
226+
203227
// fakeExponential approximates factor * e ** (numerator / denominator) using
204228
// Taylor expansion.
205229
func fakeExponential(factor, numerator, denominator *big.Int) *big.Int {

0 commit comments

Comments
 (0)