2019-09-23 15:27:30 +00:00
|
|
|
package miner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-11-25 04:45:13 +00:00
|
|
|
|
2019-12-19 20:13:17 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2019-11-25 04:45:13 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-03-25 23:16:17 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/beacon"
|
2019-11-30 23:17:50 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/gen"
|
2020-01-17 07:10:47 +00:00
|
|
|
lru "github.com/hashicorp/golang-lru"
|
2019-09-23 15:27:30 +00:00
|
|
|
)
|
|
|
|
|
2020-04-10 21:07:18 +00:00
|
|
|
func NewTestMiner(nextCh <-chan struct{}, addr address.Address) func(api.FullNode, gen.WinningPoStProver) *Miner {
|
|
|
|
return func(api api.FullNode, epp gen.WinningPoStProver) *Miner {
|
2020-01-17 07:10:47 +00:00
|
|
|
arc, err := lru.NewARC(10000)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2020-03-25 23:16:17 +00:00
|
|
|
beacon := beacon.NewMockBeacon(0)
|
2019-11-30 23:17:50 +00:00
|
|
|
m := &Miner{
|
2020-03-25 23:16:17 +00:00
|
|
|
beacon: beacon,
|
2020-01-17 07:10:47 +00:00
|
|
|
api: api,
|
|
|
|
waitFunc: chanWaiter(nextCh),
|
|
|
|
epp: epp,
|
|
|
|
minedBlockHeights: arc,
|
2019-09-23 15:27:30 +00:00
|
|
|
}
|
2019-11-30 23:17:50 +00:00
|
|
|
|
|
|
|
if err := m.Register(addr); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return m
|
2019-09-23 15:27:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 20:00:04 +00:00
|
|
|
func chanWaiter(next <-chan struct{}) func(ctx context.Context, _ uint64) error {
|
|
|
|
return func(ctx context.Context, _ uint64) error {
|
2019-09-23 15:27:30 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2019-10-09 04:38:59 +00:00
|
|
|
return ctx.Err()
|
2019-09-23 15:27:30 +00:00
|
|
|
case <-next:
|
|
|
|
}
|
|
|
|
|
2019-10-09 04:38:59 +00:00
|
|
|
return nil
|
2019-09-23 15:27:30 +00:00
|
|
|
}
|
|
|
|
}
|