|
| 1 | +// Copyright 2021 The go-ethereum Authors |
| 2 | +// This file is part of the go-ethereum library. |
| 3 | +// |
| 4 | +// The go-ethereum library is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Lesser General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// The go-ethereum library is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Lesser General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Lesser General Public License |
| 15 | +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package misc |
| 18 | + |
| 19 | +import ( |
| 20 | + "math" |
| 21 | + |
| 22 | + "github.com/ethereum/go-ethereum/core/types" |
| 23 | + "github.com/ethereum/go-ethereum/params" |
| 24 | +) |
| 25 | + |
| 26 | +// CalcExcessBlobTransactions calculates the number of blobs above the target |
| 27 | +func CalcExcessBlobTransactions(parent *types.Header, blobs uint64) uint64 { |
| 28 | + adjusted := parent.ExcessBlobs + blobs |
| 29 | + if adjusted < params.TargetBlobsPerBlock { |
| 30 | + return 0 |
| 31 | + } |
| 32 | + return adjusted - params.TargetBlobsPerBlock |
| 33 | +} |
| 34 | + |
| 35 | +// FakeExponential approximates 2 ** (num / denom) |
| 36 | +func FakeExponential(num uint64, denom uint64) uint64 { |
| 37 | + cofactor := uint64(math.Exp2(float64(num / denom))) |
| 38 | + fractional := num % denom |
| 39 | + return cofactor + (fractional*cofactor*2+ |
| 40 | + (uint64(math.Pow(float64(fractional), 2))*cofactor)/denom)/(denom*3) |
| 41 | +} |
| 42 | + |
| 43 | +func CountBlobs(txs []*types.Transaction) int { |
| 44 | + var count int |
| 45 | + for _, tx := range txs { |
| 46 | + count += len(tx.DataHashes()) |
| 47 | + } |
| 48 | + return count |
| 49 | +} |
0 commit comments