Basefee change depends on unique messages not all messages
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
1ba5dd4c72
commit
c841f26256
@ -89,11 +89,14 @@ const VerifSigCacheSize = 32000
|
|||||||
|
|
||||||
// TODO: If this is gonna stay, it should move to specs-actors
|
// TODO: If this is gonna stay, it should move to specs-actors
|
||||||
const BlockMessageLimit = 10000
|
const BlockMessageLimit = 10000
|
||||||
|
|
||||||
const BlockGasLimit = 10_000_000_000
|
const BlockGasLimit = 10_000_000_000
|
||||||
const BlockGasTarget = BlockGasLimit / 2
|
const BlockGasTarget = BlockGasLimit / 2
|
||||||
const BaseFeeMaxChangeDenom = 8 // 12.5%
|
const BaseFeeMaxChangeDenom = 8 // 12.5%
|
||||||
const InitialBaseFee = 100e6
|
const InitialBaseFee = 100e6
|
||||||
const MinimumBaseFee = 100
|
const MinimumBaseFee = 100
|
||||||
|
const PackingEfficiencyNum = 4
|
||||||
|
const PackingEfficiencyDenom = 5
|
||||||
|
|
||||||
// Actor consts
|
// Actor consts
|
||||||
// TODO: Pull from actors when its made not private
|
// TODO: Pull from actors when its made not private
|
||||||
|
@ -7,11 +7,26 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func computeNextBaseFee(baseFee types.BigInt, gasLimitUsed int64, noOfBlocks int) types.BigInt {
|
func computeNextBaseFee(baseFee types.BigInt, gasLimitUsed int64, noOfBlocks int) types.BigInt {
|
||||||
delta := gasLimitUsed/int64(noOfBlocks) - build.BlockGasTarget
|
// deta := 1/PackingEfficiency * gasLimitUsed/noOfBlocks - build.BlockGasTarget
|
||||||
|
// change := baseFee * deta / BlockGasTarget / BaseFeeMaxChangeDenom
|
||||||
|
// nextBaseFee = baseFee + change
|
||||||
|
// nextBaseFee = max(nextBaseFee, build.MinimumBaseFee)
|
||||||
|
|
||||||
|
delta := build.PackingEfficiencyDenom * gasLimitUsed / int64(noOfBlocks*build.PackingEfficiencyNum)
|
||||||
|
delta -= build.BlockGasTarget
|
||||||
|
|
||||||
|
// cap change at 12.5% (BaseFeeMaxChangeDenom) by capping delta
|
||||||
|
if delta > build.BlockGasTarget {
|
||||||
|
delta = build.BlockGasTarget
|
||||||
|
}
|
||||||
|
if delta < -build.BlockGasTarget {
|
||||||
|
delta = -build.BlockGasTarget
|
||||||
|
}
|
||||||
|
|
||||||
change := big.Mul(baseFee, big.NewInt(delta))
|
change := big.Mul(baseFee, big.NewInt(delta))
|
||||||
change = big.Div(change, big.NewInt(build.BlockGasTarget))
|
change = big.Div(change, big.NewInt(build.BlockGasTarget))
|
||||||
@ -26,17 +41,30 @@ func computeNextBaseFee(baseFee types.BigInt, gasLimitUsed int64, noOfBlocks int
|
|||||||
|
|
||||||
func (cs *ChainStore) ComputeBaseFee(ctx context.Context, ts *types.TipSet) (abi.TokenAmount, error) {
|
func (cs *ChainStore) ComputeBaseFee(ctx context.Context, ts *types.TipSet) (abi.TokenAmount, error) {
|
||||||
zero := abi.NewTokenAmount(0)
|
zero := abi.NewTokenAmount(0)
|
||||||
|
|
||||||
|
// totalLimit is sum of GasLimits of unique messages in a tipset
|
||||||
totalLimit := int64(0)
|
totalLimit := int64(0)
|
||||||
|
|
||||||
|
seen := make(map[cid.Cid]struct{})
|
||||||
|
|
||||||
for _, b := range ts.Blocks() {
|
for _, b := range ts.Blocks() {
|
||||||
msg1, msg2, err := cs.MessagesForBlock(b)
|
msg1, msg2, err := cs.MessagesForBlock(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return zero, xerrors.Errorf("error getting messages for: %s: %w", b.Cid(), err)
|
return zero, xerrors.Errorf("error getting messages for: %s: %w", b.Cid(), err)
|
||||||
}
|
}
|
||||||
for _, m := range msg1 {
|
for _, m := range msg1 {
|
||||||
totalLimit += m.GasLimit
|
c := m.Cid()
|
||||||
|
if _, ok := seen[c]; !ok {
|
||||||
|
totalLimit += m.GasLimit
|
||||||
|
seen[c] = struct{}{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, m := range msg2 {
|
for _, m := range msg2 {
|
||||||
totalLimit += m.Message.GasLimit
|
c := m.Cid()
|
||||||
|
if _, ok := seen[c]; !ok {
|
||||||
|
totalLimit += m.Message.GasLimit
|
||||||
|
seen[c] = struct{}{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parentBaseFee := ts.Blocks()[0].ParentBaseFee
|
parentBaseFee := ts.Blocks()[0].ParentBaseFee
|
||||||
|
@ -18,10 +18,10 @@ func TestBaseFee(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{100e6, 0, 1, 87.5e6},
|
{100e6, 0, 1, 87.5e6},
|
||||||
{100e6, 0, 5, 87.5e6},
|
{100e6, 0, 5, 87.5e6},
|
||||||
{100e6, build.BlockGasTarget, 1, 100e6},
|
{100e6, build.BlockGasTarget, 1, 103.125e6},
|
||||||
{100e6, build.BlockGasTarget * 2, 2, 100e6},
|
{100e6, build.BlockGasTarget * 2, 2, 103.125e6},
|
||||||
{100e6, build.BlockGasLimit * 2, 2, 112.5e6},
|
{100e6, build.BlockGasLimit * 2, 2, 112.5e6},
|
||||||
{100e6, build.BlockGasLimit * 1.5, 2, 106.25e6},
|
{100e6, build.BlockGasLimit * 1.5, 2, 110937500},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user