diff --git a/chain/blocksync/cbor_gen.go b/chain/blocksync/cbor_gen.go index 20592c2a3..fbe7145d1 100644 --- a/chain/blocksync/cbor_gen.go +++ b/chain/blocksync/cbor_gen.go @@ -7,7 +7,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" ) diff --git a/chain/types/cbor_gen.go b/chain/types/cbor_gen.go index 018dd7dac..7dca0a2ae 100644 --- a/chain/types/cbor_gen.go +++ b/chain/types/cbor_gen.go @@ -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" - cid "github.com/ipfs/go-cid" + "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" ) @@ -557,10 +557,21 @@ func (t *Message) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{136}); err != nil { + if _, err := w.Write([]byte{137}); err != nil { return err } + // t.Version (int64) (int64) + if t.Version >= 0 { + if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Version))); err != nil { + return err + } + } else { + if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.Version)-1)); err != nil { + return err + } + } + // t.To (address.Address) (struct) if err := t.To.MarshalCBOR(w); err != nil { return err @@ -629,10 +640,35 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { return fmt.Errorf("cbor input should be of type array") } - if extra != 8 { + if extra != 9 { return fmt.Errorf("cbor input had wrong number of fields") } + // t.Version (int64) (int64) + { + maj, extra, err := cbg.CborReadHeader(br) + var extraI int64 + if err != nil { + return err + } + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative oveflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.Version = int64(extraI) + } // t.To (address.Address) (struct) { diff --git a/chain/types/message.go b/chain/types/message.go index 3637b2ea8..703c33dfc 100644 --- a/chain/types/message.go +++ b/chain/types/message.go @@ -12,6 +12,8 @@ import ( "github.com/filecoin-project/go-address" ) +const MessageVersion = 0 + type ChainMsg interface { Cid() cid.Cid VMMessage() *Message @@ -20,6 +22,8 @@ type ChainMsg interface { } type Message struct { + Version int64 + To address.Address From address.Address @@ -56,6 +60,10 @@ func DecodeMessage(b []byte) (*Message, error) { return nil, err } + if msg.Version != MessageVersion { + return nil, fmt.Errorf("decoded message had incorrect version (%d)", msg.Version) + } + return &msg, nil } diff --git a/node/hello/cbor_gen.go b/node/hello/cbor_gen.go index 7c530a11a..5e0fc5bcd 100644 --- a/node/hello/cbor_gen.go +++ b/node/hello/cbor_gen.go @@ -7,7 +7,7 @@ import ( "io" "github.com/filecoin-project/specs-actors/actors/abi" - cid "github.com/ipfs/go-cid" + "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" )