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

Correct behaviour for SetAsk #433

Merged
merged 1 commit into from
Oct 14, 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
11 changes: 7 additions & 4 deletions storagemarket/impl/storedask/storedask.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ type StoredAsk struct {
// NewStoredAsk returns a new instance of StoredAsk
// It will initialize a new SignedStorageAsk on disk if one is not set
// Otherwise it loads the current SignedStorageAsk from disk
func NewStoredAsk(ds datastore.Batching, dsKey datastore.Key, spn storagemarket.StorageProviderNode, actor address.Address) (*StoredAsk, error) {

func NewStoredAsk(ds datastore.Batching, dsKey datastore.Key, spn storagemarket.StorageProviderNode, actor address.Address,
opts ...storagemarket.StorageAskOption) (*StoredAsk, error) {
s := &StoredAsk{
spn: spn,
actor: actor,
Expand Down Expand Up @@ -87,7 +87,7 @@ func NewStoredAsk(ds datastore.Batching, dsKey datastore.Key, spn storagemarket.
if s.ask == nil {
// TODO: we should be fine with this state, and just say it means 'not actively accepting deals'
// for now... lets just set a price
if err := s.SetAsk(DefaultPrice, DefaultVerifiedPrice, DefaultDuration); err != nil {
if err := s.SetAsk(DefaultPrice, DefaultVerifiedPrice, DefaultDuration, opts...); err != nil {
return nil, xerrors.Errorf("failed setting a default price: %w", err)
}
}
Expand All @@ -101,8 +101,11 @@ func (s *StoredAsk) SetAsk(price abi.TokenAmount, verifiedPrice abi.TokenAmount,
s.askLk.Lock()
defer s.askLk.Unlock()
var seqno uint64
minPieceSize := DefaultMinPieceSize
if s.ask != nil {
seqno = s.ask.Ask.SeqNo + 1
minPieceSize = s.ask.Ask.MinPieceSize

}

ctx := context.TODO()
Expand All @@ -118,7 +121,7 @@ func (s *StoredAsk) SetAsk(price abi.TokenAmount, verifiedPrice abi.TokenAmount,
Expiry: height + duration,
Miner: s.actor,
SeqNo: seqno,
MinPieceSize: DefaultMinPieceSize,
MinPieceSize: minPieceSize,
MaxPieceSize: DefaultMaxPieceSize,
}

Expand Down
29 changes: 29 additions & 0 deletions storagemarket/impl/storedask/storedask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestStoredAsk(t *testing.T) {
require.Equal(t, ask.Ask.VerifiedPrice, testVerifiedPrice)
require.Equal(t, ask.Ask.Expiry-ask.Ask.Timestamp, testDuration)
})

t.Run("node errors", func(t *testing.T) {
spnStateIDErr := &testnodes.FakeProviderNode{
FakeCommonNode: testnodes.FakeCommonNode{
Expand Down Expand Up @@ -94,6 +95,34 @@ func TestStoredAsk(t *testing.T) {
require.Error(t, err)
})
}

func TestMinPieceSize(t *testing.T) {
// create ask with options
ds := dss.MutexWrap(datastore.NewMapDatastore())
spn := &testnodes.FakeProviderNode{
FakeCommonNode: testnodes.FakeCommonNode{
SMState: testnodes.NewStorageMarketState(),
},
}
actor := address.TestAddress2
ms := abi.PaddedPieceSize(1024)
storedAsk2, err := storedask.NewStoredAsk(ds, datastore.NewKey("latest-ask"), spn, actor, storagemarket.MinPieceSize(ms))
require.NoError(t, err)
ask := storedAsk2.GetAsk()
require.EqualValues(t, ms, ask.Ask.MinPieceSize)

// now change the min piece size via set ask
testPrice := abi.NewTokenAmount(1000000000)
testVerifiedPrice := abi.NewTokenAmount(100000000)
testDuration := abi.ChainEpoch(200)
newSize := abi.PaddedPieceSize(150)
require.NoError(t, storedAsk2.SetAsk(testPrice, testVerifiedPrice, testDuration, storagemarket.MinPieceSize(newSize)))

// call get
ask = storedAsk2.GetAsk()
require.EqualValues(t, newSize, ask.Ask.MinPieceSize)
}

func TestMigrations(t *testing.T) {
ctx := context.Background()
ds := dss.MutexWrap(datastore.NewMapDatastore())
Expand Down