Skip to content

Commit

Permalink
Merge pull request #5103 from filecoin-project/feat/miner-control-config
Browse files Browse the repository at this point in the history
miner: Control address config for (pre)commits
  • Loading branch information
magik6k authored Dec 3, 2020
2 parents b190c34 + 58695dc commit 90a31fd
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 51 deletions.
19 changes: 17 additions & 2 deletions api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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
}
9 changes: 7 additions & 2 deletions api/apistruct/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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)
}
Expand Down
41 changes: 37 additions & 4 deletions cmd/lotus-storage-miner/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions documentation/en/api-methods-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [Version](#Version)
* [Actor](#Actor)
* [ActorAddress](#ActorAddress)
* [ActorAddressConfig](#ActorAddressConfig)
* [ActorSectorSize](#ActorSectorSize)
* [Auth](#Auth)
* [AuthNew](#AuthNew)
Expand Down Expand Up @@ -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.

Expand Down
13 changes: 9 additions & 4 deletions extern/storage-sealing/sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -87,6 +90,7 @@ type Sealing struct {
toUpgrade map[abi.SectorNumber]struct{}

notifee SectorStateNotifee
addrSel AddrSel

stats SectorStats

Expand All @@ -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,
Expand All @@ -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,

Expand Down
22 changes: 18 additions & 4 deletions extern/storage-sealing/states_sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)})
}
Expand Down
2 changes: 2 additions & 0 deletions node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)),
)
}
Expand Down
11 changes: 11 additions & 0 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type StorageMiner struct {
Sealing SealingConfig
Storage sectorstorage.SealerConfig
Fees MinerFeeConfig
Addresses MinerAddressConfig
}

type DealmakingConfig struct {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions node/impl/storminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type StorageMinerAPI struct {
storiface.WorkerReturn
DataTransfer dtypes.ProviderDataTransfer
Host host.Host
AddrSel *storage.AddressSelector

DS dtypes.MetadataDS

Expand Down Expand Up @@ -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{}
Loading

0 comments on commit 90a31fd

Please sign in to comment.