use specs-actors birfields
This commit is contained in:
parent
74bf9119cc
commit
48c5494cf9
@ -110,13 +110,13 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
||||
for pi, preseal := range m.Sectors {
|
||||
// Precommit
|
||||
{
|
||||
params := &miner.PreCommitSectorParams{Info: miner.SectorPreCommitInfo{
|
||||
params := &miner.SectorPreCommitInfo{
|
||||
SectorNumber: preseal.SectorID,
|
||||
SealedCID: commcid.ReplicaCommitmentV1ToCID(preseal.CommR[:]),
|
||||
SealEpoch: 0,
|
||||
DealIDs: []abi.DealID{dealIDs[pi]},
|
||||
Expiration: preseal.Deal.EndEpoch,
|
||||
}}
|
||||
}
|
||||
_, err := doExecValue(ctx, vm, maddr, m.Worker, big.Zero(), builtin.MethodsMiner.PreCommitSector, mustEnc(params))
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err)
|
||||
|
@ -183,7 +183,7 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
|
||||
From: actors.SystemAddress,
|
||||
Nonce: rewardActor.Nonce,
|
||||
To: b.Miner,
|
||||
Method: builtin.MethodsMiner.OnVerifiedElectionPoSt,
|
||||
Method: builtin.MethodsMiner.SubmitWindowedPoSt,
|
||||
GasPrice: types.NewInt(0),
|
||||
GasLimit: types.NewInt(10000000000),
|
||||
Value: types.NewInt(0),
|
||||
|
@ -1,226 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
rlepluslazy "github.com/filecoin-project/lotus/lib/rlepluslazy"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
)
|
||||
|
||||
var ErrBitFieldTooMany = errors.New("to many items in RLE")
|
||||
|
||||
type BitField struct {
|
||||
rle rlepluslazy.RLE
|
||||
|
||||
bits map[uint64]struct{}
|
||||
}
|
||||
|
||||
func NewBitField() BitField {
|
||||
bf, err := NewBitFieldFromBytes([]byte{})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("creating empty rle: %+v", err))
|
||||
}
|
||||
return bf
|
||||
}
|
||||
|
||||
func NewBitFieldFromBytes(rle []byte) (BitField, error) {
|
||||
bf := BitField{}
|
||||
rlep, err := rlepluslazy.FromBuf(rle)
|
||||
if err != nil {
|
||||
return BitField{}, xerrors.Errorf("could not decode rle+: %w", err)
|
||||
}
|
||||
bf.rle = rlep
|
||||
bf.bits = make(map[uint64]struct{})
|
||||
return bf, nil
|
||||
|
||||
}
|
||||
|
||||
func BitFieldFromSet(setBits []uint64) BitField {
|
||||
res := BitField{bits: make(map[uint64]struct{})}
|
||||
for _, b := range setBits {
|
||||
res.bits[b] = struct{}{}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func MergeBitFields(a, b BitField) (BitField, error) {
|
||||
ra, err := a.rle.RunIterator()
|
||||
if err != nil {
|
||||
return BitField{}, err
|
||||
}
|
||||
|
||||
rb, err := b.rle.RunIterator()
|
||||
if err != nil {
|
||||
return BitField{}, err
|
||||
}
|
||||
|
||||
merge, err := rlepluslazy.Sum(ra, rb)
|
||||
if err != nil {
|
||||
return BitField{}, err
|
||||
}
|
||||
|
||||
mergebytes, err := rlepluslazy.EncodeRuns(merge, nil)
|
||||
if err != nil {
|
||||
return BitField{}, err
|
||||
}
|
||||
|
||||
rle, err := rlepluslazy.FromBuf(mergebytes)
|
||||
if err != nil {
|
||||
return BitField{}, err
|
||||
}
|
||||
|
||||
return BitField{
|
||||
rle: rle,
|
||||
bits: make(map[uint64]struct{}),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (bf BitField) sum() (rlepluslazy.RunIterator, error) {
|
||||
if len(bf.bits) == 0 {
|
||||
return bf.rle.RunIterator()
|
||||
}
|
||||
|
||||
a, err := bf.rle.RunIterator()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
slc := make([]uint64, 0, len(bf.bits))
|
||||
for b := range bf.bits {
|
||||
slc = append(slc, b)
|
||||
}
|
||||
|
||||
b, err := rlepluslazy.RunsFromSlice(slc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, err := rlepluslazy.Sum(a, b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Set ...s bit in the BitField
|
||||
func (bf BitField) Set(bit uint64) {
|
||||
bf.bits[bit] = struct{}{}
|
||||
}
|
||||
|
||||
func (bf BitField) Count() (uint64, error) {
|
||||
s, err := bf.sum()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return rlepluslazy.Count(s)
|
||||
}
|
||||
|
||||
// All returns all set bits
|
||||
func (bf BitField) All(max uint64) ([]uint64, error) {
|
||||
c, err := bf.Count()
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("count errror: %w", err)
|
||||
}
|
||||
if c > max {
|
||||
return nil, xerrors.Errorf("expected %d, got %d: %w", max, c, ErrBitFieldTooMany)
|
||||
}
|
||||
|
||||
runs, err := bf.sum()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, err := rlepluslazy.SliceFromRuns(runs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (bf BitField) AllMap(max uint64) (map[uint64]bool, error) {
|
||||
c, err := bf.Count()
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("count errror: %w", err)
|
||||
}
|
||||
if c > max {
|
||||
return nil, xerrors.Errorf("expected %d, got %d: %w", max, c, ErrBitFieldTooMany)
|
||||
}
|
||||
|
||||
runs, err := bf.sum()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, err := rlepluslazy.SliceFromRuns(runs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := make(map[uint64]bool)
|
||||
for _, i := range res {
|
||||
out[i] = true
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (bf BitField) MarshalCBOR(w io.Writer) error {
|
||||
ints := make([]uint64, 0, len(bf.bits))
|
||||
for i := range bf.bits {
|
||||
ints = append(ints, i)
|
||||
}
|
||||
|
||||
s, err := bf.sum()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rle, err := rlepluslazy.EncodeRuns(s, []byte{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(rle) > 8192 {
|
||||
return xerrors.Errorf("encoded bitfield was too large (%d)", len(rle))
|
||||
}
|
||||
|
||||
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(rle)))); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = w.Write(rle); err != nil {
|
||||
return xerrors.Errorf("writing rle: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bf *BitField) UnmarshalCBOR(r io.Reader) error {
|
||||
br := cbg.GetPeeker(r)
|
||||
|
||||
maj, extra, err := cbg.CborReadHeader(br)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if extra > 8192 {
|
||||
return fmt.Errorf("array too large")
|
||||
}
|
||||
|
||||
if maj != cbg.MajByteString {
|
||||
return fmt.Errorf("expected byte array")
|
||||
}
|
||||
|
||||
buf := make([]byte, extra)
|
||||
if _, err := io.ReadFull(br, buf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rle, err := rlepluslazy.FromBuf(buf)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("could not decode rle+: %w", err)
|
||||
}
|
||||
bf.rle = rle
|
||||
bf.bits = make(map[uint64]struct{})
|
||||
|
||||
return nil
|
||||
}
|
||||
type BitField = abi.BitField
|
||||
|
2
go.mod
2
go.mod
@ -115,3 +115,5 @@ replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v
|
||||
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi
|
||||
|
||||
replace github.com/coreos/go-systemd => github.com/coreos/go-systemd/v22 v22.0.0
|
||||
|
||||
replace github.com/filecoin-project/specs-actors => /home/magik6k/gohack/github.com/filecoin-project/specs-actors
|
||||
|
@ -120,7 +120,7 @@ func (s *FPoStScheduler) checkFaults(ctx context.Context, ssi sectorbuilder.Sort
|
||||
|
||||
faultIDs = make([]abi.SectorNumber, 0, len(declaredFaults))
|
||||
for fault := range declaredFaults {
|
||||
faultIDs = append(faultIDs, abi.SectorNumber(fault))
|
||||
faultIDs = append(faultIDs, fault)
|
||||
}
|
||||
params.SectorNumbers = faultIDs
|
||||
|
||||
|
@ -98,16 +98,14 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
|
||||
}
|
||||
}
|
||||
|
||||
params := &miner.PreCommitSectorParams{
|
||||
Info: miner.SectorPreCommitInfo{
|
||||
params := &miner.SectorPreCommitInfo{
|
||||
Expiration: 0,
|
||||
SectorNumber: sector.SectorID,
|
||||
|
||||
SealedCID: commcid.ReplicaCommitmentV1ToCID(sector.CommR),
|
||||
SealEpoch: sector.Ticket.BlockHeight,
|
||||
DealIDs: nil, // sector.deals(), // TODO: REFACTOR
|
||||
},
|
||||
}
|
||||
}
|
||||
enc, aerr := actors.SerializeParams(params)
|
||||
if aerr != nil {
|
||||
return ctx.Send(SectorPreCommitFailed{xerrors.Errorf("could not serialize commit sector parameters: %w", aerr)})
|
||||
@ -259,11 +257,11 @@ func (m *Sealing) handleFaulty(ctx statemachine.Context, sector SectorInfo) erro
|
||||
// TODO: check if the fault has already been reported, and that this sector is even valid
|
||||
|
||||
// TODO: coalesce faulty sector reporting
|
||||
/*bf := types.NewBitField()
|
||||
bf.Set(uint64(sector.SectorID))*/
|
||||
bf := abi.NewBitField()
|
||||
bf.Set(uint64(sector.SectorID))
|
||||
|
||||
enc, aerr := actors.SerializeParams(&miner.DeclareTemporaryFaultsParams{
|
||||
SectorNumbers: []abi.SectorNumber{sector.SectorID},
|
||||
SectorNumbers: bf,
|
||||
Duration: 99999999, // TODO: This is very unlikely to be the correct number
|
||||
})
|
||||
if aerr != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user