Merge remote-tracking branch 'origin/devnet/7' into feat/interactive-porep

This commit is contained in:
Łukasz Magiera 2019-11-05 18:53:19 +01:00
commit ed5ccfd750
43 changed files with 1962 additions and 1152 deletions

129
api/cbor_gen.go Normal file
View File

@ -0,0 +1,129 @@
package api
import (
"fmt"
"io"
"github.com/filecoin-project/lotus/chain/types"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)
/* This file was generated by github.com/whyrusleeping/cbor-gen */
var _ = xerrors.Errorf
func (t *PaymentInfo) 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.Channel (address.Address) (struct)
if err := t.Channel.MarshalCBOR(w); err != nil {
return err
}
// t.t.ChannelMessage (cid.Cid) (struct)
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) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Vouchers)))); err != nil {
return err
}
for _, v := range t.Vouchers {
if err := v.MarshalCBOR(w); err != nil {
return err
}
}
return nil
}
func (t *PaymentInfo) 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.Channel (address.Address) (struct)
{
if err := t.Channel.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.ChannelMessage (cid.Cid) (struct)
{
pb, err := br.PeekByte()
if err != nil {
return err
}
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) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Vouchers: array too large (%d)", extra)
}
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
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
}
t.Vouchers[i] = &v
}
return nil
}

View File

@ -117,9 +117,13 @@ func (ft *fetch) wait() error {
}
func doFetch(out string, info paramFile) error {
log.Infof("Fetching %s", out)
gw := os.Getenv("IPFS_GATEWAY")
if gw == "" {
gw = gateway
}
log.Infof("Fetching %s from %s", out, gw)
resp, err := http.Get(gateway + info.Cid)
resp, err := http.Get(gw + info.Cid)
if err != nil {
return err
}

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@ func (t *AskRequest) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Miner (address.Address)
// t.t.Miner (address.Address) (struct)
if err := t.Miner.MarshalCBOR(w); err != nil {
return err
}
@ -46,7 +46,7 @@ func (t *AskRequest) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Miner (address.Address)
// t.t.Miner (address.Address) (struct)
{
@ -67,7 +67,7 @@ func (t *AskResponse) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Ask (types.SignedStorageAsk)
// t.t.Ask (types.SignedStorageAsk) (struct)
if err := t.Ask.MarshalCBOR(w); err != nil {
return err
}
@ -89,7 +89,7 @@ func (t *AskResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Ask (types.SignedStorageAsk)
// t.t.Ask (types.SignedStorageAsk) (struct)
{
@ -122,7 +122,7 @@ func (t *Proposal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.DealProposal (actors.StorageDealProposal)
// t.t.DealProposal (actors.StorageDealProposal) (struct)
if err := t.DealProposal.MarshalCBOR(w); err != nil {
return err
}
@ -144,7 +144,7 @@ func (t *Proposal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.DealProposal (actors.StorageDealProposal)
// t.t.DealProposal (actors.StorageDealProposal) (struct)
{
@ -165,12 +165,12 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.State (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.State)); err != nil {
// t.t.State (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil {
return err
}
// t.t.Message (string)
// t.t.Message (string) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Message)))); err != nil {
return err
}
@ -178,18 +178,18 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Proposal (cid.Cid)
// t.t.Proposal (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Proposal); err != nil {
return xerrors.Errorf("failed to write cid field t.Proposal: %w", err)
}
// t.t.StorageDeal (actors.StorageDeal)
// t.t.StorageDeal (actors.StorageDeal) (struct)
if err := t.StorageDeal.MarshalCBOR(w); err != nil {
return err
}
// t.t.PublishMessage (cid.Cid)
// t.t.PublishMessage (cid.Cid) (struct)
if t.PublishMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
@ -201,7 +201,7 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
}
}
// t.t.CommitMessage (cid.Cid)
// t.t.CommitMessage (cid.Cid) (struct)
if t.CommitMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
@ -231,7 +231,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.State (uint64)
// t.t.State (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -240,8 +240,8 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.State = extra
// t.t.Message (string)
t.State = uint64(extra)
// t.t.Message (string) (string)
{
sval, err := cbg.ReadString(br)
@ -251,7 +251,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
t.Message = string(sval)
}
// t.t.Proposal (cid.Cid)
// t.t.Proposal (cid.Cid) (struct)
{
@ -263,7 +263,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
t.Proposal = c
}
// t.t.StorageDeal (actors.StorageDeal)
// t.t.StorageDeal (actors.StorageDeal) (struct)
{
@ -284,7 +284,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.PublishMessage (cid.Cid)
// t.t.PublishMessage (cid.Cid) (struct)
{
@ -308,7 +308,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.CommitMessage (cid.Cid)
// t.t.CommitMessage (cid.Cid) (struct)
{
@ -344,12 +344,12 @@ func (t *SignedResponse) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Response (deals.Response)
// t.t.Response (deals.Response) (struct)
if err := t.Response.MarshalCBOR(w); err != nil {
return err
}
// t.t.Signature (types.Signature)
// t.t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil {
return err
}
@ -371,7 +371,7 @@ func (t *SignedResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Response (deals.Response)
// t.t.Response (deals.Response) (struct)
{
@ -380,7 +380,7 @@ func (t *SignedResponse) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Signature (types.Signature)
// t.t.Signature (types.Signature) (struct)
{
@ -413,38 +413,38 @@ func (t *ClientDealProposal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Data (cid.Cid)
// t.t.Data (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Data); err != nil {
return xerrors.Errorf("failed to write cid field t.Data: %w", err)
}
// t.t.PricePerEpoch (types.BigInt)
// t.t.PricePerEpoch (types.BigInt) (struct)
if err := t.PricePerEpoch.MarshalCBOR(w); err != nil {
return err
}
// t.t.ProposalExpiration (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.ProposalExpiration)); err != nil {
// t.t.ProposalExpiration (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ProposalExpiration))); err != nil {
return err
}
// t.t.Duration (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Duration)); err != nil {
// t.t.Duration (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Duration))); err != nil {
return err
}
// t.t.ProviderAddress (address.Address)
// t.t.ProviderAddress (address.Address) (struct)
if err := t.ProviderAddress.MarshalCBOR(w); err != nil {
return err
}
// t.t.Client (address.Address)
// t.t.Client (address.Address) (struct)
if err := t.Client.MarshalCBOR(w); err != nil {
return err
}
// t.t.MinerID (peer.ID)
// t.t.MinerID (peer.ID) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.MinerID)))); err != nil {
return err
}
@ -469,7 +469,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Data (cid.Cid)
// t.t.Data (cid.Cid) (struct)
{
@ -481,7 +481,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
t.Data = c
}
// t.t.PricePerEpoch (types.BigInt)
// t.t.PricePerEpoch (types.BigInt) (struct)
{
@ -490,7 +490,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.ProposalExpiration (uint64)
// t.t.ProposalExpiration (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -499,8 +499,8 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.ProposalExpiration = extra
// t.t.Duration (uint64)
t.ProposalExpiration = uint64(extra)
// t.t.Duration (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -509,8 +509,8 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Duration = extra
// t.t.ProviderAddress (address.Address)
t.Duration = uint64(extra)
// t.t.ProviderAddress (address.Address) (struct)
{
@ -519,7 +519,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Client (address.Address)
// t.t.Client (address.Address) (struct)
{
@ -528,7 +528,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.MinerID (peer.ID)
// t.t.MinerID (peer.ID) (string)
{
sval, err := cbg.ReadString(br)
@ -550,23 +550,23 @@ func (t *ClientDeal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.ProposalCid (cid.Cid)
// t.t.ProposalCid (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ProposalCid); err != nil {
return xerrors.Errorf("failed to write cid field t.ProposalCid: %w", err)
}
// t.t.Proposal (actors.StorageDealProposal)
// t.t.Proposal (actors.StorageDealProposal) (struct)
if err := t.Proposal.MarshalCBOR(w); err != nil {
return err
}
// t.t.State (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.State)); err != nil {
// t.t.State (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil {
return err
}
// t.t.Miner (peer.ID)
// t.t.Miner (peer.ID) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Miner)))); err != nil {
return err
}
@ -591,7 +591,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.ProposalCid (cid.Cid)
// t.t.ProposalCid (cid.Cid) (struct)
{
@ -603,7 +603,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
t.ProposalCid = c
}
// t.t.Proposal (actors.StorageDealProposal)
// t.t.Proposal (actors.StorageDealProposal) (struct)
{
@ -612,7 +612,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.State (uint64)
// t.t.State (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -621,8 +621,8 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.State = extra
// t.t.Miner (peer.ID)
t.State = uint64(extra)
// t.t.Miner (peer.ID) (string)
{
sval, err := cbg.ReadString(br)
@ -644,7 +644,7 @@ func (t *MinerDeal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Client (peer.ID)
// t.t.Client (peer.ID) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Client)))); err != nil {
return err
}
@ -652,35 +652,35 @@ func (t *MinerDeal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Proposal (actors.StorageDealProposal)
// t.t.Proposal (actors.StorageDealProposal) (struct)
if err := t.Proposal.MarshalCBOR(w); err != nil {
return err
}
// t.t.ProposalCid (cid.Cid)
// t.t.ProposalCid (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ProposalCid); err != nil {
return xerrors.Errorf("failed to write cid field t.ProposalCid: %w", err)
}
// t.t.State (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.State)); err != nil {
// t.t.State (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil {
return err
}
// t.t.Ref (cid.Cid)
// t.t.Ref (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Ref); err != nil {
return xerrors.Errorf("failed to write cid field t.Ref: %w", err)
}
// t.t.DealID (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.DealID)); err != nil {
// t.t.DealID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.DealID))); err != nil {
return err
}
// t.t.SectorID (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.SectorID)); err != nil {
// t.t.SectorID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorID))); err != nil {
return err
}
return nil
@ -701,7 +701,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Client (peer.ID)
// t.t.Client (peer.ID) (string)
{
sval, err := cbg.ReadString(br)
@ -711,7 +711,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
t.Client = peer.ID(sval)
}
// t.t.Proposal (actors.StorageDealProposal)
// t.t.Proposal (actors.StorageDealProposal) (struct)
{
@ -720,7 +720,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.ProposalCid (cid.Cid)
// t.t.ProposalCid (cid.Cid) (struct)
{
@ -732,7 +732,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
t.ProposalCid = c
}
// t.t.State (uint64)
// t.t.State (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -741,8 +741,8 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.State = extra
// t.t.Ref (cid.Cid)
t.State = uint64(extra)
// t.t.Ref (cid.Cid) (struct)
{
@ -754,7 +754,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
t.Ref = c
}
// t.t.DealID (uint64)
// t.t.DealID (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -763,8 +763,8 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.DealID = extra
// t.t.SectorID (uint64)
t.DealID = uint64(extra)
// t.t.SectorID (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -773,6 +773,6 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.SectorID = extra
t.SectorID = uint64(extra)
return nil
}

View File

@ -75,7 +75,7 @@ func (m mybs) Get(c cid.Cid) (block.Block, error) {
func NewGenerator() (*ChainGen, error) {
mr := repo.NewMemory(nil)
lr, err := mr.Lock()
lr, err := mr.Lock(repo.RepoStorageMiner)
if err != nil {
return nil, xerrors.Errorf("taking mem-repo lock failed: %w", err)
}
@ -279,12 +279,6 @@ func (cg *ChainGen) NextTipSetFromMiners(base *types.TipSet, miners []address.Ad
}
fts := store.NewFullTipSet(blks)
/*fmt.Println("Made a block: ", fts.TipSet().Cids())
if len(fts.TipSet().Cids()) > 1 {
for _, b := range blks {
fmt.Printf("block %s: %#v\n", b.Cid(), b.Header)
}
}*/
return &MinedTipSet{
TipSet: fts,

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/ipfs/go-cid"
"go.opencensus.io/trace"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/chain/actors"
@ -14,6 +15,9 @@ import (
)
func (sm *StateManager) CallRaw(ctx context.Context, msg *types.Message, bstate cid.Cid, r vm.Rand, bheight uint64) (*types.MessageReceipt, error) {
ctx, span := trace.StartSpan(ctx, "statemanager.CallRaw")
defer span.End()
vmi, err := vm.NewVM(bstate, bheight, r, actors.NetworkAddress, sm.cs.Blockstore())
if err != nil {
return nil, xerrors.Errorf("failed to set up vm: %w", err)
@ -29,6 +33,14 @@ func (sm *StateManager) CallRaw(ctx context.Context, msg *types.Message, bstate
msg.Value = types.NewInt(0)
}
if span.IsRecordingEvents() {
span.AddAttributes(
trace.Int64Attribute("gas_limit", int64(msg.GasLimit.Uint64())),
trace.Int64Attribute("gas_price", int64(msg.GasPrice.Uint64())),
trace.StringAttribute("value", msg.Value.String()),
)
}
fromActor, err := vmi.StateTree().GetActor(msg.From)
if err != nil {
return nil, xerrors.Errorf("call raw get actor: %s", err)

View File

@ -23,12 +23,12 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Miner (address.Address)
// t.t.Miner (address.Address) (struct)
if err := t.Miner.MarshalCBOR(w); err != nil {
return err
}
// t.t.Tickets ([]*types.Ticket)
// t.t.Tickets ([]*types.Ticket) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Tickets)))); err != nil {
return err
}
@ -38,7 +38,7 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
}
}
// t.t.ElectionProof ([]uint8)
// t.t.ElectionProof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.ElectionProof)))); err != nil {
return err
}
@ -46,7 +46,7 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Parents ([]cid.Cid)
// t.t.Parents ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Parents)))); err != nil {
return err
}
@ -56,45 +56,45 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
}
}
// t.t.ParentWeight (types.BigInt)
// t.t.ParentWeight (types.BigInt) (struct)
if err := t.ParentWeight.MarshalCBOR(w); err != nil {
return err
}
// t.t.Height (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Height)); err != nil {
// t.t.Height (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Height))); err != nil {
return err
}
// t.t.ParentStateRoot (cid.Cid)
// t.t.ParentStateRoot (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ParentStateRoot); err != nil {
return xerrors.Errorf("failed to write cid field t.ParentStateRoot: %w", err)
}
// t.t.ParentMessageReceipts (cid.Cid)
// t.t.ParentMessageReceipts (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ParentMessageReceipts); err != nil {
return xerrors.Errorf("failed to write cid field t.ParentMessageReceipts: %w", err)
}
// t.t.Messages (cid.Cid)
// t.t.Messages (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Messages); err != nil {
return xerrors.Errorf("failed to write cid field t.Messages: %w", err)
}
// t.t.BLSAggregate (types.Signature)
// t.t.BLSAggregate (types.Signature) (struct)
if err := t.BLSAggregate.MarshalCBOR(w); err != nil {
return err
}
// t.t.Timestamp (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Timestamp)); err != nil {
// t.t.Timestamp (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Timestamp))); err != nil {
return err
}
// t.t.BlockSig (types.Signature)
// t.t.BlockSig (types.Signature) (struct)
if err := t.BlockSig.MarshalCBOR(w); err != nil {
return err
}
@ -116,7 +116,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Miner (address.Address)
// t.t.Miner (address.Address) (struct)
{
@ -125,7 +125,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Tickets ([]*types.Ticket)
// t.t.Tickets ([]*types.Ticket) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -151,7 +151,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.Tickets[i] = &v
}
// t.t.ElectionProof ([]uint8)
// t.t.ElectionProof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -168,7 +168,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.ElectionProof); err != nil {
return err
}
// t.t.Parents ([]cid.Cid)
// t.t.Parents ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -193,7 +193,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.Parents[i] = c
}
// t.t.ParentWeight (types.BigInt)
// t.t.ParentWeight (types.BigInt) (struct)
{
@ -202,7 +202,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Height (uint64)
// t.t.Height (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -211,8 +211,8 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Height = extra
// t.t.ParentStateRoot (cid.Cid)
t.Height = uint64(extra)
// t.t.ParentStateRoot (cid.Cid) (struct)
{
@ -224,7 +224,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.ParentStateRoot = c
}
// t.t.ParentMessageReceipts (cid.Cid)
// t.t.ParentMessageReceipts (cid.Cid) (struct)
{
@ -236,7 +236,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.ParentMessageReceipts = c
}
// t.t.Messages (cid.Cid)
// t.t.Messages (cid.Cid) (struct)
{
@ -248,7 +248,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.Messages = c
}
// t.t.BLSAggregate (types.Signature)
// t.t.BLSAggregate (types.Signature) (struct)
{
@ -257,7 +257,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Timestamp (uint64)
// t.t.Timestamp (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -266,8 +266,8 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Timestamp = extra
// t.t.BlockSig (types.Signature)
t.Timestamp = uint64(extra)
// t.t.BlockSig (types.Signature) (struct)
{
@ -288,7 +288,7 @@ func (t *Ticket) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.VRFProof ([]uint8)
// t.t.VRFProof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.VRFProof)))); err != nil {
return err
}
@ -313,7 +313,7 @@ func (t *Ticket) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.VRFProof ([]uint8)
// t.t.VRFProof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -342,42 +342,42 @@ func (t *Message) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.To (address.Address)
// t.t.To (address.Address) (struct)
if err := t.To.MarshalCBOR(w); err != nil {
return err
}
// t.t.From (address.Address)
// t.t.From (address.Address) (struct)
if err := t.From.MarshalCBOR(w); err != nil {
return err
}
// t.t.Nonce (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Nonce)); err != nil {
// t.t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err
}
// t.t.Value (types.BigInt)
// t.t.Value (types.BigInt) (struct)
if err := t.Value.MarshalCBOR(w); err != nil {
return err
}
// t.t.GasPrice (types.BigInt)
// t.t.GasPrice (types.BigInt) (struct)
if err := t.GasPrice.MarshalCBOR(w); err != nil {
return err
}
// t.t.GasLimit (types.BigInt)
// t.t.GasLimit (types.BigInt) (struct)
if err := t.GasLimit.MarshalCBOR(w); err != nil {
return err
}
// t.t.Method (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Method)); err != nil {
// t.t.Method (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Method))); err != nil {
return err
}
// t.t.Params ([]uint8)
// t.t.Params ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Params)))); err != nil {
return err
}
@ -402,7 +402,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.To (address.Address)
// t.t.To (address.Address) (struct)
{
@ -411,7 +411,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.From (address.Address)
// t.t.From (address.Address) (struct)
{
@ -420,7 +420,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Nonce (uint64)
// t.t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -429,8 +429,8 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Nonce = extra
// t.t.Value (types.BigInt)
t.Nonce = uint64(extra)
// t.t.Value (types.BigInt) (struct)
{
@ -439,7 +439,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.GasPrice (types.BigInt)
// t.t.GasPrice (types.BigInt) (struct)
{
@ -448,7 +448,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.GasLimit (types.BigInt)
// t.t.GasLimit (types.BigInt) (struct)
{
@ -457,7 +457,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Method (uint64)
// t.t.Method (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -466,8 +466,8 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Method = extra
// t.t.Params ([]uint8)
t.Method = uint64(extra)
// t.t.Params ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -496,12 +496,12 @@ func (t *SignedMessage) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Message (types.Message)
// t.t.Message (types.Message) (struct)
if err := t.Message.MarshalCBOR(w); err != nil {
return err
}
// t.t.Signature (types.Signature)
// t.t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil {
return err
}
@ -523,7 +523,7 @@ func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Message (types.Message)
// t.t.Message (types.Message) (struct)
{
@ -532,7 +532,7 @@ func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Signature (types.Signature)
// t.t.Signature (types.Signature) (struct)
{
@ -553,13 +553,13 @@ func (t *MsgMeta) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.BlsMessages (cid.Cid)
// t.t.BlsMessages (cid.Cid) (struct)
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)
// t.t.SecpkMessages (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.SecpkMessages); err != nil {
return xerrors.Errorf("failed to write cid field t.SecpkMessages: %w", err)
@ -583,7 +583,7 @@ func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.BlsMessages (cid.Cid)
// t.t.BlsMessages (cid.Cid) (struct)
{
@ -595,7 +595,7 @@ func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error {
t.BlsMessages = c
}
// t.t.SecpkMessages (cid.Cid)
// t.t.SecpkMessages (cid.Cid) (struct)
{
@ -619,12 +619,12 @@ func (t *SignedVoucher) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.TimeLock (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.TimeLock)); err != nil {
// t.t.TimeLock (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.TimeLock))); err != nil {
return err
}
// t.t.SecretPreimage ([]uint8)
// t.t.SecretPreimage ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.SecretPreimage)))); err != nil {
return err
}
@ -632,32 +632,32 @@ func (t *SignedVoucher) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Extra (types.ModVerifyParams)
// t.t.Extra (types.ModVerifyParams) (struct)
if err := t.Extra.MarshalCBOR(w); err != nil {
return err
}
// t.t.Lane (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Lane)); err != nil {
// t.t.Lane (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Lane))); err != nil {
return err
}
// t.t.Nonce (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Nonce)); err != nil {
// t.t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err
}
// t.t.Amount (types.BigInt)
// t.t.Amount (types.BigInt) (struct)
if err := t.Amount.MarshalCBOR(w); err != nil {
return err
}
// t.t.MinCloseHeight (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.MinCloseHeight)); err != nil {
// t.t.MinCloseHeight (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.MinCloseHeight))); err != nil {
return err
}
// t.t.Merges ([]types.Merge)
// t.t.Merges ([]types.Merge) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Merges)))); err != nil {
return err
}
@ -667,7 +667,7 @@ func (t *SignedVoucher) MarshalCBOR(w io.Writer) error {
}
}
// t.t.Signature (types.Signature)
// t.t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil {
return err
}
@ -689,7 +689,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.TimeLock (uint64)
// t.t.TimeLock (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -698,8 +698,8 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.TimeLock = extra
// t.t.SecretPreimage ([]uint8)
t.TimeLock = uint64(extra)
// t.t.SecretPreimage ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -716,7 +716,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.SecretPreimage); err != nil {
return err
}
// t.t.Extra (types.ModVerifyParams)
// t.t.Extra (types.ModVerifyParams) (struct)
{
@ -737,7 +737,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Lane (uint64)
// t.t.Lane (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -746,8 +746,8 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Lane = extra
// t.t.Nonce (uint64)
t.Lane = uint64(extra)
// t.t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -756,8 +756,8 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Nonce = extra
// t.t.Amount (types.BigInt)
t.Nonce = uint64(extra)
// t.t.Amount (types.BigInt) (struct)
{
@ -766,7 +766,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.MinCloseHeight (uint64)
// t.t.MinCloseHeight (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -775,8 +775,8 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.MinCloseHeight = extra
// t.t.Merges ([]types.Merge)
t.MinCloseHeight = uint64(extra)
// t.t.Merges ([]types.Merge) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -802,7 +802,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
t.Merges[i] = v
}
// t.t.Signature (types.Signature)
// t.t.Signature (types.Signature) (struct)
{
@ -835,17 +835,17 @@ func (t *ModVerifyParams) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Actor (address.Address)
// t.t.Actor (address.Address) (struct)
if err := t.Actor.MarshalCBOR(w); err != nil {
return err
}
// t.t.Method (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Method)); err != nil {
// t.t.Method (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Method))); err != nil {
return err
}
// t.t.Data ([]uint8)
// t.t.Data ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Data)))); err != nil {
return err
}
@ -870,7 +870,7 @@ func (t *ModVerifyParams) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Actor (address.Address)
// t.t.Actor (address.Address) (struct)
{
@ -879,7 +879,7 @@ func (t *ModVerifyParams) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Method (uint64)
// t.t.Method (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -888,8 +888,8 @@ func (t *ModVerifyParams) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Method = extra
// t.t.Data ([]uint8)
t.Method = uint64(extra)
// t.t.Data ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -918,13 +918,13 @@ func (t *Merge) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Lane (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Lane)); err != nil {
// t.t.Lane (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Lane))); err != nil {
return err
}
// t.t.Nonce (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Nonce)); err != nil {
// t.t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err
}
return nil
@ -945,7 +945,7 @@ func (t *Merge) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Lane (uint64)
// t.t.Lane (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -954,8 +954,8 @@ func (t *Merge) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Lane = extra
// t.t.Nonce (uint64)
t.Lane = uint64(extra)
// t.t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -964,7 +964,7 @@ func (t *Merge) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Nonce = extra
t.Nonce = uint64(extra)
return nil
}
@ -977,24 +977,24 @@ func (t *Actor) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Code (cid.Cid)
// t.t.Code (cid.Cid) (struct)
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)
// t.t.Head (cid.Cid) (struct)
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 {
// t.t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err
}
// t.t.Balance (types.BigInt)
// t.t.Balance (types.BigInt) (struct)
if err := t.Balance.MarshalCBOR(w); err != nil {
return err
}
@ -1016,7 +1016,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Code (cid.Cid)
// t.t.Code (cid.Cid) (struct)
{
@ -1028,7 +1028,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
t.Code = c
}
// t.t.Head (cid.Cid)
// t.t.Head (cid.Cid) (struct)
{
@ -1040,7 +1040,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
t.Head = c
}
// t.t.Nonce (uint64)
// t.t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1049,8 +1049,8 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Nonce = extra
// t.t.Balance (types.BigInt)
t.Nonce = uint64(extra)
// t.t.Balance (types.BigInt) (struct)
{
@ -1071,12 +1071,12 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.ExitCode (uint8)
// t.t.ExitCode (uint8) (uint8)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ExitCode))); err != nil {
return err
}
// t.t.Return ([]uint8)
// t.t.Return ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Return)))); err != nil {
return err
}
@ -1084,7 +1084,7 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.GasUsed (types.BigInt)
// t.t.GasUsed (types.BigInt) (struct)
if err := t.GasUsed.MarshalCBOR(w); err != nil {
return err
}
@ -1106,7 +1106,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.ExitCode (uint8)
// t.t.ExitCode (uint8) (uint8)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1119,7 +1119,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("integer in input was too large for uint8 field")
}
t.ExitCode = uint8(extra)
// t.t.Return ([]uint8)
// t.t.Return ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1136,7 +1136,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.Return); err != nil {
return err
}
// t.t.GasUsed (types.BigInt)
// t.t.GasUsed (types.BigInt) (struct)
{
@ -1157,12 +1157,12 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Header (types.BlockHeader)
// t.t.Header (types.BlockHeader) (struct)
if err := t.Header.MarshalCBOR(w); err != nil {
return err
}
// t.t.BlsMessages ([]cid.Cid)
// t.t.BlsMessages ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BlsMessages)))); err != nil {
return err
}
@ -1172,7 +1172,7 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error {
}
}
// t.t.SecpkMessages ([]cid.Cid)
// t.t.SecpkMessages ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.SecpkMessages)))); err != nil {
return err
}
@ -1199,7 +1199,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Header (types.BlockHeader)
// t.t.Header (types.BlockHeader) (struct)
{
@ -1220,7 +1220,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.BlsMessages ([]cid.Cid)
// t.t.BlsMessages ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1245,7 +1245,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error {
t.BlsMessages[i] = c
}
// t.t.SecpkMessages ([]cid.Cid)
// t.t.SecpkMessages ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1282,12 +1282,12 @@ func (t *SignedStorageAsk) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Ask (types.StorageAsk)
// t.t.Ask (types.StorageAsk) (struct)
if err := t.Ask.MarshalCBOR(w); err != nil {
return err
}
// t.t.Signature (types.Signature)
// t.t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil {
return err
}
@ -1309,7 +1309,7 @@ func (t *SignedStorageAsk) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Ask (types.StorageAsk)
// t.t.Ask (types.StorageAsk) (struct)
{
@ -1330,7 +1330,7 @@ func (t *SignedStorageAsk) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Signature (types.Signature)
// t.t.Signature (types.Signature) (struct)
{
@ -1363,33 +1363,33 @@ func (t *StorageAsk) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Price (types.BigInt)
// t.t.Price (types.BigInt) (struct)
if err := t.Price.MarshalCBOR(w); err != nil {
return err
}
// t.t.MinPieceSize (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.MinPieceSize)); err != nil {
// t.t.MinPieceSize (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.MinPieceSize))); err != nil {
return err
}
// t.t.Miner (address.Address)
// t.t.Miner (address.Address) (struct)
if err := t.Miner.MarshalCBOR(w); err != nil {
return err
}
// t.t.Timestamp (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Timestamp)); err != nil {
// t.t.Timestamp (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Timestamp))); err != nil {
return err
}
// t.t.Expiry (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.Expiry)); err != nil {
// t.t.Expiry (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Expiry))); err != nil {
return err
}
// t.t.SeqNo (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.SeqNo)); err != nil {
// t.t.SeqNo (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SeqNo))); err != nil {
return err
}
return nil
@ -1410,7 +1410,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Price (types.BigInt)
// t.t.Price (types.BigInt) (struct)
{
@ -1419,7 +1419,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.MinPieceSize (uint64)
// t.t.MinPieceSize (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1428,8 +1428,8 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.MinPieceSize = extra
// t.t.Miner (address.Address)
t.MinPieceSize = uint64(extra)
// t.t.Miner (address.Address) (struct)
{
@ -1438,7 +1438,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Timestamp (uint64)
// t.t.Timestamp (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1447,8 +1447,8 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Timestamp = extra
// t.t.Expiry (uint64)
t.Timestamp = uint64(extra)
// t.t.Expiry (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1457,8 +1457,8 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Expiry = extra
// t.t.SeqNo (uint64)
t.Expiry = uint64(extra)
// t.t.SeqNo (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1467,7 +1467,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.SeqNo = extra
t.SeqNo = uint64(extra)
return nil
}

View File

@ -104,9 +104,15 @@ func NewTipSet(blks []*BlockHeader) (*TipSet, error) {
if b.Height != blks[0].Height {
return nil, fmt.Errorf("cannot create tipset with mismatching heights")
}
for i, cid := range b.Parents {
if cid != blks[0].Parents[i] {
return nil, fmt.Errorf("cannot create tipset with mismatching parents")
}
}
ts.cids = append(ts.cids, b.Cid())
// TODO: ensure the same parents
}
ts.height = blks[0].Height

View File

@ -5,6 +5,7 @@ import (
"encoding/base64"
"github.com/filecoin-project/lotus/chain/address"
cborrpc "github.com/filecoin-project/lotus/lib/cborrpc"
cbor "github.com/ipfs/go-ipld-cbor"
)
@ -46,13 +47,13 @@ func (sv *SignedVoucher) EncodedString() (string, error) {
func (sv *SignedVoucher) Equals(other *SignedVoucher) bool {
// TODO: make this less bad
selfB, err := cbor.DumpObject(sv)
selfB, err := cborrpc.Dump(sv)
if err != nil {
log.Errorf("SignedVoucher.Equals: dump self: %s", err)
return false
}
otherB, err := cbor.DumpObject(other)
otherB, err := cborrpc.Dump(other)
if err != nil {
log.Errorf("SignedVoucher.Equals: dump other: %s", err)
return false

View File

@ -229,11 +229,12 @@ var clientRetrieveCmd = &cli.Command{
order := offers[0].Order()
order.Client = payer
err = api.ClientRetrieve(ctx, order, cctx.Args().Get(1))
if err == nil {
fmt.Println("Success")
if err := api.ClientRetrieve(ctx, order, cctx.Args().Get(1)); err != nil {
return err
}
return err
fmt.Println("Success")
return nil
},
}

View File

@ -122,6 +122,7 @@ var Commands = []*cli.Command{
sendCmd,
stateCmd,
syncCmd,
unregisterMinerCmd,
versionCmd,
walletCmd,
}

32
cli/miner.go Normal file
View File

@ -0,0 +1,32 @@
package cli
import (
"fmt"
"github.com/filecoin-project/lotus/chain/address"
"gopkg.in/urfave/cli.v2"
)
var unregisterMinerCmd = &cli.Command{
Name: "unregister-miner",
Usage: "Manually unregister miner actor",
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must pass address of miner to unregister")
}
maddr, err := address.NewFromString(cctx.Args().First())
if err != nil {
return err
}
return api.MinerUnregister(ctx, maddr)
},
}

View File

@ -20,6 +20,7 @@ var stateCmd = &cli.Command{
statePledgeCollateralCmd,
stateListActorsCmd,
stateListMinersCmd,
stateGetActorCmd,
},
}
@ -251,3 +252,39 @@ var stateListActorsCmd = &cli.Command{
return nil
},
}
var stateGetActorCmd = &cli.Command{
Name: "get-actor",
Usage: "Print actor information",
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must pass address of actor to get")
}
addr, err := address.NewFromString(cctx.Args().First())
if err != nil {
return err
}
a, err := api.StateGetActor(ctx, addr, nil)
if err != nil {
return err
}
fmt.Printf("Address:\t%s\n", addr)
fmt.Printf("Balance:\t%s\n", types.FIL(a.Balance))
fmt.Printf("Nonce:\t\t%d\n", a.Nonce)
fmt.Printf("Code:\t\t%s\n", a.Code)
fmt.Printf("Head:\t\t%s\n", a.Head)
return nil
},
}

View File

@ -136,19 +136,6 @@ type handler struct {
}
func (h *handler) send(w http.ResponseWriter, r *http.Request) {
// General limiter to allow throttling all messages that can make it into the mpool
if !h.limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
// Limit based on IP
limiter := h.limiter.GetIPLimiter(r.RemoteAddr)
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
to, err := address.NewFromString(r.FormValue("address"))
if err != nil {
w.WriteHeader(400)
@ -157,12 +144,25 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) {
}
// Limit based on wallet address
limiter = h.limiter.GetWalletLimiter(to.String())
limiter := h.limiter.GetWalletLimiter(to.String())
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
// Limit based on IP
limiter = h.limiter.GetIPLimiter(r.RemoteAddr)
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
// General limiter to allow throttling all messages that can make it into the mpool
if !h.limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
smsg, err := h.api.MpoolPushMessage(h.ctx, &types.Message{
Value: sendPerRequest,
From: h.from,
@ -181,19 +181,6 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) {
}
func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
// General limiter owner allow throttling all messages that can make it into the mpool
if !h.colLimiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
// Limit based on IP
limiter := h.colLimiter.GetIPLimiter(r.RemoteAddr)
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
owner, err := address.NewFromString(r.FormValue("address"))
if err != nil {
w.WriteHeader(400)
@ -215,11 +202,25 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
log.Infof("mkactor on %s", owner)
// Limit based on wallet address
limiter = h.colLimiter.GetWalletLimiter(owner.String())
limiter := h.colLimiter.GetWalletLimiter(owner.String())
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
// Limit based on IP
limiter = h.colLimiter.GetIPLimiter(r.RemoteAddr)
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
// General limiter owner allow throttling all messages that can make it into the mpool
if !h.colLimiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
collateral, err := h.api.StatePledgeCollateral(r.Context(), nil)
if err != nil {
w.WriteHeader(400)

View File

@ -101,7 +101,7 @@ var initCmd = &cli.Command{
log.Info("Initializing repo")
if err := r.Init(); err != nil {
if err := r.Init(repo.RepoStorageMiner); err != nil {
return err
}
@ -122,7 +122,7 @@ var initCmd = &cli.Command{
}
func storageMinerInit(ctx context.Context, cctx *cli.Context, api api.FullNode, r repo.Repo) error {
lr, err := r.Lock()
lr, err := r.Lock(repo.RepoStorageMiner)
if err != nil {
return err
}

View File

@ -54,7 +54,7 @@ var DaemonCmd = &cli.Command{
return err
}
if err := r.Init(); err != nil && err != repo.ErrRepoExists {
if err := r.Init(repo.RepoFullNode); err != nil && err != repo.ErrRepoExists {
return err
}

View File

@ -6,9 +6,12 @@ import (
gen "github.com/whyrusleeping/cbor-gen"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/deals"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/paych"
"github.com/filecoin-project/lotus/retrieval"
"github.com/filecoin-project/lotus/storage"
)
@ -34,6 +37,38 @@ func main() {
os.Exit(1)
}
err = gen.WriteTupleEncodersToFile("./paych/cbor_gen.go", "paych",
paych.VoucherInfo{},
paych.ChannelInfo{},
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = gen.WriteTupleEncodersToFile("./api/cbor_gen.go", "api",
api.PaymentInfo{},
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = gen.WriteTupleEncodersToFile("./retrieval/cbor_gen.go", "retrieval",
retrieval.RetParams{},
retrieval.Query{},
retrieval.QueryResponse{},
retrieval.Unixfs0Offer{},
retrieval.DealProposal{},
retrieval.DealResponse{},
retrieval.Block{},
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
/*
err = gen.WriteTupleEncodersToFile("./chain/cbor_gen.go", "chain",
chain.BlockSyncRequest{},

4
go.mod
View File

@ -73,7 +73,7 @@ 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-20191001154818-b4b5288fcb86
github.com/whyrusleeping/cbor-gen v0.0.0-20191104210213-4418c8842f0f
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d
go.opencensus.io v0.22.0
@ -84,7 +84,7 @@ require (
go.uber.org/zap v1.10.0
go4.org v0.0.0-20190313082347-94abd6928b1d // indirect
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 // indirect
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
google.golang.org/api v0.9.0 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28

6
go.sum
View File

@ -629,8 +629,8 @@ github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba h1:X4n8JG2e2
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba/go.mod h1:CHQnYnQUEPydYCwuy8lmTHfGmdw9TKrhWV0xLx8l0oM=
github.com/whyrusleeping/cbor-gen v0.0.0-20190910031516-c1cbffdb01bb/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20190917003517-d78d67427694/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20191001154818-b4b5288fcb86 h1:cE8mRdI9JQAheSlIAkjJIpdAOPjYOzxSADaro6LNHnY=
github.com/whyrusleeping/cbor-gen v0.0.0-20191001154818-b4b5288fcb86/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20191104210213-4418c8842f0f h1:+GFA37QICd1Axd2n9uzjtvPjxJJI5PU78vpvam+hI4U=
github.com/whyrusleeping/cbor-gen v0.0.0-20191104210213-4418c8842f0f/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=
@ -762,6 +762,8 @@ golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20170915040203-e531a2a1c15f/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

View File

@ -137,6 +137,7 @@ func (c *client) makeOutChan(ctx context.Context, ftyp reflect.Type, valOut int)
// unpack chan type to make sure it's reflect.BothDir
ctyp := reflect.ChanOf(reflect.BothDir, ftyp.Out(valOut).Elem())
ch := reflect.MakeChan(ctyp, 0) // todo: buffer?
chCtx, chCancel := context.WithCancel(ctx)
retVal = ch.Convert(ftyp.Out(valOut))
buf := (&list.List{}).Init()
@ -144,6 +145,7 @@ func (c *client) makeOutChan(ctx context.Context, ftyp reflect.Type, valOut int)
return ctx, func(result []byte, ok bool) {
if !ok {
chCancel()
// remote channel closed, close ours too
ch.Close()
return
@ -173,13 +175,29 @@ func (c *client) makeOutChan(ctx context.Context, ftyp reflect.Type, valOut int)
go func() {
for buf.Len() > 0 {
front := buf.Front()
bufLk.Unlock()
ch.Send(front.Value.(reflect.Value).Elem()) // todo: select on ctx is probably a good idea
cases := []reflect.SelectCase{
{
Dir: reflect.SelectRecv,
Chan: reflect.ValueOf(chCtx.Done()),
},
{
Dir: reflect.SelectSend,
Chan: ch,
Send: front.Value.(reflect.Value).Elem(),
},
}
chosen, _, _ := reflect.Select(cases)
bufLk.Lock()
buf.Remove(front)
switch chosen {
case 0:
buf.Init()
case 1:
buf.Remove(front)
}
}
bufLk.Unlock()

46
lib/sectorbuilder/mock.go Normal file
View File

@ -0,0 +1,46 @@
package sectorbuilder
import (
"io/ioutil"
"os"
"path/filepath"
"github.com/filecoin-project/lotus/chain/address"
)
func TempSectorbuilder(sectorSize uint64) (*SectorBuilder, func(), error) {
dir, err := ioutil.TempDir("", "sbtest")
if err != nil {
return nil, nil, err
}
addr, err := address.NewFromString("t3vfxagwiegrywptkbmyohqqbfzd7xzbryjydmxso4hfhgsnv6apddyihltsbiikjf3lm7x2myiaxhuc77capq")
if err != nil {
return nil, nil, err
}
metadata := filepath.Join(dir, "meta")
sealed := filepath.Join(dir, "sealed")
staging := filepath.Join(dir, "staging")
cache := filepath.Join(dir, "cache")
sb, err := New(&Config{
SectorSize: sectorSize,
SealedDir: sealed,
StagedDir: staging,
MetadataDir: metadata,
CacheDir: cache,
WorkerThreads: 2,
Miner: addr,
})
if err != nil {
return nil, nil, err
}
return sb, func() {
if err := os.RemoveAll(dir); err != nil {
log.Warn("failed to clean up temp sectorbuilder: ", err)
}
}, nil
}

View File

@ -41,6 +41,8 @@ const CommLen = sectorbuilder.CommitmentBytesLen
type SectorBuilder struct {
handle unsafe.Pointer
Miner address.Address
rateLimit chan struct{}
}
@ -69,7 +71,8 @@ func New(cfg *Config) (*SectorBuilder, error) {
}
return &SectorBuilder{
handle: sbp,
handle: sbp,
Miner: cfg.Miner,
rateLimit: make(chan struct{}, cfg.WorkerThreads-PoStReservedWorkers),
}, nil
}

View File

@ -2,13 +2,10 @@ package sectorbuilder_test
import (
"io"
"io/ioutil"
"math/rand"
"path/filepath"
"testing"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/lib/sectorbuilder"
)
@ -24,35 +21,11 @@ func TestSealAndVerify(t *testing.T) {
t.Fatal(err)
}
dir, err := ioutil.TempDir("", "sbtest")
if err != nil {
t.Fatal(err)
}
addr, err := address.NewFromString("t3vfxagwiegrywptkbmyohqqbfzd7xzbryjydmxso4hfhgsnv6apddyihltsbiikjf3lm7x2myiaxhuc77capq")
if err != nil {
t.Fatal(err)
}
cache := filepath.Join(dir, "cache")
metadata := filepath.Join(dir, "meta")
sealed := filepath.Join(dir, "sealed")
staging := filepath.Join(dir, "staging")
sb, err := sectorbuilder.New(&sectorbuilder.Config{
SectorSize: sectorSize,
Miner: addr,
WorkerThreads: 2,
CacheDir: cache,
SealedDir: sealed,
StagedDir: staging,
MetadataDir: metadata,
})
sb, cleanup, err := sectorbuilder.TempSectorbuilder(sectorSize)
if err != nil {
t.Fatal(err)
}
defer cleanup()
dlen := sectorbuilder.UserBytesForSectorSize(sectorSize)
@ -82,7 +55,7 @@ func TestSealAndVerify(t *testing.T) {
t.Fatal(err)
}
ok, err := sectorbuilder.VerifySeal(sectorSize, pco.CommR[:], pco.CommD[:], addr, ticket.TicketBytes[:], seed.TicketBytes[:], sid, sco.Proof)
ok, err := sectorbuilder.VerifySeal(sectorSize, pco.CommR[:], pco.CommD[:], sb.Miner, ticket.TicketBytes[:], seed.TicketBytes[:], sid, sco.Proof)
if err != nil {
t.Fatal(err)
}

View File

@ -15,6 +15,7 @@ import (
pubsub "github.com/libp2p/go-libp2p-pubsub"
record "github.com/libp2p/go-libp2p-record"
"go.uber.org/fx"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain"
@ -99,11 +100,6 @@ const (
_nInvokes // keep this last
)
const (
nodeFull = iota
nodeStorageMiner
)
type Settings struct {
// modules is a map of constructors for DI
//
@ -116,14 +112,12 @@ type Settings struct {
// type, and must be applied in correct order
invokes []fx.Option
nodeType int
nodeType repo.RepoType
Online bool // Online option applied
Config bool // Config option applied
}
var defConf = config.Default()
func defaults() []Option {
return []Option{
Override(new(helpers.MetricsCtx), context.Background),
@ -160,10 +154,14 @@ func libp2p() Option {
Override(new(*pubsub.PubSub), lp2p.GossipSub()),
Override(PstoreAddSelfKeysKey, lp2p.PstoreAddSelfKeys),
Override(StartListeningKey, lp2p.StartListening(defConf.Libp2p.ListenAddresses)),
Override(StartListeningKey, lp2p.StartListening(config.DefaultFullNode().Libp2p.ListenAddresses)),
)
}
func isType(t repo.RepoType) func(s *Settings) bool {
return func(s *Settings) bool { return s.nodeType == t }
}
// Online sets up basic libp2p node
func Online() Option {
return Options(
@ -180,7 +178,7 @@ func Online() Option {
// Full node
ApplyIf(func(s *Settings) bool { return s.nodeType == nodeFull },
ApplyIf(isType(repo.RepoFullNode),
// TODO: Fix offline mode
Override(new(dtypes.BootstrapPeers), modules.BuiltinBootstrap),
@ -229,7 +227,7 @@ func Online() Option {
),
// Storage miner
ApplyIf(func(s *Settings) bool { return s.nodeType == nodeStorageMiner },
ApplyIf(func(s *Settings) bool { return s.nodeType == repo.RepoStorageMiner },
Override(new(*sectorbuilder.SectorBuilder), sectorbuilder.New),
Override(new(*sector.Store), sector.NewStore),
Override(new(*sectorblocks.SectorBlocks), sectorblocks.NewSectorBlocks),
@ -257,7 +255,7 @@ func StorageMiner(out *api.StorageMiner) Option {
),
func(s *Settings) error {
s.nodeType = nodeStorageMiner
s.nodeType = repo.RepoStorageMiner
return nil
},
@ -271,7 +269,7 @@ func StorageMiner(out *api.StorageMiner) Option {
}
// Config sets up constructors based on the provided Config
func Config(cfg *config.Root) Option {
func ConfigCommon(cfg *config.Common) Option {
return Options(
func(s *Settings) error { s.Config = true; return nil },
@ -281,45 +279,71 @@ func Config(cfg *config.Root) Option {
ApplyIf(func(s *Settings) bool { return len(cfg.Libp2p.BootstrapPeers) > 0 },
Override(new(dtypes.BootstrapPeers), modules.ConfigBootstrap(cfg.Libp2p.BootstrapPeers)),
),
ApplyIf(func(s *Settings) bool { return s.nodeType == nodeFull },
Override(HeadMetricsKey, metrics.SendHeadNotifs(cfg.Metrics.Nickname)),
),
),
)
}
func Repo(r repo.Repo) Option {
lr, err := r.Lock()
if err != nil {
return Error(err)
}
cfg, err := lr.Config()
if err != nil {
return Error(err)
}
func ConfigFullNode(cfg *config.FullNode) Option {
//ApplyIf(func(s *Settings) bool { return s.nodeType == repo.RepoFullNode }),
return Options(
Config(cfg),
Override(new(repo.LockedRepo), modules.LockedRepo(lr)), // module handles closing
Override(new(dtypes.MetadataDS), modules.Datastore),
Override(new(dtypes.ChainBlockstore), modules.ChainBlockstore),
Override(new(dtypes.ClientFilestore), modules.ClientFstore),
Override(new(dtypes.ClientBlockstore), modules.ClientBlockstore),
Override(new(dtypes.ClientDAG), modules.ClientDAG),
Override(new(ci.PrivKey), lp2p.PrivKey),
Override(new(ci.PubKey), ci.PrivKey.GetPublic),
Override(new(peer.ID), peer.IDFromPublicKey),
Override(new(types.KeyStore), modules.KeyStore),
Override(new(*dtypes.APIAlg), modules.APISecret),
ConfigCommon(&cfg.Common),
Override(HeadMetricsKey, metrics.SendHeadNotifs(cfg.Metrics.Nickname)),
)
}
func configFull(c interface{}) Option {
cfg, ok := c.(*config.FullNode)
if !ok {
return Error(xerrors.Errorf("invalid config from repo, got: %T", c))
}
return ConfigFullNode(cfg)
}
func configMiner(c interface{}) Option {
cfg, ok := c.(*config.StorageMiner)
if !ok {
return Error(xerrors.Errorf("invalid config from repo, got: %T", c))
}
return ConfigCommon(&cfg.Common)
}
func Repo(r repo.Repo) Option {
return func(settings *Settings) error {
lr, err := r.Lock(settings.nodeType)
if err != nil {
return err
}
c, err := lr.Config()
if err != nil {
return err
}
return Options(
Override(new(repo.LockedRepo), modules.LockedRepo(lr)), // module handles closing
ApplyIf(isType(repo.RepoFullNode), configFull(c)),
ApplyIf(isType(repo.RepoStorageMiner), configMiner(c)),
Override(new(dtypes.MetadataDS), modules.Datastore),
Override(new(dtypes.ChainBlockstore), modules.ChainBlockstore),
Override(new(dtypes.ClientFilestore), modules.ClientFstore),
Override(new(dtypes.ClientBlockstore), modules.ClientBlockstore),
Override(new(dtypes.ClientDAG), modules.ClientDAG),
Override(new(ci.PrivKey), lp2p.PrivKey),
Override(new(ci.PubKey), ci.PrivKey.GetPublic),
Override(new(peer.ID), peer.IDFromPublicKey),
Override(new(types.KeyStore), modules.KeyStore),
Override(new(*dtypes.APIAlg), modules.APISecret),
)(settings)
}
}
func FullAPI(out *api.FullNode) Option {
return func(s *Settings) error {
resAPI := &impl.FullNodeAPI{}
@ -334,8 +358,9 @@ type StopFunc func(context.Context) error
// New builds and starts new Filecoin node
func New(ctx context.Context, opts ...Option) (StopFunc, error) {
settings := Settings{
modules: map[interface{}]fx.Option{},
invokes: make([]fx.Option, _nInvokes),
modules: map[interface{}]fx.Option{},
invokes: make([]fx.Option, _nInvokes),
nodeType: repo.RepoFullNode,
}
// apply module options in the right order

View File

@ -1,15 +1,27 @@
package config
import "time"
import (
"encoding"
"time"
)
// Root is starting point of the config
type Root struct {
// Common is common config between full node and miner
type Common struct {
API API
Libp2p Libp2p
}
// FullNode is a full node config
type FullNode struct {
Common
Metrics Metrics
}
// StorageMiner is a storage miner config
type StorageMiner struct {
Common
}
// API contains configs for API endpoint
type API struct {
ListenAddress string
@ -26,9 +38,8 @@ type Metrics struct {
Nickname string
}
// Default returns the default config
func Default() *Root {
def := Root{
func defCommon() Common {
return Common{
API: API{
ListenAddress: "/ip6/::1/tcp/1234/http",
Timeout: Duration(30 * time.Second),
@ -40,10 +51,27 @@ func Default() *Root {
},
},
}
return &def
}
// Duration is a wrapper type for time.Duration for decoding it from TOML
// Default returns the default config
func DefaultFullNode() *FullNode {
return &FullNode{
Common: defCommon(),
}
}
func DefaultStorageMiner() *StorageMiner {
return &StorageMiner{
Common: defCommon(),
}
}
var _ encoding.TextMarshaler = (*Duration)(nil)
var _ encoding.TextUnmarshaler = (*Duration)(nil)
// Duration is a wrapper type for time.Duration
// for decoding and encoding from/to TOML
type Duration time.Duration
// UnmarshalText implements interface for TOML decoding
@ -55,3 +83,8 @@ func (dur *Duration) UnmarshalText(text []byte) error {
*dur = Duration(d)
return err
}
func (dur Duration) MarshalText() ([]byte, error) {
d := time.Duration(dur)
return []byte(d.String()), nil
}

View File

@ -1,30 +1,32 @@
package config
import (
"bytes"
"io"
"os"
"github.com/BurntSushi/toml"
"golang.org/x/xerrors"
)
// FromFile loads config from a specified file overriding defaults specified in
// the source code. If file does not exist or is empty defaults are asummed.
func FromFile(path string) (*Root, error) {
// the def parameter. If file does not exist or is empty defaults are asummed.
func FromFile(path string, def interface{}) (interface{}, error) {
file, err := os.Open(path)
switch {
case os.IsNotExist(err):
return Default(), nil
return def, nil
case err != nil:
return nil, err
}
defer file.Close() //nolint:errcheck // The file is RO
return FromReader(file)
return FromReader(file, def)
}
// FromReader loads config from a reader instance.
func FromReader(reader io.Reader) (*Root, error) {
cfg := Default()
func FromReader(reader io.Reader, def interface{}) (interface{}, error) {
cfg := def
_, err := toml.DecodeReader(reader, cfg)
if err != nil {
return nil, err
@ -32,3 +34,16 @@ func FromReader(reader io.Reader) (*Root, error) {
return cfg, nil
}
func ConfigComment(t interface{}) ([]byte, error) {
buf := new(bytes.Buffer)
_, _ = buf.WriteString("# Default config:\n")
e := toml.NewEncoder(buf)
if err := e.Encode(t); err != nil {
return nil, xerrors.Errorf("encoding config: %w", err)
}
b := buf.Bytes()
b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n#"))
return b, nil
}

View File

@ -14,16 +14,16 @@ func TestDecodeNothing(t *testing.T) {
assert := assert.New(t)
{
cfg, err := FromFile(os.DevNull)
cfg, err := FromFile(os.DevNull, DefaultFullNode())
assert.Nil(err, "error should be nil")
assert.Equal(Default(), cfg,
assert.Equal(DefaultFullNode(), cfg,
"config from empty file should be the same as default")
}
{
cfg, err := FromFile("./does-not-exist.toml")
cfg, err := FromFile("./does-not-exist.toml", DefaultFullNode())
assert.Nil(err, "error should be nil")
assert.Equal(Default(), cfg,
assert.Equal(DefaultFullNode(), cfg,
"config from not exisiting file should be the same as default")
}
}
@ -34,11 +34,11 @@ func TestParitalConfig(t *testing.T) {
[API]
Timeout = "10s"
`
expected := Default()
expected := DefaultFullNode()
expected.API.Timeout = Duration(10 * time.Second)
{
cfg, err := FromReader(bytes.NewReader([]byte(cfgString)))
cfg, err := FromReader(bytes.NewReader([]byte(cfgString)), DefaultFullNode())
assert.NoError(err, "error should be nil")
assert.Equal(expected, cfg,
"config from reader should contain changes")
@ -55,7 +55,7 @@ func TestParitalConfig(t *testing.T) {
assert.NoError(err, "closing tmp file should not error")
defer os.Remove(fname) //nolint:errcheck
cfg, err := FromFile(fname)
cfg, err := FromFile(fname, DefaultFullNode())
assert.Nil(err, "error should be nil")
assert.Equal(expected, cfg,
"config from reader should contain changes")

View File

@ -3,6 +3,7 @@ package hello
import (
"context"
"fmt"
"go.uber.org/fx"
"github.com/ipfs/go-cid"

View File

@ -3,11 +3,12 @@ package client
import (
"context"
"errors"
"golang.org/x/xerrors"
"io"
"math"
"os"
"golang.org/x/xerrors"
"github.com/ipfs/go-blockservice"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-filestore"

View File

@ -162,12 +162,12 @@ func (a *PaychAPI) PaychVoucherCreate(ctx context.Context, pch address.Address,
func (a *PaychAPI) paychVoucherCreate(ctx context.Context, pch address.Address, voucher types.SignedVoucher) (*types.SignedVoucher, error) {
ci, err := a.PaychMgr.GetChannelInfo(pch)
if err != nil {
return nil, err
return nil, xerrors.Errorf("get channel info: %w", err)
}
nonce, err := a.PaychMgr.NextNonceForLane(ctx, pch, voucher.Lane)
if err != nil {
return nil, err
return nil, xerrors.Errorf("getting next nonce for lane: %w", err)
}
sv := &voucher

View File

@ -2,6 +2,7 @@ package modules
import (
"context"
"fmt"
"math"
"path/filepath"
@ -163,7 +164,10 @@ func RegisterMiner(lc fx.Lifecycle, ds dtypes.MetadataDS, api api.FullNode) erro
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
log.Infof("Registering miner '%s' with full node", minerAddr)
return api.MinerRegister(ctx, minerAddr)
if err := api.MinerRegister(ctx, minerAddr); err != nil {
return fmt.Errorf("Failed to register miner: %s\nIf you are certain no other storage miner instance is running, try running 'lotus unregister-miner %s' and restarting the storage miner", err, minerAddr)
}
return nil
},
OnStop: func(ctx context.Context) error {
log.Infof("Unregistering miner '%s' from full node", minerAddr)

View File

@ -34,7 +34,7 @@ import (
func testStorageNode(ctx context.Context, t *testing.T, waddr address.Address, act address.Address, tnd test.TestNode) test.TestStorageNode {
r := repo.NewMemory(nil)
lr, err := r.Lock()
lr, err := r.Lock(repo.RepoStorageMiner)
require.NoError(t, err)
pk, _, err := crypto.GenerateEd25519Key(rand.Reader)

View File

@ -2,6 +2,7 @@ package repo
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
@ -33,13 +34,33 @@ const (
fsKeystore = "keystore"
)
type RepoType int
const (
_ = iota // Default is invalid
RepoFullNode RepoType = iota
RepoStorageMiner
)
func defConfForType(t RepoType) interface{} {
switch t {
case RepoFullNode:
return config.DefaultFullNode()
case RepoStorageMiner:
return config.DefaultStorageMiner()
default:
panic(fmt.Sprintf("unknown RepoType(%d)", int(t)))
}
}
var log = logging.Logger("repo")
var ErrRepoExists = xerrors.New("repo exists")
// FsRepo is struct for repo, use NewFS to create
type FsRepo struct {
path string
path string
repoType RepoType
}
var _ Repo = &FsRepo{}
@ -65,7 +86,7 @@ func (fsr *FsRepo) Exists() (bool, error) {
return !notexist, err
}
func (fsr *FsRepo) Init() error {
func (fsr *FsRepo) Init(t RepoType) error {
exist, err := fsr.Exists()
if err != nil {
return err
@ -79,18 +100,36 @@ func (fsr *FsRepo) Init() error {
if err != nil && !os.IsExist(err) {
return err
}
c, err := os.Create(filepath.Join(fsr.path, fsConfig))
if err != nil {
return err
}
if err := c.Close(); err != nil {
return err
if err := fsr.initConfig(t); err != nil {
return xerrors.Errorf("init config: %w", err)
}
return fsr.initKeystore()
}
func (fsr *FsRepo) initConfig(t RepoType) error {
c, err := os.Create(filepath.Join(fsr.path, fsConfig))
if err != nil {
return err
}
comm, err := config.ConfigComment(defConfForType(t))
if err != nil {
return xerrors.Errorf("comment: %w", err)
}
_, err = c.Write(comm)
if err != nil {
return xerrors.Errorf("write config: %w", err)
}
if err := c.Close(); err != nil {
return xerrors.Errorf("close config: %w", err)
}
return nil
}
func (fsr *FsRepo) initKeystore() error {
kstorePath := filepath.Join(fsr.path, fsKeystore)
if _, err := os.Stat(kstorePath); err == nil {
@ -142,7 +181,7 @@ func (fsr *FsRepo) APIToken() ([]byte, error) {
}
// Lock acquires exclusive lock on this repo
func (fsr *FsRepo) Lock() (LockedRepo, error) {
func (fsr *FsRepo) Lock(repoType RepoType) (LockedRepo, error) {
locked, err := fslock.Locked(fsr.path, fsLock)
if err != nil {
return nil, xerrors.Errorf("could not check lock status: %w", err)
@ -156,14 +195,16 @@ func (fsr *FsRepo) Lock() (LockedRepo, error) {
return nil, xerrors.Errorf("could not lock the repo: %w", err)
}
return &fsLockedRepo{
path: fsr.path,
closer: closer,
path: fsr.path,
repoType: repoType,
closer: closer,
}, nil
}
type fsLockedRepo struct {
path string
closer io.Closer
path string
repoType RepoType
closer io.Closer
ds datastore.Batching
dsErr error
@ -219,11 +260,11 @@ func (fsr *fsLockedRepo) Datastore(ns string) (datastore.Batching, error) {
return namespace.Wrap(fsr.ds, datastore.NewKey(ns)), nil
}
func (fsr *fsLockedRepo) Config() (*config.Root, error) {
func (fsr *fsLockedRepo) Config() (interface{}, error) {
if err := fsr.stillValid(); err != nil {
return nil, err
}
return config.FromFile(fsr.join(fsConfig))
return config.FromFile(fsr.join(fsConfig), defConfForType(fsr.repoType))
}
func (fsr *fsLockedRepo) SetAPIEndpoint(ma multiaddr.Multiaddr) error {

View File

@ -17,7 +17,7 @@ func genFsRepo(t *testing.T) (*FsRepo, func()) {
t.Fatal(err)
}
err = repo.Init()
err = repo.Init(RepoFullNode)
if err != ErrRepoExists && err != nil {
t.Fatal(err)
}

View File

@ -7,7 +7,6 @@ import (
"github.com/multiformats/go-multiaddr"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/config"
)
var (
@ -25,7 +24,7 @@ type Repo interface {
APIToken() ([]byte, error)
// Lock locks the repo for exclusive use.
Lock() (LockedRepo, error)
Lock(RepoType) (LockedRepo, error)
}
type LockedRepo interface {
@ -36,7 +35,7 @@ type LockedRepo interface {
Datastore(namespace string) (datastore.Batching, error)
// Returns config in this repo
Config() (*config.Root, error)
Config() (interface{}, error)
// SetAPIEndpoint sets the endpoint of the current API
// so it can be read by API clients

View File

@ -10,7 +10,6 @@ import (
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/config"
)
type MemRepo struct {
@ -24,12 +23,13 @@ type MemRepo struct {
token *byte
datastore datastore.Datastore
configF func() *config.Root
configF func(t RepoType) interface{}
keystore map[string]types.KeyInfo
}
type lockedMemRepo struct {
mem *MemRepo
t RepoType
sync.RWMutex
token *byte
@ -44,7 +44,7 @@ var _ Repo = &MemRepo{}
// MemRepoOptions contains options for memory repo
type MemRepoOptions struct {
Ds datastore.Datastore
ConfigF func() *config.Root
ConfigF func(RepoType) interface{}
KeyStore map[string]types.KeyInfo
}
@ -56,7 +56,7 @@ func NewMemory(opts *MemRepoOptions) *MemRepo {
opts = &MemRepoOptions{}
}
if opts.ConfigF == nil {
opts.ConfigF = config.Default
opts.ConfigF = defConfForType
}
if opts.Ds == nil {
opts.Ds = dssync.MutexWrap(datastore.NewMapDatastore())
@ -92,7 +92,7 @@ func (mem *MemRepo) APIToken() ([]byte, error) {
return mem.api.token, nil
}
func (mem *MemRepo) Lock() (LockedRepo, error) {
func (mem *MemRepo) Lock(t RepoType) (LockedRepo, error) {
select {
case mem.repoLock <- struct{}{}:
default:
@ -102,6 +102,7 @@ func (mem *MemRepo) Lock() (LockedRepo, error) {
return &lockedMemRepo{
mem: mem,
t: t,
token: mem.token,
}, nil
}
@ -143,11 +144,11 @@ func (lmem *lockedMemRepo) Datastore(ns string) (datastore.Batching, error) {
return namespace.Wrap(lmem.mem.datastore, datastore.NewKey(ns)), nil
}
func (lmem *lockedMemRepo) Config() (*config.Root, error) {
func (lmem *lockedMemRepo) Config() (interface{}, error) {
if err := lmem.checkToken(); err != nil {
return nil, err
}
return lmem.mem.configF(), nil
return lmem.mem.configF(lmem.t), nil
}
func (lmem *lockedMemRepo) SetAPIEndpoint(ma multiaddr.Multiaddr) error {

View File

@ -18,12 +18,12 @@ func basicTest(t *testing.T, repo Repo) {
}
assert.Nil(t, apima, "with no api endpoint, return should be nil")
lrepo, err := repo.Lock()
lrepo, err := repo.Lock(RepoFullNode)
assert.NoError(t, err, "should be able to lock once")
assert.NotNil(t, lrepo, "locked repo shouldn't be nil")
{
lrepo2, err := repo.Lock()
lrepo2, err := repo.Lock(RepoFullNode)
if assert.Error(t, err) {
assert.Equal(t, ErrRepoAlreadyLocked, err)
}
@ -33,7 +33,7 @@ func basicTest(t *testing.T, repo Repo) {
err = lrepo.Close()
assert.NoError(t, err, "should be able to unlock")
lrepo, err = repo.Lock()
lrepo, err = repo.Lock(RepoFullNode)
assert.NoError(t, err, "should be able to relock")
assert.NotNil(t, lrepo, "locked repo shouldn't be nil")
@ -48,7 +48,7 @@ func basicTest(t *testing.T, repo Repo) {
assert.Equal(t, ma, apima, "returned API multiaddr should be the same")
cfg, err := lrepo.Config()
assert.Equal(t, config.Default(), cfg, "there should be a default config")
assert.Equal(t, config.DefaultFullNode(), cfg, "there should be a default config")
assert.NoError(t, err, "config should not error")
err = lrepo.Close()
@ -64,7 +64,7 @@ func basicTest(t *testing.T, repo Repo) {
k1 := types.KeyInfo{Type: "foo"}
k2 := types.KeyInfo{Type: "bar"}
lrepo, err = repo.Lock()
lrepo, err = repo.Lock(RepoFullNode)
assert.NoError(t, err, "should be able to relock")
assert.NotNil(t, lrepo, "locked repo shouldn't be nil")

231
paych/cbor_gen.go Normal file
View File

@ -0,0 +1,231 @@
package paych
import (
"fmt"
"io"
"github.com/filecoin-project/lotus/chain/types"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)
/* This file was generated by github.com/whyrusleeping/cbor-gen */
var _ = xerrors.Errorf
func (t *VoucherInfo) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Voucher (types.SignedVoucher) (struct)
if err := t.Voucher.MarshalCBOR(w); err != nil {
return err
}
// t.t.Proof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil {
return err
}
if _, err := w.Write(t.Proof); err != nil {
return err
}
return nil
}
func (t *VoucherInfo) 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 != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Voucher (types.SignedVoucher) (struct)
{
pb, err := br.PeekByte()
if err != nil {
return err
}
if pb == cbg.CborNull[0] {
var nbuf [1]byte
if _, err := br.Read(nbuf[:]); err != nil {
return err
}
} else {
t.Voucher = new(types.SignedVoucher)
if err := t.Voucher.UnmarshalCBOR(br); err != nil {
return err
}
}
}
// t.t.Proof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Proof: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Proof = make([]byte, extra)
if _, err := io.ReadFull(br, t.Proof); err != nil {
return err
}
return nil
}
func (t *ChannelInfo) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{134}); err != nil {
return err
}
// t.t.Channel (address.Address) (struct)
if err := t.Channel.MarshalCBOR(w); err != nil {
return err
}
// t.t.Control (address.Address) (struct)
if err := t.Control.MarshalCBOR(w); err != nil {
return err
}
// t.t.Target (address.Address) (struct)
if err := t.Target.MarshalCBOR(w); err != nil {
return err
}
// t.t.Direction (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Direction))); err != nil {
return err
}
// t.t.Vouchers ([]*paych.VoucherInfo) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Vouchers)))); err != nil {
return err
}
for _, v := range t.Vouchers {
if err := v.MarshalCBOR(w); err != nil {
return err
}
}
// t.t.NextLane (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.NextLane))); err != nil {
return err
}
return nil
}
func (t *ChannelInfo) 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 != 6 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Channel (address.Address) (struct)
{
if err := t.Channel.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.Control (address.Address) (struct)
{
if err := t.Control.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.Target (address.Address) (struct)
{
if err := t.Target.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.Direction (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.Direction = uint64(extra)
// t.t.Vouchers ([]*paych.VoucherInfo) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Vouchers: array too large (%d)", extra)
}
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Vouchers = make([]*VoucherInfo, extra)
}
for i := 0; i < int(extra); i++ {
var v VoucherInfo
if err := v.UnmarshalCBOR(br); err != nil {
return err
}
t.Vouchers[i] = &v
}
// t.t.NextLane (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.NextLane = uint64(extra)
return nil
}

View File

@ -1,6 +1,7 @@
package paych
import (
"bytes"
"errors"
"fmt"
"strings"
@ -9,21 +10,16 @@ import (
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
dsq "github.com/ipfs/go-datastore/query"
cbor "github.com/ipfs/go-ipld-cbor"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/types"
cborrpc "github.com/filecoin-project/lotus/lib/cborrpc"
"github.com/filecoin-project/lotus/node/modules/dtypes"
)
var ErrChannelNotTracked = errors.New("channel not tracked")
func init() {
cbor.RegisterCborType(VoucherInfo{})
cbor.RegisterCborType(ChannelInfo{})
}
type Store struct {
lk sync.Mutex // TODO: this can be split per paych
@ -52,7 +48,7 @@ type ChannelInfo struct {
Control address.Address
Target address.Address
Direction int
Direction uint64
Vouchers []*VoucherInfo
NextLane uint64
}
@ -64,7 +60,7 @@ func dskeyForChannel(addr address.Address) datastore.Key {
func (ps *Store) putChannelInfo(ci *ChannelInfo) error {
k := dskeyForChannel(ci.Channel)
b, err := cbor.DumpObject(ci)
b, err := cborrpc.Dump(ci)
if err != nil {
return err
}
@ -84,7 +80,7 @@ func (ps *Store) getChannelInfo(addr address.Address) (*ChannelInfo, error) {
}
var ci ChannelInfo
if err := cbor.DecodeInto(b, &ci); err != nil {
if err := ci.UnmarshalCBOR(bytes.NewReader(b)); err != nil {
return nil, err
}
@ -161,7 +157,7 @@ func (ps *Store) findChan(filter func(*ChannelInfo) bool) (address.Address, erro
return address.Undef, err
}
if err := cbor.DecodeInto(res.Value, &ci); err != nil {
if err := ci.UnmarshalCBOR(bytes.NewReader(res.Value)); err != nil {
return address.Undef, err
}

464
retrieval/cbor_gen.go Normal file
View File

@ -0,0 +1,464 @@
package retrieval
import (
"fmt"
"io"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)
/* This file was generated by github.com/whyrusleeping/cbor-gen */
var _ = xerrors.Errorf
func (t *RetParams) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{129}); err != nil {
return err
}
// t.t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
if err := t.Unixfs0.MarshalCBOR(w); err != nil {
return err
}
return nil
}
func (t *RetParams) 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 != 1 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
{
pb, err := br.PeekByte()
if err != nil {
return err
}
if pb == cbg.CborNull[0] {
var nbuf [1]byte
if _, err := br.Read(nbuf[:]); err != nil {
return err
}
} else {
t.Unixfs0 = new(Unixfs0Offer)
if err := t.Unixfs0.UnmarshalCBOR(br); err != nil {
return err
}
}
}
return nil
}
func (t *Query) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{129}); err != nil {
return err
}
// t.t.Piece (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Piece); err != nil {
return xerrors.Errorf("failed to write cid field t.Piece: %w", err)
}
return nil
}
func (t *Query) 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 != 1 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Piece (cid.Cid) (struct)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Piece: %w", err)
}
t.Piece = c
}
return nil
}
func (t *QueryResponse) 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.Status (retrieval.QueryResponseStatus) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
return err
}
// t.t.Size (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil {
return err
}
// t.t.MinPrice (types.BigInt) (struct)
if err := t.MinPrice.MarshalCBOR(w); err != nil {
return err
}
return nil
}
func (t *QueryResponse) 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.Status (retrieval.QueryResponseStatus) (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.Status = QueryResponseStatus(extra)
// t.t.Size (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.Size = uint64(extra)
// t.t.MinPrice (types.BigInt) (struct)
{
if err := t.MinPrice.UnmarshalCBOR(br); err != nil {
return err
}
}
return nil
}
func (t *Unixfs0Offer) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Offset (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Offset))); err != nil {
return err
}
// t.t.Size (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil {
return err
}
return nil
}
func (t *Unixfs0Offer) 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 != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Offset (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.Offset = uint64(extra)
// t.t.Size (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.Size = uint64(extra)
return nil
}
func (t *DealProposal) 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.Payment (api.PaymentInfo) (struct)
if err := t.Payment.MarshalCBOR(w); err != nil {
return err
}
// t.t.Ref (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Ref); err != nil {
return xerrors.Errorf("failed to write cid field t.Ref: %w", err)
}
// t.t.Params (retrieval.RetParams) (struct)
if err := t.Params.MarshalCBOR(w); err != nil {
return err
}
return nil
}
func (t *DealProposal) 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.Payment (api.PaymentInfo) (struct)
{
if err := t.Payment.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.Ref (cid.Cid) (struct)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Ref: %w", err)
}
t.Ref = c
}
// t.t.Params (retrieval.RetParams) (struct)
{
if err := t.Params.UnmarshalCBOR(br); err != nil {
return err
}
}
return nil
}
func (t *DealResponse) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Status (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
return err
}
// t.t.Message (string) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Message)))); err != nil {
return err
}
if _, err := w.Write([]byte(t.Message)); err != nil {
return err
}
return nil
}
func (t *DealResponse) 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 != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Status (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.Status = uint64(extra)
// t.t.Message (string) (string)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
t.Message = string(sval)
}
return nil
}
func (t *Block) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Prefix ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Prefix)))); err != nil {
return err
}
if _, err := w.Write(t.Prefix); err != nil {
return err
}
// t.t.Data ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Data)))); err != nil {
return err
}
if _, err := w.Write(t.Data); err != nil {
return err
}
return nil
}
func (t *Block) 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 != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Prefix ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Prefix: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Prefix = make([]byte, extra)
if _, err := io.ReadFull(br, t.Prefix); err != nil {
return err
}
// t.t.Data ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Data: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Data = make([]byte, extra)
if _, err := io.ReadFull(br, t.Data); err != nil {
return err
}
return nil
}

View File

@ -3,15 +3,14 @@ package retrieval
import (
"context"
"io"
"io/ioutil"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api"
@ -45,7 +44,7 @@ func (c *Client) Query(ctx context.Context, p discovery.RetrievalPeer, data cid.
}
defer s.Close()
err = cborrpc.WriteCborRPC(s, Query{
err = cborrpc.WriteCborRPC(s, &Query{
Piece: data,
})
if err != nil {
@ -53,15 +52,8 @@ func (c *Client) Query(ctx context.Context, p discovery.RetrievalPeer, data cid.
return api.QueryOffer{Err: err.Error(), Miner: p.Address, MinerPeerID: p.ID}
}
// TODO: read deadline
rawResp, err := ioutil.ReadAll(s)
if err != nil {
log.Warn(err)
return api.QueryOffer{Err: err.Error(), Miner: p.Address, MinerPeerID: p.ID}
}
var resp QueryResponse
if err := cbor.DecodeInto(rawResp, &resp); err != nil {
if err := resp.UnmarshalCBOR(s); err != nil {
log.Warn(err)
return api.QueryOffer{Err: err.Error(), Miner: p.Address, MinerPeerID: p.ID}
}
@ -78,6 +70,7 @@ func (c *Client) Query(ctx context.Context, p discovery.RetrievalPeer, data cid.
type clientStream struct {
payapi payapi.PaychAPI
stream network.Stream
peeker cbg.BytePeeker
root cid.Cid
size types.BigInt
@ -127,6 +120,7 @@ func (c *Client) RetrieveUnixfs(ctx context.Context, root cid.Cid, size uint64,
cst := clientStream{
payapi: c.payapi,
stream: s,
peeker: cbg.GetPeeker(s),
root: root,
size: types.NewInt(size),
@ -167,7 +161,7 @@ func (cst *clientStream) doOneExchange(ctx context.Context, toFetch uint64, out
return xerrors.Errorf("setting up retrieval payment: %w", err)
}
deal := DealProposal{
deal := &DealProposal{
Payment: payment,
Ref: cst.root,
Params: RetParams{
@ -183,7 +177,7 @@ func (cst *clientStream) doOneExchange(ctx context.Context, toFetch uint64, out
}
var resp DealResponse
if err := cborrpc.ReadCborRPC(cst.stream, &resp); err != nil {
if err := cborrpc.ReadCborRPC(cst.peeker, &resp); err != nil {
log.Error(err)
return err
}
@ -215,7 +209,7 @@ func (cst *clientStream) fetchBlocks(toFetch uint64, out io.Writer) error {
log.Infof("block %d of %d", i+1, blocksToFetch)
var block Block
if err := cborrpc.ReadCborRPC(cst.stream, &block); err != nil {
if err := cborrpc.ReadCborRPC(cst.peeker, &block); err != nil {
return xerrors.Errorf("reading fetchBlock response: %w", err)
}

View File

@ -13,14 +13,19 @@ import (
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/cborrpc"
"github.com/filecoin-project/lotus/storage/sectorblocks"
)
type RetrMinerApi interface {
PaychVoucherAdd(context.Context, address.Address, *types.SignedVoucher, []byte, types.BigInt) (types.BigInt, error)
}
type Miner struct {
sectorBlocks *sectorblocks.SectorBlocks
full api.FullNode
full RetrMinerApi
pricePerByte types.BigInt
// TODO: Unseal price
@ -37,7 +42,7 @@ func NewMiner(sblks *sectorblocks.SectorBlocks, full api.FullNode) *Miner {
func writeErr(stream network.Stream, err error) {
log.Errorf("Retrieval deal error: %s", err)
_ = cborrpc.WriteCborRPC(stream, DealResponse{
_ = cborrpc.WriteCborRPC(stream, &DealResponse{
Status: Error,
Message: err.Error(),
})
@ -58,7 +63,7 @@ func (m *Miner) HandleQueryStream(stream network.Stream) {
return
}
answer := QueryResponse{
answer := &QueryResponse{
Status: Unavailable,
}
if err == nil {
@ -134,7 +139,7 @@ func (hnd *handlerDeal) handleNext() (bool, error) {
// If the file isn't open (new deal stream), isn't the right file, or isn't
// at the right offset, (re)open it
if hnd.open != deal.Ref || hnd.at != unixfs0.Offset {
log.Infof("opening file for sending (open '%s') (@%d, want %d)", hnd.open, hnd.at, unixfs0.Offset)
log.Infof("opening file for sending (open '%s') (@%d, want %d)", deal.Ref, hnd.at, unixfs0.Offset)
if err := hnd.openFile(deal); err != nil {
return false, err
}
@ -195,7 +200,7 @@ func (hnd *handlerDeal) openFile(deal DealProposal) error {
func (hnd *handlerDeal) accept(deal DealProposal) error {
unixfs0 := deal.Params.Unixfs0
resp := DealResponse{
resp := &DealResponse{
Status: Accepted,
}
if err := cborrpc.WriteCborRPC(hnd.stream, resp); err != nil {
@ -221,7 +226,7 @@ func (hnd *handlerDeal) accept(deal DealProposal) error {
return
}*/
block := Block{
block := &Block{
Prefix: nd.Cid().Prefix().Bytes(),
Data: nd.RawData(),
}

View File

@ -3,7 +3,6 @@ package retrieval
import (
"github.com/filecoin-project/lotus/api"
"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/filecoin-project/lotus/chain/types"
)
@ -11,7 +10,7 @@ import (
const ProtocolID = "/fil/retrieval/-1.0.0" // TODO: spec
const QueryProtocolID = "/fil/retrieval/qry/-1.0.0" // TODO: spec
type QueryResponseStatus int
type QueryResponseStatus uint64
const (
Available QueryResponseStatus = iota
@ -25,18 +24,6 @@ const (
Unsealing
)
func init() {
cbor.RegisterCborType(RetParams{})
cbor.RegisterCborType(Query{})
cbor.RegisterCborType(QueryResponse{})
cbor.RegisterCborType(Unixfs0Offer{})
cbor.RegisterCborType(DealProposal{})
cbor.RegisterCborType(DealResponse{})
cbor.RegisterCborType(Block{})
}
type Query struct {
Piece cid.Cid
// TODO: payment
@ -69,7 +56,7 @@ type DealProposal struct {
}
type DealResponse struct {
Status int
Status uint64
Message string
}