add random_beacon_type param, default to mock randomness

This commit is contained in:
Yusef Napora 2020-06-25 10:55:44 -04:00
parent e225a644f4
commit 75ff8d0689
2 changed files with 35 additions and 16 deletions

View File

@ -29,9 +29,12 @@ instances = { min = 1, max = 100, default = 5 }
sectors = { type = "int", default = 1 }
role = { type = "string" }
real_drand = { type = "bool", default = "false", desc = "set to true to use the real drand network config baked into lotus. otherwise, make sure there's a group with role='drand' and at least 2 nodes" }
random_beacon_type = { type = "enum", default = "mock", options = ["mock", "local-drand", "external-drand"] }
# params relevant to drand nodes:
# Params relevant to drand nodes. drand nodes should have role="drand", and must all be
# in the same composition group. There must be at least threshold drand nodes.
# To get lotus nodes to actually use the drand nodes, you must set random_beacon_type="local-drand"
# for the lotus node groups.
drand_period = { type = "duration", default="10s" }
drand_threshold = { type = "int", default = 2 }
drand_gossip_relay = { type = "bool", default = true }
drand_gossip_relay = { type = "bool", default = true }

View File

@ -17,6 +17,7 @@ import (
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/beacon"
genesis_chain "github.com/filecoin-project/lotus/chain/gen/genesis"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
@ -83,9 +84,13 @@ type TestEnvironment struct {
*run.InitContext
}
// workaround for default params being wrapped in quote chars
func (t *TestEnvironment) StringParam(name string) string {
return strings.Trim(t.RunEnv.StringParam(name), "\"")
}
func (t *TestEnvironment) DurationParam(name string) time.Duration {
s := strings.ReplaceAll(t.StringParam(name), "\"", "")
d, err := time.ParseDuration(s)
d, err := time.ParseDuration(t.StringParam(name))
if err != nil {
panic(fmt.Errorf("invalid duration value for param '%s': %w", name, err))
}
@ -666,20 +671,31 @@ func collectClientAddrs(t *TestEnvironment, ctx context.Context, clients int) ([
}
func getDrandConfig(ctx context.Context, t *TestEnvironment) (node.Option, error) {
if t.BooleanParam("real_drand") {
beaconType := t.StringParam("random_beacon_type")
switch beaconType {
case "external-drand":
noop := func(settings *node.Settings) error {
return nil
}
return noop, nil
case "local-drand":
cfg, err := waitForDrandConfig(ctx, t.SyncClient)
if err != nil {
t.RecordMessage("error getting drand config: %w", err)
return nil, err
}
t.RecordMessage("setting drand config: %v", cfg)
return node.Options(
node.Override(new(dtypes.DrandConfig), cfg.Config),
node.Override(new(dtypes.DrandBootstrap), cfg.GossipBootstrap),
), nil
case "mock":
return node.Override(new(beacon.RandomBeacon), modtest.RandomBeacon), nil
default:
return nil, fmt.Errorf("unknown random_beacon_type: %s", beaconType)
}
cfg, err := waitForDrandConfig(ctx, t.SyncClient)
if err != nil {
t.RecordMessage("error getting drand config: %w", err)
return nil, err
}
t.RecordMessage("setting drand config: %v", cfg)
return node.Options(
node.Override(new(dtypes.DrandConfig), cfg.Config),
node.Override(new(dtypes.DrandBootstrap), cfg.GossipBootstrap),
), nil
}