storageminer: Update api interfaces
This commit is contained in:
parent
104871d6c9
commit
a6268f055d
@ -1,86 +1,7 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/binary"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const SignatureMaxLength = 200
|
type Signature = crypto.Signature
|
||||||
|
|
||||||
type Signature crypto.Signature
|
|
||||||
|
|
||||||
func SignatureFromBytes(x []byte) (Signature, error) {
|
|
||||||
val, nr := binary.Uvarint(x)
|
|
||||||
if nr != 1 {
|
|
||||||
return Signature{}, fmt.Errorf("signatures with type field longer than one byte are invalid")
|
|
||||||
}
|
|
||||||
|
|
||||||
return Signature{
|
|
||||||
Type: crypto.SigType(val),
|
|
||||||
Data: x[1:],
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Signature) MarshalCBOR(w io.Writer) error {
|
|
||||||
if s == nil {
|
|
||||||
_, err := w.Write(cbg.CborNull)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
header := cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(s.Data)+1))
|
|
||||||
|
|
||||||
if _, err := w.Write(header); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := w.Write([]byte{byte(s.Type)}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := w.Write(s.Data); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Signature) UnmarshalCBOR(br io.Reader) error {
|
|
||||||
maj, l, err := cbg.CborReadHeader(br)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if maj != cbg.MajByteString {
|
|
||||||
return fmt.Errorf("cbor input for signature was not a byte string")
|
|
||||||
}
|
|
||||||
|
|
||||||
if l > SignatureMaxLength {
|
|
||||||
return fmt.Errorf("cbor byte array for signature was too long")
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := make([]byte, l)
|
|
||||||
if _, err := io.ReadFull(br, buf); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if buf[0] != byte(crypto.SigTypeSecp256k1) && buf[0] != byte(crypto.SigTypeBLS) {
|
|
||||||
return fmt.Errorf("invalid signature type in cbor input: %d", buf[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
s.Type = crypto.SigType(buf[0])
|
|
||||||
s.Data = buf[1:]
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Signature) Equals(o *Signature) bool {
|
|
||||||
if s == nil || o == nil {
|
|
||||||
return s == o
|
|
||||||
}
|
|
||||||
return s.Type == o.Type && bytes.Equal(s.Data, o.Data)
|
|
||||||
}
|
|
||||||
|
@ -3,7 +3,6 @@ package types
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"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/crypto"
|
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||||
"github.com/filecoin-project/specs-actors/actors/runtime"
|
"github.com/filecoin-project/specs-actors/actors/runtime"
|
||||||
@ -51,18 +50,6 @@ type VMContext interface {
|
|||||||
Context() context.Context
|
Context() context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
type VMSyscalls struct {
|
|
||||||
ValidatePoRep func(context.Context, address.Address, abi.SectorSize, []byte, []byte, []byte, []byte, []byte, abi.SectorNumber) (bool, aerrors.ActorError)
|
|
||||||
VerifyFallbackPost func(ctx context.Context,
|
|
||||||
sectorSize abi.SectorSize,
|
|
||||||
sectorInfo sectorbuilder.SortedPublicSectorInfo,
|
|
||||||
challengeSeed []byte,
|
|
||||||
proof []byte,
|
|
||||||
candidates []sectorbuilder.EPostCandidate,
|
|
||||||
proverID address.Address,
|
|
||||||
faults uint64) (bool, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type storageWrapper struct {
|
type storageWrapper struct {
|
||||||
s Storage
|
s Storage
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package modules
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/runtime"
|
||||||
|
|
||||||
"github.com/ipfs/go-bitswap"
|
"github.com/ipfs/go-bitswap"
|
||||||
"github.com/ipfs/go-bitswap/network"
|
"github.com/ipfs/go-bitswap/network"
|
||||||
@ -73,7 +74,7 @@ func ChainBlockservice(bs dtypes.ChainBlockstore, rem dtypes.ChainExchange) dtyp
|
|||||||
return blockservice.New(bs, rem)
|
return blockservice.New(bs, rem)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ChainStore(lc fx.Lifecycle, bs dtypes.ChainBlockstore, ds dtypes.MetadataDS, syscalls *types.VMSyscalls) *store.ChainStore {
|
func ChainStore(lc fx.Lifecycle, bs dtypes.ChainBlockstore, ds dtypes.MetadataDS, syscalls runtime.Syscalls) *store.ChainStore {
|
||||||
chain := store.NewChainStore(bs, ds, syscalls)
|
chain := store.NewChainStore(bs, ds, syscalls)
|
||||||
|
|
||||||
if err := chain.Load(); err != nil {
|
if err := chain.Load(); err != nil {
|
||||||
|
@ -163,13 +163,13 @@ func (s *FPoStScheduler) abortActivePoSt() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *FPoStScheduler) shouldFallbackPost(ctx context.Context, ts *types.TipSet) (abi.ChainEpoch, bool, error) {
|
func (s *FPoStScheduler) shouldFallbackPost(ctx context.Context, ts *types.TipSet) (abi.ChainEpoch, bool, error) {
|
||||||
eps, err := s.api.StateMinerElectionPeriodStart(ctx, s.actor, ts)
|
ps, err := s.api.StateMinerPostState(ctx, s.actor, ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, false, xerrors.Errorf("getting ElectionPeriodStart: %w", err)
|
return 0, false, xerrors.Errorf("getting ElectionPeriodStart: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ts.Height() >= eps+build.FallbackPoStDelay {
|
if ts.Height() >= ps.ProvingPeriodStart+build.FallbackPoStDelay {
|
||||||
return eps, ts.Height() >= eps+build.FallbackPoStDelay+StartConfidence, nil
|
return ps.ProvingPeriodStart, ts.Height() >= ps.ProvingPeriodStart+build.FallbackPoStDelay+StartConfidence, nil
|
||||||
}
|
}
|
||||||
return 0, false, nil
|
return 0, false, nil
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
logging "github.com/ipfs/go-log/v2"
|
logging "github.com/ipfs/go-log/v2"
|
||||||
@ -14,6 +13,8 @@ import (
|
|||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-sectorbuilder"
|
"github.com/filecoin-project/go-sectorbuilder"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
@ -43,7 +44,7 @@ type storageMinerApi interface {
|
|||||||
// Call a read only method on actors (no interaction with the chain required)
|
// Call a read only method on actors (no interaction with the chain required)
|
||||||
StateCall(context.Context, *types.Message, *types.TipSet) (*api.MethodCall, error)
|
StateCall(context.Context, *types.Message, *types.TipSet) (*api.MethodCall, error)
|
||||||
StateMinerWorker(context.Context, address.Address, *types.TipSet) (address.Address, error)
|
StateMinerWorker(context.Context, address.Address, *types.TipSet) (address.Address, error)
|
||||||
StateMinerElectionPeriodStart(ctx context.Context, actor address.Address, ts *types.TipSet) (abi.ChainEpoch, error)
|
StateMinerPostState(ctx context.Context, actor address.Address, ts *types.TipSet) (*miner.PoStState, error)
|
||||||
StateMinerSectors(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error)
|
StateMinerSectors(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error)
|
||||||
StateMinerProvingSet(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error)
|
StateMinerProvingSet(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error)
|
||||||
StateMinerSectorSize(context.Context, address.Address, *types.TipSet) (abi.SectorSize, error)
|
StateMinerSectorSize(context.Context, address.Address, *types.TipSet) (abi.SectorSize, error)
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
"github.com/ipfs/go-datastore/namespace"
|
"github.com/ipfs/go-datastore/namespace"
|
||||||
@ -14,6 +13,8 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-padreader"
|
"github.com/filecoin-project/go-padreader"
|
||||||
"github.com/filecoin-project/go-sectorbuilder"
|
"github.com/filecoin-project/go-sectorbuilder"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/chain/events"
|
"github.com/filecoin-project/lotus/chain/events"
|
||||||
@ -32,7 +33,7 @@ type sealingApi interface { // TODO: trim down
|
|||||||
// Call a read only method on actors (no interaction with the chain required)
|
// Call a read only method on actors (no interaction with the chain required)
|
||||||
StateCall(context.Context, *types.Message, *types.TipSet) (*api.MethodCall, error)
|
StateCall(context.Context, *types.Message, *types.TipSet) (*api.MethodCall, error)
|
||||||
StateMinerWorker(context.Context, address.Address, *types.TipSet) (address.Address, error)
|
StateMinerWorker(context.Context, address.Address, *types.TipSet) (address.Address, error)
|
||||||
StateMinerElectionPeriodStart(ctx context.Context, actor address.Address, ts *types.TipSet) (abi.ChainEpoch, error)
|
StateMinerPostState(ctx context.Context, actor address.Address, ts *types.TipSet) (*miner.PoStState, error)
|
||||||
StateMinerSectors(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error)
|
StateMinerSectors(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error)
|
||||||
StateMinerProvingSet(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error)
|
StateMinerProvingSet(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error)
|
||||||
StateMinerSectorSize(context.Context, address.Address, *types.TipSet) (abi.SectorSize, error)
|
StateMinerSectorSize(context.Context, address.Address, *types.TipSet) (abi.SectorSize, error)
|
||||||
|
Loading…
Reference in New Issue
Block a user