diff --git a/docker-images/Dockerfile.oni-buildbase b/docker-images/Dockerfile.oni-buildbase index 1b3f87e4b..f9383b2d0 100644 --- a/docker-images/Dockerfile.oni-buildbase +++ b/docker-images/Dockerfile.oni-buildbase @@ -4,7 +4,7 @@ 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 pkg-config bzr -ARG FILECOIN_FFI_COMMIT=ca281af0b6c00314382a75ae869e5cb22c83655b +ARG FILECOIN_FFI_COMMIT=5342c7c97d1a1df4650629d14f2823d52889edd9 ARG FFI_DIR=/extra/filecoin-ffi RUN mkdir -p ${FFI_DIR} \ diff --git a/docker-images/HISTORY.md b/docker-images/HISTORY.md new file mode 100644 index 000000000..7560da9e9 --- /dev/null +++ b/docker-images/HISTORY.md @@ -0,0 +1,12 @@ +# Docker image history + +## oni-buildbase + +* `v1` => initial image locking in FFI commit ca281af0b6c00314382a75ae869e5cb22c83655b. +* `v2` => no changes; released only for aligning both images to aesthetically please @nonsense :D +* `v3` => locking in FFI commit 5342c7c97d1a1df4650629d14f2823d52889edd9. + +## oni-runtime + +* `v1` => initial image with 2048 parameters. +* `v2` => adds auxiliary tools: `net-tools netcat traceroute iputils-ping wget vim curl telnet iproute2 dnsutils`. diff --git a/extra/filecoin-ffi b/extra/filecoin-ffi index ca281af0b..5342c7c97 160000 --- a/extra/filecoin-ffi +++ b/extra/filecoin-ffi @@ -1 +1 @@ -Subproject commit ca281af0b6c00314382a75ae869e5cb22c83655b +Subproject commit 5342c7c97d1a1df4650629d14f2823d52889edd9 diff --git a/lotus-soup/go.mod b/lotus-soup/go.mod index 2f1cf2bfe..5fbdd9cd9 100644 --- a/lotus-soup/go.mod +++ b/lotus-soup/go.mod @@ -6,10 +6,10 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/drand/drand v0.9.2-0.20200616080806-a94e9c1636a4 github.com/filecoin-project/go-address v0.0.2-0.20200504173055-8b6f2fb2b3ef - github.com/filecoin-project/go-fil-markets v0.3.0 + github.com/filecoin-project/go-fil-markets v0.3.1 github.com/filecoin-project/go-jsonrpc v0.1.1-0.20200602181149-522144ab4e24 github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b - github.com/filecoin-project/lotus v0.4.1-0.20200625154728-28b4476398ae + github.com/filecoin-project/lotus v0.4.1-0.20200701153027-70d83784046b github.com/filecoin-project/specs-actors v0.6.2-0.20200617175406-de392ca14121 github.com/gorilla/mux v1.7.4 github.com/influxdata/influxdb v1.8.0 // indirect @@ -17,7 +17,7 @@ require ( github.com/ipfs/go-datastore v0.4.4 github.com/ipfs/go-ipfs-files v0.0.8 github.com/ipfs/go-ipld-format v0.2.0 - github.com/ipfs/go-log/v2 v2.1.2-0.20200609205458-f8d20c392cb7 + github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4 github.com/ipfs/go-merkledag v0.3.1 github.com/ipfs/go-unixfs v0.2.4 github.com/ipld/go-car v0.1.1-0.20200526133713-1c7508d55aae diff --git a/lotus-soup/go.sum b/lotus-soup/go.sum index c69f66650..5a58be51d 100644 --- a/lotus-soup/go.sum +++ b/lotus-soup/go.sum @@ -230,6 +230,8 @@ github.com/filecoin-project/go-bitfield v0.0.0-20200416002808-b3ee67ec9060/go.mo github.com/filecoin-project/go-bitfield v0.0.1/go.mod h1:Ry9/iUlWSyjPUzlAvdnfy4Gtvrq4kWmWDztCU1yEgJY= github.com/filecoin-project/go-bitfield v0.0.2-0.20200518150651-562fdb554b6e h1:gkG/7G+iKy4He+IiQNeQn+nndFznb/vCoOR8iRQsm60= github.com/filecoin-project/go-bitfield v0.0.2-0.20200518150651-562fdb554b6e/go.mod h1:Ry9/iUlWSyjPUzlAvdnfy4Gtvrq4kWmWDztCU1yEgJY= +github.com/filecoin-project/go-bitfield v0.0.2-0.20200629135455-587b27927d38 h1:B2gUde2DlfCb5YMYNVems2orobxC3KhrX3migym1IOQ= +github.com/filecoin-project/go-bitfield v0.0.2-0.20200629135455-587b27927d38/go.mod h1:Ry9/iUlWSyjPUzlAvdnfy4Gtvrq4kWmWDztCU1yEgJY= github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2 h1:av5fw6wmm58FYMgJeoB/lK9XXrgdugYiTqkdxjTy9k8= github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2/go.mod h1:pqTiPHobNkOVM5thSRsHYjyQfq7O5QSCMhvuu9JoDlg= github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 h1:2pMXdBnCiXjfCYx/hLqFxccPoqsSveQFxVLvNxy9bus= @@ -238,16 +240,16 @@ github.com/filecoin-project/go-data-transfer v0.3.0 h1:BwBrrXu9Unh9JjjX4GAc5FfzU github.com/filecoin-project/go-data-transfer v0.3.0/go.mod h1:cONglGP4s/d+IUQw5mWZrQK+FQATQxr3AXzi4dRh0l4= github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5 h1:yvQJCW9mmi9zy+51xA01Ea2X7/dL7r8eKDPuGUjRmbo= github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5/go.mod h1:JbkIgFF/Z9BDlvrJO1FuKkaWsH673/UdFaiVS6uIHlA= -github.com/filecoin-project/go-fil-markets v0.3.0 h1:7iCGiuTSia4f4DmOn3s96NWUwMNSOI0ZHel/XgeApAQ= -github.com/filecoin-project/go-fil-markets v0.3.0/go.mod h1:UXsXi43AyUQ5ieb4yIaLgk4PVt7TAbl1UCccuNw+7ds= +github.com/filecoin-project/go-fil-markets v0.3.1 h1:YLH4ck4hQrKBpQ3fo0VcA2SXqiAosizxBJ/QHYgR9aE= +github.com/filecoin-project/go-fil-markets v0.3.1/go.mod h1:UY+/zwNXHN73HcrN6HxNDpv6KKM6ehqfCuE9vK9khF8= github.com/filecoin-project/go-jsonrpc v0.1.1-0.20200602181149-522144ab4e24 h1:Jc7vkplmZYVuaEcSXGHDwefvZIdoyyaoGDLqSr8Svms= github.com/filecoin-project/go-jsonrpc v0.1.1-0.20200602181149-522144ab4e24/go.mod h1:j6zV//WXIIY5kky873Q3iIKt/ViOE8rcijovmpxrXzM= github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6 h1:92PET+sx1Hb4W/8CgFwGuxaKbttwY+UNspYZTvXY0vs= github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6/go.mod h1:0HgYnrkeSU4lu1p+LEOeDpFsNBssa0OGGriWdA4hvaE= github.com/filecoin-project/go-paramfetch v0.0.1/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc= github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc= -github.com/filecoin-project/go-paramfetch v0.0.2-0.20200605171344-fcac609550ca h1:OGykrCr6mSn/ckk2IFbIlkc76nsgEs7tSLhZXQt7+z4= -github.com/filecoin-project/go-paramfetch v0.0.2-0.20200605171344-fcac609550ca/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc= +github.com/filecoin-project/go-paramfetch v0.0.2-0.20200701152213-3e0f0afdc261 h1:A256QonvzRaknIIAuWhe/M2dpV2otzs3NBhi5TWa/UA= +github.com/filecoin-project/go-paramfetch v0.0.2-0.20200701152213-3e0f0afdc261/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc= github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= github.com/filecoin-project/go-statemachine v0.0.0-20200612181802-4eb3d0c68eba h1:GEWb/6KQyNZt4jm8fgVcIFPH0ElAGXfHM59ZSiqPTvY= github.com/filecoin-project/go-statemachine v0.0.0-20200612181802-4eb3d0c68eba/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= @@ -255,12 +257,12 @@ github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIi github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b h1:fkRZSPrYpk42PV3/lIXiL0LHetxde7vyYYvSsttQtfg= github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b/go.mod h1:Q0GQOBtKf1oE10eSXSlhN45kDBdGvEcVOqMiffqX+N8= -github.com/filecoin-project/lotus v0.4.1-0.20200625154728-28b4476398ae h1:HuI6Y3TUFQ4Zy3NhPrZkk1aR6KbwaYH8bzFzX28wyXg= -github.com/filecoin-project/lotus v0.4.1-0.20200625154728-28b4476398ae/go.mod h1:1nbfphyE76GxxUWVPBQGhMTDAOQXZMBPBpIfn+od4qg= +github.com/filecoin-project/lotus v0.4.1-0.20200701153027-70d83784046b h1:5B4Sabzrk8lH+AD/yTUrL9yJT4AemAEtRJMHrciA7bk= +github.com/filecoin-project/lotus v0.4.1-0.20200701153027-70d83784046b/go.mod h1:hqGdmSDzUWfhss1qBHot1Yi35AHFFJ6NVuFVZJLKW1M= github.com/filecoin-project/sector-storage v0.0.0-20200615154852-728a47ab99d6/go.mod h1:M59QnAeA/oV+Z8oHFLoNpGMv0LZ8Rll+vHVXX7GirPM= -github.com/filecoin-project/sector-storage v0.0.0-20200623210524-47d93356586d/go.mod h1:8f0hWDzzIi1hKs4IVKH9RnDsO4LEHVz8BNat0okDOuY= -github.com/filecoin-project/sector-storage v0.0.0-20200623224636-de544b531601 h1:EgMmHLoJ4caLU8RzgKQux4TyX/ZploXGtIu5Q1SaxKw= -github.com/filecoin-project/sector-storage v0.0.0-20200623224636-de544b531601/go.mod h1:8f0hWDzzIi1hKs4IVKH9RnDsO4LEHVz8BNat0okDOuY= +github.com/filecoin-project/sector-storage v0.0.0-20200625154333-98ef8e4ef246/go.mod h1:8f0hWDzzIi1hKs4IVKH9RnDsO4LEHVz8BNat0okDOuY= +github.com/filecoin-project/sector-storage v0.0.0-20200630180318-4c1968f62a8f h1:EHKqNJNIcYggqfrd5nu7SV1KR93ReZygfdSV0w/jefQ= +github.com/filecoin-project/sector-storage v0.0.0-20200630180318-4c1968f62a8f/go.mod h1:r12d7tsmJKz8QDGoCvl65Ay2al6mOgDqxAGUxbyrgMs= github.com/filecoin-project/specs-actors v0.0.0-20200210130641-2d1fbd8672cf/go.mod h1:xtDZUB6pe4Pksa/bAJbJ693OilaC5Wbot9jMhLm3cZA= github.com/filecoin-project/specs-actors v0.3.0/go.mod h1:nQYnFbQ7Y0bHZyq6HDEuVlCPR+U3z5Q3wMOQ+2aiV+Y= github.com/filecoin-project/specs-actors v0.6.0/go.mod h1:dRdy3cURykh2R8O/DKqy8olScl70rmIS7GrB4hB1IDY= @@ -270,8 +272,8 @@ github.com/filecoin-project/specs-actors v0.6.2-0.20200617175406-de392ca14121/go github.com/filecoin-project/specs-storage v0.1.0/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k= github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea h1:iixjULRQFPn7Q9KlIqfwLJnlAXO10bbkI+xy5GKGdLY= github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k= -github.com/filecoin-project/storage-fsm v0.0.0-20200623213010-fe71d5b42de3 h1:nH3L7YVqrHINOmvZ+5jFjFNSi9/swXcm+uufXpkFJfo= -github.com/filecoin-project/storage-fsm v0.0.0-20200623213010-fe71d5b42de3/go.mod h1:Nl0JX9I3fIVtPEJ9HzGzO4D8LXehT9PqvUQUbNvcstc= +github.com/filecoin-project/storage-fsm v0.0.0-20200625160832-379a4655b044 h1:i4oMhv1kx/MAUxRN4EM5tag5fI1uagrwQwINgKrzUt4= +github.com/filecoin-project/storage-fsm v0.0.0-20200625160832-379a4655b044/go.mod h1:JD7fmV1BYADDcy4EYQnqFH/rUzXsh0Je0jXarCjZqSk= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= @@ -601,8 +603,8 @@ github.com/ipfs/go-log/v2 v2.0.2/go.mod h1:O7P1lJt27vWHhOwQmcFEvlmo49ry2VY2+JfBW github.com/ipfs/go-log/v2 v2.0.3/go.mod h1:O7P1lJt27vWHhOwQmcFEvlmo49ry2VY2+JfBWFaa9+0= github.com/ipfs/go-log/v2 v2.0.5/go.mod h1:eZs4Xt4ZUJQFM3DlanGhy7TkwwawCZcSByscwkWG+dw= github.com/ipfs/go-log/v2 v2.0.8/go.mod h1:eZs4Xt4ZUJQFM3DlanGhy7TkwwawCZcSByscwkWG+dw= -github.com/ipfs/go-log/v2 v2.1.2-0.20200609205458-f8d20c392cb7 h1:LtL/rvdfbKSthZGmAAD9o4KKg6HA6Qn8gXCCdgnj7lw= -github.com/ipfs/go-log/v2 v2.1.2-0.20200609205458-f8d20c392cb7/go.mod h1:2v2nsGfZsvvAJz13SyFzf9ObaqwHiHxsPLEHntrv9KM= +github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4 h1:3bijxqzQ1O9yg7gd7Aqk80oaEvsJ+uXw0zSvi2qR3Jw= +github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4/go.mod h1:2v2nsGfZsvvAJz13SyFzf9ObaqwHiHxsPLEHntrv9KM= github.com/ipfs/go-merkledag v0.0.3/go.mod h1:Oc5kIXLHokkE1hWGMBHw+oxehkAaTOqtEb7Zbh6BhLA= github.com/ipfs/go-merkledag v0.0.6/go.mod h1:QYPdnlvkOg7GnQRofu9XZimC5ZW5Wi3bKys/4GQQfto= github.com/ipfs/go-merkledag v0.2.3/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB3ClKnBAlk= diff --git a/lotus-soup/manifest.toml b/lotus-soup/manifest.toml index d948daffc..7275406c1 100644 --- a/lotus-soup/manifest.toml +++ b/lotus-soup/manifest.toml @@ -7,8 +7,8 @@ runner = "local:docker" [builders."docker:go"] enabled = true -build_base_image = "iptestground/oni-buildbase:v1" -runtime_image = "iptestground/oni-runtime:v1" +build_base_image = "iptestground/oni-buildbase:v3" +runtime_image = "iptestground/oni-runtime:v2" [runners."local:docker"] enabled = true diff --git a/lotus-soup/testkit/role_drand.go b/lotus-soup/testkit/role_drand.go index ec285b9f9..0376b4132 100644 --- a/lotus-soup/testkit/role_drand.go +++ b/lotus-soup/testkit/role_drand.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/hex" - "encoding/json" "fmt" "io/ioutil" "net" @@ -13,70 +12,198 @@ import ( "time" "github.com/drand/drand/chain" + "github.com/drand/drand/client" hclient "github.com/drand/drand/client/http" - "github.com/drand/drand/demo/node" + "github.com/drand/drand/core" + "github.com/drand/drand/key" "github.com/drand/drand/log" "github.com/drand/drand/lp2p" + dnet "github.com/drand/drand/net" + "github.com/drand/drand/protobuf/drand" + dtest "github.com/drand/drand/test" "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/libp2p/go-libp2p-core/peer" ma "github.com/multiformats/go-multiaddr" "github.com/testground/sdk-go/sync" + + "github.com/filecoin-project/oni/lotus-soup/statemachine" ) -var PrepareDrandTimeout = time.Minute +var ( + PrepareDrandTimeout = time.Minute + secretDKG = "dkgsecret" +) type DrandInstance struct { - t *TestEnvironment - - Node node.Node - GossipRelay *lp2p.GossipRelayNode + daemon *core.Drand + httpClient client.Client + ctrlClient *dnet.ControlClient + gossipRelay *lp2p.GossipRelayNode + t *TestEnvironment stateDir string + priv *key.Pair + pubAddr string + privAddr string + ctrlAddr string } -func (d *DrandInstance) Cleanup() error { - return os.RemoveAll(d.stateDir) -} - -func (d *DrandInstance) RunDefault() error { - d.t.RecordMessage("running drand node") - defer d.Cleanup() - - // TODO add ability to halt / recover on demand - d.t.WaitUntilAllDone() +func (dr *DrandInstance) Start() error { + opts := []core.ConfigOption{ + core.WithLogLevel(getLogLevel(dr.t)), + core.WithConfigFolder(dr.stateDir), + core.WithPublicListenAddress(dr.pubAddr), + core.WithPrivateListenAddress(dr.privAddr), + core.WithControlPort(dr.ctrlAddr), + core.WithInsecure(), + } + conf := core.NewConfig(opts...) + fs := key.NewFileStore(conf.ConfigFolder()) + fs.SaveKeyPair(dr.priv) + key.Save(path.Join(dr.stateDir, "public.toml"), dr.priv.Public, false) + if dr.daemon == nil { + drand, err := core.NewDrand(fs, conf) + if err != nil { + return err + } + dr.daemon = drand + } else { + drand, err := core.LoadDrand(fs, conf) + if err != nil { + return err + } + drand.StartBeacon(true) + dr.daemon = drand + } return nil } -// PrepareDrandInstance starts a drand instance and runs a DKG with the other -// members of the composition group. -// -// Once the chain is running, the leader publishes the chain info needed by -// lotus nodes on DrandConfigTopic. +func (dr *DrandInstance) Ping() bool { + cl := dr.ctrl() + if err := cl.Ping(); err != nil { + return false + } + return true +} + +func (dr *DrandInstance) Close() error { + dr.gossipRelay.Shutdown() + dr.daemon.Stop(context.Background()) + return os.RemoveAll(dr.stateDir) +} + +func (dr *DrandInstance) ctrl() *dnet.ControlClient { + if dr.ctrlClient != nil { + return dr.ctrlClient + } + cl, err := dnet.NewControlClient(dr.ctrlAddr) + if err != nil { + dr.t.RecordMessage("drand can't instantiate control client: %w", err) + return nil + } + dr.ctrlClient = cl + return cl +} + +func (dr *DrandInstance) RunDKG(nodes, thr int, timeout string, leader bool, leaderAddr string, beaconOffset int) *key.Group { + cl := dr.ctrl() + p := dr.t.DurationParam("drand_period") + t, _ := time.ParseDuration(timeout) + var grp *drand.GroupPacket + var err error + if leader { + grp, err = cl.InitDKGLeader(nodes, thr, p, t, nil, secretDKG, beaconOffset) + } else { + leader := dnet.CreatePeer(leaderAddr, false) + grp, err = cl.InitDKG(leader, nil, secretDKG) + } + if err != nil { + dr.t.RecordMessage("drand dkg run failed: %w", err) + return nil + } + kg, _ := key.GroupFromProto(grp) + return kg +} + +func (dr *DrandInstance) Halt() { + dr.t.RecordMessage("drand node #%d halting", dr.t.GroupSeq) + dr.daemon.StopBeacon() +} + +func (dr *DrandInstance) Resume() { + dr.t.RecordMessage("drand node #%d resuming", dr.t.GroupSeq) + dr.daemon.StartBeacon(true) + // block until we can fetch the round corresponding to the current time + startTime := time.Now() + round := dr.httpClient.RoundAt(startTime) + timeout := 30 * time.Second + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + done := make(chan struct{}, 1) + go func() { + for { + res, err := dr.httpClient.Get(ctx, round) + if err == nil { + dr.t.RecordMessage("drand chain caught up to round %d", res.Round()) + done <- struct{}{} + return + } + } + }() + + select { + case <-ctx.Done(): + dr.t.RecordMessage("drand chain failed to catch up after %s", timeout.String()) + case <-done: + dr.t.RecordMessage("drand chain resumed after %s catchup time", time.Since(startTime)) + } +} + +func (dr *DrandInstance) RunDefault() error { + dr.t.RecordMessage("running drand node") + + if dr.t.IsParamSet("suspend_events") { + suspender := statemachine.NewSuspender(dr, dr.t.RecordMessage) + suspender.RunEvents(dr.t.StringParam("suspend_events")) + } + + dr.t.WaitUntilAllDone() + return nil +} + +// prepareDrandNode starts a drand instance and runs a DKG with the other members of the composition group. +// Once the chain is running, the leader publishes the chain info needed by lotus nodes on +// drandConfigTopic func PrepareDrandInstance(t *TestEnvironment) (*DrandInstance, error) { - var ( - startTime = time.Now() - seq = t.GroupSeq - isLeader = seq == 1 - nNodes = t.TestGroupInstanceCount - - myAddr = t.NetClient.MustGetDataNetworkIP() - period = t.DurationParam("drand_period") - threshold = t.IntParam("drand_threshold") - runGossipRelay = t.BooleanParam("drand_gossip_relay") - - beaconOffset = 3 - ) - ctx, cancel := context.WithTimeout(context.Background(), PrepareDrandTimeout) defer cancel() - stateDir, err := ioutil.TempDir("", fmt.Sprintf("drand-%d", t.GroupSeq)) + startTime := time.Now() + + seq := t.GroupSeq + isLeader := seq == 1 + nNodes := t.TestGroupInstanceCount + + myAddr := t.NetClient.MustGetDataNetworkIP() + threshold := t.IntParam("drand_threshold") + runGossipRelay := t.BooleanParam("drand_gossip_relay") + + beaconOffset := 3 + + stateDir, err := ioutil.TempDir("/tmp", fmt.Sprintf("drand-%d", t.GroupSeq)) if err != nil { return nil, err } - // TODO(maybe): use TLS? - n := node.NewLocalNode(int(seq), period.String(), stateDir, false, myAddr.String()) + dr := DrandInstance{ + t: t, + stateDir: stateDir, + pubAddr: dtest.FreeBind(myAddr.String()), + privAddr: dtest.FreeBind(myAddr.String()), + ctrlAddr: dtest.FreeBind("localhost"), + } + dr.priv = key.NewKeyPair(dr.privAddr) // share the node addresses with other nodes // TODO: if we implement TLS, this is where we'd share public TLS keys @@ -85,17 +212,15 @@ func PrepareDrandInstance(t *TestEnvironment) (*DrandInstance, error) { PublicAddr string IsLeader bool } - addrTopic := sync.NewTopic("drand-addrs", &NodeAddr{}) var publicAddrs []string var leaderAddr string ch := make(chan *NodeAddr) _, sub := t.SyncClient.MustPublishSubscribe(ctx, addrTopic, &NodeAddr{ - PrivateAddr: n.PrivateAddr(), - PublicAddr: n.PublicAddr(), + PrivateAddr: dr.privAddr, + PublicAddr: dr.pubAddr, IsLeader: isLeader, }, ch) - for i := 0; i < nNodes; i++ { select { case msg := <-ch: @@ -107,21 +232,20 @@ func PrepareDrandInstance(t *TestEnvironment) (*DrandInstance, error) { return nil, fmt.Errorf("unable to read drand addrs from sync service: %w", err) } } - if leaderAddr == "" { return nil, fmt.Errorf("got %d drand addrs, but no leader", len(publicAddrs)) } t.SyncClient.MustSignalAndWait(ctx, "drand-start", nNodes) t.RecordMessage("Starting drand sharing ceremony") - if err := n.Start(stateDir); err != nil { + if err := dr.Start(); err != nil { return nil, err } alive := false waitSecs := 10 for i := 0; i < waitSecs; i++ { - if !n.Ping() { + if !dr.Ping() { time.Sleep(time.Second) continue } @@ -138,7 +262,7 @@ func PrepareDrandInstance(t *TestEnvironment) (*DrandInstance, error) { if !isLeader { time.Sleep(time.Second) } - grp := n.RunDKG(nNodes, threshold, period.String(), isLeader, leaderAddr, beaconOffset) + grp := dr.RunDKG(nNodes, threshold, "10s", isLeader, leaderAddr, beaconOffset) if grp == nil { return nil, fmt.Errorf("drand dkg failed") } @@ -152,19 +276,18 @@ func PrepareDrandInstance(t *TestEnvironment) (*DrandInstance, error) { t.RecordMessage("drand beacon chain started, fetching initial round via http") // verify that we can get a round of randomness from the chain using an http client info := chain.NewChainInfo(grp) - myPublicAddr := fmt.Sprintf("http://%s", n.PublicAddr()) - client, err := hclient.NewWithInfo(myPublicAddr, info, nil) + myPublicAddr := fmt.Sprintf("http://%s", dr.pubAddr) + dr.httpClient, err = hclient.NewWithInfo(myPublicAddr, info, nil) if err != nil { return nil, fmt.Errorf("unable to create drand http client: %w", err) } - _, err = client.Get(ctx, 1) + _, err = dr.httpClient.Get(ctx, 1) if err != nil { return nil, fmt.Errorf("unable to get initial drand round: %w", err) } // start gossip relay (unless disabled via testplan parameter) - var gossipRelay *lp2p.GossipRelayNode var relayAddrs []peer.AddrInfo if runGossipRelay { @@ -176,17 +299,17 @@ func PrepareDrandInstance(t *TestEnvironment) (*DrandInstance, error) { DataDir: gossipDir, IdentityPath: path.Join(gossipDir, "identity.key"), Insecure: true, - Client: client, + Client: dr.httpClient, } t.RecordMessage("starting drand gossip relay") - gossipRelay, err = lp2p.NewGossipRelayNode(log.DefaultLogger, &relayCfg) + dr.gossipRelay, err = lp2p.NewGossipRelayNode(log.NewLogger(getLogLevel(t)), &relayCfg) if err != nil { return nil, fmt.Errorf("failed to construct drand gossip relay: %w", err) } t.RecordMessage("sharing gossip relay addrs") // share the gossip relay addrs so we can publish them in DrandRuntimeInfo - relayInfo, err := relayAddrInfo(gossipRelay.Multiaddrs(), myAddr) + relayInfo, err := relayAddrInfo(dr.gossipRelay.Multiaddrs(), myAddr) if err != nil { return nil, err } @@ -217,17 +340,13 @@ func PrepareDrandInstance(t *TestEnvironment) (*DrandInstance, error) { }, GossipBootstrap: relayAddrs, } - dump, _ := json.Marshal(cfg) - t.RecordMessage("publishing drand config on sync topic: %s", string(dump)) + t.DebugSpew("publishing drand config on sync topic: %v", cfg) t.SyncClient.MustPublish(ctx, DrandConfigTopic, &cfg) } - return &DrandInstance{ - t: t, - Node: n, - GossipRelay: gossipRelay, - stateDir: stateDir, - }, nil + // signal ready state + t.SyncClient.MustSignalAndWait(ctx, StateReady, t.TestInstanceCount) + return &dr, nil } // waitForDrandConfig should be called by filecoin instances before constructing the lotus Node @@ -252,3 +371,14 @@ func relayAddrInfo(addrs []ma.Multiaddr, dataIP net.IP) (*peer.AddrInfo, error) } return nil, fmt.Errorf("no addr found with data ip %s in addrs: %v", dataIP, addrs) } + +func getLogLevel(t *TestEnvironment) int { + switch t.StringParam("drand_log_level") { + case "info": + return log.LogInfo + case "debug": + return log.LogDebug + default: + return log.LogNone + } +} diff --git a/lotus-soup/testkit/role_miner.go b/lotus-soup/testkit/role_miner.go index d27b84c55..2b2589cbe 100644 --- a/lotus-soup/testkit/role_miner.go +++ b/lotus-soup/testkit/role_miner.go @@ -304,8 +304,8 @@ func (m *LotusMiner) RunDefault() error { ) t.RecordMessage("running miner") - t.RecordMessage("block delay: %v", build.BlockDelay) - t.D().Gauge("miner.block-delay").Update(build.BlockDelay) + t.RecordMessage("block delay: %v", build.BlockDelaySecs) + t.D().Gauge("miner.block-delay").Update(float64(build.BlockDelaySecs)) ctx := context.Background() myActorAddr, err := m.MinerApi.ActorAddress(ctx)