Merge pull request #5103 from filecoin-project/feat/miner-control-config
miner: Control address config for (pre)commits
This commit is contained in:
commit
90a31fde9f
@ -5,21 +5,22 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
datatransfer "github.com/filecoin-project/go-data-transfer"
|
||||
"github.com/google/uuid"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
datatransfer "github.com/filecoin-project/go-data-transfer"
|
||||
"github.com/filecoin-project/go-fil-markets/piecestore"
|
||||
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
|
||||
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/specs-storage/storage"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/fsutil"
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
||||
"github.com/filecoin-project/specs-storage/storage"
|
||||
)
|
||||
|
||||
// StorageMiner is a low-level interface to the Filecoin network storage miner node
|
||||
@ -29,6 +30,7 @@ type StorageMiner interface {
|
||||
ActorAddress(context.Context) (address.Address, error)
|
||||
|
||||
ActorSectorSize(context.Context, address.Address) (abi.SectorSize, error)
|
||||
ActorAddressConfig(ctx context.Context) (AddressConfig, error)
|
||||
|
||||
MiningBase(context.Context) (*types.TipSet, error)
|
||||
|
||||
@ -198,3 +200,16 @@ func (st *SealSeed) Equals(ost *SealSeed) bool {
|
||||
}
|
||||
|
||||
type SectorState string
|
||||
|
||||
type AddrUse int
|
||||
|
||||
const (
|
||||
PreCommitAddr AddrUse = iota
|
||||
CommitAddr
|
||||
PoStAddr
|
||||
)
|
||||
|
||||
type AddressConfig struct {
|
||||
PreCommitControl []address.Address
|
||||
CommitControl []address.Address
|
||||
}
|
||||
|
@ -277,8 +277,9 @@ type StorageMinerStruct struct {
|
||||
CommonStruct
|
||||
|
||||
Internal struct {
|
||||
ActorAddress func(context.Context) (address.Address, error) `perm:"read"`
|
||||
ActorSectorSize func(context.Context, address.Address) (abi.SectorSize, error) `perm:"read"`
|
||||
ActorAddress func(context.Context) (address.Address, error) `perm:"read"`
|
||||
ActorSectorSize func(context.Context, address.Address) (abi.SectorSize, error) `perm:"read"`
|
||||
ActorAddressConfig func(ctx context.Context) (api.AddressConfig, error) `perm:"read"`
|
||||
|
||||
MiningBase func(context.Context) (*types.TipSet, error) `perm:"read"`
|
||||
|
||||
@ -1230,6 +1231,10 @@ func (c *StorageMinerStruct) ActorSectorSize(ctx context.Context, addr address.A
|
||||
return c.Internal.ActorSectorSize(ctx, addr)
|
||||
}
|
||||
|
||||
func (c *StorageMinerStruct) ActorAddressConfig(ctx context.Context) (api.AddressConfig, error) {
|
||||
return c.Internal.ActorAddressConfig(ctx)
|
||||
}
|
||||
|
||||
func (c *StorageMinerStruct) PledgeSector(ctx context.Context) error {
|
||||
return c.Internal.PledgeSector(ctx)
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
lcli "github.com/filecoin-project/lotus/cli"
|
||||
"github.com/filecoin-project/lotus/lib/tablewriter"
|
||||
"github.com/filecoin-project/lotus/storage"
|
||||
)
|
||||
|
||||
var actorCmd = &cli.Command{
|
||||
@ -414,9 +413,37 @@ var actorControlList = &cli.Command{
|
||||
tablewriter.Col("balance"),
|
||||
)
|
||||
|
||||
postAddr, _, err := storage.AddressFor(ctx, api, mi, storage.PoStAddr, types.FromFil(1), types.FromFil(1))
|
||||
ac, err := nodeApi.ActorAddressConfig(ctx)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("getting address for post: %w", err)
|
||||
return err
|
||||
}
|
||||
|
||||
commit := map[address.Address]struct{}{}
|
||||
precommit := map[address.Address]struct{}{}
|
||||
post := map[address.Address]struct{}{}
|
||||
|
||||
for _, ca := range mi.ControlAddresses {
|
||||
post[ca] = struct{}{}
|
||||
}
|
||||
|
||||
for _, ca := range ac.PreCommitControl {
|
||||
ca, err := api.StateLookupID(ctx, ca, types.EmptyTSK)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
delete(post, ca)
|
||||
precommit[ca] = struct{}{}
|
||||
}
|
||||
|
||||
for _, ca := range ac.CommitControl {
|
||||
ca, err := api.StateLookupID(ctx, ca, types.EmptyTSK)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
delete(post, ca)
|
||||
commit[ca] = struct{}{}
|
||||
}
|
||||
|
||||
printKey := func(name string, a address.Address) {
|
||||
@ -451,9 +478,15 @@ var actorControlList = &cli.Command{
|
||||
if a == mi.Worker {
|
||||
uses = append(uses, color.YellowString("other"))
|
||||
}
|
||||
if a == postAddr {
|
||||
if _, ok := post[a]; ok {
|
||||
uses = append(uses, color.GreenString("post"))
|
||||
}
|
||||
if _, ok := precommit[a]; ok {
|
||||
uses = append(uses, color.CyanString("precommit"))
|
||||
}
|
||||
if _, ok := commit[a]; ok {
|
||||
uses = append(uses, color.BlueString("commit"))
|
||||
}
|
||||
|
||||
tw.Write(map[string]interface{}{
|
||||
"name": name,
|
||||
|
@ -6,6 +6,7 @@
|
||||
* [Version](#Version)
|
||||
* [Actor](#Actor)
|
||||
* [ActorAddress](#ActorAddress)
|
||||
* [ActorAddressConfig](#ActorAddressConfig)
|
||||
* [ActorSectorSize](#ActorSectorSize)
|
||||
* [Auth](#Auth)
|
||||
* [AuthNew](#AuthNew)
|
||||
@ -175,6 +176,21 @@ Inputs: `null`
|
||||
|
||||
Response: `"f01234"`
|
||||
|
||||
### ActorAddressConfig
|
||||
There are not yet any comments for this method.
|
||||
|
||||
Perms: read
|
||||
|
||||
Inputs: `null`
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"PreCommitControl": null,
|
||||
"CommitControl": null
|
||||
}
|
||||
```
|
||||
|
||||
### ActorSectorSize
|
||||
There are not yet any comments for this method.
|
||||
|
||||
|
13
extern/storage-sealing/sealing.go
vendored
13
extern/storage-sealing/sealing.go
vendored
@ -14,15 +14,16 @@ import (
|
||||
logging "github.com/ipfs/go-log/v2"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
"github.com/filecoin-project/specs-storage/storage"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
padreader "github.com/filecoin-project/go-padreader"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
"github.com/filecoin-project/go-state-types/crypto"
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
statemachine "github.com/filecoin-project/go-statemachine"
|
||||
"github.com/filecoin-project/specs-storage/storage"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||
sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage"
|
||||
@ -68,6 +69,8 @@ type SealingAPI interface {
|
||||
|
||||
type SectorStateNotifee func(before, after SectorInfo)
|
||||
|
||||
type AddrSel func(ctx context.Context, mi miner.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error)
|
||||
|
||||
type Sealing struct {
|
||||
api SealingAPI
|
||||
feeCfg FeeConfig
|
||||
@ -87,6 +90,7 @@ type Sealing struct {
|
||||
toUpgrade map[abi.SectorNumber]struct{}
|
||||
|
||||
notifee SectorStateNotifee
|
||||
addrSel AddrSel
|
||||
|
||||
stats SectorStats
|
||||
|
||||
@ -111,7 +115,7 @@ type UnsealedSectorInfo struct {
|
||||
ssize abi.SectorSize
|
||||
}
|
||||
|
||||
func New(api SealingAPI, fc FeeConfig, events Events, maddr address.Address, ds datastore.Batching, sealer sectorstorage.SectorManager, sc SectorIDCounter, verif ffiwrapper.Verifier, pcp PreCommitPolicy, gc GetSealingConfigFunc, notifee SectorStateNotifee) *Sealing {
|
||||
func New(api SealingAPI, fc FeeConfig, events Events, maddr address.Address, ds datastore.Batching, sealer sectorstorage.SectorManager, sc SectorIDCounter, verif ffiwrapper.Verifier, pcp PreCommitPolicy, gc GetSealingConfigFunc, notifee SectorStateNotifee, as AddrSel) *Sealing {
|
||||
s := &Sealing{
|
||||
api: api,
|
||||
feeCfg: fc,
|
||||
@ -130,6 +134,7 @@ func New(api SealingAPI, fc FeeConfig, events Events, maddr address.Address, ds
|
||||
toUpgrade: map[abi.SectorNumber]struct{}{},
|
||||
|
||||
notifee: notifee,
|
||||
addrSel: as,
|
||||
|
||||
getConfig: gc,
|
||||
|
||||
|
22
extern/storage-sealing/states_sealing.go
vendored
22
extern/storage-sealing/states_sealing.go
vendored
@ -15,6 +15,7 @@ import (
|
||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/filecoin-project/specs-storage/storage"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||
"github.com/filecoin-project/lotus/chain/actors/policy"
|
||||
@ -191,7 +192,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
|
||||
return nil
|
||||
}
|
||||
|
||||
waddr, err := m.api.StateMinerWorkerAddress(ctx.Context(), m.maddr, tok)
|
||||
mi, err := m.api.StateMinerInfo(ctx.Context(), m.maddr, tok)
|
||||
if err != nil {
|
||||
log.Errorf("handlePreCommitting: api error, not proceeding: %+v", err)
|
||||
return nil
|
||||
@ -266,9 +267,15 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
|
||||
}
|
||||
|
||||
deposit := big.Max(depositMinimum, collateral)
|
||||
goodFunds := big.Add(deposit, m.feeCfg.MaxPreCommitGasFee)
|
||||
|
||||
from, _, err := m.addrSel(ctx.Context(), mi, api.PreCommitAddr, goodFunds, deposit)
|
||||
if err != nil {
|
||||
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("no good address to send precommit message from: %w", err)})
|
||||
}
|
||||
|
||||
log.Infof("submitting precommit for sector %d (deposit: %s): ", sector.SectorNumber, deposit)
|
||||
mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, miner.Methods.PreCommitSector, deposit, m.feeCfg.MaxPreCommitGasFee, enc.Bytes())
|
||||
mcid, err := m.api.SendMsg(ctx.Context(), from, m.maddr, miner.Methods.PreCommitSector, deposit, m.feeCfg.MaxPreCommitGasFee, enc.Bytes())
|
||||
if err != nil {
|
||||
if params.ReplaceCapacity {
|
||||
m.remarkForUpgrade(params.ReplaceSectorNumber)
|
||||
@ -426,7 +433,7 @@ func (m *Sealing) handleSubmitCommit(ctx statemachine.Context, sector SectorInfo
|
||||
return ctx.Send(SectorCommitFailed{xerrors.Errorf("could not serialize commit sector parameters: %w", err)})
|
||||
}
|
||||
|
||||
waddr, err := m.api.StateMinerWorkerAddress(ctx.Context(), m.maddr, tok)
|
||||
mi, err := m.api.StateMinerInfo(ctx.Context(), m.maddr, tok)
|
||||
if err != nil {
|
||||
log.Errorf("handleCommitting: api error, not proceeding: %+v", err)
|
||||
return nil
|
||||
@ -450,8 +457,15 @@ func (m *Sealing) handleSubmitCommit(ctx statemachine.Context, sector SectorInfo
|
||||
collateral = big.Zero()
|
||||
}
|
||||
|
||||
goodFunds := big.Add(collateral, m.feeCfg.MaxCommitGasFee)
|
||||
|
||||
from, _, err := m.addrSel(ctx.Context(), mi, api.CommitAddr, goodFunds, collateral)
|
||||
if err != nil {
|
||||
return ctx.Send(SectorCommitFailed{xerrors.Errorf("no good address to send commit message from: %w", err)})
|
||||
}
|
||||
|
||||
// TODO: check seed / ticket / deals are up to date
|
||||
mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, miner.Methods.ProveCommitSector, collateral, m.feeCfg.MaxCommitGasFee, enc.Bytes())
|
||||
mcid, err := m.api.SendMsg(ctx.Context(), from, m.maddr, miner.Methods.ProveCommitSector, collateral, m.feeCfg.MaxCommitGasFee, enc.Bytes())
|
||||
if err != nil {
|
||||
return ctx.Send(SectorCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)})
|
||||
}
|
||||
|
@ -357,6 +357,7 @@ func Online() Option {
|
||||
|
||||
Override(new(*sectorblocks.SectorBlocks), sectorblocks.NewSectorBlocks),
|
||||
Override(new(*storage.Miner), modules.StorageMiner(config.DefaultStorageMiner().Fees)),
|
||||
Override(new(*storage.AddressSelector), modules.AddressSelector(nil)),
|
||||
Override(new(dtypes.NetworkName), modules.StorageNetworkName),
|
||||
|
||||
Override(new(dtypes.StagingMultiDstore), modules.StagingMultiDatastore),
|
||||
@ -511,6 +512,7 @@ func ConfigStorageMiner(c interface{}) Option {
|
||||
Override(new(storagemarket.StorageProviderNode), storageadapter.NewProviderNodeAdapter(&cfg.Fees)),
|
||||
|
||||
Override(new(sectorstorage.SealerConfig), cfg.Storage),
|
||||
Override(new(*storage.AddressSelector), modules.AddressSelector(&cfg.Addresses)),
|
||||
Override(new(*storage.Miner), modules.StorageMiner(cfg.Fees)),
|
||||
)
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ type StorageMiner struct {
|
||||
Sealing SealingConfig
|
||||
Storage sectorstorage.SealerConfig
|
||||
Fees MinerFeeConfig
|
||||
Addresses MinerAddressConfig
|
||||
}
|
||||
|
||||
type DealmakingConfig struct {
|
||||
@ -71,6 +72,11 @@ type MinerFeeConfig struct {
|
||||
MaxMarketBalanceAddFee types.FIL
|
||||
}
|
||||
|
||||
type MinerAddressConfig struct {
|
||||
PreCommitControl []string
|
||||
CommitControl []string
|
||||
}
|
||||
|
||||
// API contains configs for API endpoint
|
||||
type API struct {
|
||||
ListenAddress string
|
||||
@ -205,6 +211,11 @@ func DefaultStorageMiner() *StorageMiner {
|
||||
MaxPublishDealsFee: types.MustParseFIL("0.05"),
|
||||
MaxMarketBalanceAddFee: types.MustParseFIL("0.007"),
|
||||
},
|
||||
|
||||
Addresses: MinerAddressConfig{
|
||||
PreCommitControl: []string{},
|
||||
CommitControl: []string{},
|
||||
},
|
||||
}
|
||||
cfg.Common.API.ListenAddress = "/ip4/127.0.0.1/tcp/2345/http"
|
||||
cfg.Common.API.RemoteListenAddress = "127.0.0.1:2345"
|
||||
|
@ -57,6 +57,7 @@ type StorageMinerAPI struct {
|
||||
storiface.WorkerReturn
|
||||
DataTransfer dtypes.ProviderDataTransfer
|
||||
Host host.Host
|
||||
AddrSel *storage.AddressSelector
|
||||
|
||||
DS dtypes.MetadataDS
|
||||
|
||||
@ -573,4 +574,8 @@ func (sm *StorageMinerAPI) CheckProvable(ctx context.Context, pp abi.RegisteredP
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) ActorAddressConfig(ctx context.Context) (api.AddressConfig, error) {
|
||||
return sm.AddrSel.AddressConfig, nil
|
||||
}
|
||||
|
||||
var _ api.StorageMiner = &StorageMinerAPI{}
|
||||
|
@ -145,6 +145,35 @@ func SectorIDCounter(ds dtypes.MetadataDS) sealing.SectorIDCounter {
|
||||
return &sidsc{sc}
|
||||
}
|
||||
|
||||
func AddressSelector(addrConf *config.MinerAddressConfig) func() (*storage.AddressSelector, error) {
|
||||
return func() (*storage.AddressSelector, error) {
|
||||
as := &storage.AddressSelector{}
|
||||
if addrConf == nil {
|
||||
return as, nil
|
||||
}
|
||||
|
||||
for _, s := range addrConf.PreCommitControl {
|
||||
addr, err := address.NewFromString(s)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("parsing precommit control address: %w", err)
|
||||
}
|
||||
|
||||
as.PreCommitControl = append(as.PreCommitControl, addr)
|
||||
}
|
||||
|
||||
for _, s := range addrConf.CommitControl {
|
||||
addr, err := address.NewFromString(s)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("parsing commit control address: %w", err)
|
||||
}
|
||||
|
||||
as.CommitControl = append(as.CommitControl, addr)
|
||||
}
|
||||
|
||||
return as, nil
|
||||
}
|
||||
}
|
||||
|
||||
type StorageMinerParams struct {
|
||||
fx.In
|
||||
|
||||
@ -158,6 +187,7 @@ type StorageMinerParams struct {
|
||||
Verifier ffiwrapper.Verifier
|
||||
GetSealingConfigFn dtypes.GetSealingConfigFunc
|
||||
Journal journal.Journal
|
||||
AddrSel *storage.AddressSelector
|
||||
}
|
||||
|
||||
func StorageMiner(fc config.MinerFeeConfig) func(params StorageMinerParams) (*storage.Miner, error) {
|
||||
@ -173,6 +203,7 @@ func StorageMiner(fc config.MinerFeeConfig) func(params StorageMinerParams) (*st
|
||||
verif = params.Verifier
|
||||
gsd = params.GetSealingConfigFn
|
||||
j = params.Journal
|
||||
as = params.AddrSel
|
||||
)
|
||||
|
||||
maddr, err := minerAddrFromDS(ds)
|
||||
@ -182,12 +213,12 @@ func StorageMiner(fc config.MinerFeeConfig) func(params StorageMinerParams) (*st
|
||||
|
||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||
|
||||
fps, err := storage.NewWindowedPoStScheduler(api, fc, sealer, sealer, j, maddr)
|
||||
fps, err := storage.NewWindowedPoStScheduler(api, fc, as, sealer, sealer, j, maddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sm, err := storage.NewMiner(api, maddr, h, ds, sealer, sc, verif, gsd, fc, j)
|
||||
sm, err := storage.NewMiner(api, maddr, h, ds, sealer, sc, verif, gsd, fc, j, as)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -5,38 +5,84 @@ import (
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
type AddrUse int
|
||||
|
||||
const (
|
||||
PreCommitAddr AddrUse = iota
|
||||
CommitAddr
|
||||
PoStAddr
|
||||
)
|
||||
|
||||
type addrSelectApi interface {
|
||||
WalletBalance(context.Context, address.Address) (types.BigInt, error)
|
||||
WalletHas(context.Context, address.Address) (bool, error)
|
||||
|
||||
StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error)
|
||||
StateLookupID(context.Context, address.Address, types.TipSetKey) (address.Address, error)
|
||||
}
|
||||
|
||||
func AddressFor(ctx context.Context, a addrSelectApi, mi miner.MinerInfo, use AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) {
|
||||
switch use {
|
||||
case PreCommitAddr, CommitAddr:
|
||||
// always use worker, at least for now
|
||||
return mi.Worker, big.Zero(), nil
|
||||
}
|
||||
type AddressSelector struct {
|
||||
api.AddressConfig
|
||||
}
|
||||
|
||||
func (as *AddressSelector) AddressFor(ctx context.Context, a addrSelectApi, mi miner.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) {
|
||||
var addrs []address.Address
|
||||
switch use {
|
||||
case api.PreCommitAddr:
|
||||
addrs = append(addrs, as.PreCommitControl...)
|
||||
case api.CommitAddr:
|
||||
addrs = append(addrs, as.CommitControl...)
|
||||
default:
|
||||
defaultCtl := map[address.Address]struct{}{}
|
||||
for _, a := range mi.ControlAddresses {
|
||||
defaultCtl[a] = struct{}{}
|
||||
}
|
||||
delete(defaultCtl, mi.Owner)
|
||||
delete(defaultCtl, mi.Worker)
|
||||
|
||||
for _, addr := range append(append([]address.Address{}, as.PreCommitControl...), as.CommitControl...) {
|
||||
if addr.Protocol() != address.ID {
|
||||
var err error
|
||||
addr, err = a.StateLookupID(ctx, addr, types.EmptyTSK)
|
||||
if err != nil {
|
||||
log.Warnw("looking up control address", "address", addr, "error", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
delete(defaultCtl, addr)
|
||||
}
|
||||
|
||||
for a := range defaultCtl {
|
||||
addrs = append(addrs, a)
|
||||
}
|
||||
}
|
||||
addrs = append(addrs, mi.Owner, mi.Worker)
|
||||
|
||||
return pickAddress(ctx, a, mi, goodFunds, minFunds, addrs)
|
||||
}
|
||||
|
||||
func pickAddress(ctx context.Context, a addrSelectApi, mi miner.MinerInfo, goodFunds, minFunds abi.TokenAmount, addrs []address.Address) (address.Address, abi.TokenAmount, error) {
|
||||
leastBad := mi.Worker
|
||||
bestAvail := minFunds
|
||||
|
||||
for _, addr := range append(mi.ControlAddresses, mi.Owner, mi.Worker) {
|
||||
ctl := map[address.Address]struct{}{}
|
||||
for _, a := range append(mi.ControlAddresses, mi.Owner, mi.Worker) {
|
||||
ctl[a] = struct{}{}
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
if addr.Protocol() != address.ID {
|
||||
addr, err := a.StateLookupID(ctx, addr, types.EmptyTSK)
|
||||
if err != nil {
|
||||
log.Warnw("looking up control address", "address", addr, "error", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := ctl[addr]; !ok {
|
||||
log.Warnw("non-control address configured for sending messages", "address", addr)
|
||||
continue
|
||||
}
|
||||
|
||||
if maybeUseAddress(ctx, a, addr, goodFunds, &leastBad, &bestAvail) {
|
||||
return leastBad, bestAvail, nil
|
||||
}
|
||||
@ -68,7 +114,7 @@ func maybeUseAddress(ctx context.Context, a addrSelectApi, addr address.Address,
|
||||
}
|
||||
|
||||
if !have {
|
||||
log.Errorw("don't have key", "key", k)
|
||||
log.Errorw("don't have key", "key", k, "address", addr)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -41,13 +41,14 @@ import (
|
||||
var log = logging.Logger("storageminer")
|
||||
|
||||
type Miner struct {
|
||||
api storageMinerApi
|
||||
feeCfg config.MinerFeeConfig
|
||||
h host.Host
|
||||
sealer sectorstorage.SectorManager
|
||||
ds datastore.Batching
|
||||
sc sealing.SectorIDCounter
|
||||
verif ffiwrapper.Verifier
|
||||
api storageMinerApi
|
||||
feeCfg config.MinerFeeConfig
|
||||
h host.Host
|
||||
sealer sectorstorage.SectorManager
|
||||
ds datastore.Batching
|
||||
sc sealing.SectorIDCounter
|
||||
verif ffiwrapper.Verifier
|
||||
addrSel *AddressSelector
|
||||
|
||||
maddr address.Address
|
||||
|
||||
@ -91,6 +92,7 @@ type storageMinerApi interface {
|
||||
StateMinerRecoveries(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error)
|
||||
StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error)
|
||||
StateNetworkVersion(context.Context, types.TipSetKey) (network.Version, error)
|
||||
StateLookupID(context.Context, address.Address, types.TipSetKey) (address.Address, error)
|
||||
|
||||
MpoolPushMessage(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error)
|
||||
|
||||
@ -113,15 +115,16 @@ type storageMinerApi interface {
|
||||
WalletHas(context.Context, address.Address) (bool, error)
|
||||
}
|
||||
|
||||
func NewMiner(api storageMinerApi, maddr address.Address, h host.Host, ds datastore.Batching, sealer sectorstorage.SectorManager, sc sealing.SectorIDCounter, verif ffiwrapper.Verifier, gsd dtypes.GetSealingConfigFunc, feeCfg config.MinerFeeConfig, journal journal.Journal) (*Miner, error) {
|
||||
func NewMiner(api storageMinerApi, maddr address.Address, h host.Host, ds datastore.Batching, sealer sectorstorage.SectorManager, sc sealing.SectorIDCounter, verif ffiwrapper.Verifier, gsd dtypes.GetSealingConfigFunc, feeCfg config.MinerFeeConfig, journal journal.Journal, as *AddressSelector) (*Miner, error) {
|
||||
m := &Miner{
|
||||
api: api,
|
||||
feeCfg: feeCfg,
|
||||
h: h,
|
||||
sealer: sealer,
|
||||
ds: ds,
|
||||
sc: sc,
|
||||
verif: verif,
|
||||
api: api,
|
||||
feeCfg: feeCfg,
|
||||
h: h,
|
||||
sealer: sealer,
|
||||
ds: ds,
|
||||
sc: sc,
|
||||
verif: verif,
|
||||
addrSel: as,
|
||||
|
||||
maddr: maddr,
|
||||
getSealConfig: gsd,
|
||||
@ -151,7 +154,12 @@ func (m *Miner) Run(ctx context.Context) error {
|
||||
adaptedAPI := NewSealingAPIAdapter(m.api)
|
||||
// TODO: Maybe we update this policy after actor upgrades?
|
||||
pcp := sealing.NewBasicPreCommitPolicy(adaptedAPI, policy.GetMaxSectorExpirationExtension()-(md.WPoStProvingPeriod*2), md.PeriodStart%md.WPoStProvingPeriod)
|
||||
m.sealing = sealing.New(adaptedAPI, fc, NewEventsAdapter(evts), m.maddr, m.ds, m.sealer, m.sc, m.verif, &pcp, sealing.GetSealingConfigFunc(m.getSealConfig), m.handleSealingNotifications)
|
||||
|
||||
as := func(ctx context.Context, mi miner.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) {
|
||||
return m.addrSel.AddressFor(ctx, m.api, mi, use, goodFunds, minFunds)
|
||||
}
|
||||
|
||||
m.sealing = sealing.New(adaptedAPI, fc, NewEventsAdapter(evts), m.maddr, m.ds, m.sealer, m.sc, m.verif, &pcp, sealing.GetSealingConfigFunc(m.getSealConfig), m.handleSealingNotifications, as)
|
||||
|
||||
go m.sealing.Run(ctx) //nolint:errcheck // logged intside the function
|
||||
|
||||
|
@ -799,7 +799,7 @@ func (s *WindowPoStScheduler) setSender(ctx context.Context, msg *types.Message,
|
||||
goodFunds := big.Add(msg.RequiredFunds(), msg.Value)
|
||||
minFunds := big.Min(big.Add(minGasFeeMsg.RequiredFunds(), minGasFeeMsg.Value), goodFunds)
|
||||
|
||||
pa, avail, err := AddressFor(ctx, s.api, mi, PoStAddr, goodFunds, minFunds)
|
||||
pa, avail, err := s.addrSel.AddressFor(ctx, s.api, mi, api.PoStAddr, goodFunds, minFunds)
|
||||
if err != nil {
|
||||
log.Errorw("error selecting address for window post", "error", err)
|
||||
return nil
|
||||
|
@ -180,6 +180,7 @@ func TestWDPostDoPost(t *testing.T) {
|
||||
proofType: proofType,
|
||||
actor: postAct,
|
||||
journal: journal.NilJournal(),
|
||||
addrSel: &AddressSelector{},
|
||||
}
|
||||
|
||||
di := &dline.Info{
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
type WindowPoStScheduler struct {
|
||||
api storageMinerApi
|
||||
feeCfg config.MinerFeeConfig
|
||||
addrSel *AddressSelector
|
||||
prover storage.Prover
|
||||
faultTracker sectorstorage.FaultTracker
|
||||
proofType abi.RegisteredPoStProof
|
||||
@ -40,7 +41,7 @@ type WindowPoStScheduler struct {
|
||||
// failLk sync.Mutex
|
||||
}
|
||||
|
||||
func NewWindowedPoStScheduler(api storageMinerApi, fc config.MinerFeeConfig, sb storage.Prover, ft sectorstorage.FaultTracker, j journal.Journal, actor address.Address) (*WindowPoStScheduler, error) {
|
||||
func NewWindowedPoStScheduler(api storageMinerApi, fc config.MinerFeeConfig, as *AddressSelector, sb storage.Prover, ft sectorstorage.FaultTracker, j journal.Journal, actor address.Address) (*WindowPoStScheduler, error) {
|
||||
mi, err := api.StateMinerInfo(context.TODO(), actor, types.EmptyTSK)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("getting sector size: %w", err)
|
||||
@ -54,6 +55,7 @@ func NewWindowedPoStScheduler(api storageMinerApi, fc config.MinerFeeConfig, sb
|
||||
return &WindowPoStScheduler{
|
||||
api: api,
|
||||
feeCfg: fc,
|
||||
addrSel: as,
|
||||
prover: sb,
|
||||
faultTracker: ft,
|
||||
proofType: rt,
|
||||
|
Loading…
Reference in New Issue
Block a user