option to turn on natural time mining
This commit is contained in:
parent
6c8abeb067
commit
da85855a6b
@ -43,33 +43,38 @@ 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 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
|
||||
|
@ -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"] }
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user