Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config for deal publishing control addresses #6697

Merged
merged 6 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,17 @@ type AddrUse int
const (
PreCommitAddr AddrUse = iota
CommitAddr
DealPublishAddr
PoStAddr

TerminateSectorsAddr
)

type AddressConfig struct {
PreCommitControl []address.Address
CommitControl []address.Address
TerminateControl []address.Address
PreCommitControl []address.Address
CommitControl []address.Address
TerminateControl []address.Address
DealPublishControl []address.Address

DisableOwnerFallback bool
DisableWorkerFallback bool
Expand Down
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
24 changes: 24 additions & 0 deletions chain/actors/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,30 @@ func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) ab
}
}

func SetProviderCollateralSupplyTarget(num, denom big.Int) {

market2.ProviderCollateralSupplyTarget = builtin2.BigFrac{
Numerator: num,
Denominator: denom,
}

market3.ProviderCollateralSupplyTarget = builtin3.BigFrac{
Numerator: num,
Denominator: denom,
}

market4.ProviderCollateralSupplyTarget = builtin4.BigFrac{
Numerator: num,
Denominator: denom,
}

market5.ProviderCollateralSupplyTarget = builtin5.BigFrac{
Numerator: num,
Denominator: denom,
}

}

func DealProviderCollateralBounds(
size abi.PaddedPieceSize, verified bool,
rawBytePower, qaPower, baselinePower abi.StoragePower,
Expand Down
11 changes: 11 additions & 0 deletions chain/actors/policy/policy.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) ab
}
}

func SetProviderCollateralSupplyTarget(num, denom big.Int) {
Copy link
Contributor

@arajasek arajasek Jul 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we throw label on here

// SetProviderCollateralSupplyTarget sets the percentage of normalized circulating
// supply that must be covered by provider collateral in a deal. This should
// only be used for testing.

{{range .versions}}
{{if (ge . 2)}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessing we're not doing this for earlier versions just because it isn't that helpful and the ProvCollateralPercentSupplyNumV0 / ProvCollateralPercentSupplyNumV1 thing is messy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't have supply target in v0 actors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and v1 actors didn't exist)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that what ProvCollateralPercentSupplyNumV0 and ProvCollateralPercentSupplyNumV1 did in v0 actors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, maybe, but somehow those don't seem to matter

market{{.}}.ProviderCollateralSupplyTarget = builtin{{.}}.BigFrac{
Numerator: num,
Denominator: denom,
}
{{end}}
{{end}}
}

func DealProviderCollateralBounds(
size abi.PaddedPieceSize, verified bool,
rawBytePower, qaPower, baselinePower abi.StoragePower,
Expand Down
14 changes: 14 additions & 0 deletions cmd/lotus-storage-miner/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ var actorControlList = &cli.Command{
commit := map[address.Address]struct{}{}
precommit := map[address.Address]struct{}{}
terminate := map[address.Address]struct{}{}
dealPublish := map[address.Address]struct{}{}
post := map[address.Address]struct{}{}

for _, ca := range mi.ControlAddresses {
Expand Down Expand Up @@ -471,6 +472,16 @@ var actorControlList = &cli.Command{
terminate[ca] = struct{}{}
}

for _, ca := range ac.DealPublishControl {
ca, err := api.StateLookupID(ctx, ca, types.EmptyTSK)
if err != nil {
return err
}

delete(post, ca)
dealPublish[ca] = struct{}{}
}

printKey := func(name string, a address.Address) {
b, err := api.WalletBalance(ctx, a)
if err != nil {
Expand Down Expand Up @@ -515,6 +526,9 @@ var actorControlList = &cli.Command{
if _, ok := terminate[a]; ok {
uses = append(uses, color.YellowString("terminate"))
}
if _, ok := dealPublish[a]; ok {
uses = append(uses, color.MagentaString("deals"))
}

tw.Write(map[string]interface{}{
"name": name,
Expand Down
1 change: 1 addition & 0 deletions documentation/en/api-v0-methods-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ Response:
"PreCommitControl": null,
"CommitControl": null,
"TerminateControl": null,
"DealPublishControl": null,
"DisableOwnerFallback": true,
"DisableWorkerFallback": true
}
Expand Down
10 changes: 7 additions & 3 deletions itests/ccupgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ func runTestCCUpgrade(t *testing.T, upgradeHeight abi.ChainEpoch) {

{
exp, err := client.StateSectorExpiration(ctx, maddr, CC, types.EmptyTSK)
require.NoError(t, err)
require.NotNil(t, exp)
require.Greater(t, 50000, int(exp.OnTime))
if err != nil {
require.Contains(t, err.Error(), "failed to find sector 3") // already cleaned up
} else {
require.NoError(t, err)
require.NotNil(t, exp)
require.Greater(t, 50000, int(exp.OnTime))
}
}
{
exp, err := client.StateSectorExpiration(ctx, maddr, Upgraded, types.EmptyTSK)
Expand Down
35 changes: 29 additions & 6 deletions itests/deals_publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import (
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
"github.com/filecoin-project/lotus/itests/kit"
"github.com/filecoin-project/lotus/markets/storageadapter"
"github.com/filecoin-project/lotus/node"
"github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/lotus/node/modules"
"github.com/filecoin-project/lotus/storage"
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
"github.com/stretchr/testify/require"
)
Expand All @@ -28,16 +32,34 @@ func TestPublishDealsBatching(t *testing.T) {

kit.QuietMiningLogs()

opts := node.Override(new(*storageadapter.DealPublisher),
storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{
Period: publishPeriod,
MaxDealsPerMsg: maxDealsPerMsg,
}),
publisherKey, err := wallet.GenerateKey(types.KTSecp256k1)
require.NoError(t, err)

opts := node.Options(
node.Override(new(*storageadapter.DealPublisher),
storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{
Period: publishPeriod,
MaxDealsPerMsg: maxDealsPerMsg,
}),
),
node.Override(new(*storage.AddressSelector), modules.AddressSelector(&config.MinerAddressConfig{
DealPublishControl: []string{
publisherKey.Address.String(),
},
DisableOwnerFallback: true,
DisableWorkerFallback: true,
})),
kit.LatestActorsAt(-1),
)

client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ConstructorOpts(opts))
client, miner, ens := kit.EnsembleMinimal(t, kit.Account(publisherKey, types.FromFil(10)), kit.MockProofs(), kit.ConstructorOpts(opts))
ens.InterconnectAll().BeginMining(10 * time.Millisecond)

_, err = client.WalletImport(ctx, &publisherKey.KeyInfo)
require.NoError(t, err)

miner.SetControlAddresses(publisherKey.Address)

dh := kit.NewDealHarness(t, client, miner)

// Starts a deal and waits until it's published
Expand Down Expand Up @@ -92,6 +114,7 @@ func TestPublishDealsBatching(t *testing.T) {
err = pubDealsParams.UnmarshalCBOR(bytes.NewReader(msg.Params))
require.NoError(t, err)
require.Len(t, pubDealsParams.Deals, int(maxDealsPerMsg))
require.Equal(t, publisherKey.Address.String(), msg.From.String())
}
}
require.Equal(t, 1, count)
Expand Down
42 changes: 42 additions & 0 deletions itests/kit/control.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package kit

import (
"context"

"github.com/stretchr/testify/require"

addr "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/big"
miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"

"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/types"
)

func (tm *TestMiner) SetControlAddresses(addrs ...addr.Address) {
ctx := context.TODO()

mi, err := tm.FullNode.StateMinerInfo(ctx, tm.ActorAddr, types.EmptyTSK)
require.NoError(tm.t, err)

cwp := &miner2.ChangeWorkerAddressParams{
NewWorker: mi.Worker,
NewControlAddrs: addrs,
}

sp, err := actors.SerializeParams(cwp)
require.NoError(tm.t, err)

smsg, err := tm.FullNode.MpoolPushMessage(ctx, &types.Message{
From: mi.Owner,
To: tm.ActorAddr,
Method: miner.Methods.ChangeWorkerAddress,

Value: big.Zero(),
Params: sp,
}, nil)
require.NoError(tm.t, err)

tm.FullNode.WaitMsg(ctx, smsg.Cid())
}
14 changes: 10 additions & 4 deletions itests/kit/funds.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"context"
"testing"

"github.com/filecoin-project/go-state-types/abi"
"github.com/stretchr/testify/require"

"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types"
Expand All @@ -27,8 +29,12 @@ func SendFunds(ctx context.Context, t *testing.T, sender *TestFullNode, recipien
sm, err := sender.MpoolPushMessage(ctx, msg, nil)
require.NoError(t, err)

res, err := sender.StateWaitMsg(ctx, sm.Cid(), 3, api.LookbackNoLimit, true)
require.NoError(t, err)
sender.WaitMsg(ctx, sm.Cid())
}

func (f *TestFullNode) WaitMsg(ctx context.Context, msg cid.Cid) {
res, err := f.StateWaitMsg(ctx, msg, 3, api.LookbackNoLimit, true)
require.NoError(f.t, err)

require.EqualValues(t, 0, res.Receipt.ExitCode, "did not successfully send funds")
require.EqualValues(f.t, 0, res.Receipt.ExitCode, "message did not successfully execute")
}
3 changes: 3 additions & 0 deletions itests/kit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors/policy"
logging "github.com/ipfs/go-log/v2"
Expand All @@ -13,6 +14,8 @@ import (
func init() {
_ = logging.SetLogLevel("*", "INFO")

policy.SetProviderCollateralSupplyTarget(big.Zero(), big.NewInt(1))

policy.SetConsensusMinerMinPower(abi.NewStoragePower(2048))
policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg2KiBV1)
policy.SetMinVerifiedDealSize(abi.NewStoragePower(256))
Expand Down
12 changes: 10 additions & 2 deletions markets/storageadapter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,16 @@ func (c *ClientNodeAdapter) ValidatePublishedDeal(ctx context.Context, deal stor
return 0, xerrors.Errorf("failed to resolve from msg ID addr: %w", err)
}

if fromid != mi.Worker {
return 0, xerrors.Errorf("deal wasn't published by storage provider: from=%s, provider=%s", pubmsg.From, deal.Proposal.Provider)
var pubOk bool
pubAddrs := append([]address.Address{mi.Worker, mi.Owner}, mi.ControlAddresses...)
for _, a := range pubAddrs {
if fromid == a {
pubOk = true
break
}
}
if !pubOk {
return 0, xerrors.Errorf("deal wasn't published by storage provider: from=%s, provider=%s,%+v", pubmsg.From, deal.Proposal.Provider, pubAddrs)
}

if pubmsg.To != miner2.StorageMarketActorAddr {
Expand Down
34 changes: 24 additions & 10 deletions markets/storageadapter/dealpublisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@ import (
"sync"
"time"

"github.com/ipfs/go-cid"
"go.uber.org/fx"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/go-state-types/big"
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/api"

"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/types"
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/lotus/storage"
)

type dealPublisherAPI interface {
ChainHead(context.Context) (*types.TipSet, error)
MpoolPushMessage(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec) (*types.SignedMessage, error)
StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error)

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)
}

// DealPublisher batches deal publishing so that many deals can be included in
Expand All @@ -40,6 +46,7 @@ type dealPublisherAPI interface {
// publish message with all deals in the queue.
type DealPublisher struct {
api dealPublisherAPI
as *storage.AddressSelector

ctx context.Context
Shutdown context.CancelFunc
Expand Down Expand Up @@ -87,14 +94,14 @@ type PublishMsgConfig struct {
func NewDealPublisher(
feeConfig *config.MinerFeeConfig,
publishMsgCfg PublishMsgConfig,
) func(lc fx.Lifecycle, full api.FullNode) *DealPublisher {
return func(lc fx.Lifecycle, full api.FullNode) *DealPublisher {
) func(lc fx.Lifecycle, full api.FullNode, as *storage.AddressSelector) *DealPublisher {
return func(lc fx.Lifecycle, full api.FullNode, as *storage.AddressSelector) *DealPublisher {
maxFee := abi.NewTokenAmount(0)
if feeConfig != nil {
maxFee = abi.TokenAmount(feeConfig.MaxPublishDealsFee)
}
publishSpec := &api.MessageSendSpec{MaxFee: maxFee}
dp := newDealPublisher(full, publishMsgCfg, publishSpec)
dp := newDealPublisher(full, as, publishMsgCfg, publishSpec)
lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
dp.Shutdown()
Expand All @@ -107,12 +114,14 @@ func NewDealPublisher(

func newDealPublisher(
dpapi dealPublisherAPI,
as *storage.AddressSelector,
publishMsgCfg PublishMsgConfig,
publishSpec *api.MessageSendSpec,
) *DealPublisher {
ctx, cancel := context.WithCancel(context.Background())
return &DealPublisher{
api: dpapi,
as: as,
ctx: ctx,
Shutdown: cancel,
maxDealsPerPublishMsg: publishMsgCfg.MaxDealsPerMsg,
Expand Down Expand Up @@ -345,9 +354,14 @@ func (p *DealPublisher) publishDealProposals(deals []market2.ClientDealProposal)
return cid.Undef, xerrors.Errorf("serializing PublishStorageDeals params failed: %w", err)
}

addr, _, err := p.as.AddressFor(p.ctx, p.api, mi, api.DealPublishAddr, big.Zero(), big.Zero())
if err != nil {
return cid.Undef, xerrors.Errorf("selecting address for publishing deals: %w", err)
}

smsg, err := p.api.MpoolPushMessage(p.ctx, &types.Message{
To: market.Address,
From: mi.Worker,
From: addr,
Value: types.NewInt(0),
Method: market.Methods.PublishStorageDeals,
Params: params,
Expand Down
Loading