Merge pull request #2259 from filecoin-project/yusef-mining-callback
add error argument to waitFunc callback in miner loop
This commit is contained in:
commit
5836dfae41
@ -59,7 +59,7 @@ func TestDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration, carExport
|
|||||||
defer close(done)
|
defer close(done)
|
||||||
for atomic.LoadInt64(&mine) == 1 {
|
for atomic.LoadInt64(&mine) == 1 {
|
||||||
time.Sleep(blocktime)
|
time.Sleep(blocktime)
|
||||||
if err := sn[0].MineOne(ctx, func(bool) {}); err != nil {
|
if err := sn[0].MineOne(ctx, func(bool, error) {}); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ func TestDoubleDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|||||||
defer close(done)
|
defer close(done)
|
||||||
for atomic.LoadInt64(&mine) == 1 {
|
for atomic.LoadInt64(&mine) == 1 {
|
||||||
time.Sleep(blocktime)
|
time.Sleep(blocktime)
|
||||||
if err := sn[0].MineOne(ctx, func(bool) {}); err != nil {
|
if err := sn[0].MineOne(ctx, func(bool, error) {}); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func (ts *testSuite) testMining(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
<-newHeads
|
<-newHeads
|
||||||
|
|
||||||
err = sn[0].MineOne(ctx, func(bool) {})
|
err = sn[0].MineOne(ctx, func(bool, error) {})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
<-newHeads
|
<-newHeads
|
||||||
@ -62,7 +62,7 @@ func (ts *testSuite) testMiningReal(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
<-newHeads
|
<-newHeads
|
||||||
|
|
||||||
err = sn[0].MineOne(ctx, func(bool) {})
|
err = sn[0].MineOne(ctx, func(bool, error) {})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
<-newHeads
|
<-newHeads
|
||||||
@ -71,7 +71,7 @@ func (ts *testSuite) testMiningReal(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, abi.ChainEpoch(1), h2.Height())
|
require.Equal(t, abi.ChainEpoch(1), h2.Height())
|
||||||
|
|
||||||
err = sn[0].MineOne(ctx, func(bool) {})
|
err = sn[0].MineOne(ctx, func(bool, error) {})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
<-newHeads
|
<-newHeads
|
||||||
@ -132,7 +132,7 @@ func TestDealMining(t *testing.T, b APIBuilder, blocktime time.Duration, carExpo
|
|||||||
prevExpect := 0
|
prevExpect := 0
|
||||||
for atomic.LoadInt32(&mine) != 0 {
|
for atomic.LoadInt32(&mine) != 0 {
|
||||||
wait := make(chan int, 2)
|
wait := make(chan int, 2)
|
||||||
mdone := func(mined bool) {
|
mdone := func(mined bool, err error) {
|
||||||
go func() {
|
go func() {
|
||||||
n := 0
|
n := 0
|
||||||
if mined {
|
if mined {
|
||||||
|
@ -18,7 +18,7 @@ type TestNode struct {
|
|||||||
type TestStorageNode struct {
|
type TestStorageNode struct {
|
||||||
api.StorageMiner
|
api.StorageMiner
|
||||||
|
|
||||||
MineOne func(context.Context, func(bool)) error
|
MineOne func(context.Context, func(bool, error)) error
|
||||||
}
|
}
|
||||||
|
|
||||||
var PresealGenesis = -1
|
var PresealGenesis = -1
|
||||||
|
@ -43,7 +43,7 @@ func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSect
|
|||||||
defer close(done)
|
defer close(done)
|
||||||
for mine {
|
for mine {
|
||||||
time.Sleep(blocktime)
|
time.Sleep(blocktime)
|
||||||
if err := sn[0].MineOne(ctx, func(bool) {}); err != nil {
|
if err := sn[0].MineOne(ctx, func(bool, error) {}); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector
|
|||||||
defer close(done)
|
defer close(done)
|
||||||
for mine {
|
for mine {
|
||||||
time.Sleep(blocktime)
|
time.Sleep(blocktime)
|
||||||
if err := sn[0].MineOne(ctx, func(bool) {}); err != nil {
|
if err := sn[0].MineOne(ctx, func(bool, error) {}); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ var preSealCmd = &cli.Command{
|
|||||||
Usage: "(optional) Key to use for signing / owner/worker addresses",
|
Usage: "(optional) Key to use for signing / owner/worker addresses",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "fake-sectors",
|
Name: "fake-sectors",
|
||||||
Value: false,
|
Value: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -186,7 +186,7 @@ func presealSector(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, sid abi.Sector
|
|||||||
}
|
}
|
||||||
|
|
||||||
func presealSectorFake(sbfs *basicfs.Provider, sid abi.SectorID, spt abi.RegisteredSealProof, ssize abi.SectorSize) (*genesis.PreSeal, error) {
|
func presealSectorFake(sbfs *basicfs.Provider, sid abi.SectorID, spt abi.RegisteredSealProof, ssize abi.SectorSize) (*genesis.PreSeal, error) {
|
||||||
paths, done, err := sbfs.AcquireSector(context.TODO(), sid, 0, stores.FTSealed | stores.FTCache, true)
|
paths, done, err := sbfs.AcquireSector(context.TODO(), sid, 0, stores.FTSealed|stores.FTCache, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("acquire unsealed sector: %w", err)
|
return nil, xerrors.Errorf("acquire unsealed sector: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
var log = logging.Logger("miner")
|
var log = logging.Logger("miner")
|
||||||
|
|
||||||
// returns a callback reporting whether we mined a blocks in this round
|
// returns a callback reporting whether we mined a blocks in this round
|
||||||
type waitFunc func(ctx context.Context, baseTime uint64) (func(bool), error)
|
type waitFunc func(ctx context.Context, baseTime uint64) (func(bool, error), error)
|
||||||
|
|
||||||
func NewMiner(api api.FullNode, epp gen.WinningPoStProver, addr address.Address) *Miner {
|
func NewMiner(api api.FullNode, epp gen.WinningPoStProver, addr address.Address) *Miner {
|
||||||
arc, err := lru.NewARC(10000)
|
arc, err := lru.NewARC(10000)
|
||||||
@ -40,12 +40,12 @@ func NewMiner(api api.FullNode, epp gen.WinningPoStProver, addr address.Address)
|
|||||||
api: api,
|
api: api,
|
||||||
epp: epp,
|
epp: epp,
|
||||||
address: addr,
|
address: addr,
|
||||||
waitFunc: func(ctx context.Context, baseTime uint64) (func(bool), error) {
|
waitFunc: func(ctx context.Context, baseTime uint64) (func(bool, error), error) {
|
||||||
// Wait around for half the block time in case other parents come in
|
// Wait around for half the block time in case other parents come in
|
||||||
deadline := baseTime + build.PropagationDelaySecs
|
deadline := baseTime + build.PropagationDelaySecs
|
||||||
time.Sleep(time.Until(time.Unix(int64(deadline), 0)))
|
time.Sleep(time.Until(time.Unix(int64(deadline), 0)))
|
||||||
|
|
||||||
return func(bool) {}, nil
|
return func(bool, error) {}, nil
|
||||||
},
|
},
|
||||||
minedBlockHeights: arc,
|
minedBlockHeights: arc,
|
||||||
}
|
}
|
||||||
@ -158,11 +158,12 @@ func (m *Miner) mine(ctx context.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("mining block failed: %+v", err)
|
log.Errorf("mining block failed: %+v", err)
|
||||||
m.niceSleep(time.Second)
|
m.niceSleep(time.Second)
|
||||||
|
onDone(false, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
lastBase = *base
|
lastBase = *base
|
||||||
|
|
||||||
onDone(b != nil)
|
onDone(b != nil, nil)
|
||||||
|
|
||||||
if b != nil {
|
if b != nil {
|
||||||
btime := time.Unix(int64(b.Header.Timestamp), 0)
|
btime := time.Unix(int64(b.Header.Timestamp), 0)
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewTestMiner(nextCh <-chan func(bool), addr address.Address) func(api.FullNode, gen.WinningPoStProver) *Miner {
|
func NewTestMiner(nextCh <-chan func(bool, error), addr address.Address) func(api.FullNode, gen.WinningPoStProver) *Miner {
|
||||||
return func(api api.FullNode, epp gen.WinningPoStProver) *Miner {
|
return func(api api.FullNode, epp gen.WinningPoStProver) *Miner {
|
||||||
arc, err := lru.NewARC(10000)
|
arc, err := lru.NewARC(10000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -31,8 +31,8 @@ func NewTestMiner(nextCh <-chan func(bool), addr address.Address) func(api.FullN
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func chanWaiter(next <-chan func(bool)) func(ctx context.Context, _ uint64) (func(bool), error) {
|
func chanWaiter(next <-chan func(bool, error)) func(ctx context.Context, _ uint64) (func(bool, error), error) {
|
||||||
return func(ctx context.Context, _ uint64) (func(bool), error) {
|
return func(ctx context.Context, _ uint64) (func(bool, error), error) {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
|
@ -116,7 +116,7 @@ func testStorageNode(ctx context.Context, t *testing.T, waddr address.Address, a
|
|||||||
// start node
|
// start node
|
||||||
var minerapi api.StorageMiner
|
var minerapi api.StorageMiner
|
||||||
|
|
||||||
mineBlock := make(chan func(bool))
|
mineBlock := make(chan func(bool, error))
|
||||||
// TODO: use stop
|
// TODO: use stop
|
||||||
_, err = node.New(ctx,
|
_, err = node.New(ctx,
|
||||||
node.StorageMiner(&minerapi),
|
node.StorageMiner(&minerapi),
|
||||||
@ -141,7 +141,7 @@ func testStorageNode(ctx context.Context, t *testing.T, waddr address.Address, a
|
|||||||
|
|
||||||
err = minerapi.NetConnect(ctx, remoteAddrs)
|
err = minerapi.NetConnect(ctx, remoteAddrs)
|
||||||
require.NoError(t, err)*/
|
require.NoError(t, err)*/
|
||||||
mineOne := func(ctx context.Context, cb func(bool)) error {
|
mineOne := func(ctx context.Context, cb func(bool, error)) error {
|
||||||
select {
|
select {
|
||||||
case mineBlock <- cb:
|
case mineBlock <- cb:
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user