2021-06-18 18:45:29 +00:00
|
|
|
package kit
|
2021-05-25 23:04:13 +00:00
|
|
|
|
|
|
|
import (
|
2021-06-10 17:25:02 +00:00
|
|
|
"context"
|
2022-03-17 20:39:52 +00:00
|
|
|
"fmt"
|
2021-05-25 23:04:13 +00:00
|
|
|
"testing"
|
2022-03-17 20:39:52 +00:00
|
|
|
"time"
|
2021-05-25 23:04:13 +00:00
|
|
|
|
2022-09-08 18:20:05 +00:00
|
|
|
libp2pcrypto "github.com/libp2p/go-libp2p/core/crypto"
|
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2021-06-17 20:58:29 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-06-14 15:00:51 +00:00
|
|
|
|
2021-06-10 17:25:02 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2021-05-25 23:04:13 +00:00
|
|
|
"github.com/filecoin-project/lotus/api/v1api"
|
2021-06-17 20:58:29 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2022-06-14 17:21:34 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/wallet/key"
|
2022-09-08 18:20:05 +00:00
|
|
|
"github.com/filecoin-project/lotus/node"
|
2021-05-25 23:04:13 +00:00
|
|
|
)
|
|
|
|
|
2022-09-08 18:20:05 +00:00
|
|
|
type Libp2p struct {
|
|
|
|
PeerID peer.ID
|
|
|
|
PrivKey libp2pcrypto.PrivKey
|
|
|
|
}
|
|
|
|
|
2021-06-11 17:26:25 +00:00
|
|
|
// TestFullNode represents a full node enrolled in an Ensemble.
|
2021-05-25 23:04:13 +00:00
|
|
|
type TestFullNode struct {
|
|
|
|
v1api.FullNode
|
|
|
|
|
|
|
|
t *testing.T
|
|
|
|
|
|
|
|
// ListenAddr is the address on which an API server is listening, if an
|
|
|
|
// API server is created for this Node.
|
|
|
|
ListenAddr multiaddr.Multiaddr
|
2022-06-14 17:21:34 +00:00
|
|
|
DefaultKey *key.Key
|
2021-05-25 23:04:13 +00:00
|
|
|
|
2022-09-08 18:20:05 +00:00
|
|
|
Pkey *Libp2p
|
|
|
|
|
|
|
|
Stop node.StopFunc
|
|
|
|
|
2021-06-11 17:26:25 +00:00
|
|
|
options nodeOpts
|
2021-05-25 23:04:13 +00:00
|
|
|
}
|
2021-06-10 17:25:02 +00:00
|
|
|
|
2022-09-08 18:20:05 +00:00
|
|
|
func (f TestFullNode) Shutdown(ctx context.Context) error {
|
|
|
|
return f.Stop(ctx)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func (f *TestFullNode) ClientImportCARFile(ctx context.Context, rseed int, size int) (res *api.ImportRes, carv1FilePath string, origFilePath string) {
|
|
|
|
carv1FilePath, origFilePath = CreateRandomCARv1(f.t, rseed, size)
|
|
|
|
res, err := f.ClientImport(ctx, api.FileRef{Path: carv1FilePath, IsCAR: true})
|
|
|
|
require.NoError(f.t, err)
|
|
|
|
return res, carv1FilePath, origFilePath
|
|
|
|
}
|
|
|
|
|
2021-06-11 17:26:25 +00:00
|
|
|
// CreateImportFile creates a random file with the specified seed and size, and
|
|
|
|
// imports it into the full node.
|
2021-06-10 17:25:02 +00:00
|
|
|
func (f *TestFullNode) CreateImportFile(ctx context.Context, rseed int, size int) (res *api.ImportRes, path string) {
|
|
|
|
path = CreateRandomFile(f.t, rseed, size)
|
|
|
|
res, err := f.ClientImport(ctx, api.FileRef{Path: path})
|
|
|
|
require.NoError(f.t, err)
|
|
|
|
return res, path
|
|
|
|
}
|
2021-06-17 20:58:29 +00:00
|
|
|
|
|
|
|
// WaitTillChain waits until a specified chain condition is met. It returns
|
|
|
|
// the first tipset where the condition is met.
|
|
|
|
func (f *TestFullNode) WaitTillChain(ctx context.Context, pred ChainPredicate) *types.TipSet {
|
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
heads, err := f.ChainNotify(ctx)
|
|
|
|
require.NoError(f.t, err)
|
|
|
|
|
|
|
|
for chg := range heads {
|
|
|
|
for _, c := range chg {
|
|
|
|
if c.Type != "apply" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if ts := c.Val; pred(ts) {
|
|
|
|
return ts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.Fail(f.t, "chain condition not met")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-03-17 20:39:52 +00:00
|
|
|
func (f *TestFullNode) WaitForSectorActive(ctx context.Context, t *testing.T, sn abi.SectorNumber, maddr address.Address) {
|
|
|
|
for {
|
|
|
|
active, err := f.StateMinerActiveSectors(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
for _, si := range active {
|
|
|
|
if si.SectorNumber == sn {
|
|
|
|
fmt.Printf("ACTIVE\n")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-12 20:37:24 +00:00
|
|
|
func (f *TestFullNode) AssignPrivKey(pkey *Libp2p) {
|
|
|
|
f.Pkey = pkey
|
2022-09-08 18:20:05 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 20:58:29 +00:00
|
|
|
// ChainPredicate encapsulates a chain condition.
|
|
|
|
type ChainPredicate func(set *types.TipSet) bool
|
|
|
|
|
|
|
|
// HeightAtLeast returns a ChainPredicate that is satisfied when the chain
|
|
|
|
// height is equal or higher to the target.
|
|
|
|
func HeightAtLeast(target abi.ChainEpoch) ChainPredicate {
|
|
|
|
return func(ts *types.TipSet) bool {
|
|
|
|
return ts.Height() >= target
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BlockMinedBy returns a ChainPredicate that is satisfied when we observe the
|
|
|
|
// first block mined by the specified miner.
|
|
|
|
func BlockMinedBy(miner address.Address) ChainPredicate {
|
|
|
|
return func(ts *types.TipSet) bool {
|
|
|
|
for _, b := range ts.Blocks() {
|
|
|
|
if b.Miner == miner {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|