Introduce base fee
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
a625943fc3
commit
722d6e8ffb
@ -89,7 +89,11 @@ 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 = 512
|
const BlockMessageLimit = 512
|
||||||
const BlockGasLimit = 7_500_000_000
|
const BlockGasLimit = 10_000_000_000
|
||||||
|
const BlockGasTarget = BlockGasLimit / 2
|
||||||
|
const BaseFeeMaxChangeDenom = 8 // 12.5%
|
||||||
|
const InitialBaseFee = 100e6
|
||||||
|
const MinimumBaseFee = 100
|
||||||
|
|
||||||
// Actor consts
|
// Actor consts
|
||||||
// TODO: Pull from actors when its made not private
|
// TODO: Pull from actors when its made not private
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/state"
|
"github.com/filecoin-project/lotus/chain/state"
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
@ -321,7 +322,16 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci
|
|||||||
verifNeeds := make(map[address.Address]abi.PaddedPieceSize)
|
verifNeeds := make(map[address.Address]abi.PaddedPieceSize)
|
||||||
var sum abi.PaddedPieceSize
|
var sum abi.PaddedPieceSize
|
||||||
|
|
||||||
vm, err := vm.NewVM(stateroot, 0, &fakeRand{}, cs.Blockstore(), mkFakedSigSyscalls(cs.VMSys()), nil)
|
vmopt := vm.VMOpts{
|
||||||
|
StateBase: stateroot,
|
||||||
|
Epoch: 0,
|
||||||
|
Rand: &fakeRand{},
|
||||||
|
Bstore: cs.Blockstore(),
|
||||||
|
Syscalls: mkFakedSigSyscalls(cs.VMSys()),
|
||||||
|
VestedCalc: nil,
|
||||||
|
BaseFee: types.NewInt(0),
|
||||||
|
}
|
||||||
|
vm, err := vm.NewVM(&vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err)
|
return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err)
|
||||||
}
|
}
|
||||||
@ -443,6 +453,7 @@ func MakeGenesisBlock(ctx context.Context, bs bstore.Blockstore, sys vm.SyscallB
|
|||||||
Data: make([]byte, 32),
|
Data: make([]byte, 32),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
ParentBaseFee: abi.NewTokenAmount(build.InitialBaseFee),
|
||||||
}
|
}
|
||||||
|
|
||||||
sb, err := b.ToStorageBlock()
|
sb, err := b.ToStorageBlock()
|
||||||
|
@ -4,9 +4,10 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/filecoin-project/lotus/chain/state"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/state"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
@ -60,7 +61,17 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
|||||||
return big.Zero(), nil
|
return big.Zero(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
vm, err := vm.NewVM(sroot, 0, &fakeRand{}, cs.Blockstore(), mkFakedSigSyscalls(cs.VMSys()), vc)
|
vmopt := &vm.VMOpts{
|
||||||
|
StateBase: sroot,
|
||||||
|
Epoch: 0,
|
||||||
|
Rand: &fakeRand{},
|
||||||
|
Bstore: cs.Blockstore(),
|
||||||
|
Syscalls: mkFakedSigSyscalls(cs.VMSys()),
|
||||||
|
VestedCalc: vc,
|
||||||
|
BaseFee: types.NewInt(0),
|
||||||
|
}
|
||||||
|
|
||||||
|
vm, err := vm.NewVM(vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err)
|
return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,12 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
|
|||||||
}
|
}
|
||||||
next.ParentWeight = pweight
|
next.ParentWeight = pweight
|
||||||
|
|
||||||
|
baseFee, err := sm.ChainStore().ComputeBaseFee(ctx, pts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("computing base fee: %w", err)
|
||||||
|
}
|
||||||
|
next.ParentBaseFee = baseFee
|
||||||
|
|
||||||
cst := cbor.NewCborStore(sm.ChainStore().Blockstore())
|
cst := cbor.NewCborStore(sm.ChainStore().Blockstore())
|
||||||
tree, err := state.LoadStateTree(cst, st)
|
tree, err := state.LoadStateTree(cst, st)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -22,7 +22,17 @@ func (sm *StateManager) CallRaw(ctx context.Context, msg *types.Message, bstate
|
|||||||
ctx, span := trace.StartSpan(ctx, "statemanager.CallRaw")
|
ctx, span := trace.StartSpan(ctx, "statemanager.CallRaw")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
vmi, err := vm.NewVM(bstate, bheight, r, sm.cs.Blockstore(), sm.cs.VMSys(), sm.GetVestedFunds)
|
vmopt := &vm.VMOpts{
|
||||||
|
StateBase: bstate,
|
||||||
|
Epoch: bheight,
|
||||||
|
Rand: r,
|
||||||
|
Bstore: sm.cs.Blockstore(),
|
||||||
|
Syscalls: sm.cs.VMSys(),
|
||||||
|
VestedCalc: sm.GetVestedFunds,
|
||||||
|
BaseFee: types.NewInt(0),
|
||||||
|
}
|
||||||
|
|
||||||
|
vmi, err := vm.NewVM(vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to set up vm: %w", err)
|
return nil, xerrors.Errorf("failed to set up vm: %w", err)
|
||||||
}
|
}
|
||||||
@ -106,7 +116,16 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
vmi, err := vm.NewVM(state, ts.Height(), r, sm.cs.Blockstore(), sm.cs.VMSys(), sm.GetVestedFunds)
|
vmopt := &vm.VMOpts{
|
||||||
|
StateBase: state,
|
||||||
|
Epoch: ts.Height(),
|
||||||
|
Rand: r,
|
||||||
|
Bstore: sm.cs.Blockstore(),
|
||||||
|
Syscalls: sm.cs.VMSys(),
|
||||||
|
VestedCalc: sm.GetVestedFunds,
|
||||||
|
BaseFee: ts.Blocks()[0].ParentBaseFee,
|
||||||
|
}
|
||||||
|
vmi, err := vm.NewVM(vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to set up vm: %w", err)
|
return nil, xerrors.Errorf("failed to set up vm: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,9 @@ import (
|
|||||||
. "github.com/filecoin-project/lotus/chain/stmgr"
|
. "github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/vm"
|
"github.com/filecoin-project/lotus/chain/vm"
|
||||||
"github.com/filecoin-project/lotus/lib/blockstore"
|
|
||||||
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
|
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
|
||||||
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
@ -151,8 +149,8 @@ func TestForkHeightTriggers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inv.Register(builtin.PaymentChannelActorCodeID, &testActor{}, &testActorState{})
|
inv.Register(builtin.PaymentChannelActorCodeID, &testActor{}, &testActorState{})
|
||||||
sm.SetVMConstructor(func(c cid.Cid, h abi.ChainEpoch, r vm.Rand, b blockstore.Blockstore, s vm.SyscallBuilder, vc vm.VestedCalculator) (*vm.VM, error) {
|
sm.SetVMConstructor(func(vmopt *vm.VMOpts) (*vm.VM, error) {
|
||||||
nvm, err := vm.NewVM(c, h, r, b, s, sm.GetVestedFunds)
|
nvm, err := vm.NewVM(vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,10 @@ package stmgr
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
@ -14,7 +15,6 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/vm"
|
"github.com/filecoin-project/lotus/chain/vm"
|
||||||
"github.com/filecoin-project/lotus/lib/blockstore"
|
|
||||||
|
|
||||||
"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"
|
||||||
@ -41,7 +41,7 @@ type StateManager struct {
|
|||||||
compWait map[string]chan struct{}
|
compWait map[string]chan struct{}
|
||||||
stlk sync.Mutex
|
stlk sync.Mutex
|
||||||
genesisMsigLk sync.Mutex
|
genesisMsigLk sync.Mutex
|
||||||
newVM func(cid.Cid, abi.ChainEpoch, vm.Rand, blockstore.Blockstore, vm.SyscallBuilder, vm.VestedCalculator) (*vm.VM, error)
|
newVM func(*vm.VMOpts) (*vm.VM, error)
|
||||||
genesisMsigs []multisig.State
|
genesisMsigs []multisig.State
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,8 +150,19 @@ type BlockMessages struct {
|
|||||||
|
|
||||||
type ExecCallback func(cid.Cid, *types.Message, *vm.ApplyRet) error
|
type ExecCallback func(cid.Cid, *types.Message, *vm.ApplyRet) error
|
||||||
|
|
||||||
func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEpoch, pstate cid.Cid, bms []BlockMessages, epoch abi.ChainEpoch, r vm.Rand, cb ExecCallback) (cid.Cid, cid.Cid, error) {
|
func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEpoch, pstate cid.Cid, bms []BlockMessages, epoch abi.ChainEpoch, r vm.Rand, cb ExecCallback, baseFee abi.TokenAmount) (cid.Cid, cid.Cid, error) {
|
||||||
vmi, err := sm.newVM(pstate, epoch, r, sm.cs.Blockstore(), sm.cs.VMSys(), sm.GetVestedFunds)
|
|
||||||
|
vmopt := &vm.VMOpts{
|
||||||
|
StateBase: pstate,
|
||||||
|
Epoch: epoch,
|
||||||
|
Rand: r,
|
||||||
|
Bstore: sm.cs.Blockstore(),
|
||||||
|
Syscalls: sm.cs.VMSys(),
|
||||||
|
VestedCalc: sm.GetVestedFunds,
|
||||||
|
BaseFee: baseFee,
|
||||||
|
}
|
||||||
|
|
||||||
|
vmi, err := sm.newVM(vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, cid.Undef, xerrors.Errorf("instantiating VM failed: %w", err)
|
return cid.Undef, cid.Undef, xerrors.Errorf("instantiating VM failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -354,8 +365,9 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
|
|||||||
|
|
||||||
blkmsgs = append(blkmsgs, bm)
|
blkmsgs = append(blkmsgs, bm)
|
||||||
}
|
}
|
||||||
|
baseFee := blks[0].ParentBaseFee
|
||||||
|
|
||||||
return sm.ApplyBlocks(ctx, parentEpoch, pstate, blkmsgs, blks[0].Height, r, cb)
|
return sm.ApplyBlocks(ctx, parentEpoch, pstate, blkmsgs, blks[0].Height, r, cb, baseFee)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) parentState(ts *types.TipSet) cid.Cid {
|
func (sm *StateManager) parentState(ts *types.TipSet) cid.Cid {
|
||||||
@ -764,7 +776,7 @@ func (sm *StateManager) ValidateChain(ctx context.Context, ts *types.TipSet) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) SetVMConstructor(nvm func(cid.Cid, abi.ChainEpoch, vm.Rand, blockstore.Blockstore, vm.SyscallBuilder, vm.VestedCalculator) (*vm.VM, error)) {
|
func (sm *StateManager) SetVMConstructor(nvm func(*vm.VMOpts) (*vm.VM, error)) {
|
||||||
sm.newVM = nvm
|
sm.newVM = nvm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +440,16 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch,
|
|||||||
}
|
}
|
||||||
|
|
||||||
r := store.NewChainRand(sm.cs, ts.Cids(), height)
|
r := store.NewChainRand(sm.cs, ts.Cids(), height)
|
||||||
vmi, err := vm.NewVM(base, height, r, sm.cs.Blockstore(), sm.cs.VMSys(), sm.GetVestedFunds)
|
vmopt := &vm.VMOpts{
|
||||||
|
StateBase: base,
|
||||||
|
Epoch: height,
|
||||||
|
Rand: r,
|
||||||
|
Bstore: sm.cs.Blockstore(),
|
||||||
|
Syscalls: sm.cs.VMSys(),
|
||||||
|
VestedCalc: sm.GetVestedFunds,
|
||||||
|
BaseFee: ts.Blocks()[0].ParentBaseFee,
|
||||||
|
}
|
||||||
|
vmi, err := vm.NewVM(vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, nil, err
|
return cid.Undef, nil, err
|
||||||
}
|
}
|
||||||
@ -595,7 +604,16 @@ func (sm *StateManager) CirculatingSupply(ctx context.Context, ts *types.TipSet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
r := store.NewChainRand(sm.cs, ts.Cids(), ts.Height())
|
r := store.NewChainRand(sm.cs, ts.Cids(), ts.Height())
|
||||||
vmi, err := vm.NewVM(st, ts.Height(), r, sm.cs.Blockstore(), sm.cs.VMSys(), sm.GetVestedFunds)
|
vmopt := &vm.VMOpts{
|
||||||
|
StateBase: st,
|
||||||
|
Epoch: ts.Height(),
|
||||||
|
Rand: r,
|
||||||
|
Bstore: sm.cs.Blockstore(),
|
||||||
|
Syscalls: sm.cs.VMSys(),
|
||||||
|
VestedCalc: sm.GetVestedFunds,
|
||||||
|
BaseFee: ts.Blocks()[0].ParentBaseFee,
|
||||||
|
}
|
||||||
|
vmi, err := vm.NewVM(vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return big.Zero(), err
|
return big.Zero(), err
|
||||||
}
|
}
|
||||||
|
42
chain/store/basefee.go
Normal file
42
chain/store/basefee.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package store
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (cs *ChainStore) ComputeBaseFee(ctx context.Context, ts *types.TipSet) (abi.TokenAmount, error) {
|
||||||
|
zero := abi.NewTokenAmount(0)
|
||||||
|
totalLimit := int64(0)
|
||||||
|
for _, b := range ts.Blocks() {
|
||||||
|
msg1, msg2, err := cs.MessagesForBlock(b)
|
||||||
|
if err != nil {
|
||||||
|
return zero, xerrors.Errorf("error getting messages for: %s: %w", b.Cid(), err)
|
||||||
|
}
|
||||||
|
for _, m := range msg1 {
|
||||||
|
totalLimit += m.GasLimit
|
||||||
|
}
|
||||||
|
for _, m := range msg2 {
|
||||||
|
totalLimit += m.Message.GasLimit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parentBaseFee := ts.Blocks()[0].ParentBaseFee
|
||||||
|
|
||||||
|
delta := totalLimit/int64(len(ts.Blocks())) - build.BlockGasTarget
|
||||||
|
|
||||||
|
change := big.Mul(parentBaseFee, big.NewInt(delta))
|
||||||
|
change = big.Div(change, big.NewInt(build.BlockGasTarget))
|
||||||
|
change = big.Div(change, big.NewInt(build.BaseFeeMaxChangeDenom))
|
||||||
|
|
||||||
|
baseFee := big.Add(parentBaseFee, change)
|
||||||
|
if big.Cmp(baseFee, big.NewInt(build.MinimumBaseFee)) < 0 {
|
||||||
|
baseFee = big.NewInt(build.MinimumBaseFee)
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseFee, nil
|
||||||
|
}
|
@ -22,7 +22,7 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn
|
|||||||
}
|
}
|
||||||
// >>> w[r] <<< + wFunction(totalPowerAtTipset(ts)) * 2^8 + (wFunction(totalPowerAtTipset(ts)) * sum(ts.blocks[].ElectionProof.WinCount) * wRatio_num * 2^8) / (e * wRatio_den)
|
// >>> w[r] <<< + wFunction(totalPowerAtTipset(ts)) * 2^8 + (wFunction(totalPowerAtTipset(ts)) * sum(ts.blocks[].ElectionProof.WinCount) * wRatio_num * 2^8) / (e * wRatio_den)
|
||||||
|
|
||||||
var out = new(big.Int).Set(ts.Blocks()[0].ParentWeight.Int)
|
var out = new(big.Int).Set(ts.ParentWeight().Int)
|
||||||
|
|
||||||
// >>> wFunction(totalPowerAtTipset(ts)) * 2^8 <<< + (wFunction(totalPowerAtTipset(ts)) * sum(ts.blocks[].ElectionProof.WinCount) * wRatio_num * 2^8) / (e * wRatio_den)
|
// >>> wFunction(totalPowerAtTipset(ts)) * 2^8 <<< + (wFunction(totalPowerAtTipset(ts)) * sum(ts.blocks[].ElectionProof.WinCount) * wRatio_num * 2^8) / (e * wRatio_den)
|
||||||
|
|
||||||
|
@ -698,6 +698,18 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
baseFeeCheck := async.Err(func() error {
|
||||||
|
baseFee, err := syncer.store.ComputeBaseFee(ctx, baseTs)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("computing base fee: %w", err)
|
||||||
|
}
|
||||||
|
if types.BigCmp(baseFee, b.Header.ParentBaseFee) != 0 {
|
||||||
|
return xerrors.Errorf("base fee doesn't match: %s (header) != %s (computed)",
|
||||||
|
b.Header.ParentBaseFee, baseFee)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
pweight, err := syncer.store.Weight(ctx, baseTs)
|
pweight, err := syncer.store.Weight(ctx, baseTs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("getting parent weight: %w", err)
|
return xerrors.Errorf("getting parent weight: %w", err)
|
||||||
@ -850,6 +862,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er
|
|||||||
wproofCheck,
|
wproofCheck,
|
||||||
winnerCheck,
|
winnerCheck,
|
||||||
msgsCheck,
|
msgsCheck,
|
||||||
|
baseFeeCheck,
|
||||||
}
|
}
|
||||||
|
|
||||||
var merr error
|
var merr error
|
||||||
|
@ -65,6 +65,9 @@ type BlockHeader struct {
|
|||||||
|
|
||||||
ForkSignaling uint64 // 14
|
ForkSignaling uint64 // 14
|
||||||
|
|
||||||
|
// ParentBaseFee is the base fee after executing parent tipset
|
||||||
|
ParentBaseFee abi.TokenAmount // 15
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
validated bool // true if the signature has been validated
|
validated bool // true if the signature has been validated
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
var _ = xerrors.Errorf
|
var _ = xerrors.Errorf
|
||||||
|
|
||||||
var lengthBufBlockHeader = []byte{143}
|
var lengthBufBlockHeader = []byte{144}
|
||||||
|
|
||||||
func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
|
func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
@ -142,6 +142,10 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// t.ParentBaseFee (big.Int) (struct)
|
||||||
|
if err := t.ParentBaseFee.MarshalCBOR(w); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +163,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return fmt.Errorf("cbor input should be of type array")
|
return fmt.Errorf("cbor input should be of type array")
|
||||||
}
|
}
|
||||||
|
|
||||||
if extra != 15 {
|
if extra != 16 {
|
||||||
return fmt.Errorf("cbor input had wrong number of fields")
|
return fmt.Errorf("cbor input had wrong number of fields")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,6 +443,15 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
|
|||||||
}
|
}
|
||||||
t.ForkSignaling = uint64(extra)
|
t.ForkSignaling = uint64(extra)
|
||||||
|
|
||||||
|
}
|
||||||
|
// t.ParentBaseFee (big.Int) (struct)
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
if err := t.ParentBaseFee.UnmarshalCBOR(br); err != nil {
|
||||||
|
return xerrors.Errorf("unmarshaling t.ParentBaseFee: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -619,7 +632,7 @@ func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var lengthBufMessage = []byte{137}
|
var lengthBufMessage = []byte{139}
|
||||||
|
|
||||||
func (t *Message) MarshalCBOR(w io.Writer) error {
|
func (t *Message) MarshalCBOR(w io.Writer) error {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
@ -680,6 +693,16 @@ func (t *Message) MarshalCBOR(w io.Writer) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// t.GasFeeCap (big.Int) (struct)
|
||||||
|
if err := t.GasFeeCap.MarshalCBOR(w); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// t.GasPremium (big.Int) (struct)
|
||||||
|
if err := t.GasPremium.MarshalCBOR(w); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// t.Method (abi.MethodNum) (uint64)
|
// t.Method (abi.MethodNum) (uint64)
|
||||||
|
|
||||||
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Method)); err != nil {
|
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Method)); err != nil {
|
||||||
@ -715,7 +738,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return fmt.Errorf("cbor input should be of type array")
|
return fmt.Errorf("cbor input should be of type array")
|
||||||
}
|
}
|
||||||
|
|
||||||
if extra != 9 {
|
if extra != 11 {
|
||||||
return fmt.Errorf("cbor input had wrong number of fields")
|
return fmt.Errorf("cbor input had wrong number of fields")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -819,6 +842,24 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
|
|||||||
|
|
||||||
t.GasLimit = int64(extraI)
|
t.GasLimit = int64(extraI)
|
||||||
}
|
}
|
||||||
|
// t.GasFeeCap (big.Int) (struct)
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
if err := t.GasFeeCap.UnmarshalCBOR(br); err != nil {
|
||||||
|
return xerrors.Errorf("unmarshaling t.GasFeeCap: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// t.GasPremium (big.Int) (struct)
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
if err := t.GasPremium.UnmarshalCBOR(br); err != nil {
|
||||||
|
return xerrors.Errorf("unmarshaling t.GasPremium: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
// t.Method (abi.MethodNum) (uint64)
|
// t.Method (abi.MethodNum) (uint64)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -32,10 +32,13 @@ type Message struct {
|
|||||||
|
|
||||||
Nonce uint64
|
Nonce uint64
|
||||||
|
|
||||||
Value BigInt
|
Value abi.TokenAmount
|
||||||
|
|
||||||
GasPrice BigInt
|
// TODO: remove
|
||||||
GasLimit int64
|
GasPrice BigInt
|
||||||
|
GasLimit int64
|
||||||
|
GasFeeCap abi.TokenAmount
|
||||||
|
GasPremium abi.TokenAmount
|
||||||
|
|
||||||
Method abi.MethodNum
|
Method abi.MethodNum
|
||||||
Params []byte
|
Params []byte
|
||||||
@ -106,7 +109,7 @@ func (m *Message) Cid() cid.Cid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) RequiredFunds() BigInt {
|
func (m *Message) RequiredFunds() BigInt {
|
||||||
return BigMul(m.GasPrice, NewInt(uint64(m.GasLimit)))
|
return BigMul(m.GasFeeCap, NewInt(uint64(m.GasLimit)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) VMMessage() *Message {
|
func (m *Message) VMMessage() *Message {
|
||||||
|
@ -2,6 +2,7 @@ package validation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
@ -89,6 +90,7 @@ func (a *Applier) ApplyTipSetMessages(epoch abi.ChainEpoch, blocks []vtypes.Bloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
var receipts []vtypes.MessageReceipt
|
var receipts []vtypes.MessageReceipt
|
||||||
|
// TODO: base fee
|
||||||
sroot, _, err := sm.ApplyBlocks(context.TODO(), epoch-1, a.stateWrapper.Root(), bms, epoch, &randWrapper{rnd}, func(c cid.Cid, msg *types.Message, ret *vm.ApplyRet) error {
|
sroot, _, err := sm.ApplyBlocks(context.TODO(), epoch-1, a.stateWrapper.Root(), bms, epoch, &randWrapper{rnd}, func(c cid.Cid, msg *types.Message, ret *vm.ApplyRet) error {
|
||||||
if msg.From == builtin.SystemActorAddr {
|
if msg.From == builtin.SystemActorAddr {
|
||||||
return nil // ignore reward and cron calls
|
return nil // ignore reward and cron calls
|
||||||
@ -104,7 +106,7 @@ func (a *Applier) ApplyTipSetMessages(epoch abi.ChainEpoch, blocks []vtypes.Bloc
|
|||||||
GasUsed: vtypes.GasUnits(ret.GasUsed),
|
GasUsed: vtypes.GasUnits(ret.GasUsed),
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
})
|
}, abi.NewTokenAmount(0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return vtypes.ApplyTipSetResult{}, err
|
return vtypes.ApplyTipSetResult{}, err
|
||||||
}
|
}
|
||||||
@ -136,7 +138,17 @@ func (a *Applier) applyMessage(epoch abi.ChainEpoch, lm types.ChainMsg) (vtypes.
|
|||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
base := a.stateWrapper.Root()
|
base := a.stateWrapper.Root()
|
||||||
|
|
||||||
lotusVM, err := vm.NewVM(base, epoch, &vmRand{}, a.stateWrapper.bs, a.syscalls, nil)
|
vmopt := &vm.VMOpts{
|
||||||
|
StateBase: base,
|
||||||
|
Epoch: epoch,
|
||||||
|
Rand: &vmRand{},
|
||||||
|
Bstore: a.stateWrapper.bs,
|
||||||
|
Syscalls: a.syscalls,
|
||||||
|
VestedCalc: nil,
|
||||||
|
BaseFee: types.NewInt(0), // TODO: basefee
|
||||||
|
}
|
||||||
|
|
||||||
|
lotusVM, err := vm.NewVM(vmopt)
|
||||||
// need to modify the VM invoker to add the puppet actor
|
// need to modify the VM invoker to add the puppet actor
|
||||||
chainValInvoker := vm.NewInvoker()
|
chainValInvoker := vm.NewInvoker()
|
||||||
chainValInvoker.Register(puppet.PuppetActorCodeID, puppet.Actor{}, puppet.State{})
|
chainValInvoker.Register(puppet.PuppetActorCodeID, puppet.Actor{}, puppet.State{})
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
bstore "github.com/filecoin-project/lotus/lib/blockstore"
|
||||||
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
|
|
||||||
block "github.com/ipfs/go-block-format"
|
block "github.com/ipfs/go-block-format"
|
||||||
@ -149,28 +151,40 @@ type VM struct {
|
|||||||
inv *Invoker
|
inv *Invoker
|
||||||
rand Rand
|
rand Rand
|
||||||
vc VestedCalculator
|
vc VestedCalculator
|
||||||
|
baseFee abi.TokenAmount
|
||||||
|
|
||||||
Syscalls SyscallBuilder
|
Syscalls SyscallBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVM(base cid.Cid, height abi.ChainEpoch, r Rand, cbs blockstore.Blockstore, syscalls SyscallBuilder, vestedCalc VestedCalculator) (*VM, error) {
|
type VMOpts struct {
|
||||||
buf := bufbstore.NewBufferedBstore(cbs)
|
StateBase cid.Cid
|
||||||
|
Epoch abi.ChainEpoch
|
||||||
|
Rand Rand
|
||||||
|
Bstore bstore.Blockstore
|
||||||
|
Syscalls SyscallBuilder
|
||||||
|
VestedCalc VestedCalculator
|
||||||
|
BaseFee abi.TokenAmount
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewVM(opts *VMOpts) (*VM, error) {
|
||||||
|
buf := bufbstore.NewBufferedBstore(opts.Bstore)
|
||||||
cst := cbor.NewCborStore(buf)
|
cst := cbor.NewCborStore(buf)
|
||||||
state, err := state.LoadStateTree(cst, base)
|
state, err := state.LoadStateTree(cst, opts.StateBase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &VM{
|
return &VM{
|
||||||
cstate: state,
|
cstate: state,
|
||||||
base: base,
|
base: opts.StateBase,
|
||||||
cst: cst,
|
cst: cst,
|
||||||
buf: buf,
|
buf: buf,
|
||||||
blockHeight: height,
|
blockHeight: opts.Epoch,
|
||||||
inv: NewInvoker(),
|
inv: NewInvoker(),
|
||||||
rand: r, // TODO: Probably should be a syscall
|
rand: opts.Rand, // TODO: Probably should be a syscall
|
||||||
vc: vestedCalc,
|
vc: opts.VestedCalc,
|
||||||
Syscalls: syscalls,
|
Syscalls: opts.Syscalls,
|
||||||
|
baseFee: opts.BaseFee,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user