2020-02-12 18:08:49 +00:00
|
|
|
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
|
|
|
|
|
|
|
package hello
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
integrate DAG store and CARv2 in deal-making (#6671)
This commit removes badger from the deal-making processes, and
moves to a new architecture with the dagstore as the cental
component on the miner-side, and CARv2s on the client-side.
Every deal that has been handed off to the sealing subsystem becomes
a shard in the dagstore. Shards are mounted via the LotusMount, which
teaches the dagstore how to load the related piece when serving
retrievals.
When the miner starts the Lotus for the first time with this patch,
we will perform a one-time migration of all active deals into the
dagstore. This is a lightweight process, and it consists simply
of registering the shards in the dagstore.
Shards are backed by the unsealed copy of the piece. This is currently
a CARv1. However, the dagstore keeps CARv2 indices for all pieces, so
when it's time to acquire a shard to serve a retrieval, the unsealed
CARv1 is joined with its index (safeguarded by the dagstore), to form
a read-only blockstore, thus taking the place of the monolithic
badger.
Data transfers have been adjusted to interface directly with CARv2 files.
On inbound transfers (client retrievals, miner storage deals), we stream
the received data into a CARv2 ReadWrite blockstore. On outbound transfers
(client storage deals, miner retrievals), we serve the data off a CARv2
ReadOnly blockstore.
Client-side imports are managed by the refactored *imports.Manager
component (when not using IPFS integration). Just like it before, we use
the go-filestore library to avoid duplicating the data from the original
file in the resulting UnixFS DAG (concretely the leaves). However, the
target of those imports are what we call "ref-CARv2s": CARv2 files placed
under the `$LOTUS_PATH/imports` directory, containing the intermediate
nodes in full, and the leaves as positional references to the original file
on disk.
Client-side retrievals are placed into CARv2 files in the location:
`$LOTUS_PATH/retrievals`.
A new set of `Dagstore*` JSON-RPC operations and `lotus-miner dagstore`
subcommands have been introduced on the miner-side to inspect and manage
the dagstore.
Despite moving to a CARv2-backed system, the IPFS integration has been
respected, and it continues to be possible to make storage deals with data
held in an IPFS node, and to perform retrievals directly into an IPFS node.
NOTE: because the "staging" and "client" Badger blockstores are no longer
used, existing imports on the client will be rendered useless. On startup,
Lotus will enumerate all imports and print WARN statements on the log for
each import that needs to be reimported. These log lines contain these
messages:
- import lacks carv2 path; import will not work; please reimport
- import has missing/broken carv2; please reimport
At the end, we will print a "sanity check completed" message indicating
the count of imports found, and how many were deemed broken.
Co-authored-by: Aarsh Shah <aarshkshah1992@gmail.com>
Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
Co-authored-by: Raúl Kripalani <raul@protocol.ai>
Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
2021-08-16 22:34:32 +00:00
|
|
|
"math"
|
2021-02-19 19:11:43 +00:00
|
|
|
"sort"
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2020-08-20 04:37:21 +00:00
|
|
|
cid "github.com/ipfs/go-cid"
|
2020-02-12 18:08:49 +00:00
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
|
|
xerrors "golang.org/x/xerrors"
|
2022-06-14 15:00:51 +00:00
|
|
|
|
|
|
|
abi "github.com/filecoin-project/go-state-types/abi"
|
2020-02-12 18:08:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = xerrors.Errorf
|
2021-02-19 19:11:43 +00:00
|
|
|
var _ = cid.Undef
|
integrate DAG store and CARv2 in deal-making (#6671)
This commit removes badger from the deal-making processes, and
moves to a new architecture with the dagstore as the cental
component on the miner-side, and CARv2s on the client-side.
Every deal that has been handed off to the sealing subsystem becomes
a shard in the dagstore. Shards are mounted via the LotusMount, which
teaches the dagstore how to load the related piece when serving
retrievals.
When the miner starts the Lotus for the first time with this patch,
we will perform a one-time migration of all active deals into the
dagstore. This is a lightweight process, and it consists simply
of registering the shards in the dagstore.
Shards are backed by the unsealed copy of the piece. This is currently
a CARv1. However, the dagstore keeps CARv2 indices for all pieces, so
when it's time to acquire a shard to serve a retrieval, the unsealed
CARv1 is joined with its index (safeguarded by the dagstore), to form
a read-only blockstore, thus taking the place of the monolithic
badger.
Data transfers have been adjusted to interface directly with CARv2 files.
On inbound transfers (client retrievals, miner storage deals), we stream
the received data into a CARv2 ReadWrite blockstore. On outbound transfers
(client storage deals, miner retrievals), we serve the data off a CARv2
ReadOnly blockstore.
Client-side imports are managed by the refactored *imports.Manager
component (when not using IPFS integration). Just like it before, we use
the go-filestore library to avoid duplicating the data from the original
file in the resulting UnixFS DAG (concretely the leaves). However, the
target of those imports are what we call "ref-CARv2s": CARv2 files placed
under the `$LOTUS_PATH/imports` directory, containing the intermediate
nodes in full, and the leaves as positional references to the original file
on disk.
Client-side retrievals are placed into CARv2 files in the location:
`$LOTUS_PATH/retrievals`.
A new set of `Dagstore*` JSON-RPC operations and `lotus-miner dagstore`
subcommands have been introduced on the miner-side to inspect and manage
the dagstore.
Despite moving to a CARv2-backed system, the IPFS integration has been
respected, and it continues to be possible to make storage deals with data
held in an IPFS node, and to perform retrievals directly into an IPFS node.
NOTE: because the "staging" and "client" Badger blockstores are no longer
used, existing imports on the client will be rendered useless. On startup,
Lotus will enumerate all imports and print WARN statements on the log for
each import that needs to be reimported. These log lines contain these
messages:
- import lacks carv2 path; import will not work; please reimport
- import has missing/broken carv2; please reimport
At the end, we will print a "sanity check completed" message indicating
the count of imports found, and how many were deemed broken.
Co-authored-by: Aarsh Shah <aarshkshah1992@gmail.com>
Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
Co-authored-by: Raúl Kripalani <raul@protocol.ai>
Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
2021-08-16 22:34:32 +00:00
|
|
|
var _ = math.E
|
2021-02-19 19:11:43 +00:00
|
|
|
var _ = sort.Sort
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2020-05-04 22:19:48 +00:00
|
|
|
var lengthBufHelloMessage = []byte{132}
|
|
|
|
|
2020-02-12 18:08:49 +00:00
|
|
|
func (t *HelloMessage) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
2022-05-23 19:11:46 +00:00
|
|
|
|
|
|
|
cw := cbg.NewCborWriter(w)
|
|
|
|
|
|
|
|
if _, err := cw.Write(lengthBufHelloMessage); err != nil {
|
2020-02-12 18:08:49 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.HeaviestTipSet ([]cid.Cid) (slice)
|
|
|
|
if len(t.HeaviestTipSet) > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Slice value in field t.HeaviestTipSet was too long")
|
|
|
|
}
|
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.HeaviestTipSet))); err != nil {
|
2020-02-12 18:08:49 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, v := range t.HeaviestTipSet {
|
2022-05-23 19:11:46 +00:00
|
|
|
if err := cbg.WriteCid(w, v); err != nil {
|
2020-02-12 18:08:49 +00:00
|
|
|
return xerrors.Errorf("failed writing cid field t.HeaviestTipSet: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 20:21:58 +00:00
|
|
|
// t.HeaviestTipSetHeight (abi.ChainEpoch) (int64)
|
|
|
|
if t.HeaviestTipSetHeight >= 0 {
|
2022-05-23 19:11:46 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.HeaviestTipSetHeight)); err != nil {
|
2020-02-25 20:21:58 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2022-05-23 19:11:46 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.HeaviestTipSetHeight-1)); err != nil {
|
2020-02-25 20:21:58 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 20:21:58 +00:00
|
|
|
// t.HeaviestTipSetWeight (big.Int) (struct)
|
2022-05-23 19:11:46 +00:00
|
|
|
if err := t.HeaviestTipSetWeight.MarshalCBOR(cw); err != nil {
|
2020-02-12 18:08:49 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.GenesisHash (cid.Cid) (struct)
|
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
if err := cbg.WriteCid(cw, t.GenesisHash); err != nil {
|
2020-02-12 18:08:49 +00:00
|
|
|
return xerrors.Errorf("failed to write cid field t.GenesisHash: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
func (t *HelloMessage) UnmarshalCBOR(r io.Reader) (err error) {
|
2020-07-14 11:45:45 +00:00
|
|
|
*t = HelloMessage{}
|
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
cr := cbg.NewCborReader(r)
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
maj, extra, err := cr.ReadHeader()
|
2020-02-12 18:08:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-05-23 19:11:46 +00:00
|
|
|
defer func() {
|
|
|
|
if err == io.EOF {
|
|
|
|
err = io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
if maj != cbg.MajArray {
|
|
|
|
return fmt.Errorf("cbor input should be of type array")
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
if extra != 4 {
|
|
|
|
return fmt.Errorf("cbor input had wrong number of fields")
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
// t.HeaviestTipSet ([]cid.Cid) (slice)
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
maj, extra, err = cr.ReadHeader()
|
2020-02-12 18:23:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
if extra > cbg.MaxLength {
|
|
|
|
return fmt.Errorf("t.HeaviestTipSet: array too large (%d)", extra)
|
|
|
|
}
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
if maj != cbg.MajArray {
|
|
|
|
return fmt.Errorf("expected cbor array")
|
|
|
|
}
|
2020-04-17 17:53:09 +00:00
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
if extra > 0 {
|
|
|
|
t.HeaviestTipSet = make([]cid.Cid, extra)
|
|
|
|
}
|
2020-04-17 17:53:09 +00:00
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
for i := 0; i < int(extra); i++ {
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
c, err := cbg.ReadCid(cr)
|
2020-02-12 18:23:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("reading cid field t.HeaviestTipSet failed: %w", err)
|
|
|
|
}
|
|
|
|
t.HeaviestTipSet[i] = c
|
|
|
|
}
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2020-02-25 20:21:58 +00:00
|
|
|
// t.HeaviestTipSetHeight (abi.ChainEpoch) (int64)
|
|
|
|
{
|
2022-05-23 19:11:46 +00:00
|
|
|
maj, extra, err := cr.ReadHeader()
|
2020-02-25 20:21:58 +00:00
|
|
|
var extraI int64
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
switch maj {
|
|
|
|
case cbg.MajUnsignedInt:
|
|
|
|
extraI = int64(extra)
|
|
|
|
if extraI < 0 {
|
|
|
|
return fmt.Errorf("int64 positive overflow")
|
|
|
|
}
|
|
|
|
case cbg.MajNegativeInt:
|
|
|
|
extraI = int64(extra)
|
|
|
|
if extraI < 0 {
|
|
|
|
return fmt.Errorf("int64 negative oveflow")
|
|
|
|
}
|
|
|
|
extraI = -1 - extraI
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("wrong type for int64 field: %d", maj)
|
|
|
|
}
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2020-02-25 20:21:58 +00:00
|
|
|
t.HeaviestTipSetHeight = abi.ChainEpoch(extraI)
|
2020-02-12 18:23:15 +00:00
|
|
|
}
|
2020-02-25 20:21:58 +00:00
|
|
|
// t.HeaviestTipSetWeight (big.Int) (struct)
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
{
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
if err := t.HeaviestTipSetWeight.UnmarshalCBOR(cr); err != nil {
|
2020-03-21 21:17:01 +00:00
|
|
|
return xerrors.Errorf("unmarshaling t.HeaviestTipSetWeight: %w", err)
|
2020-02-12 18:23:15 +00:00
|
|
|
}
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
}
|
|
|
|
// t.GenesisHash (cid.Cid) (struct)
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
{
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
c, err := cbg.ReadCid(cr)
|
2020-02-12 18:23:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to read cid field t.GenesisHash: %w", err)
|
|
|
|
}
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
t.GenesisHash = c
|
2020-02-12 18:08:49 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2020-02-12 18:23:15 +00:00
|
|
|
|
2020-05-04 22:19:48 +00:00
|
|
|
var lengthBufLatencyMessage = []byte{130}
|
|
|
|
|
2020-02-12 18:08:49 +00:00
|
|
|
func (t *LatencyMessage) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
2022-05-23 19:11:46 +00:00
|
|
|
|
|
|
|
cw := cbg.NewCborWriter(w)
|
|
|
|
|
|
|
|
if _, err := cw.Write(lengthBufLatencyMessage); err != nil {
|
2020-02-12 18:08:49 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-04 15:33:29 +00:00
|
|
|
// t.TArrival (int64) (int64)
|
|
|
|
if t.TArrival >= 0 {
|
2022-05-23 19:11:46 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.TArrival)); err != nil {
|
2020-02-12 18:23:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2022-05-23 19:11:46 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.TArrival-1)); err != nil {
|
2020-02-12 18:23:15 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
// t.TSent (int64) (int64)
|
|
|
|
if t.TSent >= 0 {
|
2022-05-23 19:11:46 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.TSent)); err != nil {
|
2020-02-12 18:23:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2022-05-23 19:11:46 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.TSent-1)); err != nil {
|
2020-02-12 18:23:15 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) (err error) {
|
2020-07-14 11:45:45 +00:00
|
|
|
*t = LatencyMessage{}
|
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
cr := cbg.NewCborReader(r)
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2022-05-23 19:11:46 +00:00
|
|
|
maj, extra, err := cr.ReadHeader()
|
2020-02-12 18:08:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-05-23 19:11:46 +00:00
|
|
|
defer func() {
|
|
|
|
if err == io.EOF {
|
|
|
|
err = io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
if maj != cbg.MajArray {
|
|
|
|
return fmt.Errorf("cbor input should be of type array")
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
if extra != 2 {
|
|
|
|
return fmt.Errorf("cbor input had wrong number of fields")
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 15:33:29 +00:00
|
|
|
// t.TArrival (int64) (int64)
|
2020-02-12 18:23:15 +00:00
|
|
|
{
|
2022-05-23 19:11:46 +00:00
|
|
|
maj, extra, err := cr.ReadHeader()
|
2020-02-12 18:23:15 +00:00
|
|
|
var extraI int64
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
2020-02-12 18:23:15 +00:00
|
|
|
switch maj {
|
|
|
|
case cbg.MajUnsignedInt:
|
|
|
|
extraI = int64(extra)
|
|
|
|
if extraI < 0 {
|
|
|
|
return fmt.Errorf("int64 positive overflow")
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
2020-02-12 18:23:15 +00:00
|
|
|
case cbg.MajNegativeInt:
|
|
|
|
extraI = int64(extra)
|
|
|
|
if extraI < 0 {
|
|
|
|
return fmt.Errorf("int64 negative oveflow")
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
2020-02-12 18:23:15 +00:00
|
|
|
extraI = -1 - extraI
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("wrong type for int64 field: %d", maj)
|
|
|
|
}
|
2020-02-12 18:08:49 +00:00
|
|
|
|
2020-08-04 15:33:29 +00:00
|
|
|
t.TArrival = int64(extraI)
|
2020-02-12 18:23:15 +00:00
|
|
|
}
|
|
|
|
// t.TSent (int64) (int64)
|
|
|
|
{
|
2022-05-23 19:11:46 +00:00
|
|
|
maj, extra, err := cr.ReadHeader()
|
2020-02-12 18:23:15 +00:00
|
|
|
var extraI int64
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
switch maj {
|
|
|
|
case cbg.MajUnsignedInt:
|
|
|
|
extraI = int64(extra)
|
|
|
|
if extraI < 0 {
|
|
|
|
return fmt.Errorf("int64 positive overflow")
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
2020-02-12 18:23:15 +00:00
|
|
|
case cbg.MajNegativeInt:
|
|
|
|
extraI = int64(extra)
|
|
|
|
if extraI < 0 {
|
|
|
|
return fmt.Errorf("int64 negative oveflow")
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
2020-02-12 18:23:15 +00:00
|
|
|
extraI = -1 - extraI
|
2020-02-12 18:08:49 +00:00
|
|
|
default:
|
2020-02-12 18:23:15 +00:00
|
|
|
return fmt.Errorf("wrong type for int64 field: %d", maj)
|
2020-02-12 18:08:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 18:23:15 +00:00
|
|
|
t.TSent = int64(extraI)
|
|
|
|
}
|
2020-02-12 18:08:49 +00:00
|
|
|
return nil
|
|
|
|
}
|