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

FRC DealProposal integration #1216

Merged
merged 2 commits into from
Mar 3, 2023
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/filecoin-project/go-legs v0.4.9
github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.10.0-rc3
github.com/filecoin-project/go-state-types v0.10.0
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/lotus v1.20.0-rc2-boost
github.com/filecoin-project/specs-actors v0.9.15
Expand All @@ -47,6 +47,7 @@ require (
github.com/graph-gophers/graphql-transport-ws v0.0.2
github.com/hashicorp/go-multierror v1.1.1
github.com/hnlq715/golang-lru v0.3.0
github.com/ipfs/go-block-format v0.1.1 // indirect
github.com/ipfs/go-blockservice v0.5.0
github.com/ipfs/go-cid v0.3.2
github.com/ipfs/go-cidutil v0.1.0
Expand Down Expand Up @@ -358,7 +359,6 @@ require (
require (
github.com/alexbrainman/goissue34681 v0.0.0-20191006012335-3fc7a47baff5 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/ipfs/go-block-format v0.1.1 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ github.com/filecoin-project/go-state-types v0.1.4/go.mod h1:xCA/WfKlC2zcn3fUmDv4
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.10.0-rc3 h1:qExCc2swTe5ndsiu9dEoMqIwppjuTNRbsAFgpzHnHbc=
github.com/filecoin-project/go-state-types v0.10.0-rc3/go.mod h1:aLIas+W8BWAfpLWEPUOGMPBdhcVwoCG4pIQSQk26024=
github.com/filecoin-project/go-state-types v0.10.0 h1:vsSThZIaPmOxNGG59+8D/HnlWRtlbdOjduH6ye+v8f0=
github.com/filecoin-project/go-state-types v0.10.0/go.mod h1:aLIas+W8BWAfpLWEPUOGMPBdhcVwoCG4pIQSQk26024=
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=
Expand Down
6 changes: 6 additions & 0 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func DefaultBoost() *Boost {
ServiceName: "boostd",
},

ContractDeals: ContractDealsConfig{
Enabled: false,
AllowlistContracts: []string{},
From: "0x0000000000000000000000000000000000000000",
},

Dealmaking: DealmakingConfig{
ConsiderOnlineStorageDeals: true,
ConsiderOfflineStorageDeals: true,
Expand Down
100 changes: 72 additions & 28 deletions storagemarket/contract_deal_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

var (
TopicHash = paddedEthHash(ethTopicHash("DealProposalCreate(bytes32,bytes,bool,uint256)")) // deals published on chain
TopicHash = paddedEthHash(ethTopicHash("DealProposalCreate(bytes32,uint64,bool,uint256)")) // deals published on chain
)

type ContractDealMonitor struct {
Expand Down Expand Up @@ -91,8 +91,7 @@ func (c *ContractDealMonitor) Start(ctx context.Context) error {
return
case resp := <-responseCh:
err := func() error {
result := resp.Result.([]interface{})[0]
event := result.(map[string]interface{})
event := resp.Result.(map[string]interface{})
topicContractAddress := event["address"].(string)
topicDealProposalID := event["topics"].([]interface{})[1].(string)

Expand All @@ -101,41 +100,24 @@ func (c *ContractDealMonitor) Start(ctx context.Context) error {
return fmt.Errorf("allowlist does not contain this contract address: %s", topicContractAddress)
}

// GetDealProposal is a free data retrieval call binding the contract method 0xf4b2e4d8.
_params := "0xf4b2e4d8" + topicDealProposalID[2:] // cut 0x prefix

toEthAddr, err := ethtypes.ParseEthAddress(topicContractAddress)
if err != nil {
return fmt.Errorf("parsing `to` eth address failed: %w", err)
}

params, err := ethtypes.DecodeHexString(_params)
if err != nil {
return fmt.Errorf("decoding params failed: %w", err)
}

res, err := c.api.EthCall(ctx, ethtypes.EthCall{
From: &fromEthAddr,
To: &toEthAddr,
Data: params,
}, "latest")
res, err := c.getDealProposal(ctx, topicContractAddress, topicDealProposalID, fromEthAddr)
if err != nil {
return fmt.Errorf("eth call erred: %w", err)
return fmt.Errorf("eth call for get deal proposal failed: %w", err)
}

begin, length, err := lengthPrefixPointsTo(res)
resParams, err := c.getExtraData(ctx, topicContractAddress, topicDealProposalID, fromEthAddr)
if err != nil {
return fmt.Errorf("length prefix points erred: %w", err)
return fmt.Errorf("eth call for extra data failed: %w", err)
}

var dpc types.ContractDealProposal
err = dpc.UnmarshalCBOR(bytes.NewReader(res[begin : begin+length]))
var dpc market.DealProposal
err = dpc.UnmarshalCBOR(bytes.NewReader(res))
if err != nil {
return fmt.Errorf("cbor unmarshal failed: %w", err)
}

var pv1 types.ContractParamsVersion1
err = pv1.UnmarshalCBOR(bytes.NewReader(dpc.Params))
err = pv1.UnmarshalCBOR(bytes.NewReader(resParams))
if err != nil {
return fmt.Errorf("params cbor unmarshal failed: %w", err)
}
Expand Down Expand Up @@ -206,7 +188,7 @@ func (c *ContractDealMonitor) Start(ctx context.Context) error {
return nil
}()
if err != nil {
log.Errorw("handling DealProposalCreate event erred: %w", err)
log.Errorw("handling DealProposalCreate event erred", "err", err)
}
}
}
Expand Down Expand Up @@ -264,3 +246,65 @@ func lengthPrefixPointsTo(output []byte) (int, int, error) {
}
return int(boffset.Uint64()), int(lengthBig.Uint64()), nil
}

func (c *ContractDealMonitor) getDealProposal(ctx context.Context, topicContractAddress string, topicDealProposalID string, fromEthAddr ethtypes.EthAddress) ([]byte, error) {
// GetDealProposal is a free data retrieval call binding the contract method 0xf4b2e4d8.
_params := "0xf4b2e4d8" + topicDealProposalID[2:] // cut 0x prefix

toEthAddr, err := ethtypes.ParseEthAddress(topicContractAddress)
if err != nil {
return nil, fmt.Errorf("parsing `to` eth address failed: %w", err)
}

params, err := ethtypes.DecodeHexString(_params)
if err != nil {
return nil, fmt.Errorf("decoding params failed: %w", err)
}

res, err := c.api.EthCall(ctx, ethtypes.EthCall{
From: &fromEthAddr,
To: &toEthAddr,
Data: params,
}, "latest")
if err != nil {
return nil, fmt.Errorf("eth call erred: %w", err)
}

begin, length, err := lengthPrefixPointsTo(res)
if err != nil {
return nil, fmt.Errorf("length prefix points erred: %w", err)
}

return res[begin : begin+length], nil
}

func (c *ContractDealMonitor) getExtraData(ctx context.Context, topicContractAddress string, topicDealProposalID string, fromEthAddr ethtypes.EthAddress) ([]byte, error) {
// GetExtraParams is a free data retrieval call binding the contract method 0x4634aed5.
_params := "0x4634aed5" + topicDealProposalID[2:] // cut 0x prefix

toEthAddr, err := ethtypes.ParseEthAddress(topicContractAddress)
if err != nil {
return nil, fmt.Errorf("parsing `to` eth address failed: %w", err)
}

params, err := ethtypes.DecodeHexString(_params)
if err != nil {
return nil, fmt.Errorf("decoding params failed: %w", err)
}

res, err := c.api.EthCall(ctx, ethtypes.EthCall{
From: &fromEthAddr,
To: &toEthAddr,
Data: params,
}, "latest")
if err != nil {
return nil, fmt.Errorf("eth call erred: %w", err)
}

begin, length, err := lengthPrefixPointsTo(res)
if err != nil {
return nil, fmt.Errorf("length prefix points erred: %w", err)
}

return res[begin : begin+length], nil
}
8 changes: 6 additions & 2 deletions storagemarket/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (c *ChainDealManager) CheckDealEquality(ctx context.Context, tok ctypes.Tip
if err != nil {
return false, err
}
return p1.PieceCID.Equals(p2.PieceCID) &&
res := p1.PieceCID.Equals(p2.PieceCID) &&
p1.PieceSize == p2.PieceSize &&
p1.VerifiedDeal == p2.VerifiedDeal &&
p1.Label.Equals(p2.Label) &&
Expand All @@ -191,5 +191,9 @@ func (c *ChainDealManager) CheckDealEquality(ctx context.Context, tok ctypes.Tip
p1.ProviderCollateral.Equals(p2.ProviderCollateral) &&
p1.ClientCollateral.Equals(p2.ClientCollateral) &&
p1.Provider == p2.Provider &&
p1ClientID == p2ClientID, nil
p1ClientID == p2ClientID

log.Debugw("check deal quality", "result", res, "p1clientid", p1ClientID, "p2clientid", p2ClientID, "label_equality", p1.Label.Equals(p2.Label), "provider_equality", p1.Provider == p2.Provider)

return res, nil
}
2 changes: 1 addition & 1 deletion storagemarket/sealingpipeline/mock/sealingpipeline.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 5 additions & 28 deletions storagemarket/types/contract_deal_proposal_types.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
package types

import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v9/market"
"github.com/ipfs/go-cid"
)

type ContractDealProposal struct {
PieceCID cid.Cid
PieceSize abi.PaddedPieceSize
VerifiedDeal bool
Client address.Address

Label market.DealLabel

StartEpoch abi.ChainEpoch
EndEpoch abi.ChainEpoch
StoragePricePerEpoch abi.TokenAmount

ProviderCollateral abi.TokenAmount
ClientCollateral abi.TokenAmount

Version string
Params []byte
}
//go:generate cbor-gen-for ContractParamsVersion1

type ContractParamsVersion1 struct {
LocationRef string
CarSize uint64
SkipIpniAnnounce bool
LocationRef string
CarSize uint64
SkipIpniAnnounce bool
RemoveUnsealedCopy bool
}
Loading