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

both StoredAsk and storage Provider are scoped to a single miner #276

Merged
merged 1 commit into from
Jun 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
17 changes: 12 additions & 5 deletions storagemarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var DefaultDealAcceptanceBuffer = abi.ChainEpoch(100)
var _ storagemarket.StorageProvider = &Provider{}

type StoredAsk interface {
GetAsk(address.Address) *storagemarket.SignedStorageAsk
GetAsk() *storagemarket.SignedStorageAsk
SetAsk(price abi.TokenAmount, duration abi.ChainEpoch, options ...storagemarket.StorageAskOption) error
}

Expand Down Expand Up @@ -259,8 +259,8 @@ func (p *Provider) ImportDataForDeal(ctx context.Context, propCid cid.Cid, data

}

func (p *Provider) GetAsk(addr address.Address) *storagemarket.SignedStorageAsk {
return p.storedAsk.GetAsk(addr)
func (p *Provider) GetAsk() *storagemarket.SignedStorageAsk {
return p.storedAsk.GetAsk()
}

func (p *Provider) ListDeals(ctx context.Context) ([]storagemarket.StorageDeal, error) {
Expand Down Expand Up @@ -327,8 +327,15 @@ func (p *Provider) HandleAskStream(s network.StorageAskStream) {
return
}

var ask *storagemarket.SignedStorageAsk
if p.actor != ar.Miner {
log.Warnf("storage provider for address %s receive ask for miner with address %s", p.actor, ar.Miner)
} else {
ask = p.storedAsk.GetAsk()
}

resp := network.AskResponse{
Ask: p.storedAsk.GetAsk(ar.Miner),
Ask: ask,
}

if err := s.WriteAskResponse(resp); err != nil {
Expand Down Expand Up @@ -446,7 +453,7 @@ func (p *providerDealEnvironment) Node() storagemarket.StorageProviderNode {
}

func (p *providerDealEnvironment) Ask() storagemarket.StorageAsk {
sask := p.p.storedAsk.GetAsk(p.p.actor)
sask := p.p.storedAsk.GetAsk()
if sask == nil {
return storagemarket.StorageAskUndefined
}
Expand Down
5 changes: 1 addition & 4 deletions storagemarket/impl/storedask/storedask.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,9 @@ func (s *StoredAsk) SetAsk(price abi.TokenAmount, duration abi.ChainEpoch, optio

}

func (s *StoredAsk) GetAsk(addr address.Address) *storagemarket.SignedStorageAsk {
func (s *StoredAsk) GetAsk() *storagemarket.SignedStorageAsk {
s.askLk.RLock()
defer s.askLk.RUnlock()
if s.actor != addr {
return nil
}
if s.ask == nil {
return nil
}
Expand Down
12 changes: 3 additions & 9 deletions storagemarket/impl/storedask/storedask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,22 @@ func TestStoredAsk(t *testing.T) {
testPrice := abi.NewTokenAmount(1000000000)
testDuration := abi.ChainEpoch(200)
t.Run("auto initializing", func(t *testing.T) {
ask := storedAsk.GetAsk(actor)
ask := storedAsk.GetAsk()
require.NotNil(t, ask)
})
t.Run("setting ask price", func(t *testing.T) {
minPieceSize := abi.PaddedPieceSize(1024)
err := storedAsk.SetAsk(testPrice, testDuration, storagemarket.MinPieceSize(minPieceSize))
require.NoError(t, err)
ask := storedAsk.GetAsk(actor)
ask := storedAsk.GetAsk()
require.Equal(t, ask.Ask.Price, testPrice)
require.Equal(t, ask.Ask.Expiry-ask.Ask.Timestamp, testDuration)
require.Equal(t, ask.Ask.MinPieceSize, minPieceSize)
})
t.Run("querying incorrect address", func(t *testing.T) {
otherAddr, err := address.NewActorAddress([]byte("other"))
require.NoError(t, err)
ask := storedAsk.GetAsk(otherAddr)
require.Nil(t, ask)
})
t.Run("reloading stored ask from disk", func(t *testing.T) {
storedAsk2, err := storedask.NewStoredAsk(ds, datastore.NewKey("latest-ask"), spn, actor)
require.NoError(t, err)
ask := storedAsk2.GetAsk(actor)
ask := storedAsk2.GetAsk()
require.Equal(t, ask.Ask.Price, testPrice)
require.Equal(t, ask.Ask.Expiry-ask.Ask.Timestamp, testDuration)
})
Expand Down
2 changes: 1 addition & 1 deletion storagemarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ type StorageProvider interface {
SetAsk(price abi.TokenAmount, duration abi.ChainEpoch, options ...StorageAskOption) error

// GetAsk returns the storage miner's ask, or nil if one does not exist.
GetAsk(addr address.Address) *SignedStorageAsk
GetAsk() *SignedStorageAsk

// ListDeals lists on-chain deals associated with this storage provider
ListDeals(ctx context.Context) ([]StorageDeal, error)
Expand Down