storageminer: Updates to new types

This commit is contained in:
Łukasz Magiera 2020-02-12 23:12:11 +01:00
parent 220bd376b4
commit 255f511abd
3 changed files with 32 additions and 55 deletions

View File

@ -40,32 +40,32 @@ From a list of parameters, create a genesis block / initial state
The process: The process:
- Bootstrap state (MakeInitialStateTree) - Bootstrap state (MakeInitialStateTree)
- Create empty state - Create empty state
- Make init actor - Make init actor
- Create accounts mappings - Create accounts mappings
- Set NextID to MinerStart - Set NextID to MinerStart
- Setup Reward (1.4B fil) - Setup Reward (1.4B fil)
- Setup Cron - Setup Cron
- Create empty power actor - Create empty power actor
- Create empty market - Create empty market
- Setup burnt fund address - Setup burnt fund address
- Initialize account / msig balances - Initialize account / msig balances
- Instantiate early vm with genesis syscalls - Instantiate early vm with genesis syscalls
- Create miners - Create miners
- Each: - Each:
- power.CreateMiner, set msg value to PowerBalance - power.CreateMiner, set msg value to PowerBalance
- market.AddFunds with correct value - market.AddFunds with correct value
- market.PublishDeals for related sectors - market.PublishDeals for related sectors
- Set precommits - Set precommits
- Commit presealed sectors - Commit presealed sectors
Data Types: Data Types:
PreSeal :{ PreSeal :{
CommR CID CommR CID
CommD CID CommD CID
SectorID SectorNumber SectorID SectorNumber
Deal market.DealProposal # Start at 0, self-deal! Deal market.DealProposal # Start at 0, self-deal!
} }
Genesis: { Genesis: {

View File

@ -7,14 +7,14 @@ import (
"time" "time"
"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/chain/actors"
"github.com/filecoin-project/lotus/chain/gen"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/gen"
"github.com/filecoin-project/lotus/chain/types"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
"go.opencensus.io/trace" "go.opencensus.io/trace"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -342,7 +342,7 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB
} }
func (m *Miner) computeVRF(ctx context.Context, addr address.Address, input []byte) ([]byte, error) { func (m *Miner) computeVRF(ctx context.Context, addr address.Address, input []byte) ([]byte, error) {
w, err := m.getMinerWorker(ctx, addr, nil) w, err := m.api.StateMinerWorker(ctx, addr, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -350,28 +350,6 @@ func (m *Miner) computeVRF(ctx context.Context, addr address.Address, input []by
return gen.ComputeVRF(ctx, m.api.WalletSign, w, addr, gen.DSepTicket, input) return gen.ComputeVRF(ctx, m.api.WalletSign, w, addr, gen.DSepTicket, input)
} }
func (m *Miner) getMinerWorker(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
ret, err := m.api.StateCall(ctx, &types.Message{
From: addr,
To: addr,
Method: actors.MAMethods.GetWorkerAddr,
}, ts)
if err != nil {
return address.Undef, xerrors.Errorf("failed to get miner worker addr: %w", err)
}
if ret.ExitCode != 0 {
return address.Undef, xerrors.Errorf("failed to get miner worker addr (exit code %d)", ret.ExitCode)
}
w, err := address.NewFromBytes(ret.Return)
if err != nil {
return address.Undef, xerrors.Errorf("GetWorkerAddr returned malformed address: %w", err)
}
return w, nil
}
func (m *Miner) computeTicket(ctx context.Context, addr address.Address, base *MiningBase) (*types.Ticket, error) { func (m *Miner) computeTicket(ctx context.Context, addr address.Address, base *MiningBase) (*types.Ticket, error) {
vrfBase := base.ts.MinTicket().VRFProof vrfBase := base.ts.MinTicket().VRFProof

View File

@ -7,6 +7,8 @@ import (
ffi "github.com/filecoin-project/filecoin-ffi" ffi "github.com/filecoin-project/filecoin-ffi"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder" sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"go.opencensus.io/trace" "go.opencensus.io/trace"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -51,7 +53,7 @@ func (s *FPoStScheduler) doPost(ctx context.Context, eps abi.ChainEpoch, ts *typ
}() }()
} }
func (s *FPoStScheduler) declareFaults(ctx context.Context, fc uint64, params *actors.DeclareFaultsParams) error { func (s *FPoStScheduler) declareFaults(ctx context.Context, fc uint64, params *miner.DeclareTemporaryFaultsParams) error {
log.Warnf("DECLARING %d FAULTS", fc) log.Warnf("DECLARING %d FAULTS", fc)
enc, aerr := actors.SerializeParams(params) enc, aerr := actors.SerializeParams(params)
@ -62,7 +64,7 @@ func (s *FPoStScheduler) declareFaults(ctx context.Context, fc uint64, params *a
msg := &types.Message{ msg := &types.Message{
To: s.actor, To: s.actor,
From: s.worker, From: s.worker,
Method: actors.MAMethods.DeclareFaults, Method: builtin.MethodsMiner.DeclareTemporaryFaults,
Params: enc, Params: enc,
Value: types.NewInt(0), Value: types.NewInt(0),
GasLimit: types.NewInt(10000000), // i dont know help GasLimit: types.NewInt(10000000), // i dont know help
@ -103,35 +105,32 @@ func (s *FPoStScheduler) checkFaults(ctx context.Context, ssi sectorbuilder.Sort
} }
} }
var faultIDs []abi.SectorNumber
if len(faults) > 0 { if len(faults) > 0 {
params := &actors.DeclareFaultsParams{Faults: types.NewBitField()} params := &miner.DeclareTemporaryFaultsParams{Duration: 900} // TODO: duration is annoying
for _, fault := range faults { for _, fault := range faults {
if _, ok := declaredFaults[abi.SectorNumber(fault.SectorNum)]; ok { if _, ok := declaredFaults[(fault.SectorNum)]; ok {
continue continue
} }
log.Warnf("new fault detected: sector %d: %s", fault.SectorNum, fault.Err) log.Warnf("new fault detected: sector %d: %s", fault.SectorNum, fault.Err)
declaredFaults[fault.SectorNum] = struct{}{} declaredFaults[fault.SectorNum] = struct{}{}
params.Faults.Set(uint64(fault.SectorNum))
} }
pc, err := params.Faults.Count() faultIDs = make([]abi.SectorNumber, 0, len(declaredFaults))
if err != nil { for fault := range declaredFaults {
return nil, xerrors.Errorf("counting faults: %w", err) faultIDs = append(faultIDs, abi.SectorNumber(fault))
} }
if pc > 0 { params.SectorNumbers = faultIDs
if err := s.declareFaults(ctx, pc, params); err != nil {
if len(faultIDs) > 0 {
if err := s.declareFaults(ctx, uint64(len(faultIDs)), params); err != nil {
return nil, err return nil, err
} }
} }
} }
faultIDs := make([]abi.SectorNumber, 0, len(declaredFaults))
for fault := range declaredFaults {
faultIDs = append(faultIDs, abi.SectorNumber(fault))
}
return faultIDs, nil return faultIDs, nil
} }