This commit is contained in:
Łukasz Magiera 2020-04-17 19:53:09 +02:00
parent 8828668541
commit 8e13920e7b
5 changed files with 86 additions and 5 deletions

View File

@ -168,9 +168,11 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Vouchers = make([]*paych.SignedVoucher, extra)
}
for i := 0; i < int(extra); i++ {
var v paych.SignedVoucher
@ -412,9 +414,11 @@ func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Refs = make([]SealedRef, extra)
}
for i := 0; i < int(extra); i++ {
var v SealedRef

View File

@ -7,7 +7,7 @@ import (
"io"
"github.com/filecoin-project/lotus/chain/types"
"github.com/ipfs/go-cid"
cid "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)
@ -81,9 +81,11 @@ func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Start = make([]cid.Cid, extra)
}
for i := 0; i < int(extra); i++ {
c, err := cbg.ReadCid(br)
@ -196,9 +198,11 @@ func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Chain = make([]*BSTipSet, extra)
}
for i := 0; i < int(extra); i++ {
var v BSTipSet
@ -364,9 +368,11 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Blocks = make([]*types.BlockHeader, extra)
}
for i := 0; i < int(extra); i++ {
var v types.BlockHeader
@ -391,9 +397,11 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.BlsMessages = make([]*types.Message, extra)
}
for i := 0; i < int(extra); i++ {
var v types.Message
@ -418,9 +426,11 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.BlsMsgIncludes = make([][]uint64, extra)
}
for i := 0; i < int(extra); i++ {
{
var maj byte
@ -439,9 +449,11 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.BlsMsgIncludes[i] = make([]uint64, extra)
}
for j := 0; j < int(extra); j++ {
maj, val, err := cbg.CborReadHeader(br)
@ -473,9 +485,11 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.SecpkMessages = make([]*types.SignedMessage, extra)
}
for i := 0; i < int(extra); i++ {
var v types.SignedMessage
@ -500,9 +514,11 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.SecpkMsgIncludes = make([][]uint64, extra)
}
for i := 0; i < int(extra); i++ {
{
var maj byte
@ -521,9 +537,11 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.SecpkMsgIncludes[i] = make([]uint64, extra)
}
for j := 0; j < int(extra); j++ {
maj, val, err := cbg.CborReadHeader(br)

View File

@ -9,7 +9,7 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
"github.com/ipfs/go-cid"
cid "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)
@ -21,7 +21,7 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{142}); err != nil {
if _, err := w.Write([]byte{143}); err != nil {
return err
}
@ -54,6 +54,20 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
}
}
// t.WinPoStProof ([]abi.PoStProof) (slice)
if len(t.WinPoStProof) > cbg.MaxLength {
return xerrors.Errorf("Slice value in field t.WinPoStProof was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.WinPoStProof)))); err != nil {
return err
}
for _, v := range t.WinPoStProof {
if err := v.MarshalCBOR(w); err != nil {
return err
}
}
// t.Parents ([]cid.Cid) (slice)
if len(t.Parents) > cbg.MaxLength {
return xerrors.Errorf("Slice value in field t.Parents was too long")
@ -138,7 +152,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 14 {
if extra != 15 {
return fmt.Errorf("cbor input had wrong number of fields")
}
@ -207,9 +221,11 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.BeaconEntries = make([]BeaconEntry, extra)
}
for i := 0; i < int(extra); i++ {
var v BeaconEntry
@ -220,6 +236,35 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.BeaconEntries[i] = v
}
// t.WinPoStProof ([]abi.PoStProof) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > cbg.MaxLength {
return fmt.Errorf("t.WinPoStProof: array too large (%d)", extra)
}
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.WinPoStProof = make([]abi.PoStProof, extra)
}
for i := 0; i < int(extra); i++ {
var v abi.PoStProof
if err := v.UnmarshalCBOR(br); err != nil {
return err
}
t.WinPoStProof[i] = v
}
// t.Parents ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br)
@ -234,9 +279,11 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Parents = make([]cid.Cid, extra)
}
for i := 0; i < int(extra); i++ {
c, err := cbg.ReadCid(br)
@ -1141,9 +1188,11 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.BlsMessages = make([]cid.Cid, extra)
}
for i := 0; i < int(extra); i++ {
c, err := cbg.ReadCid(br)
@ -1167,9 +1216,11 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.SecpkMessages = make([]cid.Cid, extra)
}
for i := 0; i < int(extra); i++ {
c, err := cbg.ReadCid(br)
@ -1261,9 +1312,11 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Cids = make([]cid.Cid, extra)
}
for i := 0; i < int(extra); i++ {
c, err := cbg.ReadCid(br)
@ -1287,9 +1340,11 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Blocks = make([]*BlockHeader, extra)
}
for i := 0; i < int(extra); i++ {
var v BlockHeader

View File

@ -7,7 +7,7 @@ import (
"io"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
cid "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)
@ -91,9 +91,11 @@ func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.HeaviestTipSet = make([]cid.Cid, extra)
}
for i := 0; i < int(extra); i++ {
c, err := cbg.ReadCid(br)

View File

@ -348,9 +348,11 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error {
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