Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consensus/misc, params: add EIP-4844 blobfee conversions #27041

Merged
merged 4 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion consensus/misc/eip4844.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ import (
"github.com/ethereum/go-ethereum/params"
)

var (
expFactor = big.NewInt(params.BlobTxMinDataGasprice)
expDenominator = big.NewInt(params.BlobTxDataGaspriceUpdateFraction)
)
holiman marked this conversation as resolved.
Show resolved Hide resolved

// CalcBlobFee calculates the blobfee from the header's excess data gas field.
func CalcBlobFee(excessDataGas *big.Int) *big.Int {
// If this block does not yet have EIP-4844 enabled, return the starting fee
if excessDataGas == nil {
return big.NewInt(params.BlobTxMinDataGasprice)
}
return fakeExponential(big.NewInt(params.BlobTxMinDataGasprice), excessDataGas, big.NewInt(params.BlobTxDataGaspriceUpdateFraction))
return fakeExponential(expFactor, excessDataGas, expDenominator)
}

// fakeExponential approximates factor * e ** (numerator / denominator) using
Expand Down
9 changes: 8 additions & 1 deletion consensus/misc/eip4844_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package misc

import (
"fmt"
"math/big"
"testing"

Expand Down Expand Up @@ -69,9 +70,15 @@ func TestFakeExponential(t *testing.T) {
{2, 5, 2, 23}, // approximate 24.36
}
for i, tt := range tests {
have := fakeExponential(big.NewInt(tt.factor), big.NewInt(tt.numerator), big.NewInt(tt.denominator))
f, n, d := big.NewInt(tt.factor), big.NewInt(tt.numerator), big.NewInt(tt.denominator)
original := fmt.Sprintf("%d %d %d", f, n, d)
have := fakeExponential(f, n, d)
if have.Int64() != tt.want {
t.Errorf("test %d: fake exponential mismatch: have %v want %v", i, have, tt.want)
}
later := fmt.Sprintf("%d %d %d", f, n, d)
if original != later {
t.Errorf("test %d: fake exponential modified arguments: have\n%v\nwant\n%v", i, later, original)
}
}
}