Fix some tests
This commit is contained in:
parent
1fd23248ff
commit
fb59b40507
@ -40,7 +40,7 @@ func TestCCUpgrade(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, error) {}); err != nil {
|
if err := sn[0].MineOne(ctx, MineNext); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/miner"
|
||||||
sealing "github.com/filecoin-project/storage-fsm"
|
sealing "github.com/filecoin-project/storage-fsm"
|
||||||
dag "github.com/ipfs/go-merkledag"
|
dag "github.com/ipfs/go-merkledag"
|
||||||
dstest "github.com/ipfs/go-merkledag/test"
|
dstest "github.com/ipfs/go-merkledag/test"
|
||||||
@ -32,6 +33,11 @@ import (
|
|||||||
ipld "github.com/ipfs/go-ipld-format"
|
ipld "github.com/ipfs/go-ipld-format"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var MineNext = miner.MineReq{
|
||||||
|
InjectNulls: 0,
|
||||||
|
Done: func(bool, error) {},
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
logging.SetAllLoggers(logging.LevelInfo)
|
logging.SetAllLoggers(logging.LevelInfo)
|
||||||
build.InsecurePoStValidation = true
|
build.InsecurePoStValidation = true
|
||||||
@ -61,7 +67,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, error) {}); err != nil {
|
if err := sn[0].MineOne(ctx, MineNext); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,7 +105,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, error) {}); err != nil {
|
if err := sn[0].MineOne(ctx, MineNext); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,7 +169,7 @@ func TestSenondDealRetrieval(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, error) {}); err != nil {
|
if err := sn[0].MineOne(ctx, MineNext); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/miner"
|
||||||
"github.com/filecoin-project/lotus/node/impl"
|
"github.com/filecoin-project/lotus/node/impl"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,7 +35,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, error) {})
|
err = sn[0].MineOne(ctx, MineNext)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
<-newHeads
|
<-newHeads
|
||||||
@ -62,7 +63,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, error) {})
|
err = sn[0].MineOne(ctx, MineNext)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
<-newHeads
|
<-newHeads
|
||||||
@ -71,7 +72,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, error) {})
|
err = sn[0].MineOne(ctx, MineNext)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
<-newHeads
|
<-newHeads
|
||||||
@ -142,11 +143,11 @@ func TestDealMining(t *testing.T, b APIBuilder, blocktime time.Duration, carExpo
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := sn[0].MineOne(ctx, mdone); err != nil {
|
if err := sn[0].MineOne(ctx, miner.MineReq{Done: mdone}); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := sn[1].MineOne(ctx, mdone); err != nil {
|
if err := sn[1].MineOne(ctx, miner.MineReq{Done: mdone}); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,19 +9,21 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||||
|
initactor "github.com/filecoin-project/specs-actors/actors/builtin/init"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/events"
|
"github.com/filecoin-project/lotus/chain/events"
|
||||||
"github.com/filecoin-project/lotus/chain/events/state"
|
"github.com/filecoin-project/lotus/chain/events/state"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/wallet"
|
"github.com/filecoin-project/lotus/chain/wallet"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/lotus/miner"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
|
||||||
initactor "github.com/filecoin-project/specs-actors/actors/builtin/init"
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
||||||
@ -167,6 +169,8 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|||||||
t.Fatal("Timed out waiting for receiver to submit vouchers")
|
t.Fatal("Timed out waiting for receiver to submit vouchers")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atomic.StoreInt64(&bm.nulls, paych.SettleDelay)
|
||||||
|
|
||||||
// collect funds (from receiver, though either party can do it)
|
// collect funds (from receiver, though either party can do it)
|
||||||
collectMsg, err := paymentReceiver.PaychCollect(ctx, channel)
|
collectMsg, err := paymentReceiver.PaychCollect(ctx, channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -224,6 +228,7 @@ type blockMiner struct {
|
|||||||
miner TestStorageNode
|
miner TestStorageNode
|
||||||
blocktime time.Duration
|
blocktime time.Duration
|
||||||
mine int64
|
mine int64
|
||||||
|
nulls int64
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +249,11 @@ func (bm *blockMiner) mineBlocks() {
|
|||||||
defer close(bm.done)
|
defer close(bm.done)
|
||||||
for atomic.LoadInt64(&bm.mine) == 1 {
|
for atomic.LoadInt64(&bm.mine) == 1 {
|
||||||
time.Sleep(bm.blocktime)
|
time.Sleep(bm.blocktime)
|
||||||
if err := bm.miner.MineOne(bm.ctx, func(bool, error) {}); err != nil {
|
nulls := atomic.SwapInt64(&bm.nulls, 0)
|
||||||
|
if err := bm.miner.MineOne(bm.ctx, miner.MineReq{
|
||||||
|
InjectNulls: abi.ChainEpoch(nulls),
|
||||||
|
Done: func(bool, error) {},
|
||||||
|
}); err != nil {
|
||||||
bm.t.Error(err)
|
bm.t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/miner"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestNode struct {
|
type TestNode struct {
|
||||||
@ -18,7 +19,7 @@ type TestNode struct {
|
|||||||
type TestStorageNode struct {
|
type TestStorageNode struct {
|
||||||
api.StorageMiner
|
api.StorageMiner
|
||||||
|
|
||||||
MineOne func(context.Context, func(bool, error)) error
|
MineOne func(context.Context, miner.MineReq) error
|
||||||
}
|
}
|
||||||
|
|
||||||
var PresealGenesis = -1
|
var PresealGenesis = -1
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
sealing "github.com/filecoin-project/storage-fsm"
|
sealing "github.com/filecoin-project/storage-fsm"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
bminer "github.com/filecoin-project/lotus/miner"
|
||||||
"github.com/filecoin-project/lotus/node/impl"
|
"github.com/filecoin-project/lotus/node/impl"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -47,13 +48,13 @@ func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSect
|
|||||||
defer close(done)
|
defer close(done)
|
||||||
for mine {
|
for mine {
|
||||||
build.Clock.Sleep(blocktime)
|
build.Clock.Sleep(blocktime)
|
||||||
if err := sn[0].MineOne(ctx, func(bool, error) {
|
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, error) {
|
||||||
select {
|
select {
|
||||||
case blockNotif <- struct{}{}:
|
case blockNotif <- struct{}{}:
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
}); err != nil {
|
}}); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +137,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector
|
|||||||
defer close(done)
|
defer close(done)
|
||||||
for mine {
|
for mine {
|
||||||
build.Clock.Sleep(blocktime)
|
build.Clock.Sleep(blocktime)
|
||||||
if err := sn[0].MineOne(ctx, func(bool, error) {}); err != nil {
|
if err := sn[0].MineOne(ctx, MineNext); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,20 +118,13 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
|||||||
|
|
||||||
// Add market funds
|
// Add market funds
|
||||||
|
|
||||||
{
|
if m.MarketBalance.GreaterThan(big.Zero()) {
|
||||||
params := mustEnc(&minerInfos[i].maddr)
|
params := mustEnc(&minerInfos[i].maddr)
|
||||||
_, err := doExecValue(ctx, vm, builtin.StorageMarketActorAddr, m.Worker, m.MarketBalance, builtin.MethodsMarket.AddBalance, params)
|
_, err := doExecValue(ctx, vm, builtin.StorageMarketActorAddr, m.Worker, m.MarketBalance, builtin.MethodsMarket.AddBalance, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err)
|
return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
|
||||||
params := mustEnc(&m.Worker)
|
|
||||||
_, err := doExecValue(ctx, vm, builtin.StorageMarketActorAddr, m.Worker, big.Zero(), builtin.MethodsMarket.AddBalance, params)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Publish preseal deals
|
// Publish preseal deals
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||||
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
|
|
||||||
@ -16,25 +15,23 @@ import (
|
|||||||
|
|
||||||
func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
|
func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
|
||||||
store := adt.WrapStore(context.TODO(), cbor.NewCborStore(bs))
|
store := adt.WrapStore(context.TODO(), cbor.NewCborStore(bs))
|
||||||
emptyhamt, err := adt.MakeEmptyMap(store).Root()
|
emptyMap, err := adt.MakeEmptyMap(store).Root()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sms := &power.State{
|
multiMap, err := adt.AsMultimap(store, emptyMap)
|
||||||
TotalRawBytePower: big.NewInt(0),
|
if err != nil {
|
||||||
TotalBytesCommitted: big.NewInt(0),
|
return nil, err
|
||||||
TotalQualityAdjPower: big.NewInt(0),
|
|
||||||
TotalQABytesCommitted: big.NewInt(0),
|
|
||||||
TotalPledgeCollateral: big.NewInt(0),
|
|
||||||
MinerCount: 0,
|
|
||||||
MinerAboveMinPowerCount: 0,
|
|
||||||
CronEventQueue: emptyhamt,
|
|
||||||
FirstCronEpoch: 0,
|
|
||||||
Claims: emptyhamt,
|
|
||||||
ProofValidationBatch: nil,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emptyMultiMap, err := multiMap.Root()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sms := power.ConstructState(emptyMap, emptyMultiMap)
|
||||||
|
|
||||||
stcid, err := store.Put(store.Context(), sms)
|
stcid, err := store.Put(store.Context(), sms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -149,7 +149,7 @@ type BlockMessages struct {
|
|||||||
type ExecCallback func(cid.Cid, *types.Message, *vm.ApplyRet) error
|
type ExecCallback func(cid.Cid, *types.Message, *vm.ApplyRet) error
|
||||||
|
|
||||||
func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEpoch, pstate cid.Cid, bms []BlockMessages, epoch abi.ChainEpoch, r vm.Rand, cb ExecCallback) (cid.Cid, cid.Cid, error) {
|
func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEpoch, pstate cid.Cid, bms []BlockMessages, epoch abi.ChainEpoch, r vm.Rand, cb ExecCallback) (cid.Cid, cid.Cid, error) {
|
||||||
vmi, err := sm.newVM(pstate, parentEpoch, r, sm.cs.Blockstore(), sm.cs.VMSys())
|
vmi, err := sm.newVM(pstate, epoch, r, sm.cs.Blockstore(), sm.cs.VMSys())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, cid.Undef, xerrors.Errorf("instantiating VM failed: %w", err)
|
return cid.Undef, cid.Undef, xerrors.Errorf("instantiating VM failed: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,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), error)
|
type waitFunc func(ctx context.Context, baseTime uint64) (func(bool, error), abi.ChainEpoch, error)
|
||||||
|
|
||||||
func randTimeOffset(width time.Duration) time.Duration {
|
func randTimeOffset(width time.Duration) time.Duration {
|
||||||
buf := make([]byte, 8)
|
buf := make([]byte, 8)
|
||||||
@ -53,7 +53,7 @@ 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), error) {
|
waitFunc: func(ctx context.Context, baseTime uint64) (func(bool, error), abi.ChainEpoch, 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
|
||||||
baseT := time.Unix(int64(deadline), 0)
|
baseT := time.Unix(int64(deadline), 0)
|
||||||
@ -62,7 +62,7 @@ func NewMiner(api api.FullNode, epp gen.WinningPoStProver, addr address.Address)
|
|||||||
|
|
||||||
build.Clock.Sleep(build.Clock.Until(baseT))
|
build.Clock.Sleep(build.Clock.Until(baseT))
|
||||||
|
|
||||||
return func(bool, error) {}, nil
|
return func(bool, error) {}, 0, nil
|
||||||
},
|
},
|
||||||
minedBlockHeights: arc,
|
minedBlockHeights: arc,
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ func (m *Miner) mine(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait until propagation delay period after block we plan to mine on
|
// Wait until propagation delay period after block we plan to mine on
|
||||||
onDone, err := m.waitFunc(ctx, prebase.TipSet.MinTimestamp())
|
onDone, injectNulls, err := m.waitFunc(ctx, prebase.TipSet.MinTimestamp())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
@ -172,6 +172,8 @@ func (m *Miner) mine(ctx context.Context) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base.NullRounds += injectNulls // testing
|
||||||
|
|
||||||
b, err := m.mineOne(ctx, base)
|
b, err := m.mineOne(ctx, base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("mining block failed: %+v", err)
|
log.Errorf("mining block failed: %+v", err)
|
||||||
|
@ -6,10 +6,16 @@ import (
|
|||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/chain/gen"
|
"github.com/filecoin-project/lotus/chain/gen"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewTestMiner(nextCh <-chan func(bool, error), addr address.Address) func(api.FullNode, gen.WinningPoStProver) *Miner {
|
type MineReq struct {
|
||||||
|
InjectNulls abi.ChainEpoch
|
||||||
|
Done func(bool, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTestMiner(nextCh <-chan MineReq, 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,13 +37,13 @@ func NewTestMiner(nextCh <-chan func(bool, error), addr address.Address) func(ap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func chanWaiter(next <-chan func(bool, error)) func(ctx context.Context, _ uint64) (func(bool, error), error) {
|
func chanWaiter(next <-chan MineReq) func(ctx context.Context, _ uint64) (func(bool, error), abi.ChainEpoch, error) {
|
||||||
return func(ctx context.Context, _ uint64) (func(bool, error), error) {
|
return func(ctx context.Context, _ uint64) (func(bool, error), abi.ChainEpoch, error) {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, ctx.Err()
|
return nil, 0, ctx.Err()
|
||||||
case cb := <-next:
|
case req := <-next:
|
||||||
return cb, nil
|
return req.Done, req.InjectNulls, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,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, error))
|
mineBlock := make(chan miner.MineReq)
|
||||||
// TODO: use stop
|
// TODO: use stop
|
||||||
_, err = node.New(ctx,
|
_, err = node.New(ctx,
|
||||||
node.StorageMiner(&minerapi),
|
node.StorageMiner(&minerapi),
|
||||||
@ -142,9 +142,9 @@ 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)) error {
|
mineOne := func(ctx context.Context, req miner.MineReq) error {
|
||||||
select {
|
select {
|
||||||
case mineBlock <- cb:
|
case mineBlock <- req:
|
||||||
return nil
|
return nil
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
|
Loading…
Reference in New Issue
Block a user