-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
testminer.go
56 lines (47 loc) · 1.49 KB
/
testminer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package miner
import (
"context"
"github.com/hashicorp/golang-lru/arc/v2"
ds "github.com/ipfs/go-datastore"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/api/v1api"
"github.com/filecoin-project/lotus/chain/gen"
"github.com/filecoin-project/lotus/chain/gen/slashfilter"
"github.com/filecoin-project/lotus/journal"
)
type MineReq struct {
InjectNulls abi.ChainEpoch
Done func(bool, abi.ChainEpoch, error)
}
func NewTestMiner(nextCh <-chan MineReq, addr address.Address) func(v1api.FullNode, gen.WinningPoStProver) *Miner {
return func(api v1api.FullNode, epp gen.WinningPoStProver) *Miner {
arc, err := arc.NewARC[abi.ChainEpoch, bool](10000)
if err != nil {
panic(err)
}
m := &Miner{
api: api,
propagationWaitFunc: chanWaiter(nextCh),
epp: epp,
minedBlockHeights: arc,
address: addr,
sf: slashfilter.New(ds.NewMapDatastore()),
journal: journal.NilJournal(),
}
if err := m.Start(context.TODO()); err != nil {
panic(err)
}
return m
}
}
func chanWaiter(next <-chan MineReq) func(ctx context.Context, _ uint64) (func(bool, abi.ChainEpoch, error), abi.ChainEpoch, error) {
return func(ctx context.Context, _ uint64) (func(bool, abi.ChainEpoch, error), abi.ChainEpoch, error) {
select {
case <-ctx.Done():
return nil, 0, ctx.Err()
case req := <-next:
return req.Done, req.InjectNulls, nil
}
}
}