Skip to content

Commit

Permalink
Merge pull request #4 from filecoin-project/feat/update_version
Browse files Browse the repository at this point in the history
update venus
  • Loading branch information
hunjixin authored Oct 14, 2021
2 parents 5a39d6f + 7844841 commit 16b3b43
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/filecoin-project/specs-actors/v2 v2.3.5
github.com/filecoin-project/specs-actors/v3 v3.1.1
github.com/filecoin-project/specs-actors/v5 v5.0.4
github.com/filecoin-project/specs-actors/v6 v6.0.0
github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506
github.com/filecoin-project/venus v1.1.0-rc1
github.com/filecoin-project/venus-auth v1.3.1-0.20210809053831-012d55d5f578
Expand Down
57 changes: 41 additions & 16 deletions storageadapter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"github.com/filecoin-project/venus/pkg/constants"
"github.com/filecoin-project/venus/pkg/wallet"

market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"

"github.com/ipfs/go-cid"
"go.uber.org/fx"
"golang.org/x/xerrors"
Expand All @@ -23,9 +26,6 @@ import (
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/exitcode"

miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"

"github.com/filecoin-project/venus-market/fundmgr"
"github.com/filecoin-project/venus-market/metrics"
"github.com/filecoin-project/venus-market/utils"
Expand Down Expand Up @@ -110,10 +110,10 @@ func (c *ClientNodeAdapter) VerifySignature(ctx context.Context, sig crypto.Sign
func (c *ClientNodeAdapter) AddFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) (cid.Cid, error) {
// (Provider Node API)
smsg, err := c.full.MpoolPushMessage(ctx, &types.Message{ //todo send to messager service
To: miner2.StorageMarketActorAddr,
To: marketactor.Address,
From: addr,
Value: amount,
Method: miner2.MethodsMarket.AddBalance,
Method: builtin6.MethodsMarket.AddBalance,
}, nil)
if err != nil {
return cid.Undef, err
Expand Down Expand Up @@ -177,15 +177,15 @@ func (c *ClientNodeAdapter) ValidatePublishedDeal(ctx context.Context, deal stor
return 0, xerrors.Errorf("deal wasn't published by piecestorage provider: from=%s, provider=%s,%+v", pubmsg.From, deal.Proposal.Provider, pubAddrs)
}

if pubmsg.To != miner2.StorageMarketActorAddr {
if pubmsg.To != marketactor.Address {
return 0, xerrors.Errorf("deal publish message wasn't set to StorageMarket actor (to=%s)", pubmsg.To)
}

if pubmsg.Method != miner2.MethodsMarket.PublishStorageDeals {
if pubmsg.Method != builtin6.MethodsMarket.PublishStorageDeals {
return 0, xerrors.Errorf("deal publish message called incorrect method (method=%s)", pubmsg.Method)
}

var params market2.PublishStorageDealsParams
var params marketactor.PublishStorageDealsParams
if err := params.UnmarshalCBOR(bytes.NewReader(pubmsg.Params)); err != nil {
return 0, err
}
Expand Down Expand Up @@ -217,12 +217,37 @@ func (c *ClientNodeAdapter) ValidatePublishedDeal(ctx context.Context, deal stor
return 0, xerrors.Errorf("deal publish failed: exit=%d", ret.Receipt.ExitCode)
}

var res market2.PublishStorageDealsReturn
if err := res.UnmarshalCBOR(bytes.NewReader(ret.Receipt.ReturnValue)); err != nil {
return 0, err
nv, err := c.full.StateNetworkVersion(ctx, ret.TipSet)
if err != nil {
return 0, xerrors.Errorf("getting network version: %w", err)
}

res, err := marketactor.DecodePublishStorageDealsReturn(ret.Receipt.ReturnValue, nv)
if err != nil {
return 0, xerrors.Errorf("decoding deal publish return: %w", err)
}

dealIDs, err := res.DealIDs()
if err != nil {
return 0, xerrors.Errorf("getting dealIDs: %w", err)
}

if dealIdx >= len(dealIDs) {
return 0, xerrors.Errorf(
"deal index %d out of bounds of deals (len %d) in publish deals message %s",
dealIdx, len(dealIDs), pubmsg.Cid())
}

valid, err := res.IsDealValid(uint64(dealIdx))
if err != nil {
return 0, xerrors.Errorf("determining deal validity: %w", err)
}

if !valid {
return 0, xerrors.New("deal was invalid at publication")
}

return res.IDs[dealIdx], nil
return dealIDs[dealIdx], nil
}

var clientOverestimation = struct {
Expand All @@ -245,12 +270,12 @@ func (c *ClientNodeAdapter) DealProviderCollateralBounds(ctx context.Context, si
}

// TODO: Remove dealID parameter, change publishCid to be cid.Cid (instead of pointer)
func (c *ClientNodeAdapter) OnDealSectorPreCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, proposal market2.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorPreCommittedCallback) error {
func (c *ClientNodeAdapter) OnDealSectorPreCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, proposal market0.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorPreCommittedCallback) error {
return c.scMgr.OnDealSectorPreCommitted(ctx, provider, marketactor.DealProposal(proposal), *publishCid, cb)
}

// TODO: Remove dealID parameter, change publishCid to be cid.Cid (instead of pointer)
func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, sectorNumber abi.SectorNumber, proposal market2.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorCommittedCallback) error {
func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, sectorNumber abi.SectorNumber, proposal market0.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorCommittedCallback) error {
return c.scMgr.OnDealSectorCommitted(ctx, provider, sectorNumber, marketactor.DealProposal(proposal), *publishCid, cb)
}

Expand Down Expand Up @@ -344,7 +369,7 @@ func (c *ClientNodeAdapter) OnDealExpiredOrSlashed(ctx context.Context, dealID a
return nil
}

func (c *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal market2.DealProposal) (*market2.ClientDealProposal, error) {
func (c *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal market0.DealProposal) (*marketactor.ClientDealProposal, error) {
// TODO: output spec signed proposal
buf, err := cborutil.Dump(&proposal)
if err != nil {
Expand All @@ -363,7 +388,7 @@ func (c *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Add
return nil, err
}

return &market2.ClientDealProposal{
return &marketactor.ClientDealProposal{
Proposal: proposal,
ClientSignature: *sig,
}, nil
Expand Down

0 comments on commit 16b3b43

Please sign in to comment.