Merge pull request #1131 from filecoin-project/feat/soft-map-cbg

cbor-gen: Soft struct-map unmarshaling
This commit is contained in:
Łukasz Magiera 2020-01-21 19:44:39 +01:00 committed by GitHub
commit cf153f89df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 599 additions and 799 deletions

View File

@ -98,13 +98,14 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type map") return fmt.Errorf("cbor input should be of type map")
} }
if extra != 3 { if extra > cbg.MaxLength {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("PaymentInfo: map struct too large (%d)", extra)
} }
var name string var name string
n := extra
// t.Channel (address.Address) (struct) for i := uint64(0); i < n; i++ {
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -115,9 +116,9 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
name = string(sval) name = string(sval)
} }
if name != "Channel" { switch name {
return fmt.Errorf("expected struct map entry %s to be Channel", name) // t.Channel (address.Address) (struct)
} case "Channel":
{ {
@ -127,19 +128,7 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
} }
// t.ChannelMessage (cid.Cid) (struct) // t.ChannelMessage (cid.Cid) (struct)
case "ChannelMessage":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "ChannelMessage" {
return fmt.Errorf("expected struct map entry %s to be ChannelMessage", name)
}
{ {
@ -164,19 +153,7 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
} }
// t.Vouchers ([]*types.SignedVoucher) (slice) // t.Vouchers ([]*types.SignedVoucher) (slice)
case "Vouchers":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Vouchers" {
return fmt.Errorf("expected struct map entry %s to be Vouchers", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -203,9 +180,13 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
t.Vouchers[i] = &v t.Vouchers[i] = &v
} }
return nil default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
} }
return nil
}
func (t *SealedRef) MarshalCBOR(w io.Writer) error { func (t *SealedRef) MarshalCBOR(w io.Writer) error {
if t == nil { if t == nil {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
@ -276,13 +257,14 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type map") return fmt.Errorf("cbor input should be of type map")
} }
if extra != 3 { if extra > cbg.MaxLength {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("SealedRef: map struct too large (%d)", extra)
} }
var name string var name string
n := extra
// t.SectorID (uint64) (uint64) for i := uint64(0); i < n; i++ {
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -293,9 +275,9 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error {
name = string(sval) name = string(sval)
} }
if name != "SectorID" { switch name {
return fmt.Errorf("expected struct map entry %s to be SectorID", name) // t.SectorID (uint64) (uint64)
} case "SectorID":
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -306,19 +288,7 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error {
} }
t.SectorID = uint64(extra) t.SectorID = uint64(extra)
// t.Offset (uint64) (uint64) // t.Offset (uint64) (uint64)
case "Offset":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Offset" {
return fmt.Errorf("expected struct map entry %s to be Offset", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -329,19 +299,7 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error {
} }
t.Offset = uint64(extra) t.Offset = uint64(extra)
// t.Size (uint64) (uint64) // t.Size (uint64) (uint64)
case "Size":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Size" {
return fmt.Errorf("expected struct map entry %s to be Size", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -351,9 +309,14 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Size = uint64(extra) t.Size = uint64(extra)
return nil
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
} }
return nil
}
func (t *SealedRefs) MarshalCBOR(w io.Writer) error { func (t *SealedRefs) MarshalCBOR(w io.Writer) error {
if t == nil { if t == nil {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
@ -401,13 +364,14 @@ func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type map") return fmt.Errorf("cbor input should be of type map")
} }
if extra != 1 { if extra > cbg.MaxLength {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("SealedRefs: map struct too large (%d)", extra)
} }
var name string var name string
n := extra
// t.Refs ([]api.SealedRef) (slice) for i := uint64(0); i < n; i++ {
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -418,9 +382,9 @@ func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error {
name = string(sval) name = string(sval)
} }
if name != "Refs" { switch name {
return fmt.Errorf("expected struct map entry %s to be Refs", name) // t.Refs ([]api.SealedRef) (slice)
} case "Refs":
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -447,5 +411,10 @@ func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error {
t.Refs[i] = v t.Refs[i] = v
} }
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
}
return nil return nil
} }

View File

@ -65,7 +65,6 @@ func TestDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration) {
defer close(done) defer close(done)
for mine { for mine {
time.Sleep(blocktime) time.Sleep(blocktime)
fmt.Println("mining a block now")
if err := sn[0].MineOne(ctx); err != nil { if err := sn[0].MineOne(ctx); err != nil {
t.Error(err) t.Error(err)
} }

View File

@ -122,7 +122,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
err = gen.WriteMapEncodersToFile("./storage/sectors/cbor_gen.go", "sectors", err = gen.WriteMapEncodersToFile("./storage/sealing/cbor_gen.go", "sealing",
sealing.SealTicket{}, sealing.SealTicket{},
sealing.SealSeed{}, sealing.SealSeed{},
sealing.Piece{}, sealing.Piece{},

2
go.mod
View File

@ -86,7 +86,7 @@ require (
github.com/prometheus/common v0.2.0 github.com/prometheus/common v0.2.0
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-20200106232624-282db0d37dbe github.com/whyrusleeping/cbor-gen v0.0.0-20200121162646-b63bacf5eaf8
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.2 go.opencensus.io v0.22.2

4
go.sum
View File

@ -711,8 +711,8 @@ github.com/whyrusleeping/cbor-gen v0.0.0-20190917003517-d78d67427694/go.mod h1:x
github.com/whyrusleeping/cbor-gen v0.0.0-20191116002219-891f55cd449d/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY= github.com/whyrusleeping/cbor-gen v0.0.0-20191116002219-891f55cd449d/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20191212224538-d370462a7e8a/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY= github.com/whyrusleeping/cbor-gen v0.0.0-20191212224538-d370462a7e8a/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20191216205031-b047b6acb3c0/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY= github.com/whyrusleeping/cbor-gen v0.0.0-20191216205031-b047b6acb3c0/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20200106232624-282db0d37dbe h1:n7En1uyDtknjLRDXebWlPGJoHvwL8AkNcSQzuOoYYYQ= github.com/whyrusleeping/cbor-gen v0.0.0-20200121162646-b63bacf5eaf8 h1:PHZv8Nu+95MBVNu3qSgg3ncxIv8hy4DzGAOBR9xYQRc=
github.com/whyrusleeping/cbor-gen v0.0.0-20200106232624-282db0d37dbe/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY= github.com/whyrusleeping/cbor-gen v0.0.0-20200121162646-b63bacf5eaf8/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=

View File

@ -66,13 +66,14 @@ func (t *TestState) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type map") return fmt.Errorf("cbor input should be of type map")
} }
if extra != 2 { if extra > cbg.MaxLength {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("TestState: map struct too large (%d)", extra)
} }
var name string var name string
n := extra
// t.A (uint64) (uint64) for i := uint64(0); i < n; i++ {
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -83,9 +84,9 @@ func (t *TestState) UnmarshalCBOR(r io.Reader) error {
name = string(sval) name = string(sval)
} }
if name != "A" { switch name {
return fmt.Errorf("expected struct map entry %s to be A", name) // t.A (uint64) (uint64)
} case "A":
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -96,19 +97,7 @@ func (t *TestState) UnmarshalCBOR(r io.Reader) error {
} }
t.A = uint64(extra) t.A = uint64(extra)
// t.B (uint64) (uint64) // t.B (uint64) (uint64)
case "B":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "B" {
return fmt.Errorf("expected struct map entry %s to be B", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -118,9 +107,14 @@ func (t *TestState) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.B = uint64(extra) t.B = uint64(extra)
return nil
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
} }
return nil
}
func (t *TestEvent) MarshalCBOR(w io.Writer) error { func (t *TestEvent) MarshalCBOR(w io.Writer) error {
if t == nil { if t == nil {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
@ -182,13 +176,14 @@ func (t *TestEvent) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type map") return fmt.Errorf("cbor input should be of type map")
} }
if extra != 2 { if extra > cbg.MaxLength {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("TestEvent: map struct too large (%d)", extra)
} }
var name string var name string
n := extra
// t.A (string) (string) for i := uint64(0); i < n; i++ {
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -199,9 +194,9 @@ func (t *TestEvent) UnmarshalCBOR(r io.Reader) error {
name = string(sval) name = string(sval)
} }
if name != "A" { switch name {
return fmt.Errorf("expected struct map entry %s to be A", name) // t.A (string) (string)
} case "A":
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -212,19 +207,7 @@ func (t *TestEvent) UnmarshalCBOR(r io.Reader) error {
t.A = string(sval) t.A = string(sval)
} }
// t.Val (uint64) (uint64) // t.Val (uint64) (uint64)
case "Val":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Val" {
return fmt.Errorf("expected struct map entry %s to be Val", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -234,5 +217,11 @@ func (t *TestEvent) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Val = uint64(extra) t.Val = uint64(extra)
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
}
return nil return nil
} }

View File

@ -393,6 +393,12 @@ func TestAPIRPC(t *testing.T) {
} }
func TestAPIDealFlow(t *testing.T) { func TestAPIDealFlow(t *testing.T) {
logging.SetLogLevel("miner", "ERROR")
logging.SetLogLevel("chainstore", "ERROR")
logging.SetLogLevel("chain", "ERROR")
logging.SetLogLevel("sub", "ERROR")
logging.SetLogLevel("storageminer", "ERROR")
test.TestDealFlow(t, mockSbBuilder, 10*time.Millisecond) test.TestDealFlow(t, mockSbBuilder, 10*time.Millisecond)
} }

View File

@ -73,13 +73,14 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type map") return fmt.Errorf("cbor input should be of type map")
} }
if extra != 2 { if extra > cbg.MaxLength {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("SealTicket: map struct too large (%d)", extra)
} }
var name string var name string
n := extra
// t.BlockHeight (uint64) (uint64) for i := uint64(0); i < n; i++ {
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -90,9 +91,9 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error {
name = string(sval) name = string(sval)
} }
if name != "BlockHeight" { switch name {
return fmt.Errorf("expected struct map entry %s to be BlockHeight", name) // t.BlockHeight (uint64) (uint64)
} case "BlockHeight":
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -103,19 +104,7 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error {
} }
t.BlockHeight = uint64(extra) t.BlockHeight = uint64(extra)
// t.TicketBytes ([]uint8) (slice) // t.TicketBytes ([]uint8) (slice)
case "TicketBytes":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "TicketBytes" {
return fmt.Errorf("expected struct map entry %s to be TicketBytes", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -132,9 +121,14 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.TicketBytes); err != nil { if _, err := io.ReadFull(br, t.TicketBytes); err != nil {
return err return err
} }
return nil
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
} }
return nil
}
func (t *SealSeed) MarshalCBOR(w io.Writer) error { func (t *SealSeed) MarshalCBOR(w io.Writer) error {
if t == nil { if t == nil {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
@ -196,13 +190,14 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type map") return fmt.Errorf("cbor input should be of type map")
} }
if extra != 2 { if extra > cbg.MaxLength {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("SealSeed: map struct too large (%d)", extra)
} }
var name string var name string
n := extra
// t.BlockHeight (uint64) (uint64) for i := uint64(0); i < n; i++ {
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -213,9 +208,9 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error {
name = string(sval) name = string(sval)
} }
if name != "BlockHeight" { switch name {
return fmt.Errorf("expected struct map entry %s to be BlockHeight", name) // t.BlockHeight (uint64) (uint64)
} case "BlockHeight":
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -226,19 +221,7 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error {
} }
t.BlockHeight = uint64(extra) t.BlockHeight = uint64(extra)
// t.TicketBytes ([]uint8) (slice) // t.TicketBytes ([]uint8) (slice)
case "TicketBytes":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "TicketBytes" {
return fmt.Errorf("expected struct map entry %s to be TicketBytes", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -255,9 +238,14 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.TicketBytes); err != nil { if _, err := io.ReadFull(br, t.TicketBytes); err != nil {
return err return err
} }
return nil
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
} }
return nil
}
func (t *Piece) MarshalCBOR(w io.Writer) error { func (t *Piece) MarshalCBOR(w io.Writer) error {
if t == nil { if t == nil {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
@ -335,13 +323,14 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type map") return fmt.Errorf("cbor input should be of type map")
} }
if extra != 3 { if extra > cbg.MaxLength {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("Piece: map struct too large (%d)", extra)
} }
var name string var name string
n := extra
// t.DealID (uint64) (uint64) for i := uint64(0); i < n; i++ {
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -352,9 +341,9 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error {
name = string(sval) name = string(sval)
} }
if name != "DealID" { switch name {
return fmt.Errorf("expected struct map entry %s to be DealID", name) // t.DealID (uint64) (uint64)
} case "DealID":
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -365,19 +354,7 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error {
} }
t.DealID = uint64(extra) t.DealID = uint64(extra)
// t.Size (uint64) (uint64) // t.Size (uint64) (uint64)
case "Size":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Size" {
return fmt.Errorf("expected struct map entry %s to be Size", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -388,19 +365,7 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error {
} }
t.Size = uint64(extra) t.Size = uint64(extra)
// t.CommP ([]uint8) (slice) // t.CommP ([]uint8) (slice)
case "CommP":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "CommP" {
return fmt.Errorf("expected struct map entry %s to be CommP", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -417,9 +382,14 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.CommP); err != nil { if _, err := io.ReadFull(br, t.CommP); err != nil {
return err return err
} }
return nil
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
} }
return nil
}
func (t *SectorInfo) MarshalCBOR(w io.Writer) error { func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
if t == nil { if t == nil {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
@ -477,7 +447,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.Pieces ([]storage.Piece) (slice) // t.Pieces ([]sealing.Piece) (slice)
if len("Pieces") > cbg.MaxLength { if len("Pieces") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Pieces\" was too long") return xerrors.Errorf("Value in field \"Pieces\" was too long")
} }
@ -571,7 +541,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.Ticket (storage.SealTicket) (struct) // t.Ticket (sealing.SealTicket) (struct)
if len("Ticket") > cbg.MaxLength { if len("Ticket") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Ticket\" was too long") return xerrors.Errorf("Value in field \"Ticket\" was too long")
} }
@ -609,7 +579,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
} }
} }
// t.Seed (storage.SealSeed) (struct) // t.Seed (sealing.SealSeed) (struct)
if len("Seed") > cbg.MaxLength { if len("Seed") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Seed\" was too long") return xerrors.Errorf("Value in field \"Seed\" was too long")
} }
@ -705,13 +675,14 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type map") return fmt.Errorf("cbor input should be of type map")
} }
if extra != 13 { if extra > cbg.MaxLength {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("SectorInfo: map struct too large (%d)", extra)
} }
var name string var name string
n := extra
// t.State (uint64) (uint64) for i := uint64(0); i < n; i++ {
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -722,9 +693,9 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
name = string(sval) name = string(sval)
} }
if name != "State" { switch name {
return fmt.Errorf("expected struct map entry %s to be State", name) // t.State (uint64) (uint64)
} case "State":
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -735,19 +706,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
} }
t.State = uint64(extra) t.State = uint64(extra)
// t.SectorID (uint64) (uint64) // t.SectorID (uint64) (uint64)
case "SectorID":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "SectorID" {
return fmt.Errorf("expected struct map entry %s to be SectorID", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -758,19 +717,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
} }
t.SectorID = uint64(extra) t.SectorID = uint64(extra)
// t.Nonce (uint64) (uint64) // t.Nonce (uint64) (uint64)
case "Nonce":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Nonce" {
return fmt.Errorf("expected struct map entry %s to be Nonce", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -780,20 +727,8 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.Nonce = uint64(extra) t.Nonce = uint64(extra)
// t.Pieces ([]storage.Piece) (slice) // t.Pieces ([]sealing.Piece) (slice)
case "Pieces":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Pieces" {
return fmt.Errorf("expected struct map entry %s to be Pieces", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -821,19 +756,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
} }
// t.CommD ([]uint8) (slice) // t.CommD ([]uint8) (slice)
case "CommD":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "CommD" {
return fmt.Errorf("expected struct map entry %s to be CommD", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -851,19 +774,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
return err return err
} }
// t.CommR ([]uint8) (slice) // t.CommR ([]uint8) (slice)
case "CommR":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "CommR" {
return fmt.Errorf("expected struct map entry %s to be CommR", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -881,19 +792,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
return err return err
} }
// t.Proof ([]uint8) (slice) // t.Proof ([]uint8) (slice)
case "Proof":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Proof" {
return fmt.Errorf("expected struct map entry %s to be Proof", name)
}
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -910,20 +809,8 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.Proof); err != nil { if _, err := io.ReadFull(br, t.Proof); err != nil {
return err return err
} }
// t.Ticket (storage.SealTicket) (struct) // t.Ticket (sealing.SealTicket) (struct)
case "Ticket":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Ticket" {
return fmt.Errorf("expected struct map entry %s to be Ticket", name)
}
{ {
@ -933,19 +820,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
} }
// t.PreCommitMessage (cid.Cid) (struct) // t.PreCommitMessage (cid.Cid) (struct)
case "PreCommitMessage":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "PreCommitMessage" {
return fmt.Errorf("expected struct map entry %s to be PreCommitMessage", name)
}
{ {
@ -969,20 +844,8 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.Seed (storage.SealSeed) (struct) // t.Seed (sealing.SealSeed) (struct)
case "Seed":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Seed" {
return fmt.Errorf("expected struct map entry %s to be Seed", name)
}
{ {
@ -992,19 +855,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
} }
// t.CommitMessage (cid.Cid) (struct) // t.CommitMessage (cid.Cid) (struct)
case "CommitMessage":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "CommitMessage" {
return fmt.Errorf("expected struct map entry %s to be CommitMessage", name)
}
{ {
@ -1029,19 +880,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
} }
// t.FaultReportMsg (cid.Cid) (struct) // t.FaultReportMsg (cid.Cid) (struct)
case "FaultReportMsg":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "FaultReportMsg" {
return fmt.Errorf("expected struct map entry %s to be FaultReportMsg", name)
}
{ {
@ -1066,19 +905,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
} }
// t.LastErr (string) (string) // t.LastErr (string) (string)
case "LastErr":
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "LastErr" {
return fmt.Errorf("expected struct map entry %s to be LastErr", name)
}
{ {
sval, err := cbg.ReadString(br) sval, err := cbg.ReadString(br)
@ -1088,5 +915,11 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
t.LastErr = string(sval) t.LastErr = string(sval)
} }
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
}
return nil return nil
} }

View File

@ -236,6 +236,10 @@ func planOne(ts ...func() (mut mutator, next api.SectorState)) func(events []sta
continue continue
} }
if err, iserr := events[0].User.(error); iserr {
log.Warnf("sector %d got error event %T: %+v", state.SectorID, events[0].User, err)
}
events[0].User.(mutator).apply(state) events[0].User.(mutator).apply(state)
state.State = next state.State = next
return nil return nil