Merge pull request #1040 from filecoin-project/feat/fork-signaling

Add fork signaling to blockheader
This commit is contained in:
Łukasz Magiera 2020-01-10 13:33:29 +01:00 committed by GitHub
commit 469136ee86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 171 additions and 4 deletions

View File

@ -23,6 +23,10 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error {
}
// t.Channel (address.Address) (struct)
if len("Channel") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Channel\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Channel")))); err != nil {
return err
}
@ -35,6 +39,10 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error {
}
// t.ChannelMessage (cid.Cid) (struct)
if len("ChannelMessage") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"ChannelMessage\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("ChannelMessage")))); err != nil {
return err
}
@ -53,6 +61,10 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error {
}
// t.Vouchers ([]*types.SignedVoucher) (slice)
if len("Vouchers") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Vouchers\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Vouchers")))); err != nil {
return err
}
@ -60,6 +72,10 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.Vouchers) > cbg.MaxLength {
return xerrors.Errorf("Slice value in field t.Vouchers was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Vouchers)))); err != nil {
return err
}
@ -200,6 +216,10 @@ func (t *SealedRef) MarshalCBOR(w io.Writer) error {
}
// t.SectorID (uint64) (uint64)
if len("SectorID") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"SectorID\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("SectorID")))); err != nil {
return err
}
@ -212,6 +232,10 @@ func (t *SealedRef) MarshalCBOR(w io.Writer) error {
}
// t.Offset (uint64) (uint64)
if len("Offset") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Offset\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Offset")))); err != nil {
return err
}
@ -224,6 +248,10 @@ func (t *SealedRef) MarshalCBOR(w io.Writer) error {
}
// t.Size (uint64) (uint64)
if len("Size") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Size\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Size")))); err != nil {
return err
}
@ -336,6 +364,10 @@ func (t *SealedRefs) MarshalCBOR(w io.Writer) error {
}
// t.Refs ([]api.SealedRef) (slice)
if len("Refs") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Refs\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Refs")))); err != nil {
return err
}
@ -343,6 +375,10 @@ func (t *SealedRefs) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.Refs) > cbg.MaxLength {
return xerrors.Errorf("Slice value in field t.Refs was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Refs)))); err != nil {
return err
}

View File

@ -5,7 +5,7 @@ import (
"io"
"github.com/filecoin-project/lotus/chain/types"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)

View File

@ -59,6 +59,8 @@ type BlockHeader struct {
Timestamp uint64
BlockSig *Signature
ForkSignaling uint64
}
func (b *BlockHeader) ToStorageBlock() (block.Block, error) {

View File

@ -19,7 +19,7 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{140}); err != nil {
if _, err := w.Write([]byte{141}); err != nil {
return err
}
@ -94,6 +94,11 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
if err := t.BlockSig.MarshalCBOR(w); err != nil {
return err
}
// t.ForkSignaling (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ForkSignaling))); err != nil {
return err
}
return nil
}
@ -108,7 +113,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 12 {
if extra != 13 {
return fmt.Errorf("cbor input had wrong number of fields")
}
@ -272,6 +277,16 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
}
}
// t.ForkSignaling (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.ForkSignaling = uint64(extra)
return nil
}

2
go.mod
View File

@ -86,7 +86,7 @@ require (
github.com/prometheus/common v0.2.0
github.com/stretchr/testify v1.4.0
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba
github.com/whyrusleeping/cbor-gen v0.0.0-20191216205031-b047b6acb3c0
github.com/whyrusleeping/cbor-gen v0.0.0-20200106232624-282db0d37dbe
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d
go.opencensus.io v0.22.2

2
go.sum
View File

@ -724,6 +724,8 @@ github.com/whyrusleeping/cbor-gen v0.0.0-20191116002219-891f55cd449d/go.mod h1:x
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 h1:efb/4CnrubzNGqQOeHErxyQ6rIsJb7GcgeSDF7fqWeI=
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-20200106232624-282db0d37dbe/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/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k=

View File

@ -22,6 +22,10 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error {
}
// t.BlockHeight (uint64) (uint64)
if len("BlockHeight") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"BlockHeight\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("BlockHeight")))); err != nil {
return err
}
@ -34,6 +38,10 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error {
}
// t.TicketBytes ([]uint8) (slice)
if len("TicketBytes") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"TicketBytes\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("TicketBytes")))); err != nil {
return err
}
@ -41,6 +49,10 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.TicketBytes) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.TicketBytes was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.TicketBytes)))); err != nil {
return err
}
@ -133,6 +145,10 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error {
}
// t.BlockHeight (uint64) (uint64)
if len("BlockHeight") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"BlockHeight\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("BlockHeight")))); err != nil {
return err
}
@ -145,6 +161,10 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error {
}
// t.TicketBytes ([]uint8) (slice)
if len("TicketBytes") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"TicketBytes\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("TicketBytes")))); err != nil {
return err
}
@ -152,6 +172,10 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.TicketBytes) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.TicketBytes was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.TicketBytes)))); err != nil {
return err
}
@ -244,6 +268,10 @@ func (t *Piece) MarshalCBOR(w io.Writer) error {
}
// t.DealID (uint64) (uint64)
if len("DealID") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"DealID\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("DealID")))); err != nil {
return err
}
@ -256,6 +284,10 @@ func (t *Piece) MarshalCBOR(w io.Writer) error {
}
// t.Size (uint64) (uint64)
if len("Size") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Size\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Size")))); err != nil {
return err
}
@ -268,6 +300,10 @@ func (t *Piece) MarshalCBOR(w io.Writer) error {
}
// t.CommP ([]uint8) (slice)
if len("CommP") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"CommP\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("CommP")))); err != nil {
return err
}
@ -275,6 +311,10 @@ func (t *Piece) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.CommP) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.CommP was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommP)))); err != nil {
return err
}
@ -390,6 +430,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.State (uint64) (uint64)
if len("State") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"State\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("State")))); err != nil {
return err
}
@ -402,6 +446,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.SectorID (uint64) (uint64)
if len("SectorID") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"SectorID\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("SectorID")))); err != nil {
return err
}
@ -414,6 +462,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.Nonce (uint64) (uint64)
if len("Nonce") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Nonce\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Nonce")))); err != nil {
return err
}
@ -426,6 +478,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.Pieces ([]storage.Piece) (slice)
if len("Pieces") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Pieces\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Pieces")))); err != nil {
return err
}
@ -433,6 +489,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.Pieces) > cbg.MaxLength {
return xerrors.Errorf("Slice value in field t.Pieces was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Pieces)))); err != nil {
return err
}
@ -443,6 +503,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.CommD ([]uint8) (slice)
if len("CommD") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"CommD\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("CommD")))); err != nil {
return err
}
@ -450,6 +514,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.CommD) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.CommD was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommD)))); err != nil {
return err
}
@ -458,6 +526,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.CommR ([]uint8) (slice)
if len("CommR") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"CommR\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("CommR")))); err != nil {
return err
}
@ -465,6 +537,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.CommR) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.CommR was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommR)))); err != nil {
return err
}
@ -473,6 +549,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.Proof ([]uint8) (slice)
if len("Proof") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Proof\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Proof")))); err != nil {
return err
}
@ -480,6 +560,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.Proof) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.Proof was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil {
return err
}
@ -488,6 +572,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.Ticket (storage.SealTicket) (struct)
if len("Ticket") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Ticket\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Ticket")))); err != nil {
return err
}
@ -500,6 +588,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.PreCommitMessage (cid.Cid) (struct)
if len("PreCommitMessage") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"PreCommitMessage\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("PreCommitMessage")))); err != nil {
return err
}
@ -518,6 +610,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.Seed (storage.SealSeed) (struct)
if len("Seed") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Seed\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Seed")))); err != nil {
return err
}
@ -530,6 +626,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.CommitMessage (cid.Cid) (struct)
if len("CommitMessage") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"CommitMessage\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("CommitMessage")))); err != nil {
return err
}
@ -548,6 +648,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.FaultReportMsg (cid.Cid) (struct)
if len("FaultReportMsg") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"FaultReportMsg\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("FaultReportMsg")))); err != nil {
return err
}
@ -566,6 +670,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
// t.LastErr (string) (string)
if len("LastErr") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"LastErr\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("LastErr")))); err != nil {
return err
}
@ -573,6 +681,10 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.LastErr) > cbg.MaxLength {
return xerrors.Errorf("Value in field t.LastErr was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.LastErr)))); err != nil {
return err
}