Merge pull request #199 from filecoin-project/feat/serialization-3

final chain serialization bits
This commit is contained in:
Whyrusleeping 2019-09-18 04:21:55 +10:00 committed by GitHub
commit 0f92df7b06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 335 additions and 111 deletions

View File

@ -25,6 +25,7 @@ func (t *InitActorState) MarshalCBOR(w io.Writer) error {
}
// t.t.AddressMap (cid.Cid)
if err := cbg.WriteCid(w, t.AddressMap); err != nil {
return xerrors.Errorf("failed to write cid field t.AddressMap: %w", err)
}
@ -54,11 +55,14 @@ func (t *InitActorState) UnmarshalCBOR(r io.Reader) error {
// t.t.AddressMap (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.AddressMap: %w", err)
}
t.AddressMap = c
}
// t.t.NextID (uint64)
@ -83,6 +87,7 @@ func (t *ExecParams) MarshalCBOR(w io.Writer) error {
}
// t.t.Code (cid.Cid)
if err := cbg.WriteCid(w, t.Code); err != nil {
return xerrors.Errorf("failed to write cid field t.Code: %w", err)
}
@ -115,11 +120,14 @@ func (t *ExecParams) UnmarshalCBOR(r io.Reader) error {
// t.t.Code (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Code: %w", err)
}
t.Code = c
}
// t.t.Params ([]uint8)
@ -194,6 +202,7 @@ func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error {
}
// t.t.Info (cid.Cid)
if err := cbg.WriteCid(w, t.Info); err != nil {
return xerrors.Errorf("failed to write cid field t.Info: %w", err)
}
@ -209,6 +218,7 @@ func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error {
}
// t.t.Sectors (cid.Cid)
if err := cbg.WriteCid(w, t.Sectors); err != nil {
return xerrors.Errorf("failed to write cid field t.Sectors: %w", err)
}
@ -219,6 +229,7 @@ func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error {
}
// t.t.ProvingSet (cid.Cid)
if err := cbg.WriteCid(w, t.ProvingSet); err != nil {
return xerrors.Errorf("failed to write cid field t.ProvingSet: %w", err)
}
@ -268,11 +279,14 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
// t.t.Info (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Info: %w", err)
}
t.Info = c
}
// t.t.DePledgedCollateral (types.BigInt)
@ -295,11 +309,14 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
// t.t.Sectors (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Sectors: %w", err)
}
t.Sectors = c
}
// t.t.SectorSetSize (uint64)
@ -314,11 +331,14 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
// t.t.ProvingSet (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.ProvingSet: %w", err)
}
t.ProvingSet = c
}
// t.t.ProvingSetSize (uint64)
@ -1057,6 +1077,7 @@ func (t *MultiSigActorState) UnmarshalCBOR(r io.Reader) error {
t.Signers = make([]address.Address, extra)
}
for i := 0; i < int(extra); i++ {
var v address.Address
if err := v.UnmarshalCBOR(br); err != nil {
return err
@ -1102,6 +1123,7 @@ func (t *MultiSigActorState) UnmarshalCBOR(r io.Reader) error {
t.Transactions = make([]MTransaction, extra)
}
for i := 0; i < int(extra); i++ {
var v MTransaction
if err := v.UnmarshalCBOR(br); err != nil {
return err
@ -1171,6 +1193,7 @@ func (t *MultiSigConstructorParams) UnmarshalCBOR(r io.Reader) error {
t.Signers = make([]address.Address, extra)
}
for i := 0; i < int(extra); i++ {
var v address.Address
if err := v.UnmarshalCBOR(br); err != nil {
return err
@ -1600,6 +1623,7 @@ func (t *MTransaction) UnmarshalCBOR(r io.Reader) error {
t.Approved = make([]address.Address, extra)
}
for i := 0; i < int(extra); i++ {
var v address.Address
if err := v.UnmarshalCBOR(br); err != nil {
return err
@ -2195,8 +2219,15 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error {
}
// t.t.ChannelMessage (cid.Cid)
if err := cbg.WriteCid(w, *t.ChannelMessage); err != nil {
return xerrors.Errorf("failed to write cid field t.ChannelMessage: %w", err)
if t.ChannelMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
return err
}
} else {
if err := cbg.WriteCid(w, *t.ChannelMessage); err != nil {
return xerrors.Errorf("failed to write cid field t.ChannelMessage: %w", err)
}
}
// t.t.Vouchers ([]*types.SignedVoucher)
@ -2247,11 +2278,26 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
// t.t.ChannelMessage (cid.Cid)
{
c, err := cbg.ReadCid(br)
pb, err := br.PeekByte()
if err != nil {
return xerrors.Errorf("failed to read cid field t.ChannelMessage: %w", err)
return err
}
t.ChannelMessage = &c
if pb == cbg.CborNull[0] {
var nbuf [1]byte
if _, err := br.Read(nbuf[:]); err != nil {
return err
}
} else {
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.ChannelMessage: %w", err)
}
t.ChannelMessage = &c
}
}
// t.t.Vouchers ([]*types.SignedVoucher)
@ -2270,6 +2316,7 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
t.Vouchers = make([]*types.SignedVoucher, extra)
}
for i := 0; i < int(extra); i++ {
var v types.SignedVoucher
if err := v.UnmarshalCBOR(br); err != nil {
return err
@ -2291,6 +2338,7 @@ func (t *StorageMarketState) MarshalCBOR(w io.Writer) error {
}
// t.t.Miners (cid.Cid)
if err := cbg.WriteCid(w, t.Miners); err != nil {
return xerrors.Errorf("failed to write cid field t.Miners: %w", err)
}
@ -2320,11 +2368,14 @@ func (t *StorageMarketState) UnmarshalCBOR(r io.Reader) error {
// t.t.Miners (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Miners: %w", err)
}
t.Miners = c
}
// t.t.TotalStorage (types.BigInt)

View File

@ -3,11 +3,12 @@ package gen
import (
"context"
amt "github.com/filecoin-project/go-amt-ipld"
bls "github.com/filecoin-project/go-bls-sigs"
cid "github.com/ipfs/go-cid"
hamt "github.com/ipfs/go-hamt-ipld"
"github.com/pkg/errors"
"github.com/whyrusleeping/sharray"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-lotus/chain/actors"
@ -77,14 +78,14 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
}
}
var receipts []interface{}
var receipts []cbg.CBORMarshaler
for _, msg := range blsMessages {
rec, err := vmi.ApplyMessage(ctx, msg)
if err != nil {
return nil, errors.Wrap(err, "apply message failure")
}
receipts = append(receipts, rec.MessageReceipt)
receipts = append(receipts, &rec.MessageReceipt)
}
for _, msg := range secpkMessages {
rec, err := vmi.ApplyMessage(ctx, &msg.Message)
@ -92,20 +93,20 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
return nil, errors.Wrap(err, "apply message failure")
}
receipts = append(receipts, rec.MessageReceipt)
receipts = append(receipts, &rec.MessageReceipt)
}
cst := hamt.CSTFromBstore(sm.ChainStore().Blockstore())
blsmsgroot, err := sharray.Build(context.TODO(), 4, toIfArr(blsMsgCids), cst)
bs := amt.WrapBlockstore(sm.ChainStore().Blockstore())
blsmsgroot, err := amt.FromArray(bs, toIfArr(blsMsgCids))
if err != nil {
return nil, err
return nil, xerrors.Errorf("building bls amt: %w", err)
}
secpkmsgroot, err := sharray.Build(context.TODO(), 4, toIfArr(secpkMsgCids), cst)
secpkmsgroot, err := amt.FromArray(bs, toIfArr(secpkMsgCids))
if err != nil {
return nil, err
return nil, xerrors.Errorf("building secpk amt: %w", err)
}
mmcid, err := cst.Put(context.TODO(), &types.MsgMeta{
mmcid, err := bs.Put(&types.MsgMeta{
BlsMessages: blsmsgroot,
SecpkMessages: secpkmsgroot,
})
@ -114,9 +115,9 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
}
next.Messages = mmcid
rectroot, err := sharray.Build(context.TODO(), 4, receipts, cst)
rectroot, err := amt.FromArray(bs, receipts)
if err != nil {
return nil, err
return nil, xerrors.Errorf("failed to build receipts amt: %w", err)
}
next.MessageReceipts = rectroot
@ -142,6 +143,7 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
return nil, xerrors.Errorf("failed to get signing bytes for block: %w", err)
}
cst := hamt.CSTFromBstore(sm.ChainStore().Blockstore())
waddr, err := vm.ResolveToKeyAddr(vmi.StateTree(), cst, worker)
if err != nil {
return nil, xerrors.Errorf("failed to resolve miner address to key address: %w", err)
@ -178,10 +180,11 @@ func aggregateSignatures(sigs []types.Signature) (types.Signature, error) {
}, nil
}
func toIfArr(cids []cid.Cid) []interface{} {
out := make([]interface{}, 0, len(cids))
func toIfArr(cids []cid.Cid) []cbg.CBORMarshaler {
out := make([]cbg.CBORMarshaler, 0, len(cids))
for _, c := range cids {
out = append(out, c)
oc := cbg.CborCid(c)
out = append(out, &oc)
}
return out
}

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
amt "github.com/filecoin-project/go-amt-ipld"
"github.com/filecoin-project/go-lotus/build"
actors "github.com/filecoin-project/go-lotus/chain/actors"
"github.com/filecoin-project/go-lotus/chain/address"
@ -19,7 +20,6 @@ import (
bstore "github.com/ipfs/go-ipfs-blockstore"
peer "github.com/libp2p/go-libp2p-peer"
cbg "github.com/whyrusleeping/cbor-gen"
sharray "github.com/whyrusleeping/sharray"
)
type GenesisBootstrap struct {
@ -287,11 +287,11 @@ func MakeGenesisBlock(bs bstore.Blockstore, balances map[address.Address]types.B
return nil, xerrors.Errorf("setup storage miners failed: %w", err)
}
cst := hamt.CSTFromBstore(bs)
blks := amt.WrapBlockstore(bs)
emptyroot, err := sharray.Build(context.TODO(), 4, []interface{}{}, cst)
emptyroot, err := amt.FromArray(blks, nil)
if err != nil {
return nil, xerrors.Errorf("sharray build failed: %w", err)
return nil, xerrors.Errorf("amt build failed: %w", err)
}
mm := &types.MsgMeta{

View File

@ -6,7 +6,6 @@ import (
"github.com/ipfs/go-cid"
hamt "github.com/ipfs/go-hamt-ipld"
cbor "github.com/ipfs/go-ipld-cbor"
logging "github.com/ipfs/go-log"
"golang.org/x/xerrors"
@ -101,8 +100,8 @@ func (st *StateTree) GetActor(addr address.Address) (*types.Actor, error) {
return cact, nil
}
var thing interface{}
err := st.root.Find(context.TODO(), string(addr.Bytes()), &thing)
var act types.Actor
err := st.root.Find(context.TODO(), string(addr.Bytes()), &act)
if err != nil {
if err == hamt.ErrNotFound {
return nil, types.ErrActorNotFound
@ -110,16 +109,6 @@ func (st *StateTree) GetActor(addr address.Address) (*types.Actor, error) {
return nil, err
}
var act types.Actor
badout, err := cbor.DumpObject(thing)
if err != nil {
return nil, err
}
if err := cbor.DecodeInto(badout, &act); err != nil {
return nil, err
}
st.actorcache[addr] = &act
return &act, nil

View File

@ -7,8 +7,8 @@ import (
"fmt"
"sync"
amt "github.com/filecoin-project/go-amt-ipld"
"github.com/filecoin-project/go-lotus/chain/types"
"golang.org/x/xerrors"
block "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
@ -18,8 +18,9 @@ import (
bstore "github.com/ipfs/go-ipfs-blockstore"
logging "github.com/ipfs/go-log"
"github.com/pkg/errors"
cbg "github.com/whyrusleeping/cbor-gen"
pubsub "github.com/whyrusleeping/pubsub"
sharray "github.com/whyrusleeping/sharray"
"golang.org/x/xerrors"
)
var log = logging.Logger("chainstore")
@ -487,25 +488,21 @@ func (cs *ChainStore) GetSignedMessage(c cid.Cid) (*types.SignedMessage, error)
return types.DecodeSignedMessage(sb.RawData())
}
func (cs *ChainStore) readSharrayCids(root cid.Cid) ([]cid.Cid, error) {
cst := hamt.CSTFromBstore(cs.bs)
shar, err := sharray.Load(context.TODO(), root, 4, cst)
func (cs *ChainStore) readAMTCids(root cid.Cid) ([]cid.Cid, error) {
bs := amt.WrapBlockstore(cs.bs)
a, err := amt.LoadAMT(bs, root)
if err != nil {
return nil, errors.Wrap(err, "sharray load")
return nil, xerrors.Errorf("amt load: %w", err)
}
var cids []cid.Cid
err = shar.ForEach(context.TODO(), func(i interface{}) error {
c, ok := i.(cid.Cid)
if !ok {
return fmt.Errorf("value in message sharray was not a cid")
for i := uint64(0); i < a.Count; i++ {
var c cbg.CborCid
if err := a.Get(i, &c); err != nil {
return nil, xerrors.Errorf("failed to load cid from amt: %w", err)
}
cids = append(cids, c)
return nil
})
if err != nil {
return nil, err
cids = append(cids, cid.Cid(c))
}
return cids, nil
@ -518,12 +515,12 @@ func (cs *ChainStore) MessagesForBlock(b *types.BlockHeader) ([]*types.Message,
return nil, nil, xerrors.Errorf("failed to load msgmeta: %w", err)
}
blscids, err := cs.readSharrayCids(msgmeta.BlsMessages)
blscids, err := cs.readAMTCids(msgmeta.BlsMessages)
if err != nil {
return nil, nil, errors.Wrap(err, "loading bls message cids for block")
}
secpkcids, err := cs.readSharrayCids(msgmeta.SecpkMessages)
secpkcids, err := cs.readAMTCids(msgmeta.SecpkMessages)
if err != nil {
return nil, nil, errors.Wrap(err, "loading secpk message cids for block")
}
@ -542,24 +539,14 @@ func (cs *ChainStore) MessagesForBlock(b *types.BlockHeader) ([]*types.Message,
}
func (cs *ChainStore) GetReceipt(b *types.BlockHeader, i int) (*types.MessageReceipt, error) {
cst := hamt.CSTFromBstore(cs.bs)
shar, err := sharray.Load(context.TODO(), b.MessageReceipts, 4, cst)
bs := amt.WrapBlockstore(cs.bs)
a, err := amt.LoadAMT(bs, b.MessageReceipts)
if err != nil {
return nil, errors.Wrap(err, "sharray load")
return nil, errors.Wrap(err, "amt load")
}
ival, err := shar.Get(context.TODO(), i)
if err != nil {
return nil, err
}
// @warpfork, @EricMyhre help me. save me.
out, err := json.Marshal(ival)
if err != nil {
return nil, err
}
var r types.MessageReceipt
if err := json.Unmarshal(out, &r); err != nil {
if err := a.Get(uint64(i), &r); err != nil {
return nil, err
}
@ -652,7 +639,7 @@ func (cs *ChainStore) blockContainsMsg(blk *types.BlockHeader, msg cid.Cid) (*ty
return nil, err
}
blscids, err := cs.readSharrayCids(msgmeta.BlsMessages)
blscids, err := cs.readAMTCids(msgmeta.BlsMessages)
if err != nil {
return nil, errors.Wrap(err, "loading bls message cids for block")
}
@ -663,7 +650,7 @@ func (cs *ChainStore) blockContainsMsg(blk *types.BlockHeader, msg cid.Cid) (*ty
}
}
secpkcids, err := cs.readSharrayCids(msgmeta.SecpkMessages)
secpkcids, err := cs.readAMTCids(msgmeta.SecpkMessages)
if err != nil {
return nil, errors.Wrap(err, "loading secpk message cids for block")
}

View File

@ -6,8 +6,6 @@ import (
"sync"
"time"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/chain/actors"
"github.com/filecoin-project/go-lotus/chain/address"
@ -17,14 +15,15 @@ import (
"github.com/filecoin-project/go-lotus/chain/vm"
"github.com/filecoin-project/go-lotus/lib/vdf"
amt "github.com/filecoin-project/go-amt-ipld"
"github.com/ipfs/go-cid"
dstore "github.com/ipfs/go-datastore"
"github.com/ipfs/go-hamt-ipld"
bstore "github.com/ipfs/go-ipfs-blockstore"
logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/pkg/errors"
"github.com/whyrusleeping/sharray"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
)
var log = logging.Logger("chain")
@ -153,7 +152,7 @@ func copyBlockstore(from, to bstore.Blockstore) error {
// either validate it here, or ensure that its validated elsewhere (maybe make
// sure the blocksync code checks it?)
// maybe this code should actually live in blocksync??
func zipTipSetAndMessages(cst *hamt.CborIpldStore, ts *types.TipSet, allbmsgs []*types.Message, allsmsgs []*types.SignedMessage, bmi, smi [][]uint64) (*store.FullTipSet, error) {
func zipTipSetAndMessages(bs amt.Blocks, ts *types.TipSet, allbmsgs []*types.Message, allsmsgs []*types.SignedMessage, bmi, smi [][]uint64) (*store.FullTipSet, error) {
if len(ts.Blocks()) != len(smi) || len(ts.Blocks()) != len(bmi) {
return nil, fmt.Errorf("msgincl length didnt match tipset size")
}
@ -161,30 +160,32 @@ func zipTipSetAndMessages(cst *hamt.CborIpldStore, ts *types.TipSet, allbmsgs []
fts := &store.FullTipSet{}
for bi, b := range ts.Blocks() {
var smsgs []*types.SignedMessage
var smsgCids []interface{}
var smsgCids []cbg.CBORMarshaler
for _, m := range smi[bi] {
smsgs = append(smsgs, allsmsgs[m])
smsgCids = append(smsgCids, allsmsgs[m].Cid())
c := cbg.CborCid(allsmsgs[m].Cid())
smsgCids = append(smsgCids, &c)
}
smroot, err := sharray.Build(context.TODO(), 4, smsgCids, cst)
smroot, err := amt.FromArray(bs, smsgCids)
if err != nil {
return nil, err
}
var bmsgs []*types.Message
var bmsgCids []interface{}
var bmsgCids []cbg.CBORMarshaler
for _, m := range bmi[bi] {
bmsgs = append(bmsgs, allbmsgs[m])
bmsgCids = append(bmsgCids, allbmsgs[m].Cid())
c := cbg.CborCid(allbmsgs[m].Cid())
bmsgCids = append(bmsgCids, &c)
}
bmroot, err := sharray.Build(context.TODO(), 4, bmsgCids, cst)
bmroot, err := amt.FromArray(bs, bmsgCids)
if err != nil {
return nil, err
}
mrcid, err := cst.Put(context.TODO(), &types.MsgMeta{
mrcid, err := bs.Put(&types.MsgMeta{
BlsMessages: bmroot,
SecpkMessages: smroot,
})
@ -453,14 +454,14 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
return xerrors.Errorf("fund transfer failed: %w", err)
}
var receipts []interface{}
var receipts []cbg.CBORMarshaler
for i, m := range b.BlsMessages {
receipt, err := vmi.ApplyMessage(ctx, m)
if err != nil {
return xerrors.Errorf("failed executing bls message %d in block %s: %w", i, b.Header.Cid(), err)
}
receipts = append(receipts, receipt.MessageReceipt)
receipts = append(receipts, &receipt.MessageReceipt)
}
for i, m := range b.SecpkMessages {
@ -469,13 +470,13 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
return xerrors.Errorf("failed executing secpk message %d in block %s: %w", i, b.Header.Cid(), err)
}
receipts = append(receipts, receipt.MessageReceipt)
receipts = append(receipts, &receipt.MessageReceipt)
}
cst := hamt.CSTFromBstore(syncer.store.Blockstore())
recptRoot, err := sharray.Build(context.TODO(), 4, receipts, cst)
bs := amt.WrapBlockstore(syncer.store.Blockstore())
recptRoot, err := amt.FromArray(bs, receipts)
if err != nil {
return xerrors.Errorf("building receipts sharray failed: %w", err)
return xerrors.Errorf("building receipts amt failed: %w", err)
}
if recptRoot != b.Header.MessageReceipts {
return fmt.Errorf("receipts mismatched")
@ -614,11 +615,11 @@ func (syncer *Syncer) iterFullTipsets(headers []*types.TipSet, cb func(*store.Fu
// temp storage so we don't persist data we dont want to
ds := dstore.NewMapDatastore()
bs := bstore.NewBlockstore(ds)
cst := hamt.CSTFromBstore(bs)
blks := amt.WrapBlockstore(bs)
this := headers[i-bsi]
bstip := bstips[len(bstips)-(bsi+1)]
fts, err := zipTipSetAndMessages(cst, this, bstip.BlsMessages, bstip.SecpkMessages, bstip.BlsMsgIncludes, bstip.SecpkMsgIncludes)
fts, err := zipTipSetAndMessages(blks, this, bstip.BlsMessages, bstip.SecpkMessages, bstip.BlsMsgIncludes, bstip.SecpkMsgIncludes)
if err != nil {
log.Warn("zipping failed: ", err, bsi, i)
log.Warn("height: ", this.Height())

View File

@ -4,15 +4,10 @@ import (
"fmt"
"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
)
var ErrActorNotFound = fmt.Errorf("actor not found")
func init() {
cbor.RegisterCborType(Actor{})
}
type Actor struct {
Code cid.Cid
Head cid.Cid

View File

@ -3,6 +3,7 @@ package types
import (
"fmt"
"io"
"math"
cid "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
@ -66,11 +67,13 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
}
// t.t.StateRoot (cid.Cid)
if err := cbg.WriteCid(w, t.StateRoot); err != nil {
return xerrors.Errorf("failed to write cid field t.StateRoot: %w", err)
}
// t.t.Messages (cid.Cid)
if err := cbg.WriteCid(w, t.Messages); err != nil {
return xerrors.Errorf("failed to write cid field t.Messages: %w", err)
}
@ -81,6 +84,7 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
}
// t.t.MessageReceipts (cid.Cid)
if err := cbg.WriteCid(w, t.MessageReceipts); err != nil {
return xerrors.Errorf("failed to write cid field t.MessageReceipts: %w", err)
}
@ -138,6 +142,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.Tickets = make([]*Ticket, extra)
}
for i := 0; i < int(extra); i++ {
var v Ticket
if err := v.UnmarshalCBOR(br); err != nil {
return err
@ -210,20 +215,26 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
// t.t.StateRoot (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.StateRoot: %w", err)
}
t.StateRoot = c
}
// t.t.Messages (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Messages: %w", err)
}
t.Messages = c
}
// t.t.BLSAggregate (types.Signature)
@ -237,11 +248,14 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
// t.t.MessageReceipts (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.MessageReceipts: %w", err)
}
t.MessageReceipts = c
}
// t.t.Timestamp (uint64)
@ -590,14 +604,17 @@ func (t *MsgMeta) MarshalCBOR(w io.Writer) error {
}
// t.t.BlsMessages (cid.Cid)
if err := cbg.WriteCid(w, t.BlsMessages); err != nil {
return xerrors.Errorf("failed to write cid field t.BlsMessages: %w", err)
}
// t.t.SecpkMessages (cid.Cid)
if err := cbg.WriteCid(w, t.SecpkMessages); err != nil {
return xerrors.Errorf("failed to write cid field t.SecpkMessages: %w", err)
}
return nil
}
@ -619,20 +636,26 @@ func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error {
// t.t.BlsMessages (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.BlsMessages: %w", err)
}
t.BlsMessages = c
}
// t.t.SecpkMessages (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.SecpkMessages: %w", err)
}
t.SecpkMessages = c
}
return nil
}
@ -820,6 +843,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
t.Merges = make([]Merge, extra)
}
for i := 0; i < int(extra); i++ {
var v Merge
if err := v.UnmarshalCBOR(br); err != nil {
return err
@ -993,3 +1017,183 @@ func (t *Merge) UnmarshalCBOR(r io.Reader) error {
t.Nonce = extra
return nil
}
func (t *Actor) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{132}); err != nil {
return err
}
// t.t.Code (cid.Cid)
if err := cbg.WriteCid(w, t.Code); err != nil {
return xerrors.Errorf("failed to write cid field t.Code: %w", err)
}
// t.t.Head (cid.Cid)
if err := cbg.WriteCid(w, t.Head); err != nil {
return xerrors.Errorf("failed to write cid field t.Head: %w", err)
}
// t.t.Nonce (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Nonce)); err != nil {
return err
}
// t.t.Balance (types.BigInt)
if err := t.Balance.MarshalCBOR(w); err != nil {
return err
}
return nil
}
func (t *Actor) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 4 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Code (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Code: %w", err)
}
t.Code = c
}
// t.t.Head (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Head: %w", err)
}
t.Head = c
}
// t.t.Nonce (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.Nonce = extra
// t.t.Balance (types.BigInt)
{
if err := t.Balance.UnmarshalCBOR(br); err != nil {
return err
}
}
return nil
}
func (t *MessageReceipt) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{131}); err != nil {
return err
}
// t.t.ExitCode (uint8)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ExitCode))); err != nil {
return err
}
// t.t.Return ([]uint8)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Return)))); err != nil {
return err
}
if _, err := w.Write(t.Return); err != nil {
return err
}
// t.t.GasUsed (types.BigInt)
if err := t.GasUsed.MarshalCBOR(w); err != nil {
return err
}
return nil
}
func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 3 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.ExitCode (uint8)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint8 field")
}
if extra > math.MaxUint8 {
return fmt.Errorf("integer in input was too large for uint8 field")
}
t.ExitCode = uint8(extra)
// t.t.Return ([]uint8)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("array too large")
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Return = make([]byte, extra)
if _, err := io.ReadFull(br, t.Return); err != nil {
return err
}
// t.t.GasUsed (types.BigInt)
{
if err := t.GasUsed.UnmarshalCBOR(br); err != nil {
return err
}
}
return nil
}

View File

@ -2,14 +2,8 @@ package types
import (
"bytes"
cbor "github.com/ipfs/go-ipld-cbor"
)
func init() {
cbor.RegisterCborType(MessageReceipt{})
}
type MessageReceipt struct {
ExitCode uint8
Return []byte

View File

@ -19,6 +19,8 @@ func main() {
types.SignedVoucher{},
types.ModVerifyParams{},
types.Merge{},
types.Actor{},
types.MessageReceipt{},
)
if err != nil {
fmt.Println(err)

5
go.mod
View File

@ -6,7 +6,7 @@ require (
contrib.go.opencensus.io/exporter/jaeger v0.1.0
github.com/BurntSushi/toml v0.3.1
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/filecoin-project/go-amt-ipld v0.0.0-20190828233303-a41bd0b6f985
github.com/filecoin-project/go-amt-ipld v0.0.0-20190917010905-40ffeec492ae
github.com/filecoin-project/go-bls-sigs v0.0.0-20190718224239-4bc4b8a7bbf8
github.com/filecoin-project/go-leb128 v0.0.0-20190212224330-8d79a5489543
github.com/filecoin-project/go-sectorbuilder v0.0.0-00010101000000-000000000000
@ -67,10 +67,9 @@ require (
github.com/polydawn/refmt v0.0.0-20190809202753-05966cbd336a
github.com/stretchr/testify v1.4.0
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba
github.com/whyrusleeping/cbor-gen v0.0.0-20190910224804-fde80d83b106
github.com/whyrusleeping/cbor-gen v0.0.0-20190917010546-c55df54645cb
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d
github.com/whyrusleeping/sharray v0.0.0-20190718051354-e41931821e33
go.opencensus.io v0.22.0
go.uber.org/dig v1.7.0 // indirect
go.uber.org/fx v1.9.0

13
go.sum
View File

@ -68,8 +68,8 @@ github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5m
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/filecoin-project/go-amt-ipld v0.0.0-20190828233303-a41bd0b6f985 h1:rpid5Xgp6GnDACqZvugxWvJ8L1HpyttUkzpUk/4BPXk=
github.com/filecoin-project/go-amt-ipld v0.0.0-20190828233303-a41bd0b6f985/go.mod h1:muo8IeR187EUiX5AcMmIb0XSgpSU3qrszgh+pGWf3rY=
github.com/filecoin-project/go-amt-ipld v0.0.0-20190917010905-40ffeec492ae h1:rSg6wenxKdXby0piY57Vv5gOJR6Eibqq/4PxEk6KjvE=
github.com/filecoin-project/go-amt-ipld v0.0.0-20190917010905-40ffeec492ae/go.mod h1:lKjJYPg2kwbav5f78i5YA8kGccnZn18IySbpneXvaQs=
github.com/filecoin-project/go-leb128 v0.0.0-20190212224330-8d79a5489543 h1:aMJGfgqe1QDhAVwxRg5fjCRF533xHidiKsugk7Vvzug=
github.com/filecoin-project/go-leb128 v0.0.0-20190212224330-8d79a5489543/go.mod h1:mjrHv1cDGJWDlGmC0eDc1E5VJr8DmL9XMUcaFwiuKg8=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
@ -601,11 +601,12 @@ github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc h1:BCPnHtcboa
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc/go.mod h1:r45hJU7yEoA81k6MWNhpMj/kms0n14dkzkxYHoB96UM=
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba h1:X4n8JG2e2biEZZXdBKt9HX7DN3bYGFUqljqqy0DqgnY=
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba/go.mod h1:CHQnYnQUEPydYCwuy8lmTHfGmdw9TKrhWV0xLx8l0oM=
github.com/whyrusleeping/cbor-gen v0.0.0-20190822231004-8db835b09a5a/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20190910031516-c1cbffdb01bb h1:8yBVx6dgk1GfkiWOQ+RbeDDBLCOZxOtmZ949O2uj5H4=
github.com/whyrusleeping/cbor-gen v0.0.0-20190910031516-c1cbffdb01bb/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20190910224804-fde80d83b106 h1:PRWDVakEjB5ju0toKWbXSExfi5BB+oU87/8GhBKXIWE=
github.com/whyrusleeping/cbor-gen v0.0.0-20190910224804-fde80d83b106/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20190917003517-d78d67427694 h1:Bjfm012LwDvjZvjPDU/oHwm7uX5U/yRHZaQt6gtbGlI=
github.com/whyrusleeping/cbor-gen v0.0.0-20190917003517-d78d67427694/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20190917010546-c55df54645cb h1:Lc5MOczpVOeI/KwFoib6BMBQ1PfFxMzm/yOUfEeQP+o=
github.com/whyrusleeping/cbor-gen v0.0.0-20190917010546-c55df54645cb/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=
@ -621,8 +622,6 @@ github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 h1:
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7/go.mod h1:X2c0RVCI1eSUFI8eLcY3c0423ykwiUdxLJtkDvruhjI=
github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d h1:wnjWu1N8UTNf2zzF5FWlEyNNbNw5GMVHaHaaLdvdTdA=
github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d/go.mod h1:g7ckxrjiFh8mi1AY7ox23PZD0g6QU/TxW3U3unX7I3A=
github.com/whyrusleeping/sharray v0.0.0-20190718051354-e41931821e33 h1:7Bsg3GZnFAhdadeyRie9ReenkK2XbC2FlOpJQgTzpbA=
github.com/whyrusleeping/sharray v0.0.0-20190718051354-e41931821e33/go.mod h1:c1pwhNePDPlcYJZinQlfLTOKwTmVf45nfdTg73yOOcA=
github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee h1:lYbXeSvJi5zk5GLKVuid9TVjS9a0OmLIDKTfoZBL6Ow=
github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee/go.mod h1:m2aV4LZI4Aez7dP5PMyVKEHhUyEJ/RjmPEDOpDvudHg=
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=