Merge pull request #76 from filecoin-project/feat/mine-natural-time

Option to mine in natural time
This commit is contained in:
vyzo 2020-06-29 20:24:19 +03:00 committed by GitHub
commit 24730e158b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 100 additions and 37 deletions

View File

@ -43,33 +43,40 @@ func runMiner(t *TestEnvironment) error {
// mine / stop mining
mine := true
done := make(chan struct{})
go func() {
defer close(done)
var i int
for i = 0; mine; i++ {
// synchronize all miners to mine the next block
t.RecordMessage("synchronizing all miners to mine next block [%d]", i)
stateMineNext := sync.State(fmt.Sprintf("mine-block-%d", i))
t.SyncClient.MustSignalAndWait(ctx, stateMineNext, miners)
ch := make(chan struct{})
err := miner.MineOne(ctx, func(mined bool) {
if mined {
t.D().Counter(fmt.Sprintf("block.mine,miner=%s", myActorAddr)).Inc(1)
if miner.MineOne != nil {
go func() {
defer t.RecordMessage("shutting down mining")
defer close(done)
var i int
for i = 0; mine; i++ {
// synchronize all miners to mine the next block
t.RecordMessage("synchronizing all miners to mine next block [%d]", i)
stateMineNext := sync.State(fmt.Sprintf("mine-block-%d", i))
t.SyncClient.MustSignalAndWait(ctx, stateMineNext, miners)
ch := make(chan struct{})
err := miner.MineOne(ctx, func(mined bool) {
if mined {
t.D().Counter(fmt.Sprintf("block.mine,miner=%s", myActorAddr)).Inc(1)
}
close(ch)
})
if err != nil {
panic(err)
}
close(ch)
})
if err != nil {
panic(err)
<-ch
}
<-ch
}
// signal the last block to make sure no miners are left stuck waiting for the next block signal
// while the others have stopped
stateMineLast := sync.State(fmt.Sprintf("mine-block-%d", i))
t.SyncClient.MustSignalEntry(ctx, stateMineLast)
}()
// signal the last block to make sure no miners are left stuck waiting for the next block signal
// while the others have stopped
stateMineLast := sync.State(fmt.Sprintf("mine-block-%d", i))
t.SyncClient.MustSignalEntry(ctx, stateMineLast)
}()
} else {
close(done)
}
// wait for a signal from all clients to stop mining
err = <-t.SyncClient.MustBarrier(ctx, stateStopMining, clients).C
@ -78,7 +85,6 @@ func runMiner(t *TestEnvironment) error {
}
mine = false
t.RecordMessage("shutting down mining")
<-done
t.SyncClient.MustSignalAndWait(ctx, stateDone, t.TestInstanceCount)

View File

@ -0,0 +1,49 @@
[metadata]
name = "lotus-soup"
author = ""
[global]
plan = "lotus-soup"
case = "lotus-baseline"
total_instances = 6
builder = "docker:go"
runner = "local:docker"
[global.build_config]
enable_go_build_cache = true
[global.run.test_params]
clients = "3"
miners = "2"
genesis_timestamp_offset = "100000"
balance = "2000000000"
sectors = "10"
random_beacon_type = "mock"
[[groups]]
id = "bootstrapper"
[groups.instances]
count = 1
percentage = 0.0
[groups.run]
[groups.run.test_params]
role = "bootstrapper"
[[groups]]
id = "miners"
[groups.instances]
count = 2
percentage = 0.0
[groups.run]
[groups.run.test_params]
role = "miner"
mining_mode = "natural"
[[groups]]
id = "clients"
[groups.instances]
count = 3
percentage = 0.0
[groups.run]
[groups.run.test_params]
role = "client"

View File

@ -41,3 +41,6 @@ instances = { min = 1, max = 100, default = 5 }
# Params relevant to pubsub tracing
enable_pubsub_tracer = { type = "bool", default = false }
# Mining Mode: synchronized -vs- natural time
mining_mode = { type = "enum", default = "synchronized", options = ["synchronized", "natural"] }

View File

@ -397,15 +397,29 @@ func prepareMiner(t *TestEnvironment) (*Node, error) {
return nil, err
}
mineBlock := make(chan func(bool))
stop2, err := node.New(context.Background(),
minerOpts := []node.Option{
node.StorageMiner(&n.minerApi),
node.Online(),
node.Repo(minerRepo),
node.Override(new(api.FullNode), n.fullApi),
node.Override(new(*miner.Miner), miner.NewTestMiner(mineBlock, minerAddr)),
withMinerListenAddress(minerIP),
)
}
if t.StringParam("mining_mode") != "natural" {
mineBlock := make(chan func(bool))
minerOpts = append(minerOpts,
node.Override(new(*miner.Miner), miner.NewTestMiner(mineBlock, minerAddr)))
n.MineOne = func(ctx context.Context, cb func(bool)) error {
select {
case mineBlock <- cb:
return nil
case <-ctx.Done():
return ctx.Err()
}
}
}
stop2, err := node.New(context.Background(), minerOpts...)
if err != nil {
stop1(context.TODO())
return nil, err
@ -430,15 +444,6 @@ func prepareMiner(t *TestEnvironment) (*Node, error) {
panic(err)
}
n.MineOne = func(ctx context.Context, cb func(bool)) error {
select {
case mineBlock <- cb:
return nil
case <-ctx.Done():
return ctx.Err()
}
}
// add local storage for presealed sectors
err = n.minerApi.StorageAddLocal(ctx, presealDir)
if err != nil {