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

send state identifiery when getting miner worker address #153

Merged
merged 3 commits into from
Mar 17, 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
10 changes: 9 additions & 1 deletion retrievalmarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,15 @@ func (p *provider) HandleQueryStream(stream rmnet.RetrievalQueryStream) {
MaxPaymentIntervalIncrease: p.paymentIntervalIncrease,
}

paymentAddress, err := p.node.GetMinerWorker(context.TODO(), p.minerAddress)
ctx := context.TODO()

tok, _, err := p.node.GetChainHead(ctx)
if err != nil {
log.Errorf("Retrieval query: GetChainHead: %s", err)
return
}

paymentAddress, err := p.node.GetMinerWorkerAddress(ctx, p.minerAddress, tok)
if err != nil {
log.Errorf("Retrieval query: Lookup Payment Address: %s", err)
answer.Status = retrievalmarket.QueryResponseError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (trpn *TestRetrievalProviderNode) SavePaymentVoucher(
}

// GetMinerWorker translates an address
func (trpn *TestRetrievalProviderNode) GetMinerWorker(ctx context.Context, addr address.Address) (address.Address, error) {
func (trpn *TestRetrievalProviderNode) GetMinerWorkerAddress(ctx context.Context, addr address.Address, tok shared.TipSetToken) (address.Address, error) {
return addr, nil
}

Expand Down
6 changes: 3 additions & 3 deletions retrievalmarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"fmt"
"io"

"github.com/filecoin-project/go-fil-markets/shared"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer"

"github.com/filecoin-project/go-fil-markets/shared"
)

//go:generate cbor-gen-for Query QueryResponse DealProposal DealResponse Params QueryParams DealPayment Block ClientDealState ProviderDealState PaymentInfo
Expand Down Expand Up @@ -316,7 +316,7 @@ type RetrievalProviderNode interface {
GetChainHead(ctx context.Context) (shared.TipSetToken, abi.ChainEpoch, error)

// returns the worker address associated with a miner
GetMinerWorker(ctx context.Context, miner address.Address) (address.Address, error)
GetMinerWorkerAddress(ctx context.Context, miner address.Address, tok shared.TipSetToken) (address.Address, error)
UnsealSector(ctx context.Context, sectorID uint64, offset uint64, length uint64) (io.ReadCloser, error)
SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paych.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount) (abi.TokenAmount, error)
}
Expand Down
7 changes: 6 additions & 1 deletion storagemarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ func (p *providerDealEnvironment) SendSignedResponse(ctx context.Context, resp *
return xerrors.Errorf("couldn't send response: %w", err)
}

sig, err := providerutils.SignMinerData(ctx, resp, p.p.actor, p.Node().GetMinerWorker, p.Node().SignBytes)
tok, _, err := p.p.spn.GetChainHead(ctx)
if err != nil {
return xerrors.Errorf("couldn't get chain head: %w", err)
}

sig, err := providerutils.SignMinerData(ctx, resp, p.p.actor, tok, p.Node().GetMinerWorkerAddress, p.Node().SignBytes)
if err != nil {
return xerrors.Errorf("failed to sign response message: %w", err)
}
Expand Down
7 changes: 6 additions & 1 deletion storagemarket/impl/providerstates/provider_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ func VerifyData(ctx fsm.Context, environment ProviderDealEnvironment, deal stora

// PublishDeal publishes a deal on chain and sends the deal id back to the client
func PublishDeal(ctx fsm.Context, environment ProviderDealEnvironment, deal storagemarket.MinerDeal) error {
waddr, err := environment.Node().GetMinerWorker(ctx.Context(), deal.Proposal.Provider)
tok, _, err := environment.Node().GetChainHead(ctx.Context())
if err != nil {
return ctx.Trigger(storagemarket.ProviderEventNodeErrored, xerrors.Errorf("acquiring chain head: %w", err))
}

waddr, err := environment.Node().GetMinerWorkerAddress(ctx.Context(), deal.Proposal.Provider, tok)
if err != nil {
return ctx.Trigger(storagemarket.ProviderEventNodeErrored, xerrors.Errorf("looking up miner worker: %w", err))
}
Expand Down
7 changes: 4 additions & 3 deletions storagemarket/impl/providerutils/providerutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
logging "github.com/ipfs/go-log/v2"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-fil-markets/shared"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-fil-markets/storagemarket/impl/requestvalidation"
)
Expand Down Expand Up @@ -41,19 +42,19 @@ func VerifyProposal(sdp market.ClientDealProposal, verifier VerifyFunc) error {
}

// WorkerLookupFunc is a function that can lookup a miner worker address from a storage miner actor
type WorkerLookupFunc func(context.Context, address.Address) (address.Address, error)
type WorkerLookupFunc func(context.Context, address.Address, shared.TipSetToken) (address.Address, error)

// SignFunc is a function that can sign a set of bytes with a given address
type SignFunc func(context.Context, address.Address, []byte) (*crypto.Signature, error)

// SignMinerData signs the given data structure with a signature for the given address
func SignMinerData(ctx context.Context, data interface{}, address address.Address, workerLookup WorkerLookupFunc, sign SignFunc) (*crypto.Signature, error) {
func SignMinerData(ctx context.Context, data interface{}, address address.Address, tok shared.TipSetToken, workerLookup WorkerLookupFunc, sign SignFunc) (*crypto.Signature, error) {
msg, err := cborutil.Dump(data)
if err != nil {
return nil, xerrors.Errorf("serializing: %w", err)
}

worker, err := workerLookup(ctx, address)
worker, err := workerLookup(ctx, address, tok)
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions storagemarket/impl/providerutils/providerutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/libp2p/go-libp2p-core/peer"
"github.com/stretchr/testify/require"

"github.com/filecoin-project/go-fil-markets/shared"
"github.com/filecoin-project/go-fil-markets/shared_testutil"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-fil-markets/storagemarket/impl/providerutils"
Expand Down Expand Up @@ -56,7 +57,7 @@ func TestVerifyProposal(t *testing.T) {

func TestSignMinerData(t *testing.T) {
ctx := context.Background()
successLookup := func(context.Context, address.Address) (address.Address, error) {
successLookup := func(context.Context, address.Address, shared.TipSetToken) (address.Address, error) {
return address.TestAddress2, nil
}
successSign := func(context.Context, address.Address, []byte) (*crypto.Signature, error) {
Expand All @@ -82,7 +83,7 @@ func TestSignMinerData(t *testing.T) {
},
"worker lookup errors": {
data: shared_testutil.MakeTestStorageAsk(),
workerLookup: func(context.Context, address.Address) (address.Address, error) {
workerLookup: func(context.Context, address.Address, shared.TipSetToken) (address.Address, error) {
return address.Undef, errors.New("Something went wrong")
},
signBytes: successSign,
Expand All @@ -99,7 +100,7 @@ func TestSignMinerData(t *testing.T) {
}
for name, data := range tests {
t.Run(name, func(t *testing.T) {
_, err := providerutils.SignMinerData(ctx, data.data, address.TestAddress, data.workerLookup, data.signBytes)
_, err := providerutils.SignMinerData(ctx, data.data, address.TestAddress, shared.TipSetToken{}, data.workerLookup, data.signBytes)
require.Equal(t, err != nil, data.shouldErr)
})
}
Expand Down
11 changes: 9 additions & 2 deletions storagemarket/impl/storedask/storedask.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func (s *StoredAsk) AddAsk(price abi.TokenAmount, duration abi.ChainEpoch) error
seqno = s.ask.Ask.SeqNo + 1
}

_, height, err := s.spn.GetChainHead(context.TODO())
ctx := context.TODO()

_, height, err := s.spn.GetChainHead(ctx)
if err != nil {
return err
}
Expand All @@ -73,7 +75,12 @@ func (s *StoredAsk) AddAsk(price abi.TokenAmount, duration abi.ChainEpoch) error
MinPieceSize: defaultMinPieceSize,
}

sig, err := providerutils.SignMinerData(context.TODO(), ask, s.actor, s.spn.GetMinerWorker, s.spn.SignBytes)
tok, _, err := s.spn.GetChainHead(ctx)
if err != nil {
return err
}

sig, err := providerutils.SignMinerData(ctx, ask, s.actor, tok, s.spn.GetMinerWorkerAddress, s.spn.SignBytes)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions storagemarket/testnodes/testnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
"context"
"io"

"github.com/filecoin-project/go-fil-markets/shared"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/ipfs/go-cid"

"github.com/filecoin-project/go-fil-markets/shared"
"github.com/filecoin-project/go-fil-markets/shared_testutil"
"github.com/filecoin-project/go-fil-markets/storagemarket"
)
Expand Down Expand Up @@ -229,7 +228,7 @@ func (n *FakeProviderNode) OnDealComplete(ctx context.Context, deal storagemarke
}

// GetMinerWorker returns the address specified by MinerAddr
func (n *FakeProviderNode) GetMinerWorker(ctx context.Context, miner address.Address) (address.Address, error) {
func (n *FakeProviderNode) GetMinerWorkerAddress(ctx context.Context, miner address.Address, tok shared.TipSetToken) (address.Address, error) {
if n.MinerWorkerError == nil {
return n.MinerAddr, nil
}
Expand Down
2 changes: 1 addition & 1 deletion storagemarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ type StorageProviderNode interface {
OnDealComplete(ctx context.Context, deal MinerDeal, pieceSize abi.UnpaddedPieceSize, pieceReader io.Reader) error

// returns the worker address associated with a miner
GetMinerWorker(ctx context.Context, miner address.Address) (address.Address, error)
GetMinerWorkerAddress(ctx context.Context, addr address.Address, tok shared.TipSetToken) (address.Address, error)

// Signs bytes
SignBytes(ctx context.Context, signer address.Address, b []byte) (*crypto.Signature, error)
Expand Down