more misc fixes

This commit is contained in:
whyrusleeping 2020-03-01 17:09:38 -08:00
parent 4521ff3e95
commit 60b19c51ef
9 changed files with 67 additions and 17 deletions

View File

@ -74,6 +74,7 @@ func TestDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
fmt.Println("Client data cid: ", fcid)
deal, err := client.ClientStartDeal(ctx, fcid, addr, maddr, types.NewInt(1000000), 100) deal, err := client.ClientStartDeal(ctx, fcid, addr, maddr, types.NewInt(1000000), 100)
if err != nil { if err != nil {
t.Fatalf("%+v", err) t.Fatalf("%+v", err)

View File

@ -186,9 +186,34 @@ func GetMinerSectorSize(ctx context.Context, sm *StateManager, ts *types.TipSet,
return mas.Info.SectorSize, nil return mas.Info.SectorSize, nil
} }
func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (uint64, error) { func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (bool, error) {
log.Warn("stub GetMinerSlashed") var mas miner.State
return 0, nil _, err := sm.LoadActorState(ctx, maddr, &mas, ts)
if err != nil {
return false, xerrors.Errorf("(get miner slashed) failed to load miner actor state")
}
if mas.PoStState.HasFailedPost() {
return true, nil
}
var spas power.State
_, err = sm.LoadActorState(ctx, builtin.StoragePowerActorAddr, &spas, ts)
if err != nil {
return false, xerrors.Errorf("(get miner slashed) failed to load power actor state")
}
store := sm.cs.Store(ctx)
claims := adt.AsMap(store, spas.Claims)
ok, err := claims.Get(power.AddrKey(maddr), nil)
if err != nil {
return false, err
}
if !ok {
return true, nil
}
return false, nil
} }
func GetMinerFaults(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) ([]abi.SectorNumber, error) { func GetMinerFaults(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) ([]abi.SectorNumber, error) {

View File

@ -523,13 +523,13 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
} }
winnerCheck := async.Err(func() error { winnerCheck := async.Err(func() error {
slashedAt, err := stmgr.GetMinerSlashed(ctx, syncer.sm, baseTs, h.Miner) slashed, err := stmgr.GetMinerSlashed(ctx, syncer.sm, baseTs, h.Miner)
if err != nil { if err != nil {
return xerrors.Errorf("failed to check if block miner was slashed: %w", err) return xerrors.Errorf("failed to check if block miner was slashed: %w", err)
} }
if slashedAt != 0 { if slashed {
return xerrors.Errorf("received block was from miner slashed at height %d", slashedAt) return xerrors.Errorf("received block was from slashed or invalid miner")
} }
mpow, tpow, err := stmgr.GetPower(ctx, syncer.sm, baseTs, h.Miner) mpow, tpow, err := stmgr.GetPower(ctx, syncer.sm, baseTs, h.Miner)

View File

@ -9,6 +9,7 @@ import (
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli" lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/miner" "github.com/filecoin-project/lotus/miner"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/crypto"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -68,7 +69,7 @@ func init() {
} }
epostp := &types.EPostProof{ epostp := &types.EPostProof{
Proof: []byte("valid proof"), Proofs: []abi.PoStProof{{ProofBytes: []byte("valid proof")}},
Candidates: []types.EPostTicket{ Candidates: []types.EPostTicket{
{ {
ChallengeIndex: 0, ChallengeIndex: 0,

4
go.mod
View File

@ -114,3 +114,7 @@ require (
replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v1.18.0 replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v1.18.0
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi
replace github.com/filecoin-project/specs-actors => ../specs-actors
replace github.com/filecoin-project/go-fil-markets => ../go-fil-markets

View File

@ -77,7 +77,7 @@ func (a *StateAPI) StateMinerPower(ctx context.Context, maddr address.Address, t
if err != nil { if err != nil {
return api.MinerPower{}, err return api.MinerPower{}, err
} }
if slashed != 0 { if slashed {
mpow = types.NewInt(0) mpow = types.NewInt(0)
} }
} }

View File

@ -14,16 +14,21 @@ import (
commcid "github.com/filecoin-project/go-fil-commcid" commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/go-sectorbuilder/fs" "github.com/filecoin-project/go-sectorbuilder/fs"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log"
"golang.org/x/xerrors" "golang.org/x/xerrors"
) )
var log = logging.Logger("sbmock")
type SBMock struct { type SBMock struct {
sectors map[abi.SectorNumber]*sectorState sectors map[abi.SectorNumber]*sectorState
sectorSize abi.SectorSize sectorSize abi.SectorSize
nextSectorID abi.SectorNumber nextSectorID abi.SectorNumber
rateLimit chan struct{} rateLimit chan struct{}
proofType abi.RegisteredProof
lk sync.Mutex lk sync.Mutex
} }
@ -31,11 +36,17 @@ type SBMock struct {
type mockVerif struct{} type mockVerif struct{}
func NewMockSectorBuilder(threads int, ssize abi.SectorSize) *SBMock { func NewMockSectorBuilder(threads int, ssize abi.SectorSize) *SBMock {
rt, _, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
panic(err)
}
return &SBMock{ return &SBMock{
sectors: make(map[abi.SectorNumber]*sectorState), sectors: make(map[abi.SectorNumber]*sectorState),
sectorSize: ssize, sectorSize: ssize,
nextSectorID: 5, nextSectorID: 5,
rateLimit: make(chan struct{}, threads), rateLimit: make(chan struct{}, threads),
proofType: rt,
} }
} }
@ -64,6 +75,7 @@ func (sb *SBMock) RateLimit() func() {
} }
func (sb *SBMock) AddPiece(ctx context.Context, size abi.UnpaddedPieceSize, sectorId abi.SectorNumber, r io.Reader, existingPieces []abi.UnpaddedPieceSize) (abi.PieceInfo, error) { func (sb *SBMock) AddPiece(ctx context.Context, size abi.UnpaddedPieceSize, sectorId abi.SectorNumber, r io.Reader, existingPieces []abi.UnpaddedPieceSize) (abi.PieceInfo, error) {
log.Warn("Add piece: ", sectorId, size, sb.proofType)
sb.lk.Lock() sb.lk.Lock()
ss, ok := sb.sectors[sectorId] ss, ok := sb.sectors[sectorId]
if !ok { if !ok {
@ -76,12 +88,12 @@ func (sb *SBMock) AddPiece(ctx context.Context, size abi.UnpaddedPieceSize, sect
ss.lk.Lock() ss.lk.Lock()
defer ss.lk.Unlock() defer ss.lk.Unlock()
b, err := ioutil.ReadAll(r) c, err := sectorbuilder.GeneratePieceCIDFromFile(sb.proofType, r, size)
if err != nil { if err != nil {
return abi.PieceInfo{}, err return abi.PieceInfo{}, xerrors.Errorf("failed to generate piece cid: %w", err)
} }
c := commcid.DataCommitmentV1ToCID(b[:32]) // hax log.Warn("Generated Piece CID: ", c)
ss.pieces = append(ss.pieces, c) ss.pieces = append(ss.pieces, c)
return abi.PieceInfo{ return abi.PieceInfo{
@ -131,6 +143,7 @@ func (sb *SBMock) GenerateFallbackPoSt([]abi.SectorInfo, abi.PoStRandomness, []a
} }
func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticket abi.SealRandomness, pieces []abi.PieceInfo) (cid.Cid, cid.Cid, error) { func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticket abi.SealRandomness, pieces []abi.PieceInfo) (cid.Cid, cid.Cid, error) {
log.Warn("Seal PreCommit", sid)
sb.lk.Lock() sb.lk.Lock()
ss, ok := sb.sectors[sid] ss, ok := sb.sectors[sid]
sb.lk.Unlock() sb.lk.Unlock()
@ -175,7 +188,14 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticke
return cid.Undef, cid.Undef, err return cid.Undef, cid.Undef, err
} }
cc, _, err := commcid.CIDToCommitment(commd) commR := commRfromD(commd)
return commR, commd, nil
}
// so we can 'verify' that the commR comes from the commD
func commRfromD(commD cid.Cid) cid.Cid {
cc, _, err := commcid.CIDToCommitment(commD)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -185,12 +205,11 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticke
commr[32-(i+1)] = cc[i] commr[32-(i+1)] = cc[i]
} }
commR := commcid.DataCommitmentV1ToCID(commr) return commcid.DataCommitmentV1ToCID(commr)
return commd, commR, nil
} }
func (sb *SBMock) SealCommit(ctx context.Context, sid abi.SectorNumber, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, sealedCid cid.Cid, unsealed cid.Cid) ([]byte, error) { func (sb *SBMock) SealCommit(ctx context.Context, sid abi.SectorNumber, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, sealedCid cid.Cid, unsealed cid.Cid) ([]byte, error) {
log.Warn("Seal Commit!", sid, sealedCid, unsealed)
sb.lk.Lock() sb.lk.Lock()
ss, ok := sb.sectors[sid] ss, ok := sb.sectors[sid]
sb.lk.Unlock() sb.lk.Unlock()

View File

@ -108,7 +108,7 @@ func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api se
} }
if cid.Cid(c) != *si.CommD { if cid.Cid(c) != *si.CommD {
return &ErrBadCommD{xerrors.Errorf("on chain CommD differs from sector: %x != %x", r.Return, si.CommD)} return &ErrBadCommD{xerrors.Errorf("on chain CommD differs from sector: %s != %s", cid.Cid(c), si.CommD)}
} }
if int64(head.Height())-int64(si.Ticket.Epoch+build.SealRandomnessLookback) > build.SealRandomnessLookbackLimit { if int64(head.Height())-int64(si.Ticket.Epoch+build.SealRandomnessLookback) > build.SealRandomnessLookbackLimit {

View File

@ -91,7 +91,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
case *ErrBadCommD: // TODO: Should this just back to packing? (not really needed since handleUnsealed will do that too) case *ErrBadCommD: // TODO: Should this just back to packing? (not really needed since handleUnsealed will do that too)
return ctx.Send(SectorSealFailed{xerrors.Errorf("bad CommD error: %w", err)}) return ctx.Send(SectorSealFailed{xerrors.Errorf("bad CommD error: %w", err)})
case *ErrExpiredTicket: case *ErrExpiredTicket:
return ctx.Send(SectorSealFailed{xerrors.Errorf("bad CommD error: %w", err)}) return ctx.Send(SectorSealFailed{xerrors.Errorf("ticket expired: %w", err)})
default: default:
return xerrors.Errorf("checkSeal sanity check error: %w", err) return xerrors.Errorf("checkSeal sanity check error: %w", err)
} }