mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
consensus/misc/4844: fix blob price computation, add test
This commit is contained in:
parent
1478f6a64e
commit
af45e2e9ee
2 changed files with 60 additions and 1 deletions
|
|
@ -155,7 +155,7 @@ func calcExcessBlobGas(isOsaka bool, bcfg *BlobConfig, parent *types.Header) uin
|
|||
var (
|
||||
baseCost = big.NewInt(params.BlobBaseCost)
|
||||
reservePrice = baseCost.Mul(baseCost, parent.BaseFee)
|
||||
blobPrice = bcfg.blobPrice(excessBlobGas)
|
||||
blobPrice = bcfg.blobPrice(parentExcessBlobGas)
|
||||
)
|
||||
if reservePrice.Cmp(blobPrice) > 0 {
|
||||
scaledExcess := parentBlobGasUsed * uint64(bcfg.Max-bcfg.Target) / uint64(bcfg.Max)
|
||||
|
|
|
|||
|
|
@ -91,6 +91,65 @@ func TestCalcBlobFee(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCalcBlobFeePostOsaka(t *testing.T) {
|
||||
zero := uint64(0)
|
||||
bpo1 := uint64(1754836608)
|
||||
bpo2 := uint64(1754934912)
|
||||
bpo3 := uint64(1755033216)
|
||||
|
||||
tests := []struct {
|
||||
excessBlobGas uint64
|
||||
blobGasUsed uint64
|
||||
blobfee uint64
|
||||
basefee uint64
|
||||
parenttime uint64
|
||||
headertime uint64
|
||||
}{
|
||||
{5149252, 1310720, 5617366, 30, 1754904516, 1754904528},
|
||||
{19251039, 2490368, 20107103, 50, 1755033204, 1755033216},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
config := ¶ms.ChainConfig{
|
||||
LondonBlock: big.NewInt(0),
|
||||
CancunTime: &zero,
|
||||
PragueTime: &zero,
|
||||
OsakaTime: &zero,
|
||||
BPO1Time: &bpo1,
|
||||
BPO2Time: &bpo2,
|
||||
BPO3Time: &bpo3,
|
||||
BlobScheduleConfig: ¶ms.BlobScheduleConfig{
|
||||
Cancun: params.DefaultCancunBlobConfig,
|
||||
Prague: params.DefaultPragueBlobConfig,
|
||||
Osaka: params.DefaultOsakaBlobConfig,
|
||||
BPO1: ¶ms.BlobConfig{
|
||||
Target: 9,
|
||||
Max: 14,
|
||||
UpdateFraction: 8832827,
|
||||
},
|
||||
BPO2: ¶ms.BlobConfig{
|
||||
Target: 14,
|
||||
Max: 21,
|
||||
UpdateFraction: 13739630,
|
||||
},
|
||||
BPO3: ¶ms.BlobConfig{
|
||||
Target: 21,
|
||||
Max: 32,
|
||||
UpdateFraction: 20609697,
|
||||
},
|
||||
}}
|
||||
parent := &types.Header{
|
||||
ExcessBlobGas: &tt.excessBlobGas,
|
||||
BlobGasUsed: &tt.blobGasUsed,
|
||||
BaseFee: big.NewInt(int64(tt.basefee)),
|
||||
Time: tt.parenttime,
|
||||
}
|
||||
have := CalcExcessBlobGas(config, parent, tt.headertime)
|
||||
if have != tt.blobfee {
|
||||
t.Errorf("test %d: blobfee mismatch: have %v want %v", i, have, tt.blobfee)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFakeExponential(t *testing.T) {
|
||||
tests := []struct {
|
||||
factor int64
|
||||
|
|
|
|||
Loading…
Reference in a new issue