forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a807a41
commit 4b91455
Showing
6 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2023 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package misc | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/scroll-tech/go-ethereum/params" | ||
) | ||
|
||
var ( | ||
minBlobGasPrice = big.NewInt(params.BlobTxMinBlobGasprice) | ||
blobGaspriceUpdateFraction = big.NewInt(params.BlobTxBlobGaspriceUpdateFraction) | ||
) | ||
|
||
// CalcExcessBlobGas calculates the excess blob gas after applying the set of | ||
// blobs on top of the excess blob gas. | ||
func CalcExcessBlobGas(parentExcessBlobGas uint64, parentBlobGasUsed uint64) uint64 { | ||
excessBlobGas := parentExcessBlobGas + parentBlobGasUsed | ||
if excessBlobGas < params.BlobTxTargetBlobGasPerBlock { | ||
return 0 | ||
} | ||
return excessBlobGas - params.BlobTxTargetBlobGasPerBlock | ||
} | ||
|
||
// CalcBlobFee calculates the blobfee from the header's excess blob gas field. | ||
func CalcBlobFee(excessBlobGas uint64) *big.Int { | ||
return fakeExponential(minBlobGasPrice, new(big.Int).SetUint64(excessBlobGas), blobGaspriceUpdateFraction) | ||
} | ||
|
||
// fakeExponential approximates factor * e ** (numerator / denominator) using | ||
// Taylor expansion. | ||
func fakeExponential(factor, numerator, denominator *big.Int) *big.Int { | ||
var ( | ||
output = new(big.Int) | ||
accum = new(big.Int).Mul(factor, denominator) | ||
) | ||
for i := 1; accum.Sign() > 0; i++ { | ||
output.Add(output, accum) | ||
|
||
accum.Mul(accum, numerator) | ||
accum.Div(accum, denominator) | ||
accum.Div(accum, big.NewInt(int64(i))) | ||
} | ||
return output.Div(output, denominator) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters