From dd01c6722800f8bc1edef14957d4d65773bb63bc Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Mon, 18 Sep 2023 13:57:32 +0800 Subject: [PATCH] feat: add id to MinerDeal --- venus-shared/api/market/v0/method.md | 5 ++++ venus-shared/api/market/v1/method.md | 5 ++++ venus-shared/types/market/cbor_gen.go | 40 +++++++++++++++++++++++++-- venus-shared/types/market/storage.go | 2 ++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/venus-shared/api/market/v0/method.md b/venus-shared/api/market/v0/method.md index aa84d88f89..f5c785d63f 100644 --- a/venus-shared/api/market/v0/method.md +++ b/venus-shared/api/market/v0/method.md @@ -570,6 +570,7 @@ Inputs: [ [ { + "ID": "07070707-0707-0707-0707-070707070707", "Proposal": { "PieceCID": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" @@ -1287,6 +1288,7 @@ Inputs: Response: ```json { + "ID": "07070707-0707-0707-0707-070707070707", "Proposal": { "PieceCID": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" @@ -1363,6 +1365,7 @@ Inputs: `[]` Response: ```json { + "ID": "07070707-0707-0707-0707-070707070707", "Proposal": { "PieceCID": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" @@ -1542,6 +1545,7 @@ Inputs: ```json [ { + "ID": "07070707-0707-0707-0707-070707070707", "Proposal": { "PieceCID": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" @@ -1721,6 +1725,7 @@ Response: ```json [ { + "ID": "07070707-0707-0707-0707-070707070707", "Proposal": { "PieceCID": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" diff --git a/venus-shared/api/market/v1/method.md b/venus-shared/api/market/v1/method.md index 24522672e6..5cbf2057c9 100644 --- a/venus-shared/api/market/v1/method.md +++ b/venus-shared/api/market/v1/method.md @@ -571,6 +571,7 @@ Inputs: [ [ { + "ID": "07070707-0707-0707-0707-070707070707", "Proposal": { "PieceCID": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" @@ -1288,6 +1289,7 @@ Inputs: Response: ```json { + "ID": "07070707-0707-0707-0707-070707070707", "Proposal": { "PieceCID": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" @@ -1364,6 +1366,7 @@ Inputs: `[]` Response: ```json { + "ID": "07070707-0707-0707-0707-070707070707", "Proposal": { "PieceCID": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" @@ -1543,6 +1546,7 @@ Inputs: ```json [ { + "ID": "07070707-0707-0707-0707-070707070707", "Proposal": { "PieceCID": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" @@ -1722,6 +1726,7 @@ Response: ```json [ { + "ID": "07070707-0707-0707-0707-070707070707", "Proposal": { "PieceCID": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" diff --git a/venus-shared/types/market/cbor_gen.go b/venus-shared/types/market/cbor_gen.go index 8bdf0930b5..278bcb394e 100644 --- a/venus-shared/types/market/cbor_gen.go +++ b/venus-shared/types/market/cbor_gen.go @@ -766,7 +766,7 @@ func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) (err error) { return nil } -var lengthBufMinerDeal = []byte{152, 24} +var lengthBufMinerDeal = []byte{152, 25} func (t *MinerDeal) MarshalCBOR(w io.Writer) error { if t == nil { @@ -780,6 +780,19 @@ func (t *MinerDeal) MarshalCBOR(w io.Writer) error { return err } + // t.ID (uuid.UUID) (array) + if len(t.ID) > cbg.ByteArrayMaxLen { + return xerrors.Errorf("Byte array in field t.ID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.ID))); err != nil { + return err + } + + if _, err := cw.Write(t.ID[:]); err != nil { + return err + } + // t.ClientDealProposal (market.ClientDealProposal) (struct) if err := t.ClientDealProposal.MarshalCBOR(cw); err != nil { return err @@ -996,10 +1009,33 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) (err error) { return fmt.Errorf("cbor input should be of type array") } - if extra != 24 { + if extra != 25 { return fmt.Errorf("cbor input had wrong number of fields") } + // t.ID (uuid.UUID) (array) + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > cbg.ByteArrayMaxLen { + return fmt.Errorf("t.ID: byte array too large (%d)", extra) + } + if maj != cbg.MajByteString { + return fmt.Errorf("expected byte array") + } + + if extra != 16 { + return fmt.Errorf("expected array to have 16 elements") + } + + t.ID = [16]uint8{} + + if _, err := io.ReadFull(cr, t.ID[:]); err != nil { + return err + } // t.ClientDealProposal (market.ClientDealProposal) (struct) { diff --git a/venus-shared/types/market/storage.go b/venus-shared/types/market/storage.go index f18c8413d0..c9557a35b1 100644 --- a/venus-shared/types/market/storage.go +++ b/venus-shared/types/market/storage.go @@ -11,12 +11,14 @@ import ( "github.com/filecoin-project/go-state-types/abi" crypto "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/venus/venus-shared/types" + "github.com/google/uuid" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p/core/peer" cbg "github.com/whyrusleeping/cbor-gen" ) type MinerDeal struct { + ID uuid.UUID types.ClientDealProposal ProposalCid cid.Cid AddFundsCid *cid.Cid