2019-07-10 13:06:04 +00:00
|
|
|
package node_test
|
2019-07-09 16:27:07 +00:00
|
|
|
|
|
|
|
import (
|
2019-07-24 23:23:06 +00:00
|
|
|
"bytes"
|
2019-07-09 16:27:07 +00:00
|
|
|
"context"
|
2019-10-03 00:02:06 +00:00
|
|
|
"crypto/rand"
|
2019-11-30 04:31:16 +00:00
|
|
|
"io/ioutil"
|
2019-07-09 16:36:40 +00:00
|
|
|
"net/http/httptest"
|
2020-06-01 12:59:51 +00:00
|
|
|
"os"
|
2019-07-09 16:27:07 +00:00
|
|
|
"testing"
|
2020-01-14 02:51:14 +00:00
|
|
|
"time"
|
2019-07-09 16:27:07 +00:00
|
|
|
|
2020-03-30 14:08:20 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/lotuslog"
|
|
|
|
"github.com/filecoin-project/lotus/storage/mockstorage"
|
|
|
|
"github.com/filecoin-project/sector-storage/ffiwrapper"
|
|
|
|
|
2020-04-28 17:13:46 +00:00
|
|
|
"github.com/filecoin-project/go-storedcounter"
|
2019-09-23 15:27:30 +00:00
|
|
|
"github.com/ipfs/go-datastore"
|
2020-01-08 19:10:57 +00:00
|
|
|
logging "github.com/ipfs/go-log/v2"
|
2020-01-09 13:23:44 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/crypto"
|
2019-09-23 15:27:30 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
2019-07-24 23:25:14 +00:00
|
|
|
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
|
2019-09-23 15:27:30 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-07-10 17:28:49 +00:00
|
|
|
|
2020-02-23 15:50:36 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-05-20 17:43:22 +00:00
|
|
|
"github.com/filecoin-project/go-jsonrpc"
|
2020-02-23 15:50:36 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
|
|
|
saminer "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
2020-03-10 22:42:41 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
2020-05-14 02:32:04 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
|
2020-02-23 15:50:36 +00:00
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
"github.com/filecoin-project/lotus/api/client"
|
|
|
|
"github.com/filecoin-project/lotus/api/test"
|
2020-02-23 15:50:36 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2020-02-23 15:50:36 +00:00
|
|
|
genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-02-23 15:50:36 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/wallet"
|
2019-11-30 04:31:16 +00:00
|
|
|
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
|
2020-02-23 15:50:36 +00:00
|
|
|
genesis "github.com/filecoin-project/lotus/genesis"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/miner"
|
|
|
|
"github.com/filecoin-project/lotus/node"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules"
|
|
|
|
modtest "github.com/filecoin-project/lotus/node/modules/testing"
|
|
|
|
"github.com/filecoin-project/lotus/node/repo"
|
2020-03-30 14:08:20 +00:00
|
|
|
sectorstorage "github.com/filecoin-project/sector-storage"
|
2020-03-27 23:00:21 +00:00
|
|
|
"github.com/filecoin-project/sector-storage/mock"
|
2019-07-09 16:27:07 +00:00
|
|
|
)
|
|
|
|
|
2019-11-30 22:22:26 +00:00
|
|
|
func init() {
|
2019-12-02 12:51:16 +00:00
|
|
|
_ = logging.SetLogLevel("*", "INFO")
|
2019-12-03 01:41:31 +00:00
|
|
|
|
2020-03-10 22:42:41 +00:00
|
|
|
power.ConsensusMinerMinPower = big.NewInt(2048)
|
2020-05-12 16:58:43 +00:00
|
|
|
saminer.SupportedProofTypes = map[abi.RegisteredProof]struct{}{
|
|
|
|
abi.RegisteredProof_StackedDRG2KiBSeal: {},
|
|
|
|
}
|
2020-05-14 02:32:04 +00:00
|
|
|
verifreg.MinVerifiedDealSize = big.NewInt(256)
|
2019-11-30 22:22:26 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 02:04:33 +00:00
|
|
|
func testStorageNode(ctx context.Context, t *testing.T, waddr address.Address, act address.Address, pk crypto.PrivKey, tnd test.TestNode, mn mocknet.Mocknet, opts node.Option) test.TestStorageNode {
|
2019-09-23 15:27:30 +00:00
|
|
|
r := repo.NewMemory(nil)
|
|
|
|
|
2019-11-12 17:59:38 +00:00
|
|
|
lr, err := r.Lock(repo.StorageMiner)
|
2019-09-23 15:27:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-10-03 00:02:06 +00:00
|
|
|
ks, err := lr.KeyStore()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
kbytes, err := pk.Bytes()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = ks.Put("libp2p-host", types.KeyInfo{
|
|
|
|
Type: "libp2p-host",
|
|
|
|
PrivateKey: kbytes,
|
|
|
|
})
|
2019-09-23 15:27:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ds, err := lr.Datastore("/metadata")
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = ds.Put(datastore.NewKey("miner-address"), act.Bytes())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-05-19 23:24:59 +00:00
|
|
|
nic := storedcounter.New(ds, datastore.NewKey(modules.StorageCounterDSPrefix))
|
2020-06-01 12:49:48 +00:00
|
|
|
for i := 0; i < test.GenesisPreseals; i++ {
|
2020-05-27 20:53:20 +00:00
|
|
|
_, err := nic.Next()
|
|
|
|
require.NoError(t, err)
|
2020-03-06 07:30:20 +00:00
|
|
|
}
|
2020-05-27 20:53:20 +00:00
|
|
|
_, err = nic.Next()
|
|
|
|
require.NoError(t, err)
|
2020-03-06 07:30:20 +00:00
|
|
|
|
2019-09-23 15:27:30 +00:00
|
|
|
err = lr.Close()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-10-03 00:02:06 +00:00
|
|
|
peerid, err := peer.IDFromPrivateKey(pk)
|
2019-09-23 15:27:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-02-23 07:49:15 +00:00
|
|
|
enc, err := actors.SerializeParams(&saminer.ChangePeerIDParams{NewID: peerid})
|
2019-09-23 15:27:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
msg := &types.Message{
|
|
|
|
To: act,
|
|
|
|
From: waddr,
|
2020-02-23 07:49:15 +00:00
|
|
|
Method: builtin.MethodsMiner.ChangePeerID,
|
2019-09-23 15:27:30 +00:00
|
|
|
Params: enc,
|
|
|
|
Value: types.NewInt(0),
|
|
|
|
GasPrice: types.NewInt(0),
|
2020-03-18 20:45:37 +00:00
|
|
|
GasLimit: 1000000,
|
2019-09-23 15:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = tnd.MpoolPushMessage(ctx, msg)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// start node
|
|
|
|
var minerapi api.StorageMiner
|
|
|
|
|
2020-04-23 21:12:42 +00:00
|
|
|
mineBlock := make(chan func(bool))
|
2019-09-23 15:27:30 +00:00
|
|
|
// TODO: use stop
|
|
|
|
_, err = node.New(ctx,
|
|
|
|
node.StorageMiner(&minerapi),
|
|
|
|
node.Online(),
|
|
|
|
node.Repo(r),
|
2019-10-23 11:02:00 +00:00
|
|
|
node.Test(),
|
2019-09-23 15:27:30 +00:00
|
|
|
|
2019-11-06 17:21:37 +00:00
|
|
|
node.MockHost(mn),
|
|
|
|
|
2019-09-23 15:27:30 +00:00
|
|
|
node.Override(new(api.FullNode), tnd),
|
2019-11-30 23:17:50 +00:00
|
|
|
node.Override(new(*miner.Miner), miner.NewTestMiner(mineBlock, act)),
|
2020-01-14 02:04:33 +00:00
|
|
|
|
|
|
|
opts,
|
2019-09-23 15:27:30 +00:00
|
|
|
)
|
2019-11-30 04:31:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to construct node: %v", err)
|
|
|
|
}
|
2019-09-23 15:27:30 +00:00
|
|
|
|
|
|
|
/*// Bootstrap with full node
|
|
|
|
remoteAddrs, err := tnd.NetAddrsListen(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = minerapi.NetConnect(ctx, remoteAddrs)
|
|
|
|
require.NoError(t, err)*/
|
2020-04-23 21:12:42 +00:00
|
|
|
mineOne := func(ctx context.Context, cb func(bool)) error {
|
2019-11-30 23:17:50 +00:00
|
|
|
select {
|
2020-04-23 21:12:42 +00:00
|
|
|
case mineBlock <- cb:
|
2019-11-30 23:17:50 +00:00
|
|
|
return nil
|
|
|
|
case <-ctx.Done():
|
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
}
|
2019-09-23 15:27:30 +00:00
|
|
|
|
2019-12-02 12:51:16 +00:00
|
|
|
return test.TestStorageNode{StorageMiner: minerapi, MineOne: mineOne}
|
2019-09-23 15:27:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 17:50:52 +00:00
|
|
|
func builder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test.TestNode, []test.TestStorageNode) {
|
2019-07-09 16:27:07 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
mn := mocknet.New(ctx)
|
|
|
|
|
2019-09-23 15:27:30 +00:00
|
|
|
fulls := make([]test.TestNode, nFull)
|
|
|
|
storers := make([]test.TestStorageNode, len(storage))
|
2019-07-09 16:27:07 +00:00
|
|
|
|
2019-11-06 06:26:50 +00:00
|
|
|
pk, _, err := crypto.GenerateEd25519Key(rand.Reader)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
minerPid, err := peer.IDFromPrivateKey(pk)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-07-24 23:23:06 +00:00
|
|
|
var genbuf bytes.Buffer
|
|
|
|
|
2019-11-30 04:43:53 +00:00
|
|
|
if len(storage) > 1 {
|
2019-11-30 04:31:16 +00:00
|
|
|
panic("need more peer IDs")
|
|
|
|
}
|
|
|
|
// PRESEAL SECTION, TRY TO REPLACE WITH BETTER IN THE FUTURE
|
|
|
|
// TODO: would be great if there was a better way to fake the preseals
|
2020-02-23 07:49:15 +00:00
|
|
|
|
|
|
|
var genms []genesis.Miner
|
|
|
|
var maddrs []address.Address
|
2020-02-23 20:32:14 +00:00
|
|
|
var genaccs []genesis.Actor
|
|
|
|
var keys []*wallet.Key
|
2019-11-30 23:17:50 +00:00
|
|
|
|
|
|
|
var presealDirs []string
|
2019-11-30 04:31:16 +00:00
|
|
|
for i := 0; i < len(storage); i++ {
|
2020-02-23 15:50:36 +00:00
|
|
|
maddr, err := address.NewIDAddress(genesis2.MinerStart + uint64(i))
|
2019-11-30 04:31:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
tdir, err := ioutil.TempDir("", "preseal-memgen")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-06-01 12:49:48 +00:00
|
|
|
genm, k, err := seed.PreSeal(maddr, abi.RegisteredProof_StackedDRG2KiBPoSt, 0, test.GenesisPreseals, tdir, []byte("make genesis mem random"), nil)
|
2019-11-30 04:31:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-02-23 20:32:14 +00:00
|
|
|
genm.PeerId = minerPid
|
|
|
|
|
|
|
|
wk, err := wallet.NewKey(*k)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2019-11-30 23:17:50 +00:00
|
|
|
|
2020-02-23 20:32:14 +00:00
|
|
|
genaccs = append(genaccs, genesis.Actor{
|
|
|
|
Type: genesis.TAccount,
|
2020-05-11 21:13:02 +00:00
|
|
|
Balance: big.Mul(big.NewInt(50000), types.NewInt(build.FilecoinPrecision)),
|
2020-02-23 20:32:14 +00:00
|
|
|
Meta: (&genesis.AccountMeta{Owner: wk.Address}).ActorMeta(),
|
|
|
|
})
|
|
|
|
|
|
|
|
keys = append(keys, wk)
|
2019-11-30 23:17:50 +00:00
|
|
|
presealDirs = append(presealDirs, tdir)
|
2020-02-23 07:49:15 +00:00
|
|
|
maddrs = append(maddrs, maddr)
|
|
|
|
genms = append(genms, *genm)
|
|
|
|
}
|
|
|
|
|
|
|
|
templ := &genesis.Template{
|
2020-04-14 03:05:19 +00:00
|
|
|
Accounts: genaccs,
|
|
|
|
Miners: genms,
|
2020-04-17 23:13:02 +00:00
|
|
|
Timestamp: uint64(time.Now().Unix() - 10000), // some time sufficiently far in the past
|
2019-11-30 04:31:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// END PRESEAL SECTION
|
|
|
|
|
2019-09-23 15:27:30 +00:00
|
|
|
for i := 0; i < nFull; i++ {
|
2019-07-24 23:23:06 +00:00
|
|
|
var genesis node.Option
|
|
|
|
if i == 0 {
|
2020-02-23 07:49:15 +00:00
|
|
|
genesis = node.Override(new(modules.Genesis), modtest.MakeGenesisMem(&genbuf, *templ))
|
2019-07-24 23:23:06 +00:00
|
|
|
} else {
|
|
|
|
genesis = node.Override(new(modules.Genesis), modules.LoadGenesis(genbuf.Bytes()))
|
|
|
|
}
|
|
|
|
|
2019-07-09 16:27:07 +00:00
|
|
|
var err error
|
2019-09-17 14:45:09 +00:00
|
|
|
// TODO: Don't ignore stop
|
|
|
|
_, err = node.New(ctx,
|
2019-09-23 15:27:30 +00:00
|
|
|
node.FullAPI(&fulls[i].FullNode),
|
2019-07-10 13:06:04 +00:00
|
|
|
node.Online(),
|
2019-07-18 15:52:48 +00:00
|
|
|
node.Repo(repo.NewMemory(nil)),
|
2019-07-29 19:34:34 +00:00
|
|
|
node.MockHost(mn),
|
2019-10-23 11:02:00 +00:00
|
|
|
node.Test(),
|
2019-07-24 23:23:06 +00:00
|
|
|
|
|
|
|
genesis,
|
2019-07-09 16:27:07 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-09-23 15:27:30 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-23 17:50:52 +00:00
|
|
|
for i, def := range storage {
|
2019-09-23 15:27:30 +00:00
|
|
|
// TODO: support non-bootstrap miners
|
|
|
|
if i != 0 {
|
|
|
|
t.Fatal("only one storage node supported")
|
|
|
|
}
|
2020-04-23 17:50:52 +00:00
|
|
|
if def.Full != 0 {
|
2019-09-23 15:27:30 +00:00
|
|
|
t.Fatal("storage nodes only supported on the first full node")
|
|
|
|
}
|
|
|
|
|
2020-04-23 17:50:52 +00:00
|
|
|
f := fulls[def.Full]
|
2020-02-23 20:32:14 +00:00
|
|
|
if _, err := f.FullNode.WalletImport(ctx, &keys[i].KeyInfo); err != nil {
|
2020-03-05 22:02:01 +00:00
|
|
|
t.Fatal(err)
|
2020-02-23 20:32:14 +00:00
|
|
|
}
|
|
|
|
if err := f.FullNode.WalletSetDefault(ctx, keys[i].Address); err != nil {
|
2020-03-05 22:02:01 +00:00
|
|
|
t.Fatal(err)
|
2020-02-23 20:32:14 +00:00
|
|
|
}
|
2019-09-23 15:27:30 +00:00
|
|
|
|
2020-02-23 07:49:15 +00:00
|
|
|
genMiner := maddrs[i]
|
|
|
|
wa := genms[i].Worker
|
2019-09-23 15:27:30 +00:00
|
|
|
|
2020-01-14 02:04:33 +00:00
|
|
|
storers[i] = testStorageNode(ctx, t, wa, genMiner, pk, f, mn, node.Options())
|
2020-03-05 22:02:01 +00:00
|
|
|
if err := storers[i].StorageAddLocal(ctx, presealDirs[i]); err != nil {
|
2020-03-18 01:08:11 +00:00
|
|
|
t.Fatalf("%+v", err)
|
2019-11-30 23:17:50 +00:00
|
|
|
}
|
2020-03-05 22:02:01 +00:00
|
|
|
/*
|
|
|
|
sma := storers[i].StorageMiner.(*impl.StorageMinerAPI)
|
2019-11-30 23:17:50 +00:00
|
|
|
|
2020-03-05 22:02:01 +00:00
|
|
|
psd := presealDirs[i]
|
|
|
|
*/
|
2019-07-09 16:27:07 +00:00
|
|
|
}
|
|
|
|
|
2019-07-09 17:03:36 +00:00
|
|
|
if err := mn.LinkAll(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-09-23 15:27:30 +00:00
|
|
|
return fulls, storers
|
2019-07-09 16:27:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 17:50:52 +00:00
|
|
|
func mockSbBuilder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test.TestNode, []test.TestStorageNode) {
|
2020-01-13 20:47:27 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
mn := mocknet.New(ctx)
|
|
|
|
|
|
|
|
fulls := make([]test.TestNode, nFull)
|
|
|
|
storers := make([]test.TestStorageNode, len(storage))
|
|
|
|
|
|
|
|
var genbuf bytes.Buffer
|
|
|
|
|
|
|
|
// PRESEAL SECTION, TRY TO REPLACE WITH BETTER IN THE FUTURE
|
|
|
|
// TODO: would be great if there was a better way to fake the preseals
|
|
|
|
|
2020-02-23 07:49:15 +00:00
|
|
|
var genms []genesis.Miner
|
2020-02-23 15:50:36 +00:00
|
|
|
var genaccs []genesis.Actor
|
2020-02-23 07:49:15 +00:00
|
|
|
var maddrs []address.Address
|
2020-01-13 20:47:27 +00:00
|
|
|
var presealDirs []string
|
2020-02-23 15:50:36 +00:00
|
|
|
var keys []*wallet.Key
|
2020-04-23 21:12:42 +00:00
|
|
|
var pidKeys []crypto.PrivKey
|
2020-01-13 20:47:27 +00:00
|
|
|
for i := 0; i < len(storage); i++ {
|
2020-02-23 15:50:36 +00:00
|
|
|
maddr, err := address.NewIDAddress(genesis2.MinerStart + uint64(i))
|
2020-01-13 20:47:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
tdir, err := ioutil.TempDir("", "preseal-memgen")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-04-23 17:50:52 +00:00
|
|
|
|
|
|
|
preseals := storage[i].Preseal
|
|
|
|
if preseals == test.PresealGenesis {
|
2020-06-01 12:49:48 +00:00
|
|
|
preseals = test.GenesisPreseals
|
2020-04-23 17:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
genm, k, err := mockstorage.PreSeal(2048, maddr, preseals)
|
2020-01-13 20:47:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-04-23 21:12:42 +00:00
|
|
|
|
|
|
|
pk, _, err := crypto.GenerateEd25519Key(rand.Reader)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
minerPid, err := peer.IDFromPrivateKey(pk)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-02-23 15:50:36 +00:00
|
|
|
genm.PeerId = minerPid
|
|
|
|
|
|
|
|
wk, err := wallet.NewKey(*k)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2020-01-13 20:47:27 +00:00
|
|
|
|
2020-02-23 15:50:36 +00:00
|
|
|
genaccs = append(genaccs, genesis.Actor{
|
|
|
|
Type: genesis.TAccount,
|
2020-05-11 21:13:02 +00:00
|
|
|
Balance: big.Mul(big.NewInt(50000), types.NewInt(build.FilecoinPrecision)),
|
2020-02-23 15:50:36 +00:00
|
|
|
Meta: (&genesis.AccountMeta{Owner: wk.Address}).ActorMeta(),
|
|
|
|
})
|
|
|
|
|
|
|
|
keys = append(keys, wk)
|
2020-04-23 21:12:42 +00:00
|
|
|
pidKeys = append(pidKeys, pk)
|
2020-01-13 20:47:27 +00:00
|
|
|
presealDirs = append(presealDirs, tdir)
|
2020-02-23 07:49:15 +00:00
|
|
|
maddrs = append(maddrs, maddr)
|
|
|
|
genms = append(genms, *genm)
|
|
|
|
}
|
|
|
|
templ := &genesis.Template{
|
2020-04-14 03:05:19 +00:00
|
|
|
Accounts: genaccs,
|
|
|
|
Miners: genms,
|
2020-06-01 12:49:48 +00:00
|
|
|
Timestamp: uint64(time.Now().Unix() - (build.BlockDelay * 20000)),
|
2020-01-13 20:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// END PRESEAL SECTION
|
|
|
|
|
|
|
|
for i := 0; i < nFull; i++ {
|
|
|
|
var genesis node.Option
|
|
|
|
if i == 0 {
|
2020-02-23 07:49:15 +00:00
|
|
|
genesis = node.Override(new(modules.Genesis), modtest.MakeGenesisMem(&genbuf, *templ))
|
2020-01-13 20:47:27 +00:00
|
|
|
} else {
|
|
|
|
genesis = node.Override(new(modules.Genesis), modules.LoadGenesis(genbuf.Bytes()))
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
// TODO: Don't ignore stop
|
|
|
|
_, err = node.New(ctx,
|
|
|
|
node.FullAPI(&fulls[i].FullNode),
|
|
|
|
node.Online(),
|
|
|
|
node.Repo(repo.NewMemory(nil)),
|
|
|
|
node.MockHost(mn),
|
|
|
|
node.Test(),
|
|
|
|
|
2020-03-26 02:50:56 +00:00
|
|
|
node.Override(new(ffiwrapper.Verifier), mock.MockVerifier),
|
2020-01-13 20:47:27 +00:00
|
|
|
|
|
|
|
genesis,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2020-02-23 15:50:36 +00:00
|
|
|
t.Fatalf("%+v", err)
|
2020-01-13 20:47:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 17:50:52 +00:00
|
|
|
for i, def := range storage {
|
2020-01-13 20:47:27 +00:00
|
|
|
// TODO: support non-bootstrap miners
|
2020-04-23 17:50:52 +00:00
|
|
|
if def.Full != 0 {
|
2020-01-13 20:47:27 +00:00
|
|
|
t.Fatal("storage nodes only supported on the first full node")
|
|
|
|
}
|
|
|
|
|
2020-04-23 17:50:52 +00:00
|
|
|
f := fulls[def.Full]
|
2020-02-23 15:50:36 +00:00
|
|
|
if _, err := f.FullNode.WalletImport(ctx, &keys[i].KeyInfo); err != nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
if err := f.FullNode.WalletSetDefault(ctx, keys[i].Address); err != nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2020-01-13 20:47:27 +00:00
|
|
|
|
2020-04-23 21:12:42 +00:00
|
|
|
storers[i] = testStorageNode(ctx, t, genms[i].Worker, maddrs[i], pidKeys[i], f, mn, node.Options(
|
2020-03-23 11:40:02 +00:00
|
|
|
node.Override(new(sectorstorage.SectorManager), func() (sectorstorage.SectorManager, error) {
|
2020-05-12 17:58:12 +00:00
|
|
|
return mock.NewMockSectorMgr(build.DefaultSectorSize()), nil
|
2020-03-05 22:02:01 +00:00
|
|
|
}),
|
2020-04-17 23:01:11 +00:00
|
|
|
node.Override(new(ffiwrapper.Verifier), mock.MockVerifier),
|
2020-03-23 11:40:02 +00:00
|
|
|
node.Unset(new(*sectorstorage.Manager)),
|
2020-01-14 02:04:33 +00:00
|
|
|
))
|
2020-01-13 20:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := mn.LinkAll(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fulls, storers
|
|
|
|
}
|
|
|
|
|
2019-07-09 16:27:07 +00:00
|
|
|
func TestAPI(t *testing.T) {
|
|
|
|
test.TestApis(t, builder)
|
|
|
|
}
|
2019-07-09 16:36:40 +00:00
|
|
|
|
2020-04-23 17:50:52 +00:00
|
|
|
func rpcBuilder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test.TestNode, []test.TestStorageNode) {
|
2019-09-23 15:27:30 +00:00
|
|
|
fullApis, storaApis := builder(t, nFull, storage)
|
|
|
|
fulls := make([]test.TestNode, nFull)
|
|
|
|
storers := make([]test.TestStorageNode, len(storage))
|
|
|
|
|
|
|
|
for i, a := range fullApis {
|
|
|
|
rpcServer := jsonrpc.NewServer()
|
|
|
|
rpcServer.Register("Filecoin", a)
|
|
|
|
testServ := httptest.NewServer(rpcServer) // todo: close
|
2019-07-09 16:36:40 +00:00
|
|
|
|
2019-09-23 15:27:30 +00:00
|
|
|
var err error
|
2019-10-04 16:02:25 +00:00
|
|
|
fulls[i].FullNode, _, err = client.NewFullNodeRPC("ws://"+testServ.Listener.Addr().String(), nil)
|
2019-09-23 15:27:30 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2019-07-09 16:36:40 +00:00
|
|
|
|
2019-09-23 15:27:30 +00:00
|
|
|
for i, a := range storaApis {
|
2019-07-09 16:36:40 +00:00
|
|
|
rpcServer := jsonrpc.NewServer()
|
|
|
|
rpcServer.Register("Filecoin", a)
|
|
|
|
testServ := httptest.NewServer(rpcServer) // todo: close
|
2019-07-15 16:28:00 +00:00
|
|
|
|
|
|
|
var err error
|
2019-10-04 16:02:25 +00:00
|
|
|
storers[i].StorageMiner, _, err = client.NewStorageMinerRPC("ws://"+testServ.Listener.Addr().String(), nil)
|
2019-07-15 16:28:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-11-30 23:17:50 +00:00
|
|
|
storers[i].MineOne = a.MineOne
|
2019-07-09 16:36:40 +00:00
|
|
|
}
|
2019-09-23 15:27:30 +00:00
|
|
|
|
|
|
|
return fulls, storers
|
2019-07-09 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPIRPC(t *testing.T) {
|
|
|
|
test.TestApis(t, rpcBuilder)
|
|
|
|
}
|
2019-11-06 06:26:50 +00:00
|
|
|
|
|
|
|
func TestAPIDealFlow(t *testing.T) {
|
2020-01-21 16:05:10 +00:00
|
|
|
logging.SetLogLevel("miner", "ERROR")
|
2020-03-06 07:30:20 +00:00
|
|
|
logging.SetLogLevel("chainstore", "ERROR")
|
2020-01-21 16:05:10 +00:00
|
|
|
logging.SetLogLevel("chain", "ERROR")
|
|
|
|
logging.SetLogLevel("sub", "ERROR")
|
|
|
|
logging.SetLogLevel("storageminer", "ERROR")
|
|
|
|
|
2020-03-31 19:55:42 +00:00
|
|
|
t.Run("TestDealFlow", func(t *testing.T) {
|
|
|
|
test.TestDealFlow(t, mockSbBuilder, 10*time.Millisecond, false)
|
|
|
|
})
|
2020-03-30 14:08:20 +00:00
|
|
|
t.Run("WithExportedCAR", func(t *testing.T) {
|
|
|
|
test.TestDealFlow(t, mockSbBuilder, 10*time.Millisecond, true)
|
|
|
|
})
|
2020-04-21 18:38:28 +00:00
|
|
|
t.Run("TestDoubleDealFlow", func(t *testing.T) {
|
|
|
|
test.TestDoubleDealFlow(t, mockSbBuilder, 10*time.Millisecond)
|
|
|
|
})
|
2020-01-14 02:04:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPIDealFlowReal(t *testing.T) {
|
2019-12-09 15:49:46 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping test in short mode")
|
|
|
|
}
|
2020-03-25 18:21:53 +00:00
|
|
|
lotuslog.SetupLogLevels()
|
2020-03-06 07:30:20 +00:00
|
|
|
logging.SetLogLevel("miner", "ERROR")
|
|
|
|
logging.SetLogLevel("chainstore", "ERROR")
|
|
|
|
logging.SetLogLevel("chain", "ERROR")
|
|
|
|
logging.SetLogLevel("sub", "ERROR")
|
|
|
|
logging.SetLogLevel("storageminer", "ERROR")
|
|
|
|
|
2020-03-30 14:08:20 +00:00
|
|
|
test.TestDealFlow(t, builder, time.Second, false)
|
2019-11-06 06:26:50 +00:00
|
|
|
}
|
2020-04-23 21:12:42 +00:00
|
|
|
|
|
|
|
func TestDealMining(t *testing.T) {
|
|
|
|
logging.SetLogLevel("miner", "ERROR")
|
|
|
|
logging.SetLogLevel("chainstore", "ERROR")
|
|
|
|
logging.SetLogLevel("chain", "ERROR")
|
|
|
|
logging.SetLogLevel("sub", "ERROR")
|
|
|
|
logging.SetLogLevel("storageminer", "ERROR")
|
|
|
|
|
|
|
|
test.TestDealMining(t, mockSbBuilder, 50*time.Millisecond, false)
|
|
|
|
}
|
2020-06-01 12:49:48 +00:00
|
|
|
|
|
|
|
func TestPledgeSectors(t *testing.T) {
|
|
|
|
logging.SetLogLevel("miner", "ERROR")
|
|
|
|
logging.SetLogLevel("chainstore", "ERROR")
|
|
|
|
logging.SetLogLevel("chain", "ERROR")
|
|
|
|
logging.SetLogLevel("sub", "ERROR")
|
|
|
|
logging.SetLogLevel("storageminer", "ERROR")
|
|
|
|
|
|
|
|
t.Run("1", func(t *testing.T) {
|
|
|
|
test.TestPledgeSector(t, mockSbBuilder, 50*time.Millisecond, 1)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("100", func(t *testing.T) {
|
|
|
|
test.TestPledgeSector(t, mockSbBuilder, 50*time.Millisecond, 100)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("1000", func(t *testing.T) {
|
|
|
|
if testing.Short() { // takes ~16s
|
|
|
|
t.Skip("skipping test in short mode")
|
|
|
|
}
|
|
|
|
|
|
|
|
test.TestPledgeSector(t, mockSbBuilder, 50*time.Millisecond, 1000)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWindowedPost(t *testing.T) {
|
2020-06-01 12:59:51 +00:00
|
|
|
if os.Getenv("LOTUS_TEST_WINDOW_POST") != "1" {
|
|
|
|
t.Skip("this takes a few minutes, set LOTUS_TEST_WINDOW_POST=1 to run")
|
2020-06-01 12:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
logging.SetLogLevel("miner", "ERROR")
|
|
|
|
logging.SetLogLevel("chainstore", "ERROR")
|
|
|
|
logging.SetLogLevel("chain", "ERROR")
|
|
|
|
logging.SetLogLevel("sub", "ERROR")
|
|
|
|
logging.SetLogLevel("storageminer", "ERROR")
|
|
|
|
|
2020-06-01 12:59:51 +00:00
|
|
|
test.TestWindowPost(t, mockSbBuilder, 5*time.Millisecond, 10)
|
2020-06-01 12:49:48 +00:00
|
|
|
}
|