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 {
t.Fatal(err)
}
fmt.Println("Client data cid: ", fcid)
deal, err := client.ClientStartDeal(ctx, fcid, addr, maddr, types.NewInt(1000000), 100)
if err != nil {
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
}
func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (uint64, error) {
log.Warn("stub GetMinerSlashed")
return 0, nil
func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (bool, error) {
var mas miner.State
_, 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) {

View File

@ -523,13 +523,13 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
}
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 {
return xerrors.Errorf("failed to check if block miner was slashed: %w", err)
}
if slashedAt != 0 {
return xerrors.Errorf("received block was from miner slashed at height %d", slashedAt)
if slashed {
return xerrors.Errorf("received block was from slashed or invalid 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"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/miner"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto"
"golang.org/x/xerrors"
@ -68,7 +69,7 @@ func init() {
}
epostp := &types.EPostProof{
Proof: []byte("valid proof"),
Proofs: []abi.PoStProof{{ProofBytes: []byte("valid proof")}},
Candidates: []types.EPostTicket{
{
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/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 {
return api.MinerPower{}, err
}
if slashed != 0 {
if slashed {
mpow = types.NewInt(0)
}
}

View File

@ -14,16 +14,21 @@ import (
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/go-sectorbuilder/fs"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log"
"golang.org/x/xerrors"
)
var log = logging.Logger("sbmock")
type SBMock struct {
sectors map[abi.SectorNumber]*sectorState
sectorSize abi.SectorSize
nextSectorID abi.SectorNumber
rateLimit chan struct{}
proofType abi.RegisteredProof
lk sync.Mutex
}
@ -31,11 +36,17 @@ type SBMock struct {
type mockVerif struct{}
func NewMockSectorBuilder(threads int, ssize abi.SectorSize) *SBMock {
rt, _, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
panic(err)
}
return &SBMock{
sectors: make(map[abi.SectorNumber]*sectorState),
sectorSize: ssize,
nextSectorID: 5,
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) {
log.Warn("Add piece: ", sectorId, size, sb.proofType)
sb.lk.Lock()
ss, ok := sb.sectors[sectorId]
if !ok {
@ -76,12 +88,12 @@ func (sb *SBMock) AddPiece(ctx context.Context, size abi.UnpaddedPieceSize, sect
ss.lk.Lock()
defer ss.lk.Unlock()
b, err := ioutil.ReadAll(r)
c, err := sectorbuilder.GeneratePieceCIDFromFile(sb.proofType, r, size)
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)
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) {
log.Warn("Seal PreCommit", sid)
sb.lk.Lock()
ss, ok := sb.sectors[sid]
sb.lk.Unlock()
@ -175,7 +188,14 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticke
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 {
panic(err)
}
@ -185,12 +205,11 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticke
commr[32-(i+1)] = cc[i]
}
commR := commcid.DataCommitmentV1ToCID(commr)
return commd, commR, nil
return commcid.DataCommitmentV1ToCID(commr)
}
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()
ss, ok := sb.sectors[sid]
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 {
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 {

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)
return ctx.Send(SectorSealFailed{xerrors.Errorf("bad CommD error: %w", err)})
case *ErrExpiredTicket:
return ctx.Send(SectorSealFailed{xerrors.Errorf("bad CommD error: %w", err)})
return ctx.Send(SectorSealFailed{xerrors.Errorf("ticket expired: %w", err)})
default:
return xerrors.Errorf("checkSeal sanity check error: %w", err)
}