mirror of
https://github.com/filecoin-project/lotus.git
synced 2025-08-24 09:22:17 +08:00

* Support Forrest parity testing for F3 participation APIs For parity testing, Forest nodes need to decode an F3 participation ticket that is issued by Lotus. Lotus so happens to use CBOR to encode tickets, which it then decodes to issue a lease. The lease issuer is of type `peer.ID` which is an alias of type `string` that may contain non UTF-8 characters. If this type is used directly in CBOR encoding then it gets encoded as string, which works fine in Golang but not Rust, which in turn results in decoding issues in Forest. To avoid this use `[]byte` as the type to encode the issuer public key. In Lotus, the value will be the binary marshalling of `peer.ID` that issued the ticket. While at it, also fix two issues that were brought up during discussion: * A miner must not be able to ask for a ticket to participate in zero instances. Validate and return error if instances is set to zero. * Use CBOR tuple encoding for a slightly better efficient wire encoding of ticket. `cborgen.Write*` APIs explicitly create a given file; hence the need to separate the file to which tuple kinds are generated since the existing encoding for types in `api/cbor_gen.go` use maps.
169 lines
3.1 KiB
Go
169 lines
3.1 KiB
Go
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
|
|
|
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"math"
|
|
"sort"
|
|
|
|
cid "github.com/ipfs/go-cid"
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
xerrors "golang.org/x/xerrors"
|
|
|
|
gpbft "github.com/filecoin-project/go-f3/gpbft"
|
|
)
|
|
|
|
var _ = xerrors.Errorf
|
|
var _ = cid.Undef
|
|
var _ = math.E
|
|
var _ = sort.Sort
|
|
|
|
var lengthBufF3ParticipationLease = []byte{133}
|
|
|
|
func (t *F3ParticipationLease) MarshalCBOR(w io.Writer) error {
|
|
if t == nil {
|
|
_, err := w.Write(cbg.CborNull)
|
|
return err
|
|
}
|
|
|
|
cw := cbg.NewCborWriter(w)
|
|
|
|
if _, err := cw.Write(lengthBufF3ParticipationLease); err != nil {
|
|
return err
|
|
}
|
|
|
|
// t.Network (gpbft.NetworkName) (string)
|
|
if len(t.Network) > 8192 {
|
|
return xerrors.Errorf("Value in field t.Network was too long")
|
|
}
|
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Network))); err != nil {
|
|
return err
|
|
}
|
|
if _, err := cw.WriteString(string(t.Network)); err != nil {
|
|
return err
|
|
}
|
|
|
|
// t.Issuer (string) (string)
|
|
if len(t.Issuer) > 8192 {
|
|
return xerrors.Errorf("Value in field t.Issuer was too long")
|
|
}
|
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Issuer))); err != nil {
|
|
return err
|
|
}
|
|
if _, err := cw.WriteString(string(t.Issuer)); err != nil {
|
|
return err
|
|
}
|
|
|
|
// t.MinerID (uint64) (uint64)
|
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.MinerID)); err != nil {
|
|
return err
|
|
}
|
|
|
|
// t.FromInstance (uint64) (uint64)
|
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.FromInstance)); err != nil {
|
|
return err
|
|
}
|
|
|
|
// t.ValidityTerm (uint64) (uint64)
|
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.ValidityTerm)); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (t *F3ParticipationLease) UnmarshalCBOR(r io.Reader) (err error) {
|
|
*t = F3ParticipationLease{}
|
|
|
|
cr := cbg.NewCborReader(r)
|
|
|
|
maj, extra, err := cr.ReadHeader()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() {
|
|
if err == io.EOF {
|
|
err = io.ErrUnexpectedEOF
|
|
}
|
|
}()
|
|
|
|
if maj != cbg.MajArray {
|
|
return fmt.Errorf("cbor input should be of type array")
|
|
}
|
|
|
|
if extra != 5 {
|
|
return fmt.Errorf("cbor input had wrong number of fields")
|
|
}
|
|
|
|
// t.Network (gpbft.NetworkName) (string)
|
|
|
|
{
|
|
sval, err := cbg.ReadStringWithMax(cr, 8192)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
t.Network = gpbft.NetworkName(sval)
|
|
}
|
|
// t.Issuer (string) (string)
|
|
|
|
{
|
|
sval, err := cbg.ReadStringWithMax(cr, 8192)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
t.Issuer = string(sval)
|
|
}
|
|
// t.MinerID (uint64) (uint64)
|
|
|
|
{
|
|
|
|
maj, extra, err = cr.ReadHeader()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if maj != cbg.MajUnsignedInt {
|
|
return fmt.Errorf("wrong type for uint64 field")
|
|
}
|
|
t.MinerID = uint64(extra)
|
|
|
|
}
|
|
// t.FromInstance (uint64) (uint64)
|
|
|
|
{
|
|
|
|
maj, extra, err = cr.ReadHeader()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if maj != cbg.MajUnsignedInt {
|
|
return fmt.Errorf("wrong type for uint64 field")
|
|
}
|
|
t.FromInstance = uint64(extra)
|
|
|
|
}
|
|
// t.ValidityTerm (uint64) (uint64)
|
|
|
|
{
|
|
|
|
maj, extra, err = cr.ReadHeader()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if maj != cbg.MajUnsignedInt {
|
|
return fmt.Errorf("wrong type for uint64 field")
|
|
}
|
|
t.ValidityTerm = uint64(extra)
|
|
|
|
}
|
|
return nil
|
|
}
|