use runtime image for lotus testplans (#35)

* use runtime image

* no need to compile with `make 2k`

* use new go-sdk /2 (#36)

* use new go-sdk

* use custom runtime image (#38)

* improve runtime image

* remove redundant runners

* enable go build cache

* remove replace lotus directive

* add git clone for lotus as part of manifest.toml

* use base build image

* compile `lotus-testground` on `current master` from Lotus (#41)

* automated scripts to build/push base build and runtime images

* go mod tidy and new version of lotus in manifest

* fix types

* fix storage miner (#42)

* fix storage miner

* update runtime image to ubuntu
This commit is contained in:
Anton Evangelatov 2020-06-22 17:17:42 +02:00 committed by GitHub
parent c176f24d05
commit 512915b4c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 656 additions and 314 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
lotus

View File

@ -0,0 +1,14 @@
ARG GO_VERSION=1.14.2
FROM golang:${GO_VERSION}-buster
RUN apt-get update && apt-get install -y ca-certificates llvm clang mesa-opencl-icd ocl-icd-opencl-dev jq gcc git bzr pkg-config
ARG LOTUS_VERSION
RUN git clone https://github.com/filecoin-project/lotus.git /lotus && cd /lotus && git checkout ${LOTUS_VERSION} && git submodule update --init
RUN cd /lotus/extern/filecoin-ffi \
&& make \
&& mkdir /tmp/filecoin-ffi \
&& cp -R /lotus/extern/filecoin-ffi /tmp

View File

@ -0,0 +1,25 @@
ARG GO_VERSION=1.14.2
ARG RUNTIME_IMAGE=ubuntu:18.04
FROM golang:${GO_VERSION}-buster AS builder
RUN apt-get update && apt-get install -y ca-certificates llvm clang mesa-opencl-icd ocl-icd-opencl-dev jq gcc git bzr pkg-config
ARG LOTUS_VERSION
RUN git clone https://github.com/filecoin-project/lotus.git /lotus && cd /lotus && git checkout ${LOTUS_VERSION} && git submodule update --init && make 2k
RUN cd /lotus/extern/filecoin-ffi \
&& make \
&& mkdir /tmp/filecoin-ffi \
&& cp -R /lotus/extern/filecoin-ffi /tmp
RUN /lotus/lotus fetch-params 2048
FROM ${RUNTIME_IMAGE} AS binary
COPY --from=builder /var/tmp/filecoin-proof-parameters/* /var/tmp/filecoin-proof-parameters/
COPY --from=builder /lotus/build/bootstrap/* /lotus/build/bootstrap/
COPY --from=builder /lotus/build/proof-params/* /lotus/build/proof-params/
COPY --from=builder /usr/lib/x86_64-linux-gnu/* /lib/x86_64-linux-gnu/* /usr/lib/

View File

@ -0,0 +1,27 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -e
set -x
err_report() {
echo "Error on line $1"
}
trap 'err_report $LINENO' ERR
COMMIT=$1
# Validate required arguments
if [ -z "$COMMIT" ]
then
echo -e "Please provider commit of Lotus to build against. For example: \`./build.sh 596ed33\`"
exit 2
fi
my_dir="$(dirname "$0")"
docker build --build-arg LOTUS_VERSION=$COMMIT -t iptestground/oni-buildbase:$COMMIT -f $my_dir/Dockerfile.oni-buildbase $my_dir
docker build --build-arg LOTUS_VERSION=$COMMIT -t iptestground/oni-runtime:$COMMIT -f $my_dir/Dockerfile.oni-runtime $my_dir

View File

@ -0,0 +1,25 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -e
set -x
err_report() {
echo "Error on line $1"
}
trap 'err_report $LINENO' ERR
COMMIT=$1
# Validate required arguments
if [ -z "$COMMIT" ]
then
echo -e "Please provider commit of Lotus to build against. For example: \`./push.sh 596ed33\`"
exit 2
fi
docker push iptestground/oni-buildbase:$COMMIT
docker push iptestground/oni-runtime:$COMMIT

View File

@ -1,21 +1,19 @@
module github.com/testground/testground/plans/network
module github.com/filecoin-project/oni/lotus-testground
go 1.14
require (
github.com/davecgh/go-spew v1.1.1
github.com/filecoin-project/go-address v0.0.2-0.20200504173055-8b6f2fb2b3ef
github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b
github.com/filecoin-project/lotus v0.3.1-0.20200518172415-1ed618334471
github.com/filecoin-project/sector-storage v0.0.0-20200522011946-a59ca7536a95
github.com/filecoin-project/specs-actors v0.5.4-0.20200521014528-0df536f7e461
github.com/filecoin-project/sector-storage v0.0.0-20200618073200-d9de9b7cb4b4
github.com/filecoin-project/specs-actors v0.6.2-0.20200617175406-de392ca14121
github.com/ipfs/go-datastore v0.4.4
github.com/ipfs/go-ipfs-blockstore v1.0.0
github.com/labstack/gommon v0.3.0
github.com/libp2p/go-libp2p v0.9.4
github.com/libp2p/go-libp2p-core v0.5.7
github.com/libp2p/go-libp2p-crypto v0.1.0
github.com/testground/sdk-go v0.2.0
github.com/testground/sdk-go v0.2.3-0.20200617132925-2e4d69f9ba38
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
)

File diff suppressed because it is too large Load Diff

View File

@ -4,18 +4,18 @@ import (
"bytes"
"context"
"crypto/rand"
"errors"
"fmt"
"io/ioutil"
"net"
"time"
"github.com/davecgh/go-spew/spew"
"github.com/ipfs/go-datastore"
blockstore "github.com/ipfs/go-ipfs-blockstore"
peer "github.com/libp2p/go-libp2p-core/peer"
crypto "github.com/libp2p/go-libp2p-crypto"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
"github.com/testground/sdk-go/network"
"github.com/testground/sdk-go/run"
"github.com/testground/sdk-go/runtime"
"github.com/testground/sdk-go/sync"
"golang.org/x/xerrors"
@ -45,14 +45,14 @@ import (
func init() {
power.ConsensusMinerMinPower = big.NewInt(2048)
saminer.SupportedProofTypes = map[abi.RegisteredProof]struct{}{
abi.RegisteredProof_StackedDRG2KiBSeal: {},
saminer.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{
abi.RegisteredSealProof_StackedDrg2KiBV1: {},
}
verifreg.MinVerifiedDealSize = big.NewInt(256)
}
var testcases = map[string]runtime.TestCaseFn{
"lotus-network": lotusNetwork,
var testcases = map[string]interface{}{
"lotus-network": lotusNetwork(),
}
type GenesisMessage struct {
@ -60,7 +60,7 @@ type GenesisMessage struct {
}
func main() {
runtime.InvokeMap(testcases)
run.InvokeMap(testcases)
}
func setupLotusNode(genesis []byte) (api.FullNode, error) {
@ -142,7 +142,7 @@ func testStorageNode(ctx context.Context, waddr address.Address, act address.Add
return nil, err
}
enc, err := actors.SerializeParams(&saminer.ChangePeerIDParams{NewID: peerid})
enc, err := actors.SerializeParams(&saminer.ChangePeerIDParams{NewID: abi.PeerID(peerid)})
if err != nil {
return nil, err
}
@ -184,21 +184,25 @@ func testStorageNode(ctx context.Context, waddr address.Address, act address.Add
return minerapi, nil
}
func setupStorageNode(fnode api.FullNode, key *wallet.Key, maddr, worker address.Address, preSealDir string, numPreSeals int) (api.StorageMiner, error) {
func setupStorageNode(runenv *runtime.RunEnv, fnode api.FullNode, key *wallet.Key, maddr, worker address.Address, preSealDir string, numPreSeals int) (api.StorageMiner, error) {
ctx := context.TODO()
runenv.RecordMessage("Wallet Import")
if _, err := fnode.WalletImport(ctx, &key.KeyInfo); err != nil {
return nil, err
}
runenv.RecordMessage("Wallet Set Defaults")
if err := fnode.WalletSetDefault(ctx, key.Address); err != nil {
return nil, err
}
runenv.RecordMessage("test Storage Node")
storageNode, err := testStorageNode(ctx, worker, maddr, fnode, node.Options(), numPreSeals)
if err != nil {
return nil, err
}
if preSealDir != "" {
runenv.RecordMessage("Storage Add Local")
if err := storageNode.StorageAddLocal(ctx, preSealDir); err != nil {
return nil, err
}
@ -221,7 +225,7 @@ func runPreSeal(runenv *runtime.RunEnv, maddr address.Address, minerPid peer.ID)
return nil, err
}
genm, k, err := seed.PreSeal(maddr, abi.RegisteredProof_StackedDRG2KiBPoSt, 0, nGenesisPreseals, tdir, []byte("make genesis mem random"), nil)
genm, k, err := seed.PreSeal(maddr, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, nGenesisPreseals, tdir, []byte("make genesis mem random"), nil)
if err != nil {
return nil, err
}
@ -246,164 +250,145 @@ func runPreSeal(runenv *runtime.RunEnv, maddr address.Address, minerPid peer.ID)
}, nil
}
func lotusNetwork(runenv *runtime.RunEnv) error {
func lotusNetwork() run.InitializedTestCaseFn {
return func(runenv *runtime.RunEnv, initCtx *run.InitContext) error {
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
defer cancel()
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
defer cancel()
var (
client = initCtx.SyncClient
seq = initCtx.GlobalSeq
)
runenv.RecordMessage("before sync.MustBoundClient")
client := sync.MustBoundClient(ctx, runenv)
defer client.Close()
minerCount := runenv.IntParam("miner-count")
if minerCount > runenv.TestInstanceCount {
return errors.New("cannot have more miners than nodes")
}
if !runenv.TestSidecar {
//return nil
}
var maddr address.Address
var minerPid peer.ID
var mpsi *PreSealInfo
netclient := network.NewClient(client, runenv)
runenv.RecordMessage("before netclient.MustWaitNetworkInitialized")
netclient.MustWaitNetworkInitialized(ctx)
preSealTopic := sync.NewTopic("preseals", &PreSealInfo{})
if seq <= int64(minerCount) { // sequence numbers start at 1
runenv.RecordMessage("Running preseal (seq = %d)", seq)
minerCount := runenv.IntParam("miner-count")
if minerCount > runenv.TestInstanceCount {
return fmt.Errorf("cannot have more miners than nodes")
}
pk, _, err := crypto.GenerateEd25519Key(rand.Reader)
if err != nil {
return err
}
config := &network.Config{
// Control the "default" network. At the moment, this is the only network.
Network: "default",
mpid, err := peer.IDFromPrivateKey(pk)
if err != nil {
return err
}
minerPid = mpid
// Enable this network. Setting this to false will disconnect this test
// instance from this network. You probably don't want to do that.
Enable: true,
CallbackState: "network-configured",
}
ma, err := address.NewIDAddress(uint64(1000 + seq - 1))
if err != nil {
return err
}
maddr = ma
_ = config
runenv.RecordMessage("before netclient.MustConfigureNetwork")
//netclient.MustConfigureNetwork(ctx, config)
psi, err := runPreSeal(runenv, maddr, minerPid)
if err != nil {
return err
}
seq := client.MustSignalAndWait(ctx, "ip-allocation", runenv.TestInstanceCount)
mpsi = psi
client.Publish(ctx, preSealTopic, psi)
}
var maddr address.Address
var minerPid peer.ID
var mpsi *PreSealInfo
//time.Sleep(300 * time.Second)
preSealTopic := sync.NewTopic("preseals", &PreSealInfo{})
if seq <= int64(minerCount) { // sequence numbers start at 1
runenv.RecordMessage("Running preseal (seq = %d)", seq)
genesisTopic := sync.NewTopic("genesis", &GenesisMessage{})
pk, _, err := crypto.GenerateEd25519Key(rand.Reader)
var genesisBytes []byte
if seq == 1 {
var genaccs []genesis.Actor
var genms []genesis.Miner
var preSeals []*PreSealInfo
psch := make(chan *PreSealInfo)
client.MustSubscribe(ctx, preSealTopic, psch)
for i := 0; i < minerCount; i++ {
psi := <-psch
preSeals = append(preSeals, psi)
genms = append(genms, psi.GenMiner)
genaccs = append(genaccs, psi.GenAct)
}
runenv.RecordMessage("have %d genesis miners", len(preSeals))
templ := &genesis.Template{
Accounts: genaccs,
Miners: genms,
Timestamp: uint64(time.Now().Unix() - 10000), // some time sufficiently far in the past
}
runenv.RecordMessage("genminer: %s %s", genms[0].Owner, genms[0].Worker)
runenv.RecordMessage("making a genesis file: %d %d", len(templ.Accounts), len(templ.Miners))
bs := blockstore.NewBlockstore(datastore.NewMapDatastore())
bs = blockstore.NewIdStore(bs)
var genbuf bytes.Buffer
_, err := modtest.MakeGenesisMem(&genbuf, *templ)(bs, vm.Syscalls(&genFakeVerifier{}))()
if err != nil {
runenv.RecordMessage("genesis file failure: %v", err)
return xerrors.Errorf("failed to make genesis file: %w", err)
}
runenv.RecordMessage("now broadcasting genesis file (len = %d)", genbuf.Len())
genesisBytes = genbuf.Bytes()
client.MustPublish(ctx, genesisTopic, &GenesisMessage{
GenBuf: genbuf.Bytes(),
})
} else {
gench := make(chan *GenesisMessage)
client.MustSubscribe(ctx, genesisTopic, gench)
genm := <-gench
genesisBytes = genm.GenBuf
}
runenv.RecordMessage("about to set up lotus node (len = %d)", len(genesisBytes))
lnode, err := setupLotusNode(genesisBytes)
if err != nil {
return err
}
mpid, err := peer.IDFromPrivateKey(pk)
if err != nil {
return err
}
minerPid = mpid
ma, err := address.NewIDAddress(uint64(1000 + seq - 1))
if err != nil {
return err
}
maddr = ma
psi, err := runPreSeal(runenv, maddr, minerPid)
id, err := lnode.ID(ctx)
if err != nil {
return err
}
mpsi = psi
client.Publish(ctx, preSealTopic, psi)
}
runenv.RecordMessage("Lotus node ID is: %s", id)
genesisTopic := sync.NewTopic("genesis", &GenesisMessage{})
var genesisBytes []byte
if seq == 1 {
var genaccs []genesis.Actor
var genms []genesis.Miner
var preSeals []*PreSealInfo
psch := make(chan *PreSealInfo)
client.MustSubscribe(ctx, preSealTopic, psch)
for i := 0; i < minerCount; i++ {
psi := <-psch
preSeals = append(preSeals, psi)
genms = append(genms, psi.GenMiner)
genaccs = append(genaccs, psi.GenAct)
}
runenv.RecordMessage("have %d genesis miners", len(preSeals))
templ := &genesis.Template{
Accounts: genaccs,
Miners: genms,
Timestamp: uint64(time.Now().Unix() - 10000), // some time sufficiently far in the past
}
runenv.RecordMessage("genminer: %s %s", genms[0].Owner, genms[0].Worker)
runenv.RecordMessage("making a genesis file: %d %d", len(templ.Accounts), len(templ.Miners))
bs := blockstore.NewBlockstore(datastore.NewMapDatastore())
bs = blockstore.NewIdStore(bs)
var genbuf bytes.Buffer
_, err := modtest.MakeGenesisMem(&genbuf, *templ)(bs, vm.Syscalls(&genFakeVerifier{}))()
gents, err := lnode.ChainGetGenesis(ctx)
if err != nil {
runenv.RecordMessage("genesis file failure: %v", err)
return xerrors.Errorf("failed to make genesis file: %w", err)
return err
}
runenv.RecordMessage("now broadcasting genesis file (len = %d)", genbuf.Len())
runenv.RecordMessage("Genesis cid: %s", gents.Key())
genesisBytes = genbuf.Bytes()
client.MustPublish(ctx, genesisTopic, &GenesisMessage{
GenBuf: genbuf.Bytes(),
})
} else {
gench := make(chan *GenesisMessage)
client.MustSubscribe(ctx, genesisTopic, gench)
withMiner := seq < int64(minerCount)
genm := <-gench
genesisBytes = genm.GenBuf
}
if withMiner {
runenv.RecordMessage("Setup storage node")
sminer, err := setupStorageNode(runenv, lnode, mpsi.WKey, maddr, mpsi.WKey.Address, mpsi.Dir, nGenesisPreseals)
if err != nil {
return xerrors.Errorf("failed to set up storage miner: %w", err)
}
runenv.RecordMessage("about to set up lotus node (len = %d)", len(genesisBytes))
lnode, err := setupLotusNode(genesisBytes)
if err != nil {
return err
}
id, err := lnode.ID(ctx)
if err != nil {
return err
}
runenv.RecordMessage("Lotus node ID is: %s", id)
gents, err := lnode.ChainGetGenesis(ctx)
if err != nil {
return err
}
runenv.RecordMessage("Genesis cid: %s", gents.Key())
withMiner := seq < int64(minerCount)
if withMiner {
sminer, err := setupStorageNode(lnode, mpsi.WKey, maddr, mpsi.WKey.Address, mpsi.Dir, nGenesisPreseals)
if err != nil {
return xerrors.Errorf("failed to set up storage miner: %w", err)
fmt.Println(sminer)
}
spew.Dump(sminer)
return nil
}
return nil
}
func sameAddrs(a, b []net.Addr) bool {
@ -438,6 +423,6 @@ func (m genFakeVerifier) VerifyWindowPoSt(ctx context.Context, info abi.WindowPo
panic("not supported")
}
func (m genFakeVerifier) GenerateWinningPoStSectorChallenge(ctx context.Context, proof abi.RegisteredProof, id abi.ActorID, randomness abi.PoStRandomness, u uint64) ([]uint64, error) {
func (m genFakeVerifier) GenerateWinningPoStSectorChallenge(ctx context.Context, proof abi.RegisteredPoStProof, id abi.ActorID, randomness abi.PoStRandomness, u uint64) ([]uint64, error) {
panic("not supported")
}

View File

@ -6,38 +6,21 @@ runner = "local:exec"
[builders."docker:go"]
enabled = true
skip_runtime_image = true
[builders."docker:go".dockerfile_extensions]
pre_mod_download = """
RUN apt-get update && apt-get install -y ca-certificates llvm clang mesa-opencl-icd ocl-icd-opencl-dev jq gcc git bzr pkg-config
ARG LOTUS_VERSION=c6a8fe16
RUN git clone https://github.com/filecoin-project/lotus.git ${PLAN_DIR}/../lotus && cd ${PLAN_DIR}/../lotus && git checkout ${LOTUS_VERSION} && git submodule update --init && make 2k
RUN cd ${PLAN_DIR}/../lotus/extern/filecoin-ffi \
&& make \
&& mkdir /tmp/filecoin-ffi \
&& cp -R ${PLAN_DIR}/../lotus/extern/filecoin-ffi /tmp
"""
[builders."exec:go"]
enabled = true
runtime_image = "iptestground/oni-runtime:596ed33"
build_base_image = "iptestground/oni-buildbase:596ed33"
enable_go_build_cache = true
skip_runtime_image = false
[runners."local:docker"]
enabled = true
[runners."local:exec"]
enabled = true
[runners."cluster:swarm"]
enabled = true
[runners."cluster:k8s"]
enabled = true
# seq 0
[[testcases]]
name = "lotus-network"
instances = { min = 2, max = 2, default = 2 }
instances = { min = 5, max = 5, default = 5 }
[testcases.params]
miner-count = { type = "int", default = 1 }
miner-count = { type = "int", default = 2 }