Merge pull request #6629 from filecoin-project/feat/pledge-from-miner-balance
Config for collateral from miner available balance
This commit is contained in:
commit
583a8a13d9
@ -836,6 +836,11 @@ workflows:
|
|||||||
suite: itest-sector_finalize_early
|
suite: itest-sector_finalize_early
|
||||||
target: "./itests/sector_finalize_early_test.go"
|
target: "./itests/sector_finalize_early_test.go"
|
||||||
|
|
||||||
|
- test:
|
||||||
|
name: test-itest-sector_miner_collateral
|
||||||
|
suite: itest-sector_miner_collateral
|
||||||
|
target: "./itests/sector_miner_collateral_test.go"
|
||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: test-itest-sector_pledge
|
name: test-itest-sector_pledge
|
||||||
suite: itest-sector_pledge
|
suite: itest-sector_pledge
|
||||||
|
47
extern/storage-sealing/commit_batch.go
vendored
47
extern/storage-sealing/commit_batch.go
vendored
@ -7,10 +7,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/network"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
@ -18,13 +14,16 @@ import (
|
|||||||
"github.com/filecoin-project/go-bitfield"
|
"github.com/filecoin-project/go-bitfield"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
|
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
|
||||||
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/policy"
|
"github.com/filecoin-project/lotus/chain/actors/policy"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
|
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
|
||||||
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
||||||
"github.com/filecoin-project/lotus/node/config"
|
"github.com/filecoin-project/lotus/node/config"
|
||||||
@ -46,6 +45,7 @@ type CommitBatcherApi interface {
|
|||||||
StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok TipSetToken) (*miner.SectorPreCommitOnChainInfo, error)
|
StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok TipSetToken) (*miner.SectorPreCommitOnChainInfo, error)
|
||||||
StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error)
|
StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error)
|
||||||
StateNetworkVersion(ctx context.Context, tok TipSetToken) (network.Version, error)
|
StateNetworkVersion(ctx context.Context, tok TipSetToken) (network.Version, error)
|
||||||
|
StateMinerAvailableBalance(context.Context, address.Address, TipSetToken) (big.Int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AggregateInput struct {
|
type AggregateInput struct {
|
||||||
@ -225,7 +225,7 @@ func (b *CommitBatcher) maybeStartBatch(notif bool) ([]sealiface.CommitBatchRes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if individual {
|
if individual {
|
||||||
res, err = b.processIndividually()
|
res, err = b.processIndividually(cfg)
|
||||||
} else {
|
} else {
|
||||||
res, err = b.processBatch(cfg)
|
res, err = b.processBatch(cfg)
|
||||||
}
|
}
|
||||||
@ -341,6 +341,10 @@ func (b *CommitBatcher) processBatch(cfg sealiface.Config) ([]sealiface.CommitBa
|
|||||||
aggFee := big.Div(big.Mul(policy.AggregateNetworkFee(nv, len(infos), bf), aggFeeNum), aggFeeDen)
|
aggFee := big.Div(big.Mul(policy.AggregateNetworkFee(nv, len(infos), bf), aggFeeNum), aggFeeDen)
|
||||||
|
|
||||||
needFunds := big.Add(collateral, aggFee)
|
needFunds := big.Add(collateral, aggFee)
|
||||||
|
needFunds, err = collateralSendAmount(b.mctx, b.api, b.maddr, cfg, needFunds)
|
||||||
|
if err != nil {
|
||||||
|
return []sealiface.CommitBatchRes{res}, err
|
||||||
|
}
|
||||||
|
|
||||||
goodFunds := big.Add(maxFee, needFunds)
|
goodFunds := big.Add(maxFee, needFunds)
|
||||||
|
|
||||||
@ -361,12 +365,26 @@ func (b *CommitBatcher) processBatch(cfg sealiface.Config) ([]sealiface.CommitBa
|
|||||||
return []sealiface.CommitBatchRes{res}, nil
|
return []sealiface.CommitBatchRes{res}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *CommitBatcher) processIndividually() ([]sealiface.CommitBatchRes, error) {
|
func (b *CommitBatcher) processIndividually(cfg sealiface.Config) ([]sealiface.CommitBatchRes, error) {
|
||||||
mi, err := b.api.StateMinerInfo(b.mctx, b.maddr, nil)
|
mi, err := b.api.StateMinerInfo(b.mctx, b.maddr, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("couldn't get miner info: %w", err)
|
return nil, xerrors.Errorf("couldn't get miner info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
avail := types.TotalFilecoinInt
|
||||||
|
|
||||||
|
if cfg.CollateralFromMinerBalance && !cfg.DisableCollateralFallback {
|
||||||
|
avail, err = b.api.StateMinerAvailableBalance(b.mctx, b.maddr, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("getting available miner balance: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
avail = big.Sub(avail, cfg.AvailableBalanceBuffer)
|
||||||
|
if avail.LessThan(big.Zero()) {
|
||||||
|
avail = big.Zero()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tok, _, err := b.api.ChainHead(b.mctx)
|
tok, _, err := b.api.ChainHead(b.mctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -380,7 +398,7 @@ func (b *CommitBatcher) processIndividually() ([]sealiface.CommitBatchRes, error
|
|||||||
FailedSectors: map[abi.SectorNumber]string{},
|
FailedSectors: map[abi.SectorNumber]string{},
|
||||||
}
|
}
|
||||||
|
|
||||||
mcid, err := b.processSingle(mi, sn, info, tok)
|
mcid, err := b.processSingle(cfg, mi, &avail, sn, info, tok)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("process single error: %+v", err) // todo: return to user
|
log.Errorf("process single error: %+v", err) // todo: return to user
|
||||||
r.FailedSectors[sn] = err.Error()
|
r.FailedSectors[sn] = err.Error()
|
||||||
@ -394,7 +412,7 @@ func (b *CommitBatcher) processIndividually() ([]sealiface.CommitBatchRes, error
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *CommitBatcher) processSingle(mi miner.MinerInfo, sn abi.SectorNumber, info AggregateInput, tok TipSetToken) (cid.Cid, error) {
|
func (b *CommitBatcher) processSingle(cfg sealiface.Config, mi miner.MinerInfo, avail *abi.TokenAmount, sn abi.SectorNumber, info AggregateInput, tok TipSetToken) (cid.Cid, error) {
|
||||||
enc := new(bytes.Buffer)
|
enc := new(bytes.Buffer)
|
||||||
params := &miner.ProveCommitSectorParams{
|
params := &miner.ProveCommitSectorParams{
|
||||||
SectorNumber: sn,
|
SectorNumber: sn,
|
||||||
@ -410,6 +428,19 @@ func (b *CommitBatcher) processSingle(mi miner.MinerInfo, sn abi.SectorNumber, i
|
|||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.CollateralFromMinerBalance {
|
||||||
|
c := big.Sub(collateral, *avail)
|
||||||
|
*avail = big.Sub(*avail, collateral)
|
||||||
|
collateral = c
|
||||||
|
|
||||||
|
if collateral.LessThan(big.Zero()) {
|
||||||
|
collateral = big.Zero()
|
||||||
|
}
|
||||||
|
if (*avail).LessThan(big.Zero()) {
|
||||||
|
*avail = big.Zero()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
goodFunds := big.Add(collateral, big.Int(b.feeCfg.MaxCommitGasFee))
|
goodFunds := big.Add(collateral, big.Int(b.feeCfg.MaxCommitGasFee))
|
||||||
|
|
||||||
from, _, err := b.addrSel(b.mctx, mi, api.CommitAddr, goodFunds, collateral)
|
from, _, err := b.addrSel(b.mctx, mi, api.CommitAddr, goodFunds, collateral)
|
||||||
|
@ -88,6 +88,21 @@ func (mr *MockCommitBatcherApiMockRecorder) SendMsg(arg0, arg1, arg2, arg3, arg4
|
|||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMsg", reflect.TypeOf((*MockCommitBatcherApi)(nil).SendMsg), arg0, arg1, arg2, arg3, arg4, arg5, arg6)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMsg", reflect.TypeOf((*MockCommitBatcherApi)(nil).SendMsg), arg0, arg1, arg2, arg3, arg4, arg5, arg6)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StateMinerAvailableBalance mocks base method.
|
||||||
|
func (m *MockCommitBatcherApi) StateMinerAvailableBalance(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (big.Int, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "StateMinerAvailableBalance", arg0, arg1, arg2)
|
||||||
|
ret0, _ := ret[0].(big.Int)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// StateMinerAvailableBalance indicates an expected call of StateMinerAvailableBalance.
|
||||||
|
func (mr *MockCommitBatcherApiMockRecorder) StateMinerAvailableBalance(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateMinerAvailableBalance", reflect.TypeOf((*MockCommitBatcherApi)(nil).StateMinerAvailableBalance), arg0, arg1, arg2)
|
||||||
|
}
|
||||||
|
|
||||||
// StateMinerInfo mocks base method.
|
// StateMinerInfo mocks base method.
|
||||||
func (m *MockCommitBatcherApi) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (miner.MinerInfo, error) {
|
func (m *MockCommitBatcherApi) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (miner.MinerInfo, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
|
@ -71,6 +71,21 @@ func (mr *MockPreCommitBatcherApiMockRecorder) SendMsg(arg0, arg1, arg2, arg3, a
|
|||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMsg", reflect.TypeOf((*MockPreCommitBatcherApi)(nil).SendMsg), arg0, arg1, arg2, arg3, arg4, arg5, arg6)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMsg", reflect.TypeOf((*MockPreCommitBatcherApi)(nil).SendMsg), arg0, arg1, arg2, arg3, arg4, arg5, arg6)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StateMinerAvailableBalance mocks base method.
|
||||||
|
func (m *MockPreCommitBatcherApi) StateMinerAvailableBalance(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (big.Int, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "StateMinerAvailableBalance", arg0, arg1, arg2)
|
||||||
|
ret0, _ := ret[0].(big.Int)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// StateMinerAvailableBalance indicates an expected call of StateMinerAvailableBalance.
|
||||||
|
func (mr *MockPreCommitBatcherApiMockRecorder) StateMinerAvailableBalance(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateMinerAvailableBalance", reflect.TypeOf((*MockPreCommitBatcherApi)(nil).StateMinerAvailableBalance), arg0, arg1, arg2)
|
||||||
|
}
|
||||||
|
|
||||||
// StateMinerInfo mocks base method.
|
// StateMinerInfo mocks base method.
|
||||||
func (m *MockPreCommitBatcherApi) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (miner.MinerInfo, error) {
|
func (m *MockPreCommitBatcherApi) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (miner.MinerInfo, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
|
11
extern/storage-sealing/precommit_batch.go
vendored
11
extern/storage-sealing/precommit_batch.go
vendored
@ -7,9 +7,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/policy"
|
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
@ -20,7 +17,9 @@ import (
|
|||||||
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
|
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/policy"
|
||||||
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
||||||
"github.com/filecoin-project/lotus/node/config"
|
"github.com/filecoin-project/lotus/node/config"
|
||||||
)
|
)
|
||||||
@ -30,6 +29,7 @@ import (
|
|||||||
type PreCommitBatcherApi interface {
|
type PreCommitBatcherApi interface {
|
||||||
SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, maxFee abi.TokenAmount, params []byte) (cid.Cid, error)
|
SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, maxFee abi.TokenAmount, params []byte) (cid.Cid, error)
|
||||||
StateMinerInfo(context.Context, address.Address, TipSetToken) (miner.MinerInfo, error)
|
StateMinerInfo(context.Context, address.Address, TipSetToken) (miner.MinerInfo, error)
|
||||||
|
StateMinerAvailableBalance(context.Context, address.Address, TipSetToken) (big.Int, error)
|
||||||
ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error)
|
ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,6 +226,11 @@ func (b *PreCommitBatcher) processBatch(cfg sealiface.Config) ([]sealiface.PreCo
|
|||||||
deposit = big.Add(deposit, p.deposit)
|
deposit = big.Add(deposit, p.deposit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deposit, err := collateralSendAmount(b.mctx, b.api, b.maddr, cfg, deposit)
|
||||||
|
if err != nil {
|
||||||
|
return []sealiface.PreCommitBatchRes{res}, err
|
||||||
|
}
|
||||||
|
|
||||||
enc := new(bytes.Buffer)
|
enc := new(bytes.Buffer)
|
||||||
if err := params.MarshalCBOR(enc); err != nil {
|
if err := params.MarshalCBOR(enc); err != nil {
|
||||||
return []sealiface.PreCommitBatchRes{res}, xerrors.Errorf("couldn't serialize PreCommitSectorBatchParams: %w", err)
|
return []sealiface.PreCommitBatchRes{res}, xerrors.Errorf("couldn't serialize PreCommitSectorBatchParams: %w", err)
|
||||||
|
4
extern/storage-sealing/sealiface/config.go
vendored
4
extern/storage-sealing/sealiface/config.go
vendored
@ -24,6 +24,10 @@ type Config struct {
|
|||||||
|
|
||||||
FinalizeEarly bool
|
FinalizeEarly bool
|
||||||
|
|
||||||
|
CollateralFromMinerBalance bool
|
||||||
|
AvailableBalanceBuffer abi.TokenAmount
|
||||||
|
DisableCollateralFallback bool
|
||||||
|
|
||||||
BatchPreCommits bool
|
BatchPreCommits bool
|
||||||
MaxPreCommitBatch int
|
MaxPreCommitBatch int
|
||||||
PreCommitBatchWait time.Duration
|
PreCommitBatchWait time.Duration
|
||||||
|
1
extern/storage-sealing/sealing.go
vendored
1
extern/storage-sealing/sealing.go
vendored
@ -59,6 +59,7 @@ type SealingAPI interface {
|
|||||||
StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error)
|
StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error)
|
||||||
StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error)
|
StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error)
|
||||||
StateMinerInfo(context.Context, address.Address, TipSetToken) (miner.MinerInfo, error)
|
StateMinerInfo(context.Context, address.Address, TipSetToken) (miner.MinerInfo, error)
|
||||||
|
StateMinerAvailableBalance(context.Context, address.Address, TipSetToken) (big.Int, error)
|
||||||
StateMinerSectorAllocated(context.Context, address.Address, abi.SectorNumber, TipSetToken) (bool, error)
|
StateMinerSectorAllocated(context.Context, address.Address, abi.SectorNumber, TipSetToken) (bool, error)
|
||||||
StateMarketStorageDeal(context.Context, abi.DealID, TipSetToken) (*api.MarketDeal, error)
|
StateMarketStorageDeal(context.Context, abi.DealID, TipSetToken) (*api.MarketDeal, error)
|
||||||
StateMarketStorageDealProposal(context.Context, abi.DealID, TipSetToken) (market.DealProposal, error)
|
StateMarketStorageDealProposal(context.Context, abi.DealID, TipSetToken) (market.DealProposal, error)
|
||||||
|
14
extern/storage-sealing/states_sealing.go
vendored
14
extern/storage-sealing/states_sealing.go
vendored
@ -357,11 +357,16 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
params, deposit, tok, err := m.preCommitParams(ctx, sector)
|
params, pcd, tok, err := m.preCommitParams(ctx, sector)
|
||||||
if params == nil || err != nil {
|
if params == nil || err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deposit, err := collateralSendAmount(ctx.Context(), m.api, m.maddr, cfg, pcd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
enc := new(bytes.Buffer)
|
enc := new(bytes.Buffer)
|
||||||
if err := params.MarshalCBOR(enc); err != nil {
|
if err := params.MarshalCBOR(enc); err != nil {
|
||||||
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("could not serialize pre-commit sector parameters: %w", err)})
|
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("could not serialize pre-commit sector parameters: %w", err)})
|
||||||
@ -389,7 +394,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
|
|||||||
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)})
|
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)})
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.Send(SectorPreCommitted{Message: mcid, PreCommitDeposit: deposit, PreCommitInfo: *params})
|
return ctx.Send(SectorPreCommitted{Message: mcid, PreCommitDeposit: pcd, PreCommitInfo: *params})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Sealing) handleSubmitPreCommitBatch(ctx statemachine.Context, sector SectorInfo) error {
|
func (m *Sealing) handleSubmitPreCommitBatch(ctx statemachine.Context, sector SectorInfo) error {
|
||||||
@ -628,6 +633,11 @@ func (m *Sealing) handleSubmitCommit(ctx statemachine.Context, sector SectorInfo
|
|||||||
collateral = big.Zero()
|
collateral = big.Zero()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
collateral, err = collateralSendAmount(ctx.Context(), m.api, m.maddr, cfg, collateral)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
goodFunds := big.Add(collateral, big.Int(m.feeCfg.MaxCommitGasFee))
|
goodFunds := big.Add(collateral, big.Int(m.feeCfg.MaxCommitGasFee))
|
||||||
|
|
||||||
from, _, err := m.addrSel(ctx.Context(), mi, api.CommitAddr, goodFunds, collateral)
|
from, _, err := m.addrSel(ctx.Context(), mi, api.CommitAddr, goodFunds, collateral)
|
||||||
|
34
extern/storage-sealing/utils.go
vendored
34
extern/storage-sealing/utils.go
vendored
@ -1,9 +1,16 @@
|
|||||||
package sealing
|
package sealing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
|
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
||||||
)
|
)
|
||||||
|
|
||||||
func fillersFromRem(in abi.UnpaddedPieceSize) ([]abi.UnpaddedPieceSize, error) {
|
func fillersFromRem(in abi.UnpaddedPieceSize) ([]abi.UnpaddedPieceSize, error) {
|
||||||
@ -55,3 +62,30 @@ func (m *Sealing) GetSectorInfo(sid abi.SectorNumber) (SectorInfo, error) {
|
|||||||
err := m.sectors.Get(uint64(sid)).Get(&out)
|
err := m.sectors.Get(uint64(sid)).Get(&out)
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func collateralSendAmount(ctx context.Context, api interface {
|
||||||
|
StateMinerAvailableBalance(context.Context, address.Address, TipSetToken) (big.Int, error)
|
||||||
|
}, maddr address.Address, cfg sealiface.Config, collateral abi.TokenAmount) (abi.TokenAmount, error) {
|
||||||
|
if cfg.CollateralFromMinerBalance {
|
||||||
|
if cfg.DisableCollateralFallback {
|
||||||
|
return big.Zero(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
avail, err := api.StateMinerAvailableBalance(ctx, maddr, nil)
|
||||||
|
if err != nil {
|
||||||
|
return big.Zero(), xerrors.Errorf("getting available miner balance: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
avail = big.Sub(avail, cfg.AvailableBalanceBuffer)
|
||||||
|
if avail.LessThan(big.Zero()) {
|
||||||
|
avail = big.Zero()
|
||||||
|
}
|
||||||
|
|
||||||
|
collateral = big.Sub(collateral, avail)
|
||||||
|
if collateral.LessThan(big.Zero()) {
|
||||||
|
collateral = big.Zero()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return collateral, nil
|
||||||
|
}
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
func TestQuotePriceForUnsealedRetrieval(t *testing.T) {
|
func TestQuotePriceForUnsealedRetrieval(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
blocktime = time.Second
|
blocktime = 50 * time.Millisecond
|
||||||
)
|
)
|
||||||
|
|
||||||
kit.QuietMiningLogs()
|
kit.QuietMiningLogs()
|
||||||
|
132
itests/sector_miner_collateral_test.go
Normal file
132
itests/sector_miner_collateral_test.go
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
package itests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/api"
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
||||||
|
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
||||||
|
"github.com/filecoin-project/lotus/itests/kit"
|
||||||
|
"github.com/filecoin-project/lotus/node"
|
||||||
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
|
"github.com/filecoin-project/lotus/node/repo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMinerBalanceCollateral(t *testing.T) {
|
||||||
|
kit.QuietMiningLogs()
|
||||||
|
|
||||||
|
blockTime := 5 * time.Millisecond
|
||||||
|
|
||||||
|
runTest := func(t *testing.T, enabled bool, nSectors int, batching bool) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
opts := kit.ConstructorOpts(
|
||||||
|
kit.LatestActorsAt(-1),
|
||||||
|
node.ApplyIf(node.IsType(repo.StorageMiner), node.Override(new(dtypes.GetSealingConfigFunc), func() (dtypes.GetSealingConfigFunc, error) {
|
||||||
|
return func() (sealiface.Config, error) {
|
||||||
|
return sealiface.Config{
|
||||||
|
MaxWaitDealsSectors: 4,
|
||||||
|
MaxSealingSectors: 4,
|
||||||
|
MaxSealingSectorsForDeals: 4,
|
||||||
|
AlwaysKeepUnsealedCopy: true,
|
||||||
|
WaitDealsDelay: time.Hour,
|
||||||
|
|
||||||
|
BatchPreCommits: batching,
|
||||||
|
AggregateCommits: batching,
|
||||||
|
|
||||||
|
PreCommitBatchWait: time.Hour,
|
||||||
|
CommitBatchWait: time.Hour,
|
||||||
|
|
||||||
|
MinCommitBatch: nSectors,
|
||||||
|
MaxPreCommitBatch: nSectors,
|
||||||
|
MaxCommitBatch: nSectors,
|
||||||
|
|
||||||
|
CollateralFromMinerBalance: enabled,
|
||||||
|
AvailableBalanceBuffer: big.Zero(),
|
||||||
|
DisableCollateralFallback: false,
|
||||||
|
AggregateAboveBaseFee: big.Zero(),
|
||||||
|
}, nil
|
||||||
|
}, nil
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
full, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), opts)
|
||||||
|
ens.InterconnectAll().BeginMining(blockTime)
|
||||||
|
full.WaitTillChain(ctx, kit.HeightAtLeast(10))
|
||||||
|
|
||||||
|
toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
|
||||||
|
|
||||||
|
for len(toCheck) > 0 {
|
||||||
|
states := map[api.SectorState]int{}
|
||||||
|
for n := range toCheck {
|
||||||
|
st, err := miner.StorageMiner.SectorsStatus(ctx, n, false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
states[st.State]++
|
||||||
|
if st.State == api.SectorState(sealing.Proving) {
|
||||||
|
delete(toCheck, n)
|
||||||
|
}
|
||||||
|
if strings.Contains(string(st.State), "Fail") {
|
||||||
|
t.Fatal("sector in a failed state", st.State)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
build.Clock.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
// check that sector messages had zero value set
|
||||||
|
sl, err := miner.SectorsList(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
for _, number := range sl {
|
||||||
|
si, err := miner.SectorsStatus(ctx, number, false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.NotNil(t, si.PreCommitMsg)
|
||||||
|
pc, err := full.ChainGetMessage(ctx, *si.PreCommitMsg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if enabled {
|
||||||
|
require.Equal(t, big.Zero(), pc.Value)
|
||||||
|
} else {
|
||||||
|
require.NotEqual(t, big.Zero(), pc.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NotNil(t, si.CommitMsg)
|
||||||
|
c, err := full.ChainGetMessage(ctx, *si.CommitMsg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if enabled {
|
||||||
|
require.Equal(t, big.Zero(), c.Value)
|
||||||
|
}
|
||||||
|
// commit value might be zero even with !enabled because in test devnets
|
||||||
|
// precommit deposit tends to be greater than collateral required at
|
||||||
|
// commit time.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("nobatch", func(t *testing.T) {
|
||||||
|
runTest(t, true, 1, false)
|
||||||
|
})
|
||||||
|
t.Run("batch-1", func(t *testing.T) {
|
||||||
|
runTest(t, true, 1, true) // individual commit instead of aggregate
|
||||||
|
})
|
||||||
|
t.Run("batch-4", func(t *testing.T) {
|
||||||
|
runTest(t, true, 4, true)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("nobatch-frombalance-disabled", func(t *testing.T) {
|
||||||
|
runTest(t, false, 1, false)
|
||||||
|
})
|
||||||
|
t.Run("batch-1-frombalance-disabled", func(t *testing.T) {
|
||||||
|
runTest(t, false, 1, true) // individual commit instead of aggregate
|
||||||
|
})
|
||||||
|
t.Run("batch-4-frombalance-disabled", func(t *testing.T) {
|
||||||
|
runTest(t, false, 4, true)
|
||||||
|
})
|
||||||
|
}
|
@ -136,6 +136,13 @@ type SealingConfig struct {
|
|||||||
// Run sector finalization before submitting sector proof to the chain
|
// Run sector finalization before submitting sector proof to the chain
|
||||||
FinalizeEarly bool
|
FinalizeEarly bool
|
||||||
|
|
||||||
|
// Whether to use available miner balance for sector collateral instead of sending it with each message
|
||||||
|
CollateralFromMinerBalance bool
|
||||||
|
// Minimum available balance to keep in the miner actor before sending it with messages
|
||||||
|
AvailableBalanceBuffer types.FIL
|
||||||
|
// Don't send collateral with messages even if there is no available balance in the miner actor
|
||||||
|
DisableCollateralFallback bool
|
||||||
|
|
||||||
// enable / disable precommit batching (takes effect after nv13)
|
// enable / disable precommit batching (takes effect after nv13)
|
||||||
BatchPreCommits bool
|
BatchPreCommits bool
|
||||||
// maximum precommit batch size - batches will be sent immediately above this size
|
// maximum precommit batch size - batches will be sent immediately above this size
|
||||||
@ -334,6 +341,10 @@ func DefaultStorageMiner() *StorageMiner {
|
|||||||
AlwaysKeepUnsealedCopy: true,
|
AlwaysKeepUnsealedCopy: true,
|
||||||
FinalizeEarly: false,
|
FinalizeEarly: false,
|
||||||
|
|
||||||
|
CollateralFromMinerBalance: false,
|
||||||
|
AvailableBalanceBuffer: types.FIL(big.Zero()),
|
||||||
|
DisableCollateralFallback: false,
|
||||||
|
|
||||||
BatchPreCommits: true,
|
BatchPreCommits: true,
|
||||||
MaxPreCommitBatch: miner5.PreCommitSectorBatchMaxSize, // up to 256 sectors
|
MaxPreCommitBatch: miner5.PreCommitSectorBatchMaxSize, // up to 256 sectors
|
||||||
PreCommitBatchWait: Duration(24 * time.Hour), // this should be less than 31.5 hours, which is the expiration of a precommit ticket
|
PreCommitBatchWait: Duration(24 * time.Hour), // this should be less than 31.5 hours, which is the expiration of a precommit ticket
|
||||||
|
@ -875,6 +875,10 @@ func NewSetSealConfigFunc(r repo.LockedRepo) (dtypes.SetSealingConfigFunc, error
|
|||||||
AlwaysKeepUnsealedCopy: cfg.AlwaysKeepUnsealedCopy,
|
AlwaysKeepUnsealedCopy: cfg.AlwaysKeepUnsealedCopy,
|
||||||
FinalizeEarly: cfg.FinalizeEarly,
|
FinalizeEarly: cfg.FinalizeEarly,
|
||||||
|
|
||||||
|
CollateralFromMinerBalance: cfg.CollateralFromMinerBalance,
|
||||||
|
AvailableBalanceBuffer: types.FIL(cfg.AvailableBalanceBuffer),
|
||||||
|
DisableCollateralFallback: cfg.DisableCollateralFallback,
|
||||||
|
|
||||||
BatchPreCommits: cfg.BatchPreCommits,
|
BatchPreCommits: cfg.BatchPreCommits,
|
||||||
MaxPreCommitBatch: cfg.MaxPreCommitBatch,
|
MaxPreCommitBatch: cfg.MaxPreCommitBatch,
|
||||||
PreCommitBatchWait: config.Duration(cfg.PreCommitBatchWait),
|
PreCommitBatchWait: config.Duration(cfg.PreCommitBatchWait),
|
||||||
@ -905,6 +909,10 @@ func ToSealingConfig(cfg *config.StorageMiner) sealiface.Config {
|
|||||||
AlwaysKeepUnsealedCopy: cfg.Sealing.AlwaysKeepUnsealedCopy,
|
AlwaysKeepUnsealedCopy: cfg.Sealing.AlwaysKeepUnsealedCopy,
|
||||||
FinalizeEarly: cfg.Sealing.FinalizeEarly,
|
FinalizeEarly: cfg.Sealing.FinalizeEarly,
|
||||||
|
|
||||||
|
CollateralFromMinerBalance: cfg.Sealing.CollateralFromMinerBalance,
|
||||||
|
AvailableBalanceBuffer: types.BigInt(cfg.Sealing.AvailableBalanceBuffer),
|
||||||
|
DisableCollateralFallback: cfg.Sealing.DisableCollateralFallback,
|
||||||
|
|
||||||
BatchPreCommits: cfg.Sealing.BatchPreCommits,
|
BatchPreCommits: cfg.Sealing.BatchPreCommits,
|
||||||
MaxPreCommitBatch: cfg.Sealing.MaxPreCommitBatch,
|
MaxPreCommitBatch: cfg.Sealing.MaxPreCommitBatch,
|
||||||
PreCommitBatchWait: time.Duration(cfg.Sealing.PreCommitBatchWait),
|
PreCommitBatchWait: time.Duration(cfg.Sealing.PreCommitBatchWait),
|
||||||
|
@ -76,6 +76,15 @@ func (s SealingAPIAdapter) StateMinerInfo(ctx context.Context, maddr address.Add
|
|||||||
return s.delegate.StateMinerInfo(ctx, maddr, tsk)
|
return s.delegate.StateMinerInfo(ctx, maddr, tsk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s SealingAPIAdapter) StateMinerAvailableBalance(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) (big.Int, error) {
|
||||||
|
tsk, err := types.TipSetKeyFromBytes(tok)
|
||||||
|
if err != nil {
|
||||||
|
return big.Zero(), xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.delegate.StateMinerAvailableBalance(ctx, maddr, tsk)
|
||||||
|
}
|
||||||
|
|
||||||
func (s SealingAPIAdapter) StateMinerWorkerAddress(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) (address.Address, error) {
|
func (s SealingAPIAdapter) StateMinerWorkerAddress(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) (address.Address, error) {
|
||||||
// TODO: update storage-fsm to just StateMinerInfo
|
// TODO: update storage-fsm to just StateMinerInfo
|
||||||
mi, err := s.StateMinerInfo(ctx, maddr, tok)
|
mi, err := s.StateMinerInfo(ctx, maddr, tok)
|
||||||
|
@ -86,6 +86,7 @@ type fullNodeFilteredAPI interface {
|
|||||||
StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error)
|
StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error)
|
||||||
StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error)
|
StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error)
|
||||||
StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error)
|
StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error)
|
||||||
|
StateMinerAvailableBalance(ctx context.Context, maddr address.Address, tok types.TipSetKey) (types.BigInt, error)
|
||||||
StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]api.Deadline, error)
|
StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]api.Deadline, error)
|
||||||
StateMinerPartitions(context.Context, address.Address, uint64, types.TipSetKey) ([]api.Partition, error)
|
StateMinerPartitions(context.Context, address.Address, uint64, types.TipSetKey) ([]api.Partition, error)
|
||||||
StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error)
|
StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error)
|
||||||
|
Loading…
Reference in New Issue
Block a user