Merge pull request #527 from filecoin-project/fix/retrieval-serialization

fix serialization of paych vouchers
This commit is contained in:
Łukasz Magiera 2019-11-05 18:34:42 +01:00 committed by GitHub
commit de1d014f8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 1485 additions and 620 deletions

129
api/cbor_gen.go Normal file
View File

@ -0,0 +1,129 @@
package api
import (
"fmt"
"io"
"github.com/filecoin-project/lotus/chain/types"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)
/* This file was generated by github.com/whyrusleeping/cbor-gen */
var _ = xerrors.Errorf
func (t *PaymentInfo) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{131}); err != nil {
return err
}
// t.t.Channel (address.Address) (struct)
if err := t.Channel.MarshalCBOR(w); err != nil {
return err
}
// t.t.ChannelMessage (cid.Cid) (struct)
if t.ChannelMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
return err
}
} else {
if err := cbg.WriteCid(w, *t.ChannelMessage); err != nil {
return xerrors.Errorf("failed to write cid field t.ChannelMessage: %w", err)
}
}
// t.t.Vouchers ([]*types.SignedVoucher) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Vouchers)))); err != nil {
return err
}
for _, v := range t.Vouchers {
if err := v.MarshalCBOR(w); err != nil {
return err
}
}
return nil
}
func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 3 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Channel (address.Address) (struct)
{
if err := t.Channel.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.ChannelMessage (cid.Cid) (struct)
{
pb, err := br.PeekByte()
if err != nil {
return err
}
if pb == cbg.CborNull[0] {
var nbuf [1]byte
if _, err := br.Read(nbuf[:]); err != nil {
return err
}
} else {
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.ChannelMessage: %w", err)
}
t.ChannelMessage = &c
}
}
// t.t.Vouchers ([]*types.SignedVoucher) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Vouchers: array too large (%d)", extra)
}
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Vouchers = make([]*types.SignedVoucher, extra)
}
for i := 0; i < int(extra); i++ {
var v types.SignedVoucher
if err := v.UnmarshalCBOR(br); err != nil {
return err
}
t.Vouchers[i] = &v
}
return nil
}

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@ func (t *AskRequest) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Miner (address.Address) // t.t.Miner (address.Address) (struct)
if err := t.Miner.MarshalCBOR(w); err != nil { if err := t.Miner.MarshalCBOR(w); err != nil {
return err return err
} }
@ -46,7 +46,7 @@ func (t *AskRequest) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Miner (address.Address) // t.t.Miner (address.Address) (struct)
{ {
@ -67,7 +67,7 @@ func (t *AskResponse) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Ask (types.SignedStorageAsk) // t.t.Ask (types.SignedStorageAsk) (struct)
if err := t.Ask.MarshalCBOR(w); err != nil { if err := t.Ask.MarshalCBOR(w); err != nil {
return err return err
} }
@ -89,7 +89,7 @@ func (t *AskResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Ask (types.SignedStorageAsk) // t.t.Ask (types.SignedStorageAsk) (struct)
{ {
@ -122,7 +122,7 @@ func (t *Proposal) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.DealProposal (actors.StorageDealProposal) // t.t.DealProposal (actors.StorageDealProposal) (struct)
if err := t.DealProposal.MarshalCBOR(w); err != nil { if err := t.DealProposal.MarshalCBOR(w); err != nil {
return err return err
} }
@ -144,7 +144,7 @@ func (t *Proposal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.DealProposal (actors.StorageDealProposal) // t.t.DealProposal (actors.StorageDealProposal) (struct)
{ {
@ -165,12 +165,12 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.State (uint64) // t.t.State (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.State)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil {
return err return err
} }
// t.t.Message (string) // t.t.Message (string) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Message)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Message)))); err != nil {
return err return err
} }
@ -178,18 +178,18 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Proposal (cid.Cid) // t.t.Proposal (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Proposal); err != nil { if err := cbg.WriteCid(w, t.Proposal); err != nil {
return xerrors.Errorf("failed to write cid field t.Proposal: %w", err) return xerrors.Errorf("failed to write cid field t.Proposal: %w", err)
} }
// t.t.StorageDeal (actors.StorageDeal) // t.t.StorageDeal (actors.StorageDeal) (struct)
if err := t.StorageDeal.MarshalCBOR(w); err != nil { if err := t.StorageDeal.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.PublishMessage (cid.Cid) // t.t.PublishMessage (cid.Cid) (struct)
if t.PublishMessage == nil { if t.PublishMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil { if _, err := w.Write(cbg.CborNull); err != nil {
@ -201,7 +201,7 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
} }
} }
// t.t.CommitMessage (cid.Cid) // t.t.CommitMessage (cid.Cid) (struct)
if t.CommitMessage == nil { if t.CommitMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil { if _, err := w.Write(cbg.CborNull); err != nil {
@ -231,7 +231,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.State (uint64) // t.t.State (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -240,8 +240,8 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.State = extra t.State = uint64(extra)
// t.t.Message (string) // t.t.Message (string) (string)
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -251,7 +251,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
t.Message = string(sval) t.Message = string(sval)
} }
// t.t.Proposal (cid.Cid) // t.t.Proposal (cid.Cid) (struct)
{ {
@ -263,7 +263,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
t.Proposal = c t.Proposal = c
} }
// t.t.StorageDeal (actors.StorageDeal) // t.t.StorageDeal (actors.StorageDeal) (struct)
{ {
@ -284,7 +284,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.PublishMessage (cid.Cid) // t.t.PublishMessage (cid.Cid) (struct)
{ {
@ -308,7 +308,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.CommitMessage (cid.Cid) // t.t.CommitMessage (cid.Cid) (struct)
{ {
@ -344,12 +344,12 @@ func (t *SignedResponse) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Response (deals.Response) // t.t.Response (deals.Response) (struct)
if err := t.Response.MarshalCBOR(w); err != nil { if err := t.Response.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Signature (types.Signature) // t.t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil { if err := t.Signature.MarshalCBOR(w); err != nil {
return err return err
} }
@ -371,7 +371,7 @@ func (t *SignedResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Response (deals.Response) // t.t.Response (deals.Response) (struct)
{ {
@ -380,7 +380,7 @@ func (t *SignedResponse) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Signature (types.Signature) // t.t.Signature (types.Signature) (struct)
{ {
@ -413,38 +413,38 @@ func (t *ClientDealProposal) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Data (cid.Cid) // t.t.Data (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Data); err != nil { if err := cbg.WriteCid(w, t.Data); err != nil {
return xerrors.Errorf("failed to write cid field t.Data: %w", err) return xerrors.Errorf("failed to write cid field t.Data: %w", err)
} }
// t.t.PricePerEpoch (types.BigInt) // t.t.PricePerEpoch (types.BigInt) (struct)
if err := t.PricePerEpoch.MarshalCBOR(w); err != nil { if err := t.PricePerEpoch.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.ProposalExpiration (uint64) // t.t.ProposalExpiration (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.ProposalExpiration)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ProposalExpiration))); err != nil {
return err return err
} }
// t.t.Duration (uint64) // t.t.Duration (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Duration)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Duration))); err != nil {
return err return err
} }
// t.t.ProviderAddress (address.Address) // t.t.ProviderAddress (address.Address) (struct)
if err := t.ProviderAddress.MarshalCBOR(w); err != nil { if err := t.ProviderAddress.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Client (address.Address) // t.t.Client (address.Address) (struct)
if err := t.Client.MarshalCBOR(w); err != nil { if err := t.Client.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.MinerID (peer.ID) // t.t.MinerID (peer.ID) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.MinerID)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.MinerID)))); err != nil {
return err return err
} }
@ -469,7 +469,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Data (cid.Cid) // t.t.Data (cid.Cid) (struct)
{ {
@ -481,7 +481,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
t.Data = c t.Data = c
} }
// t.t.PricePerEpoch (types.BigInt) // t.t.PricePerEpoch (types.BigInt) (struct)
{ {
@ -490,7 +490,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.ProposalExpiration (uint64) // t.t.ProposalExpiration (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -499,8 +499,8 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.ProposalExpiration = extra t.ProposalExpiration = uint64(extra)
// t.t.Duration (uint64) // t.t.Duration (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -509,8 +509,8 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Duration = extra t.Duration = uint64(extra)
// t.t.ProviderAddress (address.Address) // t.t.ProviderAddress (address.Address) (struct)
{ {
@ -519,7 +519,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Client (address.Address) // t.t.Client (address.Address) (struct)
{ {
@ -528,7 +528,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.MinerID (peer.ID) // t.t.MinerID (peer.ID) (string)
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -550,23 +550,23 @@ func (t *ClientDeal) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.ProposalCid (cid.Cid) // t.t.ProposalCid (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ProposalCid); err != nil { if err := cbg.WriteCid(w, t.ProposalCid); err != nil {
return xerrors.Errorf("failed to write cid field t.ProposalCid: %w", err) return xerrors.Errorf("failed to write cid field t.ProposalCid: %w", err)
} }
// t.t.Proposal (actors.StorageDealProposal) // t.t.Proposal (actors.StorageDealProposal) (struct)
if err := t.Proposal.MarshalCBOR(w); err != nil { if err := t.Proposal.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.State (uint64) // t.t.State (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.State)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil {
return err return err
} }
// t.t.Miner (peer.ID) // t.t.Miner (peer.ID) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Miner)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Miner)))); err != nil {
return err return err
} }
@ -591,7 +591,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.ProposalCid (cid.Cid) // t.t.ProposalCid (cid.Cid) (struct)
{ {
@ -603,7 +603,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
t.ProposalCid = c t.ProposalCid = c
} }
// t.t.Proposal (actors.StorageDealProposal) // t.t.Proposal (actors.StorageDealProposal) (struct)
{ {
@ -612,7 +612,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.State (uint64) // t.t.State (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -621,8 +621,8 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.State = extra t.State = uint64(extra)
// t.t.Miner (peer.ID) // t.t.Miner (peer.ID) (string)
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -644,7 +644,7 @@ func (t *MinerDeal) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Client (peer.ID) // t.t.Client (peer.ID) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Client)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Client)))); err != nil {
return err return err
} }
@ -652,35 +652,35 @@ func (t *MinerDeal) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Proposal (actors.StorageDealProposal) // t.t.Proposal (actors.StorageDealProposal) (struct)
if err := t.Proposal.MarshalCBOR(w); err != nil { if err := t.Proposal.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.ProposalCid (cid.Cid) // t.t.ProposalCid (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ProposalCid); err != nil { if err := cbg.WriteCid(w, t.ProposalCid); err != nil {
return xerrors.Errorf("failed to write cid field t.ProposalCid: %w", err) return xerrors.Errorf("failed to write cid field t.ProposalCid: %w", err)
} }
// t.t.State (uint64) // t.t.State (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.State)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil {
return err return err
} }
// t.t.Ref (cid.Cid) // t.t.Ref (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Ref); err != nil { if err := cbg.WriteCid(w, t.Ref); err != nil {
return xerrors.Errorf("failed to write cid field t.Ref: %w", err) return xerrors.Errorf("failed to write cid field t.Ref: %w", err)
} }
// t.t.DealID (uint64) // t.t.DealID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.DealID)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.DealID))); err != nil {
return err return err
} }
// t.t.SectorID (uint64) // t.t.SectorID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.SectorID)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorID))); err != nil {
return err return err
} }
return nil return nil
@ -701,7 +701,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Client (peer.ID) // t.t.Client (peer.ID) (string)
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -711,7 +711,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
t.Client = peer.ID(sval) t.Client = peer.ID(sval)
} }
// t.t.Proposal (actors.StorageDealProposal) // t.t.Proposal (actors.StorageDealProposal) (struct)
{ {
@ -720,7 +720,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.ProposalCid (cid.Cid) // t.t.ProposalCid (cid.Cid) (struct)
{ {
@ -732,7 +732,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
t.ProposalCid = c t.ProposalCid = c
} }
// t.t.State (uint64) // t.t.State (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -741,8 +741,8 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.State = extra t.State = uint64(extra)
// t.t.Ref (cid.Cid) // t.t.Ref (cid.Cid) (struct)
{ {
@ -754,7 +754,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
t.Ref = c t.Ref = c
} }
// t.t.DealID (uint64) // t.t.DealID (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -763,8 +763,8 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.DealID = extra t.DealID = uint64(extra)
// t.t.SectorID (uint64) // t.t.SectorID (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -773,6 +773,6 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.SectorID = extra t.SectorID = uint64(extra)
return nil return nil
} }

View File

@ -2,6 +2,7 @@ package deals
import ( import (
"bytes" "bytes"
"github.com/filecoin-project/lotus/lib/cborrpc" "github.com/filecoin-project/lotus/lib/cborrpc"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"

View File

@ -279,12 +279,6 @@ func (cg *ChainGen) NextTipSetFromMiners(base *types.TipSet, miners []address.Ad
} }
fts := store.NewFullTipSet(blks) fts := store.NewFullTipSet(blks)
fmt.Println("Made a block: ", fts.TipSet().Cids())
if len(fts.TipSet().Cids()) > 1 {
for _, b := range blks {
fmt.Printf("block %s: %#v\n", b.Cid(), b.Header)
}
}
return &MinedTipSet{ return &MinedTipSet{
TipSet: fts, TipSet: fts,

View File

@ -5,7 +5,7 @@ import (
"io" "io"
"math" "math"
"github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors" xerrors "golang.org/x/xerrors"
) )
@ -23,12 +23,12 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Miner (address.Address) // t.t.Miner (address.Address) (struct)
if err := t.Miner.MarshalCBOR(w); err != nil { if err := t.Miner.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Tickets ([]*types.Ticket) // t.t.Tickets ([]*types.Ticket) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Tickets)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Tickets)))); err != nil {
return err return err
} }
@ -38,7 +38,7 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
} }
} }
// t.t.ElectionProof ([]uint8) // t.t.ElectionProof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.ElectionProof)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.ElectionProof)))); err != nil {
return err return err
} }
@ -46,7 +46,7 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Parents ([]cid.Cid) // t.t.Parents ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Parents)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Parents)))); err != nil {
return err return err
} }
@ -56,45 +56,45 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
} }
} }
// t.t.ParentWeight (types.BigInt) // t.t.ParentWeight (types.BigInt) (struct)
if err := t.ParentWeight.MarshalCBOR(w); err != nil { if err := t.ParentWeight.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Height (uint64) // t.t.Height (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Height)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Height))); err != nil {
return err return err
} }
// t.t.ParentStateRoot (cid.Cid) // t.t.ParentStateRoot (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ParentStateRoot); err != nil { if err := cbg.WriteCid(w, t.ParentStateRoot); err != nil {
return xerrors.Errorf("failed to write cid field t.ParentStateRoot: %w", err) return xerrors.Errorf("failed to write cid field t.ParentStateRoot: %w", err)
} }
// t.t.ParentMessageReceipts (cid.Cid) // t.t.ParentMessageReceipts (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ParentMessageReceipts); err != nil { if err := cbg.WriteCid(w, t.ParentMessageReceipts); err != nil {
return xerrors.Errorf("failed to write cid field t.ParentMessageReceipts: %w", err) return xerrors.Errorf("failed to write cid field t.ParentMessageReceipts: %w", err)
} }
// t.t.Messages (cid.Cid) // t.t.Messages (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Messages); err != nil { if err := cbg.WriteCid(w, t.Messages); err != nil {
return xerrors.Errorf("failed to write cid field t.Messages: %w", err) return xerrors.Errorf("failed to write cid field t.Messages: %w", err)
} }
// t.t.BLSAggregate (types.Signature) // t.t.BLSAggregate (types.Signature) (struct)
if err := t.BLSAggregate.MarshalCBOR(w); err != nil { if err := t.BLSAggregate.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Timestamp (uint64) // t.t.Timestamp (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Timestamp)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Timestamp))); err != nil {
return err return err
} }
// t.t.BlockSig (types.Signature) // t.t.BlockSig (types.Signature) (struct)
if err := t.BlockSig.MarshalCBOR(w); err != nil { if err := t.BlockSig.MarshalCBOR(w); err != nil {
return err return err
} }
@ -116,7 +116,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Miner (address.Address) // t.t.Miner (address.Address) (struct)
{ {
@ -125,7 +125,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Tickets ([]*types.Ticket) // t.t.Tickets ([]*types.Ticket) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -151,7 +151,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.Tickets[i] = &v t.Tickets[i] = &v
} }
// t.t.ElectionProof ([]uint8) // t.t.ElectionProof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -168,7 +168,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.ElectionProof); err != nil { if _, err := io.ReadFull(br, t.ElectionProof); err != nil {
return err return err
} }
// t.t.Parents ([]cid.Cid) // t.t.Parents ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -193,7 +193,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.Parents[i] = c t.Parents[i] = c
} }
// t.t.ParentWeight (types.BigInt) // t.t.ParentWeight (types.BigInt) (struct)
{ {
@ -202,7 +202,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Height (uint64) // t.t.Height (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -211,8 +211,8 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Height = extra t.Height = uint64(extra)
// t.t.ParentStateRoot (cid.Cid) // t.t.ParentStateRoot (cid.Cid) (struct)
{ {
@ -224,7 +224,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.ParentStateRoot = c t.ParentStateRoot = c
} }
// t.t.ParentMessageReceipts (cid.Cid) // t.t.ParentMessageReceipts (cid.Cid) (struct)
{ {
@ -236,7 +236,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.ParentMessageReceipts = c t.ParentMessageReceipts = c
} }
// t.t.Messages (cid.Cid) // t.t.Messages (cid.Cid) (struct)
{ {
@ -248,7 +248,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.Messages = c t.Messages = c
} }
// t.t.BLSAggregate (types.Signature) // t.t.BLSAggregate (types.Signature) (struct)
{ {
@ -257,7 +257,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Timestamp (uint64) // t.t.Timestamp (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -266,8 +266,8 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Timestamp = extra t.Timestamp = uint64(extra)
// t.t.BlockSig (types.Signature) // t.t.BlockSig (types.Signature) (struct)
{ {
@ -288,7 +288,7 @@ func (t *Ticket) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.VRFProof ([]uint8) // t.t.VRFProof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.VRFProof)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.VRFProof)))); err != nil {
return err return err
} }
@ -313,7 +313,7 @@ func (t *Ticket) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.VRFProof ([]uint8) // t.t.VRFProof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -342,42 +342,42 @@ func (t *Message) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.To (address.Address) // t.t.To (address.Address) (struct)
if err := t.To.MarshalCBOR(w); err != nil { if err := t.To.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.From (address.Address) // t.t.From (address.Address) (struct)
if err := t.From.MarshalCBOR(w); err != nil { if err := t.From.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Nonce (uint64) // t.t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Nonce)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err return err
} }
// t.t.Value (types.BigInt) // t.t.Value (types.BigInt) (struct)
if err := t.Value.MarshalCBOR(w); err != nil { if err := t.Value.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.GasPrice (types.BigInt) // t.t.GasPrice (types.BigInt) (struct)
if err := t.GasPrice.MarshalCBOR(w); err != nil { if err := t.GasPrice.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.GasLimit (types.BigInt) // t.t.GasLimit (types.BigInt) (struct)
if err := t.GasLimit.MarshalCBOR(w); err != nil { if err := t.GasLimit.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Method (uint64) // t.t.Method (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Method)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Method))); err != nil {
return err return err
} }
// t.t.Params ([]uint8) // t.t.Params ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Params)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Params)))); err != nil {
return err return err
} }
@ -402,7 +402,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.To (address.Address) // t.t.To (address.Address) (struct)
{ {
@ -411,7 +411,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.From (address.Address) // t.t.From (address.Address) (struct)
{ {
@ -420,7 +420,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Nonce (uint64) // t.t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -429,8 +429,8 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Nonce = extra t.Nonce = uint64(extra)
// t.t.Value (types.BigInt) // t.t.Value (types.BigInt) (struct)
{ {
@ -439,7 +439,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.GasPrice (types.BigInt) // t.t.GasPrice (types.BigInt) (struct)
{ {
@ -448,7 +448,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.GasLimit (types.BigInt) // t.t.GasLimit (types.BigInt) (struct)
{ {
@ -457,7 +457,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Method (uint64) // t.t.Method (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -466,8 +466,8 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Method = extra t.Method = uint64(extra)
// t.t.Params ([]uint8) // t.t.Params ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -496,12 +496,12 @@ func (t *SignedMessage) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Message (types.Message) // t.t.Message (types.Message) (struct)
if err := t.Message.MarshalCBOR(w); err != nil { if err := t.Message.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Signature (types.Signature) // t.t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil { if err := t.Signature.MarshalCBOR(w); err != nil {
return err return err
} }
@ -523,7 +523,7 @@ func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Message (types.Message) // t.t.Message (types.Message) (struct)
{ {
@ -532,7 +532,7 @@ func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Signature (types.Signature) // t.t.Signature (types.Signature) (struct)
{ {
@ -553,13 +553,13 @@ func (t *MsgMeta) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.BlsMessages (cid.Cid) // t.t.BlsMessages (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.BlsMessages); err != nil { if err := cbg.WriteCid(w, t.BlsMessages); err != nil {
return xerrors.Errorf("failed to write cid field t.BlsMessages: %w", err) return xerrors.Errorf("failed to write cid field t.BlsMessages: %w", err)
} }
// t.t.SecpkMessages (cid.Cid) // t.t.SecpkMessages (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.SecpkMessages); err != nil { if err := cbg.WriteCid(w, t.SecpkMessages); err != nil {
return xerrors.Errorf("failed to write cid field t.SecpkMessages: %w", err) return xerrors.Errorf("failed to write cid field t.SecpkMessages: %w", err)
@ -583,7 +583,7 @@ func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.BlsMessages (cid.Cid) // t.t.BlsMessages (cid.Cid) (struct)
{ {
@ -595,7 +595,7 @@ func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error {
t.BlsMessages = c t.BlsMessages = c
} }
// t.t.SecpkMessages (cid.Cid) // t.t.SecpkMessages (cid.Cid) (struct)
{ {
@ -619,12 +619,12 @@ func (t *SignedVoucher) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.TimeLock (uint64) // t.t.TimeLock (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.TimeLock)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.TimeLock))); err != nil {
return err return err
} }
// t.t.SecretPreimage ([]uint8) // t.t.SecretPreimage ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.SecretPreimage)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.SecretPreimage)))); err != nil {
return err return err
} }
@ -632,32 +632,32 @@ func (t *SignedVoucher) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Extra (types.ModVerifyParams) // t.t.Extra (types.ModVerifyParams) (struct)
if err := t.Extra.MarshalCBOR(w); err != nil { if err := t.Extra.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Lane (uint64) // t.t.Lane (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Lane)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Lane))); err != nil {
return err return err
} }
// t.t.Nonce (uint64) // t.t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Nonce)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err return err
} }
// t.t.Amount (types.BigInt) // t.t.Amount (types.BigInt) (struct)
if err := t.Amount.MarshalCBOR(w); err != nil { if err := t.Amount.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.MinCloseHeight (uint64) // t.t.MinCloseHeight (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.MinCloseHeight)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.MinCloseHeight))); err != nil {
return err return err
} }
// t.t.Merges ([]types.Merge) // t.t.Merges ([]types.Merge) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Merges)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Merges)))); err != nil {
return err return err
} }
@ -667,7 +667,7 @@ func (t *SignedVoucher) MarshalCBOR(w io.Writer) error {
} }
} }
// t.t.Signature (types.Signature) // t.t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil { if err := t.Signature.MarshalCBOR(w); err != nil {
return err return err
} }
@ -689,7 +689,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.TimeLock (uint64) // t.t.TimeLock (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -698,8 +698,8 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.TimeLock = extra t.TimeLock = uint64(extra)
// t.t.SecretPreimage ([]uint8) // t.t.SecretPreimage ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -716,7 +716,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.SecretPreimage); err != nil { if _, err := io.ReadFull(br, t.SecretPreimage); err != nil {
return err return err
} }
// t.t.Extra (types.ModVerifyParams) // t.t.Extra (types.ModVerifyParams) (struct)
{ {
@ -737,7 +737,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Lane (uint64) // t.t.Lane (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -746,8 +746,8 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Lane = extra t.Lane = uint64(extra)
// t.t.Nonce (uint64) // t.t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -756,8 +756,8 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Nonce = extra t.Nonce = uint64(extra)
// t.t.Amount (types.BigInt) // t.t.Amount (types.BigInt) (struct)
{ {
@ -766,7 +766,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.MinCloseHeight (uint64) // t.t.MinCloseHeight (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -775,8 +775,8 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.MinCloseHeight = extra t.MinCloseHeight = uint64(extra)
// t.t.Merges ([]types.Merge) // t.t.Merges ([]types.Merge) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -802,7 +802,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
t.Merges[i] = v t.Merges[i] = v
} }
// t.t.Signature (types.Signature) // t.t.Signature (types.Signature) (struct)
{ {
@ -835,17 +835,17 @@ func (t *ModVerifyParams) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Actor (address.Address) // t.t.Actor (address.Address) (struct)
if err := t.Actor.MarshalCBOR(w); err != nil { if err := t.Actor.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Method (uint64) // t.t.Method (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Method)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Method))); err != nil {
return err return err
} }
// t.t.Data ([]uint8) // t.t.Data ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Data)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Data)))); err != nil {
return err return err
} }
@ -870,7 +870,7 @@ func (t *ModVerifyParams) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Actor (address.Address) // t.t.Actor (address.Address) (struct)
{ {
@ -879,7 +879,7 @@ func (t *ModVerifyParams) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Method (uint64) // t.t.Method (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -888,8 +888,8 @@ func (t *ModVerifyParams) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Method = extra t.Method = uint64(extra)
// t.t.Data ([]uint8) // t.t.Data ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -918,13 +918,13 @@ func (t *Merge) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Lane (uint64) // t.t.Lane (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Lane)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Lane))); err != nil {
return err return err
} }
// t.t.Nonce (uint64) // t.t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Nonce)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err return err
} }
return nil return nil
@ -945,7 +945,7 @@ func (t *Merge) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Lane (uint64) // t.t.Lane (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -954,8 +954,8 @@ func (t *Merge) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Lane = extra t.Lane = uint64(extra)
// t.t.Nonce (uint64) // t.t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -964,7 +964,7 @@ func (t *Merge) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Nonce = extra t.Nonce = uint64(extra)
return nil return nil
} }
@ -977,24 +977,24 @@ func (t *Actor) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Code (cid.Cid) // t.t.Code (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Code); err != nil { if err := cbg.WriteCid(w, t.Code); err != nil {
return xerrors.Errorf("failed to write cid field t.Code: %w", err) return xerrors.Errorf("failed to write cid field t.Code: %w", err)
} }
// t.t.Head (cid.Cid) // t.t.Head (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Head); err != nil { if err := cbg.WriteCid(w, t.Head); err != nil {
return xerrors.Errorf("failed to write cid field t.Head: %w", err) return xerrors.Errorf("failed to write cid field t.Head: %w", err)
} }
// t.t.Nonce (uint64) // t.t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Nonce)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err return err
} }
// t.t.Balance (types.BigInt) // t.t.Balance (types.BigInt) (struct)
if err := t.Balance.MarshalCBOR(w); err != nil { if err := t.Balance.MarshalCBOR(w); err != nil {
return err return err
} }
@ -1016,7 +1016,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Code (cid.Cid) // t.t.Code (cid.Cid) (struct)
{ {
@ -1028,7 +1028,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
t.Code = c t.Code = c
} }
// t.t.Head (cid.Cid) // t.t.Head (cid.Cid) (struct)
{ {
@ -1040,7 +1040,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
t.Head = c t.Head = c
} }
// t.t.Nonce (uint64) // t.t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -1049,8 +1049,8 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Nonce = extra t.Nonce = uint64(extra)
// t.t.Balance (types.BigInt) // t.t.Balance (types.BigInt) (struct)
{ {
@ -1071,12 +1071,12 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.ExitCode (uint8) // t.t.ExitCode (uint8) (uint8)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ExitCode))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ExitCode))); err != nil {
return err return err
} }
// t.t.Return ([]uint8) // t.t.Return ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Return)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Return)))); err != nil {
return err return err
} }
@ -1084,7 +1084,7 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.GasUsed (types.BigInt) // t.t.GasUsed (types.BigInt) (struct)
if err := t.GasUsed.MarshalCBOR(w); err != nil { if err := t.GasUsed.MarshalCBOR(w); err != nil {
return err return err
} }
@ -1106,7 +1106,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.ExitCode (uint8) // t.t.ExitCode (uint8) (uint8)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -1119,7 +1119,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("integer in input was too large for uint8 field") return fmt.Errorf("integer in input was too large for uint8 field")
} }
t.ExitCode = uint8(extra) t.ExitCode = uint8(extra)
// t.t.Return ([]uint8) // t.t.Return ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -1136,7 +1136,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.Return); err != nil { if _, err := io.ReadFull(br, t.Return); err != nil {
return err return err
} }
// t.t.GasUsed (types.BigInt) // t.t.GasUsed (types.BigInt) (struct)
{ {
@ -1157,12 +1157,12 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Header (types.BlockHeader) // t.t.Header (types.BlockHeader) (struct)
if err := t.Header.MarshalCBOR(w); err != nil { if err := t.Header.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.BlsMessages ([]cid.Cid) // t.t.BlsMessages ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BlsMessages)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BlsMessages)))); err != nil {
return err return err
} }
@ -1172,7 +1172,7 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error {
} }
} }
// t.t.SecpkMessages ([]cid.Cid) // t.t.SecpkMessages ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.SecpkMessages)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.SecpkMessages)))); err != nil {
return err return err
} }
@ -1199,7 +1199,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Header (types.BlockHeader) // t.t.Header (types.BlockHeader) (struct)
{ {
@ -1220,7 +1220,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.BlsMessages ([]cid.Cid) // t.t.BlsMessages ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -1245,7 +1245,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error {
t.BlsMessages[i] = c t.BlsMessages[i] = c
} }
// t.t.SecpkMessages ([]cid.Cid) // t.t.SecpkMessages ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -1282,12 +1282,12 @@ func (t *SignedStorageAsk) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Ask (types.StorageAsk) // t.t.Ask (types.StorageAsk) (struct)
if err := t.Ask.MarshalCBOR(w); err != nil { if err := t.Ask.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Signature (types.Signature) // t.t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil { if err := t.Signature.MarshalCBOR(w); err != nil {
return err return err
} }
@ -1309,7 +1309,7 @@ func (t *SignedStorageAsk) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Ask (types.StorageAsk) // t.t.Ask (types.StorageAsk) (struct)
{ {
@ -1330,7 +1330,7 @@ func (t *SignedStorageAsk) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Signature (types.Signature) // t.t.Signature (types.Signature) (struct)
{ {
@ -1363,33 +1363,33 @@ func (t *StorageAsk) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Price (types.BigInt) // t.t.Price (types.BigInt) (struct)
if err := t.Price.MarshalCBOR(w); err != nil { if err := t.Price.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.MinPieceSize (uint64) // t.t.MinPieceSize (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.MinPieceSize)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.MinPieceSize))); err != nil {
return err return err
} }
// t.t.Miner (address.Address) // t.t.Miner (address.Address) (struct)
if err := t.Miner.MarshalCBOR(w); err != nil { if err := t.Miner.MarshalCBOR(w); err != nil {
return err return err
} }
// t.t.Timestamp (uint64) // t.t.Timestamp (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Timestamp)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Timestamp))); err != nil {
return err return err
} }
// t.t.Expiry (uint64) // t.t.Expiry (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Expiry)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Expiry))); err != nil {
return err return err
} }
// t.t.SeqNo (uint64) // t.t.SeqNo (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.SeqNo)); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SeqNo))); err != nil {
return err return err
} }
return nil return nil
@ -1410,7 +1410,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.Price (types.BigInt) // t.t.Price (types.BigInt) (struct)
{ {
@ -1419,7 +1419,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.MinPieceSize (uint64) // t.t.MinPieceSize (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -1428,8 +1428,8 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.MinPieceSize = extra t.MinPieceSize = uint64(extra)
// t.t.Miner (address.Address) // t.t.Miner (address.Address) (struct)
{ {
@ -1438,7 +1438,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.t.Timestamp (uint64) // t.t.Timestamp (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -1447,8 +1447,8 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Timestamp = extra t.Timestamp = uint64(extra)
// t.t.Expiry (uint64) // t.t.Expiry (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -1457,8 +1457,8 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Expiry = extra t.Expiry = uint64(extra)
// t.t.SeqNo (uint64) // t.t.SeqNo (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -1467,6 +1467,6 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.SeqNo = extra t.SeqNo = uint64(extra)
return nil return nil
} }

View File

@ -5,6 +5,7 @@ import (
"encoding/base64" "encoding/base64"
"github.com/filecoin-project/lotus/chain/address" "github.com/filecoin-project/lotus/chain/address"
cborrpc "github.com/filecoin-project/lotus/lib/cborrpc"
cbor "github.com/ipfs/go-ipld-cbor" cbor "github.com/ipfs/go-ipld-cbor"
) )
@ -46,13 +47,13 @@ func (sv *SignedVoucher) EncodedString() (string, error) {
func (sv *SignedVoucher) Equals(other *SignedVoucher) bool { func (sv *SignedVoucher) Equals(other *SignedVoucher) bool {
// TODO: make this less bad // TODO: make this less bad
selfB, err := cbor.DumpObject(sv) selfB, err := cborrpc.Dump(sv)
if err != nil { if err != nil {
log.Errorf("SignedVoucher.Equals: dump self: %s", err) log.Errorf("SignedVoucher.Equals: dump self: %s", err)
return false return false
} }
otherB, err := cbor.DumpObject(other) otherB, err := cborrpc.Dump(other)
if err != nil { if err != nil {
log.Errorf("SignedVoucher.Equals: dump other: %s", err) log.Errorf("SignedVoucher.Equals: dump other: %s", err)
return false return false

View File

@ -229,11 +229,12 @@ var clientRetrieveCmd = &cli.Command{
order := offers[0].Order() order := offers[0].Order()
order.Client = payer order.Client = payer
err = api.ClientRetrieve(ctx, order, cctx.Args().Get(1)) if err := api.ClientRetrieve(ctx, order, cctx.Args().Get(1)); err != nil {
if err == nil { return err
fmt.Println("Success")
} }
return err
fmt.Println("Success")
return nil
}, },
} }

View File

@ -6,9 +6,12 @@ import (
gen "github.com/whyrusleeping/cbor-gen" gen "github.com/whyrusleeping/cbor-gen"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/deals" "github.com/filecoin-project/lotus/chain/deals"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/paych"
"github.com/filecoin-project/lotus/retrieval"
) )
func main() { func main() {
@ -32,6 +35,38 @@ func main() {
os.Exit(1) os.Exit(1)
} }
err = gen.WriteTupleEncodersToFile("./paych/cbor_gen.go", "paych",
paych.VoucherInfo{},
paych.ChannelInfo{},
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = gen.WriteTupleEncodersToFile("./api/cbor_gen.go", "api",
api.PaymentInfo{},
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = gen.WriteTupleEncodersToFile("./retrieval/cbor_gen.go", "retrieval",
retrieval.RetParams{},
retrieval.Query{},
retrieval.QueryResponse{},
retrieval.Unixfs0Offer{},
retrieval.DealProposal{},
retrieval.DealResponse{},
retrieval.Block{},
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
/* /*
err = gen.WriteTupleEncodersToFile("./chain/cbor_gen.go", "chain", err = gen.WriteTupleEncodersToFile("./chain/cbor_gen.go", "chain",
chain.BlockSyncRequest{}, chain.BlockSyncRequest{},

4
go.mod
View File

@ -73,7 +73,7 @@ require (
github.com/polydawn/refmt v0.0.0-20190809202753-05966cbd336a github.com/polydawn/refmt v0.0.0-20190809202753-05966cbd336a
github.com/stretchr/testify v1.4.0 github.com/stretchr/testify v1.4.0
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba
github.com/whyrusleeping/cbor-gen v0.0.0-20191001154818-b4b5288fcb86 github.com/whyrusleeping/cbor-gen v0.0.0-20191104210213-4418c8842f0f
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d
go.opencensus.io v0.22.0 go.opencensus.io v0.22.0
@ -84,7 +84,7 @@ require (
go.uber.org/zap v1.10.0 go.uber.org/zap v1.10.0
go4.org v0.0.0-20190313082347-94abd6928b1d // indirect go4.org v0.0.0-20190313082347-94abd6928b1d // indirect
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 // indirect golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 // indirect
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
google.golang.org/api v0.9.0 // indirect google.golang.org/api v0.9.0 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28 gopkg.in/cheggaaa/pb.v1 v1.0.28

6
go.sum
View File

@ -628,8 +628,8 @@ github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba h1:X4n8JG2e2
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba/go.mod h1:CHQnYnQUEPydYCwuy8lmTHfGmdw9TKrhWV0xLx8l0oM= github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba/go.mod h1:CHQnYnQUEPydYCwuy8lmTHfGmdw9TKrhWV0xLx8l0oM=
github.com/whyrusleeping/cbor-gen v0.0.0-20190910031516-c1cbffdb01bb/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY= github.com/whyrusleeping/cbor-gen v0.0.0-20190910031516-c1cbffdb01bb/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20190917003517-d78d67427694/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY= github.com/whyrusleeping/cbor-gen v0.0.0-20190917003517-d78d67427694/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20191001154818-b4b5288fcb86 h1:cE8mRdI9JQAheSlIAkjJIpdAOPjYOzxSADaro6LNHnY= github.com/whyrusleeping/cbor-gen v0.0.0-20191104210213-4418c8842f0f h1:+GFA37QICd1Axd2n9uzjtvPjxJJI5PU78vpvam+hI4U=
github.com/whyrusleeping/cbor-gen v0.0.0-20191001154818-b4b5288fcb86/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY= github.com/whyrusleeping/cbor-gen v0.0.0-20191104210213-4418c8842f0f/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E=
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k=
@ -755,6 +755,8 @@ golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20170915040203-e531a2a1c15f/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20170915040203-e531a2a1c15f/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

42
lib/sectorbuilder/mock.go Normal file
View File

@ -0,0 +1,42 @@
package sectorbuilder
import (
"io/ioutil"
"os"
"path/filepath"
"github.com/filecoin-project/lotus/chain/address"
)
func TempSectorbuilder(sectorSize uint64) (*SectorBuilder, func(), error) {
dir, err := ioutil.TempDir("", "sbtest")
if err != nil {
return nil, nil, err
}
addr, err := address.NewFromString("t3vfxagwiegrywptkbmyohqqbfzd7xzbryjydmxso4hfhgsnv6apddyihltsbiikjf3lm7x2myiaxhuc77capq")
if err != nil {
return nil, nil, err
}
metadata := filepath.Join(dir, "meta")
sealed := filepath.Join(dir, "sealed")
staging := filepath.Join(dir, "staging")
sb, err := New(&SectorBuilderConfig{
SectorSize: sectorSize,
SealedDir: sealed,
StagedDir: staging,
MetadataDir: metadata,
Miner: addr,
})
if err != nil {
return nil, nil, err
}
return sb, func() {
if err := os.RemoveAll(dir); err != nil {
log.Warn("failed to clean up temp sectorbuilder: ", err)
}
}, nil
}

View File

@ -32,6 +32,8 @@ const CommLen = sectorbuilder.CommitmentBytesLen
type SectorBuilder struct { type SectorBuilder struct {
handle unsafe.Pointer handle unsafe.Pointer
Miner address.Address
} }
type SectorBuilderConfig struct { type SectorBuilderConfig struct {
@ -52,6 +54,7 @@ func New(cfg *SectorBuilderConfig) (*SectorBuilder, error) {
return &SectorBuilder{ return &SectorBuilder{
handle: sbp, handle: sbp,
Miner: cfg.Miner,
}, nil }, nil
} }

View File

@ -3,15 +3,12 @@ package sectorbuilder_test
import ( import (
"context" "context"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"path/filepath"
"testing" "testing"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/lib/sectorbuilder" "github.com/filecoin-project/lotus/lib/sectorbuilder"
"github.com/filecoin-project/lotus/storage/sector" "github.com/filecoin-project/lotus/storage/sector"
) )
@ -26,30 +23,11 @@ func TestSealAndVerify(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
dir, err := ioutil.TempDir("", "sbtest") sb, cleanup, err := sectorbuilder.TempSectorbuilder(sectorSize)
if err != nil {
t.Fatal(err)
}
addr, err := address.NewFromString("t3vfxagwiegrywptkbmyohqqbfzd7xzbryjydmxso4hfhgsnv6apddyihltsbiikjf3lm7x2myiaxhuc77capq")
if err != nil {
t.Fatal(err)
}
metadata := filepath.Join(dir, "meta")
sealed := filepath.Join(dir, "sealed")
staging := filepath.Join(dir, "staging")
sb, err := sectorbuilder.New(&sectorbuilder.SectorBuilderConfig{
SectorSize: sectorSize,
SealedDir: sealed,
StagedDir: staging,
MetadataDir: metadata,
Miner: addr,
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer cleanup()
// TODO: Consider fixing // TODO: Consider fixing
store := sector.NewStore(sb, datastore.NewMapDatastore(), func(ctx context.Context) (*sectorbuilder.SealTicket, error) { store := sector.NewStore(sb, datastore.NewMapDatastore(), func(ctx context.Context) (*sectorbuilder.SealTicket, error) {
@ -75,7 +53,7 @@ func TestSealAndVerify(t *testing.T) {
ssinfo := <-store.Incoming() ssinfo := <-store.Incoming()
ok, err := sectorbuilder.VerifySeal(sectorSize, ssinfo.CommR[:], ssinfo.CommD[:], addr, ssinfo.Ticket.TicketBytes[:], ssinfo.SectorID, ssinfo.Proof) ok, err := sectorbuilder.VerifySeal(sectorSize, ssinfo.CommR[:], ssinfo.CommD[:], sb.Miner, ssinfo.Ticket.TicketBytes[:], ssinfo.SectorID, ssinfo.Proof)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -3,6 +3,7 @@ package hello
import ( import (
"context" "context"
"fmt" "fmt"
"go.uber.org/fx" "go.uber.org/fx"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"

View File

@ -3,11 +3,12 @@ package client
import ( import (
"context" "context"
"errors" "errors"
"golang.org/x/xerrors"
"io" "io"
"math" "math"
"os" "os"
"golang.org/x/xerrors"
"github.com/ipfs/go-blockservice" "github.com/ipfs/go-blockservice"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/ipfs/go-filestore" "github.com/ipfs/go-filestore"

View File

@ -162,12 +162,12 @@ func (a *PaychAPI) PaychVoucherCreate(ctx context.Context, pch address.Address,
func (a *PaychAPI) paychVoucherCreate(ctx context.Context, pch address.Address, voucher types.SignedVoucher) (*types.SignedVoucher, error) { func (a *PaychAPI) paychVoucherCreate(ctx context.Context, pch address.Address, voucher types.SignedVoucher) (*types.SignedVoucher, error) {
ci, err := a.PaychMgr.GetChannelInfo(pch) ci, err := a.PaychMgr.GetChannelInfo(pch)
if err != nil { if err != nil {
return nil, err return nil, xerrors.Errorf("get channel info: %w", err)
} }
nonce, err := a.PaychMgr.NextNonceForLane(ctx, pch, voucher.Lane) nonce, err := a.PaychMgr.NextNonceForLane(ctx, pch, voucher.Lane)
if err != nil { if err != nil {
return nil, err return nil, xerrors.Errorf("getting next nonce for lane: %w", err)
} }
sv := &voucher sv := &voucher

231
paych/cbor_gen.go Normal file
View File

@ -0,0 +1,231 @@
package paych
import (
"fmt"
"io"
"github.com/filecoin-project/lotus/chain/types"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)
/* This file was generated by github.com/whyrusleeping/cbor-gen */
var _ = xerrors.Errorf
func (t *VoucherInfo) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Voucher (types.SignedVoucher) (struct)
if err := t.Voucher.MarshalCBOR(w); err != nil {
return err
}
// t.t.Proof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil {
return err
}
if _, err := w.Write(t.Proof); err != nil {
return err
}
return nil
}
func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Voucher (types.SignedVoucher) (struct)
{
pb, err := br.PeekByte()
if err != nil {
return err
}
if pb == cbg.CborNull[0] {
var nbuf [1]byte
if _, err := br.Read(nbuf[:]); err != nil {
return err
}
} else {
t.Voucher = new(types.SignedVoucher)
if err := t.Voucher.UnmarshalCBOR(br); err != nil {
return err
}
}
}
// t.t.Proof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Proof: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Proof = make([]byte, extra)
if _, err := io.ReadFull(br, t.Proof); err != nil {
return err
}
return nil
}
func (t *ChannelInfo) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{134}); err != nil {
return err
}
// t.t.Channel (address.Address) (struct)
if err := t.Channel.MarshalCBOR(w); err != nil {
return err
}
// t.t.Control (address.Address) (struct)
if err := t.Control.MarshalCBOR(w); err != nil {
return err
}
// t.t.Target (address.Address) (struct)
if err := t.Target.MarshalCBOR(w); err != nil {
return err
}
// t.t.Direction (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Direction))); err != nil {
return err
}
// t.t.Vouchers ([]*paych.VoucherInfo) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Vouchers)))); err != nil {
return err
}
for _, v := range t.Vouchers {
if err := v.MarshalCBOR(w); err != nil {
return err
}
}
// t.t.NextLane (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.NextLane))); err != nil {
return err
}
return nil
}
func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 6 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Channel (address.Address) (struct)
{
if err := t.Channel.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.Control (address.Address) (struct)
{
if err := t.Control.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.Target (address.Address) (struct)
{
if err := t.Target.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.Direction (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Direction = uint64(extra)
// t.t.Vouchers ([]*paych.VoucherInfo) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Vouchers: array too large (%d)", extra)
}
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Vouchers = make([]*VoucherInfo, extra)
}
for i := 0; i < int(extra); i++ {
var v VoucherInfo
if err := v.UnmarshalCBOR(br); err != nil {
return err
}
t.Vouchers[i] = &v
}
// t.t.NextLane (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.NextLane = uint64(extra)
return nil
}

View File

@ -1,6 +1,7 @@
package paych package paych
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
@ -9,21 +10,16 @@ import (
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace" "github.com/ipfs/go-datastore/namespace"
dsq "github.com/ipfs/go-datastore/query" dsq "github.com/ipfs/go-datastore/query"
cbor "github.com/ipfs/go-ipld-cbor"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/lotus/chain/address" "github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
cborrpc "github.com/filecoin-project/lotus/lib/cborrpc"
"github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/modules/dtypes"
) )
var ErrChannelNotTracked = errors.New("channel not tracked") var ErrChannelNotTracked = errors.New("channel not tracked")
func init() {
cbor.RegisterCborType(VoucherInfo{})
cbor.RegisterCborType(ChannelInfo{})
}
type Store struct { type Store struct {
lk sync.Mutex // TODO: this can be split per paych lk sync.Mutex // TODO: this can be split per paych
@ -52,7 +48,7 @@ type ChannelInfo struct {
Control address.Address Control address.Address
Target address.Address Target address.Address
Direction int Direction uint64
Vouchers []*VoucherInfo Vouchers []*VoucherInfo
NextLane uint64 NextLane uint64
} }
@ -64,7 +60,7 @@ func dskeyForChannel(addr address.Address) datastore.Key {
func (ps *Store) putChannelInfo(ci *ChannelInfo) error { func (ps *Store) putChannelInfo(ci *ChannelInfo) error {
k := dskeyForChannel(ci.Channel) k := dskeyForChannel(ci.Channel)
b, err := cbor.DumpObject(ci) b, err := cborrpc.Dump(ci)
if err != nil { if err != nil {
return err return err
} }
@ -84,7 +80,7 @@ func (ps *Store) getChannelInfo(addr address.Address) (*ChannelInfo, error) {
} }
var ci ChannelInfo var ci ChannelInfo
if err := cbor.DecodeInto(b, &ci); err != nil { if err := ci.UnmarshalCBOR(bytes.NewReader(b)); err != nil {
return nil, err return nil, err
} }
@ -161,7 +157,7 @@ func (ps *Store) findChan(filter func(*ChannelInfo) bool) (address.Address, erro
return address.Undef, err return address.Undef, err
} }
if err := cbor.DecodeInto(res.Value, &ci); err != nil { if err := ci.UnmarshalCBOR(bytes.NewReader(res.Value)); err != nil {
return address.Undef, err return address.Undef, err
} }

464
retrieval/cbor_gen.go Normal file
View File

@ -0,0 +1,464 @@
package retrieval
import (
"fmt"
"io"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)
/* This file was generated by github.com/whyrusleeping/cbor-gen */
var _ = xerrors.Errorf
func (t *RetParams) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{129}); err != nil {
return err
}
// t.t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
if err := t.Unixfs0.MarshalCBOR(w); err != nil {
return err
}
return nil
}
func (t *RetParams) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 1 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
{
pb, err := br.PeekByte()
if err != nil {
return err
}
if pb == cbg.CborNull[0] {
var nbuf [1]byte
if _, err := br.Read(nbuf[:]); err != nil {
return err
}
} else {
t.Unixfs0 = new(Unixfs0Offer)
if err := t.Unixfs0.UnmarshalCBOR(br); err != nil {
return err
}
}
}
return nil
}
func (t *Query) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{129}); err != nil {
return err
}
// t.t.Piece (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Piece); err != nil {
return xerrors.Errorf("failed to write cid field t.Piece: %w", err)
}
return nil
}
func (t *Query) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 1 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Piece (cid.Cid) (struct)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Piece: %w", err)
}
t.Piece = c
}
return nil
}
func (t *QueryResponse) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{131}); err != nil {
return err
}
// t.t.Status (retrieval.QueryResponseStatus) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
return err
}
// t.t.Size (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil {
return err
}
// t.t.MinPrice (types.BigInt) (struct)
if err := t.MinPrice.MarshalCBOR(w); err != nil {
return err
}
return nil
}
func (t *QueryResponse) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 3 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Status (retrieval.QueryResponseStatus) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Status = QueryResponseStatus(extra)
// t.t.Size (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Size = uint64(extra)
// t.t.MinPrice (types.BigInt) (struct)
{
if err := t.MinPrice.UnmarshalCBOR(br); err != nil {
return err
}
}
return nil
}
func (t *Unixfs0Offer) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Offset (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Offset))); err != nil {
return err
}
// t.t.Size (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil {
return err
}
return nil
}
func (t *Unixfs0Offer) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Offset (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Offset = uint64(extra)
// t.t.Size (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Size = uint64(extra)
return nil
}
func (t *DealProposal) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{131}); err != nil {
return err
}
// t.t.Payment (api.PaymentInfo) (struct)
if err := t.Payment.MarshalCBOR(w); err != nil {
return err
}
// t.t.Ref (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Ref); err != nil {
return xerrors.Errorf("failed to write cid field t.Ref: %w", err)
}
// t.t.Params (retrieval.RetParams) (struct)
if err := t.Params.MarshalCBOR(w); err != nil {
return err
}
return nil
}
func (t *DealProposal) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 3 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Payment (api.PaymentInfo) (struct)
{
if err := t.Payment.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.Ref (cid.Cid) (struct)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Ref: %w", err)
}
t.Ref = c
}
// t.t.Params (retrieval.RetParams) (struct)
{
if err := t.Params.UnmarshalCBOR(br); err != nil {
return err
}
}
return nil
}
func (t *DealResponse) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Status (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
return err
}
// t.t.Message (string) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Message)))); err != nil {
return err
}
if _, err := w.Write([]byte(t.Message)); err != nil {
return err
}
return nil
}
func (t *DealResponse) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Status (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Status = uint64(extra)
// t.t.Message (string) (string)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
t.Message = string(sval)
}
return nil
}
func (t *Block) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Prefix ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Prefix)))); err != nil {
return err
}
if _, err := w.Write(t.Prefix); err != nil {
return err
}
// t.t.Data ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Data)))); err != nil {
return err
}
if _, err := w.Write(t.Data); err != nil {
return err
}
return nil
}
func (t *Block) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Prefix ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Prefix: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Prefix = make([]byte, extra)
if _, err := io.ReadFull(br, t.Prefix); err != nil {
return err
}
// t.t.Data ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Data: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Data = make([]byte, extra)
if _, err := io.ReadFull(br, t.Data); err != nil {
return err
}
return nil
}

View File

@ -3,15 +3,14 @@ package retrieval
import ( import (
"context" "context"
"io" "io"
"io/ioutil"
blocks "github.com/ipfs/go-block-format" blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
@ -45,7 +44,7 @@ func (c *Client) Query(ctx context.Context, p discovery.RetrievalPeer, data cid.
} }
defer s.Close() defer s.Close()
err = cborrpc.WriteCborRPC(s, Query{ err = cborrpc.WriteCborRPC(s, &Query{
Piece: data, Piece: data,
}) })
if err != nil { if err != nil {
@ -53,15 +52,8 @@ func (c *Client) Query(ctx context.Context, p discovery.RetrievalPeer, data cid.
return api.QueryOffer{Err: err.Error(), Miner: p.Address, MinerPeerID: p.ID} return api.QueryOffer{Err: err.Error(), Miner: p.Address, MinerPeerID: p.ID}
} }
// TODO: read deadline
rawResp, err := ioutil.ReadAll(s)
if err != nil {
log.Warn(err)
return api.QueryOffer{Err: err.Error(), Miner: p.Address, MinerPeerID: p.ID}
}
var resp QueryResponse var resp QueryResponse
if err := cbor.DecodeInto(rawResp, &resp); err != nil { if err := resp.UnmarshalCBOR(s); err != nil {
log.Warn(err) log.Warn(err)
return api.QueryOffer{Err: err.Error(), Miner: p.Address, MinerPeerID: p.ID} return api.QueryOffer{Err: err.Error(), Miner: p.Address, MinerPeerID: p.ID}
} }
@ -78,6 +70,7 @@ func (c *Client) Query(ctx context.Context, p discovery.RetrievalPeer, data cid.
type clientStream struct { type clientStream struct {
payapi payapi.PaychAPI payapi payapi.PaychAPI
stream network.Stream stream network.Stream
peeker cbg.BytePeeker
root cid.Cid root cid.Cid
size types.BigInt size types.BigInt
@ -127,6 +120,7 @@ func (c *Client) RetrieveUnixfs(ctx context.Context, root cid.Cid, size uint64,
cst := clientStream{ cst := clientStream{
payapi: c.payapi, payapi: c.payapi,
stream: s, stream: s,
peeker: cbg.GetPeeker(s),
root: root, root: root,
size: types.NewInt(size), size: types.NewInt(size),
@ -167,7 +161,7 @@ func (cst *clientStream) doOneExchange(ctx context.Context, toFetch uint64, out
return xerrors.Errorf("setting up retrieval payment: %w", err) return xerrors.Errorf("setting up retrieval payment: %w", err)
} }
deal := DealProposal{ deal := &DealProposal{
Payment: payment, Payment: payment,
Ref: cst.root, Ref: cst.root,
Params: RetParams{ Params: RetParams{
@ -183,7 +177,7 @@ func (cst *clientStream) doOneExchange(ctx context.Context, toFetch uint64, out
} }
var resp DealResponse var resp DealResponse
if err := cborrpc.ReadCborRPC(cst.stream, &resp); err != nil { if err := cborrpc.ReadCborRPC(cst.peeker, &resp); err != nil {
log.Error(err) log.Error(err)
return err return err
} }
@ -215,7 +209,7 @@ func (cst *clientStream) fetchBlocks(toFetch uint64, out io.Writer) error {
log.Infof("block %d of %d", i+1, blocksToFetch) log.Infof("block %d of %d", i+1, blocksToFetch)
var block Block var block Block
if err := cborrpc.ReadCborRPC(cst.stream, &block); err != nil { if err := cborrpc.ReadCborRPC(cst.peeker, &block); err != nil {
return xerrors.Errorf("reading fetchBlock response: %w", err) return xerrors.Errorf("reading fetchBlock response: %w", err)
} }

View File

@ -13,14 +13,19 @@ import (
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/cborrpc" "github.com/filecoin-project/lotus/lib/cborrpc"
"github.com/filecoin-project/lotus/storage/sectorblocks" "github.com/filecoin-project/lotus/storage/sectorblocks"
) )
type RetrMinerApi interface {
PaychVoucherAdd(context.Context, address.Address, *types.SignedVoucher, []byte, types.BigInt) (types.BigInt, error)
}
type Miner struct { type Miner struct {
sectorBlocks *sectorblocks.SectorBlocks sectorBlocks *sectorblocks.SectorBlocks
full api.FullNode full RetrMinerApi
pricePerByte types.BigInt pricePerByte types.BigInt
// TODO: Unseal price // TODO: Unseal price
@ -37,7 +42,7 @@ func NewMiner(sblks *sectorblocks.SectorBlocks, full api.FullNode) *Miner {
func writeErr(stream network.Stream, err error) { func writeErr(stream network.Stream, err error) {
log.Errorf("Retrieval deal error: %s", err) log.Errorf("Retrieval deal error: %s", err)
_ = cborrpc.WriteCborRPC(stream, DealResponse{ _ = cborrpc.WriteCborRPC(stream, &DealResponse{
Status: Error, Status: Error,
Message: err.Error(), Message: err.Error(),
}) })
@ -58,7 +63,7 @@ func (m *Miner) HandleQueryStream(stream network.Stream) {
return return
} }
answer := QueryResponse{ answer := &QueryResponse{
Status: Unavailable, Status: Unavailable,
} }
if err == nil { if err == nil {
@ -134,7 +139,7 @@ func (hnd *handlerDeal) handleNext() (bool, error) {
// If the file isn't open (new deal stream), isn't the right file, or isn't // If the file isn't open (new deal stream), isn't the right file, or isn't
// at the right offset, (re)open it // at the right offset, (re)open it
if hnd.open != deal.Ref || hnd.at != unixfs0.Offset { if hnd.open != deal.Ref || hnd.at != unixfs0.Offset {
log.Infof("opening file for sending (open '%s') (@%d, want %d)", hnd.open, hnd.at, unixfs0.Offset) log.Infof("opening file for sending (open '%s') (@%d, want %d)", deal.Ref, hnd.at, unixfs0.Offset)
if err := hnd.openFile(deal); err != nil { if err := hnd.openFile(deal); err != nil {
return false, err return false, err
} }
@ -195,7 +200,7 @@ func (hnd *handlerDeal) openFile(deal DealProposal) error {
func (hnd *handlerDeal) accept(deal DealProposal) error { func (hnd *handlerDeal) accept(deal DealProposal) error {
unixfs0 := deal.Params.Unixfs0 unixfs0 := deal.Params.Unixfs0
resp := DealResponse{ resp := &DealResponse{
Status: Accepted, Status: Accepted,
} }
if err := cborrpc.WriteCborRPC(hnd.stream, resp); err != nil { if err := cborrpc.WriteCborRPC(hnd.stream, resp); err != nil {
@ -221,7 +226,7 @@ func (hnd *handlerDeal) accept(deal DealProposal) error {
return return
}*/ }*/
block := Block{ block := &Block{
Prefix: nd.Cid().Prefix().Bytes(), Prefix: nd.Cid().Prefix().Bytes(),
Data: nd.RawData(), Data: nd.RawData(),
} }

View File

@ -3,7 +3,6 @@ package retrieval
import ( import (
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
) )
@ -11,7 +10,7 @@ import (
const ProtocolID = "/fil/retrieval/-1.0.0" // TODO: spec const ProtocolID = "/fil/retrieval/-1.0.0" // TODO: spec
const QueryProtocolID = "/fil/retrieval/qry/-1.0.0" // TODO: spec const QueryProtocolID = "/fil/retrieval/qry/-1.0.0" // TODO: spec
type QueryResponseStatus int type QueryResponseStatus uint64
const ( const (
Available QueryResponseStatus = iota Available QueryResponseStatus = iota
@ -25,18 +24,6 @@ const (
Unsealing Unsealing
) )
func init() {
cbor.RegisterCborType(RetParams{})
cbor.RegisterCborType(Query{})
cbor.RegisterCborType(QueryResponse{})
cbor.RegisterCborType(Unixfs0Offer{})
cbor.RegisterCborType(DealProposal{})
cbor.RegisterCborType(DealResponse{})
cbor.RegisterCborType(Block{})
}
type Query struct { type Query struct {
Piece cid.Cid Piece cid.Cid
// TODO: payment // TODO: payment
@ -69,7 +56,7 @@ type DealProposal struct {
} }
type DealResponse struct { type DealResponse struct {
Status int Status uint64
Message string Message string
} }