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

Include chain height when running custom decision logic #322

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 11 additions & 35 deletions storagemarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ import (
"github.com/filecoin-project/go-fil-markets/storagemarket/network"
)

// DefaultDealAcceptanceBuffer is the minimum number of epochs ahead of the current epoch
// a deal's StartEpoch must be for the deal to be accepted.
// The StartEpoch must be more than simply greater than the current epoch because we
// need time to transfer data, publish the deal on chain, and seal the sector with the data
var DefaultDealAcceptanceBuffer = abi.ChainEpoch(100)
var _ storagemarket.StorageProvider = &Provider{}
var _ network.StorageReceiver = &Provider{}

Expand All @@ -61,7 +56,6 @@ type Provider struct {
dataTransfer datatransfer.Manager
universalRetrievalEnabled bool
customDealDeciderFunc DealDeciderFunc
dealAcceptanceBuffer abi.ChainEpoch
pubSub *pubsub.PubSub

deals fsm.Group
Expand All @@ -78,14 +72,6 @@ func EnableUniversalRetrieval() StorageProviderOption {
}
}

// DealAcceptanceBuffer allows a provider to set a buffer (in epochs) to account for the time
// required for data transfer, deal verification, publishing, sealing, and committing.
func DealAcceptanceBuffer(buffer abi.ChainEpoch) StorageProviderOption {
return func(p *Provider) {
p.dealAcceptanceBuffer = buffer
}
}

// DealDeciderFunc is a function which evaluates an incoming deal to decide if
// it its accepted
// It returns:
Expand Down Expand Up @@ -119,18 +105,17 @@ func NewProvider(net network.StorageMarketNetwork,
pio := pieceio.NewPieceIOWithStore(carIO, fs, bs)

h := &Provider{
net: net,
proofType: rt,
spn: spn,
fs: fs,
pio: pio,
pieceStore: pieceStore,
conns: connmanager.NewConnManager(),
storedAsk: storedAsk,
actor: minerAddress,
dataTransfer: dataTransfer,
dealAcceptanceBuffer: DefaultDealAcceptanceBuffer,
pubSub: pubsub.New(providerDispatcher),
net: net,
proofType: rt,
spn: spn,
fs: fs,
pio: pio,
pieceStore: pieceStore,
conns: connmanager.NewConnManager(),
storedAsk: storedAsk,
actor: minerAddress,
dataTransfer: dataTransfer,
pubSub: pubsub.New(providerDispatcher),
}

deals, err := newProviderStateMachine(
Expand Down Expand Up @@ -485,11 +470,6 @@ func (p *Provider) Configure(options ...StorageProviderOption) {
}
}

// DealAcceptanceBuffer returns the current deal acceptance buffer
func (p *Provider) DealAcceptanceBuffer() abi.ChainEpoch {
return p.dealAcceptanceBuffer
}

// UniversalRetrievalEnabled returns whether or not universal retrieval
// (retrieval by any CID, not just the root payload CID) is enabled
// for this provider
Expand Down Expand Up @@ -648,10 +628,6 @@ func (p *providerDealEnvironment) Disconnect(proposalCid cid.Cid) error {
return p.p.conns.Disconnect(proposalCid)
}

func (p *providerDealEnvironment) DealAcceptanceBuffer() abi.ChainEpoch {
return p.p.dealAcceptanceBuffer
}

func (p *providerDealEnvironment) RunCustomDecisionLogic(ctx context.Context, deal storagemarket.MinerDeal) (bool, string, error) {
if p.p.customDealDeciderFunc == nil {
return true, "", nil
Expand Down
4 changes: 0 additions & 4 deletions storagemarket/impl/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package storageimpl_test
import (
"testing"

"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/stretchr/testify/assert"

storageimpl "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
Expand All @@ -13,13 +12,10 @@ func TestConfigure(t *testing.T) {
p := &storageimpl.Provider{}

assert.False(t, p.UniversalRetrievalEnabled())
assert.Equal(t, abi.ChainEpoch(0), p.DealAcceptanceBuffer())

p.Configure(
storageimpl.EnableUniversalRetrieval(),
storageimpl.DealAcceptanceBuffer(abi.ChainEpoch(123)),
)

assert.True(t, p.UniversalRetrievalEnabled())
assert.Equal(t, abi.ChainEpoch(123), p.DealAcceptanceBuffer())
}
7 changes: 1 addition & 6 deletions storagemarket/impl/providerstates/provider_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type ProviderDealEnvironment interface {
Disconnect(proposalCid cid.Cid) error
FileStore() filestore.FileStore
PieceStore() piecestore.PieceStore
DealAcceptanceBuffer() abi.ChainEpoch
RunCustomDecisionLogic(context.Context, storagemarket.MinerDeal) (bool, string, error)
}

Expand All @@ -47,7 +46,7 @@ type ProviderStateEntryFunc func(ctx fsm.Context, environment ProviderDealEnviro

// ValidateDealProposal validates a proposed deal against the provider criteria
func ValidateDealProposal(ctx fsm.Context, environment ProviderDealEnvironment, deal storagemarket.MinerDeal) error {
tok, height, err := environment.Node().GetChainHead(ctx.Context())
tok, _, err := environment.Node().GetChainHead(ctx.Context())
if err != nil {
return ctx.Trigger(storagemarket.ProviderEventDealRejected, xerrors.Errorf("node error getting most recent state id: %w", err))
}
Expand All @@ -62,10 +61,6 @@ func ValidateDealProposal(ctx fsm.Context, environment ProviderDealEnvironment,
return ctx.Trigger(storagemarket.ProviderEventDealRejected, xerrors.Errorf("incorrect provider for deal"))
}

if height > proposal.StartEpoch-environment.DealAcceptanceBuffer() {
return ctx.Trigger(storagemarket.ProviderEventDealRejected, xerrors.Errorf("deal start epoch is too soon or deal already expired"))
}

// TODO: check StorageCollateral

minPrice := big.Div(big.Mul(environment.Ask().Price, abi.NewTokenAmount(int64(proposal.PieceSize))), abi.NewTokenAmount(1<<30))
Expand Down
24 changes: 0 additions & 24 deletions storagemarket/impl/providerstates/provider_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,6 @@ func TestValidateDealProposal(t *testing.T) {
require.Equal(t, "deal rejected: node error getting most recent state id: couldn't get id", deal.Message)
},
},
"CurrentHeight <= StartEpoch - DealAcceptanceBuffer() succeeds": {
environmentParams: environmentParams{DealAcceptanceBuffer: 10},
dealParams: dealParams{StartEpoch: 200},
nodeParams: nodeParams{Height: 190},
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment) {
tut.AssertDealState(t, storagemarket.StorageDealAcceptWait, deal.State)
},
},
"CurrentHeight > StartEpoch - DealAcceptanceBuffer() fails": {
environmentParams: environmentParams{DealAcceptanceBuffer: 10},
dealParams: dealParams{StartEpoch: 200},
nodeParams: nodeParams{Height: 191},
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment) {
tut.AssertDealState(t, storagemarket.StorageDealRejecting, deal.State)
require.Equal(t, "deal rejected: deal start epoch is too soon or deal already expired", deal.Message)
},
},
"PricePerEpoch too low": {
dealParams: dealParams{
StoragePricePerEpoch: abi.NewTokenAmount(5000),
Expand Down Expand Up @@ -899,7 +882,6 @@ type environmentParams struct {
GenerateCommPError error
SendSignedResponseError error
DisconnectError error
DealAcceptanceBuffer int64
TagsProposal bool
RejectDeal bool
RejectReason string
Expand Down Expand Up @@ -1048,7 +1030,6 @@ func makeExecutor(ctx context.Context,
rejectDeal: params.RejectDeal,
rejectReason: params.RejectReason,
decisionError: params.DecisionError,
dealAcceptanceBuffer: abi.ChainEpoch(params.DealAcceptanceBuffer),
fs: fs,
pieceStore: pieceStore,
}
Expand Down Expand Up @@ -1097,7 +1078,6 @@ type fakeEnvironment struct {
decisionError error
fs filestore.FileStore
pieceStore piecestore.PieceStore
dealAcceptanceBuffer abi.ChainEpoch
expectedTags map[string]struct{}
receivedTags map[string]struct{}
}
Expand Down Expand Up @@ -1139,10 +1119,6 @@ func (fe *fakeEnvironment) PieceStore() piecestore.PieceStore {
return fe.pieceStore
}

func (fe *fakeEnvironment) DealAcceptanceBuffer() abi.ChainEpoch {
return fe.dealAcceptanceBuffer
}

func (fe *fakeEnvironment) RunCustomDecisionLogic(context.Context, storagemarket.MinerDeal) (bool, string, error) {
return !fe.rejectDeal, fe.rejectReason, fe.decisionError
}