Merge pull request #817 from filecoin-project/testnet-staging

Testnet
This commit is contained in:
Whyrusleeping 2019-12-11 18:54:20 +01:00 committed by GitHub
commit f16cc0322e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
108 changed files with 3916 additions and 1998 deletions

View File

@ -68,7 +68,7 @@ jobs:
- run: sudo apt-get install npm
- restore_cache:
name: restore go mod cache
key: v1-go-deps-{{ arch }}-{{ checksum "/home/circleci/project/lotus/go.mod" }}
key: v1-go-deps-{{ arch }}-{{ checksum "/home/circleci/project/go.mod" }}
- run:
command: make buildall
- store_artifacts:

7
CHANGELOG.md Normal file
View File

@ -0,0 +1,7 @@
# lotus changelog
## 0.1.0 / 2019-12-11
We are very excited to release **lotus** 0.1.0. This is our testnet release. To install lotus and join the testnet, please visit [docs.lotu.sh](docs.lotu.sh). Please file bug reports as [issues](https://github.com/filecoin-project/lotus/issues).
A huge thank you to all contributors for this testnet release!

View File

@ -1,3 +1,5 @@
SHELL=/usr/bin/env bash
all: build
.PHONY: all
@ -70,7 +72,16 @@ lotus-seal-worker: $(BUILD_DEPS)
.PHONY: lotus-seal-worker
BINS+=lotus-seal-worker
lotus-shed: $(BUILD_DEPS)
rm -f lotus-shed
go build $(GOFLAGS) -o lotus-shed ./cmd/lotus-shed
.PHONY: lotus-seal-worker
BINS+=lotus-seal-worker
build: lotus lotus-storage-miner lotus-seal-worker
@[[ $$(type -P "lotus") ]] && echo "Caution: you have \
an existing lotus binary in your PATH. This may cause problems if you don't run 'sudo make install'" || true
.PHONY: build
install:

View File

@ -10,6 +10,8 @@ import (
"github.com/filecoin-project/lotus/build"
)
type Permission = string
type Common interface {
// Auth
AuthVerify(ctx context.Context, token string) ([]Permission, error)

View File

@ -29,6 +29,10 @@ const (
CommitFailed
FailedUnrecoverable
Faulty // sector is corrupted or gone for some reason
FaultReported // sector has been declared as a fault on chain
FaultedFinal // fault declared on chain
)
var SectorStates = []string{
@ -39,6 +43,7 @@ var SectorStates = []string{
PreCommitting: "PreCommitting",
PreCommitted: "PreCommitted",
Committing: "Committing",
CommitWait: "CommitWait",
Proving: "Proving",
SealFailed: "SealFailed",
@ -47,6 +52,10 @@ var SectorStates = []string{
CommitFailed: "CommitFailed",
FailedUnrecoverable: "FailedUnrecoverable",
Faulty: "Faulty",
FaultReported: "FaultReported",
FaultedFinal: "FaultedFinal",
}
// StorageMiner is a low-level interface to the Filecoin network storage miner node
@ -87,9 +96,9 @@ type SectorInfo struct {
Deals []uint64
Ticket sectorbuilder.SealTicket
Seed sectorbuilder.SealSeed
Retries uint64
Retries uint64
LastErr string
LastErr string
}
type SealedRef struct {

View File

@ -1,50 +1,50 @@
package api
package apistruct
import (
"context"
"reflect"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api"
)
type permKey int
var permCtxKey permKey
type Permission = string
const (
// When changing these, update docs/API.md too
PermRead Permission = "read" // default
PermWrite Permission = "write"
PermSign Permission = "sign" // Use wallet keys for signing
PermAdmin Permission = "admin" // Manage permissions
PermRead api.Permission = "read" // default
PermWrite api.Permission = "write"
PermSign api.Permission = "sign" // Use wallet keys for signing
PermAdmin api.Permission = "admin" // Manage permissions
)
var AllPermissions = []Permission{PermRead, PermWrite, PermSign, PermAdmin}
var defaultPerms = []Permission{PermRead}
var AllPermissions = []api.Permission{PermRead, PermWrite, PermSign, PermAdmin}
var defaultPerms = []api.Permission{PermRead}
func WithPerm(ctx context.Context, perms []Permission) context.Context {
func WithPerm(ctx context.Context, perms []api.Permission) context.Context {
return context.WithValue(ctx, permCtxKey, perms)
}
func PermissionedStorMinerAPI(a StorageMiner) StorageMiner {
func PermissionedStorMinerAPI(a api.StorageMiner) api.StorageMiner {
var out StorageMinerStruct
permissionedAny(a, &out.Internal)
permissionedAny(a, &out.CommonStruct.Internal)
return &out
}
func PermissionedFullAPI(a FullNode) FullNode {
func PermissionedFullAPI(a api.FullNode) api.FullNode {
var out FullNodeStruct
permissionedAny(a, &out.Internal)
permissionedAny(a, &out.CommonStruct.Internal)
return &out
}
func HasPerm(ctx context.Context, perm Permission) bool {
callerPerms, ok := ctx.Value(permCtxKey).([]Permission)
func HasPerm(ctx context.Context, perm api.Permission) bool {
callerPerms, ok := ctx.Value(permCtxKey).([]api.Permission)
if !ok {
callerPerms = defaultPerms
}
@ -63,7 +63,7 @@ func permissionedAny(in interface{}, out interface{}) {
for f := 0; f < rint.NumField(); f++ {
field := rint.Type().Field(f)
requiredPerm := Permission(field.Tag.Get("perm"))
requiredPerm := api.Permission(field.Tag.Get("perm"))
if requiredPerm == "" {
panic("missing 'perm' tag on " + field.Name) // ok
}

View File

@ -1,4 +1,4 @@
package api
package apistruct
import (
"context"
@ -9,6 +9,7 @@ import (
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/store"
@ -20,8 +21,8 @@ var _ = AllPermissions
type CommonStruct struct {
Internal struct {
AuthVerify func(ctx context.Context, token string) ([]Permission, error) `perm:"read"`
AuthNew func(ctx context.Context, perms []Permission) ([]byte, error) `perm:"admin"`
AuthVerify func(ctx context.Context, token string) ([]api.Permission, error) `perm:"read"`
AuthNew func(ctx context.Context, perms []api.Permission) ([]byte, error) `perm:"admin"`
NetConnectedness func(context.Context, peer.ID) (network.Connectedness, error) `perm:"read"`
NetPeers func(context.Context) ([]peer.AddrInfo, error) `perm:"read"`
@ -29,8 +30,8 @@ type CommonStruct struct {
NetAddrsListen func(context.Context) (peer.AddrInfo, error) `perm:"read"`
NetDisconnect func(context.Context, peer.ID) error `perm:"write"`
ID func(context.Context) (peer.ID, error) `perm:"read"`
Version func(context.Context) (Version, error) `perm:"read"`
ID func(context.Context) (peer.ID, error) `perm:"read"`
Version func(context.Context) (api.Version, error) `perm:"read"`
}
}
@ -44,16 +45,16 @@ type FullNodeStruct struct {
ChainGetRandomness func(context.Context, types.TipSetKey, int64) ([]byte, error) `perm:"read"`
ChainGetBlock func(context.Context, cid.Cid) (*types.BlockHeader, error) `perm:"read"`
ChainGetTipSet func(context.Context, types.TipSetKey) (*types.TipSet, error) `perm:"read"`
ChainGetBlockMessages func(context.Context, cid.Cid) (*BlockMessages, error) `perm:"read"`
ChainGetBlockMessages func(context.Context, cid.Cid) (*api.BlockMessages, error) `perm:"read"`
ChainGetParentReceipts func(context.Context, cid.Cid) ([]*types.MessageReceipt, error) `perm:"read"`
ChainGetParentMessages func(context.Context, cid.Cid) ([]Message, error) `perm:"read"`
ChainGetParentMessages func(context.Context, cid.Cid) ([]api.Message, error) `perm:"read"`
ChainGetTipSetByHeight func(context.Context, uint64, *types.TipSet) (*types.TipSet, error) `perm:"read"`
ChainReadObj func(context.Context, cid.Cid) ([]byte, error) `perm:"read"`
ChainSetHead func(context.Context, *types.TipSet) error `perm:"admin"`
ChainGetGenesis func(context.Context) (*types.TipSet, error) `perm:"read"`
ChainTipSetWeight func(context.Context, *types.TipSet) (types.BigInt, error) `perm:"read"`
SyncState func(context.Context) (*SyncState, error) `perm:"read"`
SyncState func(context.Context) (*api.SyncState, error) `perm:"read"`
SyncSubmitBlock func(ctx context.Context, blk *types.BlockMsg) error `perm:"write"`
SyncIncomingBlocks func(ctx context.Context) (<-chan *types.BlockHeader, error) `perm:"read"`
@ -61,7 +62,7 @@ type FullNodeStruct struct {
MpoolPush func(context.Context, *types.SignedMessage) error `perm:"write"`
MpoolPushMessage func(context.Context, *types.Message) (*types.SignedMessage, error) `perm:"sign"`
MpoolGetNonce func(context.Context, address.Address) (uint64, error) `perm:"read"`
MpoolSub func(context.Context) (<-chan MpoolUpdate, error) `perm:"read"`
MpoolSub func(context.Context) (<-chan api.MpoolUpdate, error) `perm:"read"`
MinerCreateBlock func(context.Context, address.Address, *types.TipSet, *types.Ticket, *types.EPostProof, []*types.SignedMessage, uint64, uint64) (*types.BlockMsg, error) `perm:"write"`
@ -77,28 +78,28 @@ type FullNodeStruct struct {
WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"`
ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"admin"`
ClientListImports func(ctx context.Context) ([]Import, error) `perm:"write"`
ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"`
ClientHasLocal func(ctx context.Context, root cid.Cid) (bool, error) `perm:"write"`
ClientFindData func(ctx context.Context, root cid.Cid) ([]QueryOffer, error) `perm:"read"`
ClientFindData func(ctx context.Context, root cid.Cid) ([]api.QueryOffer, error) `perm:"read"`
ClientStartDeal func(ctx context.Context, data cid.Cid, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) `perm:"admin"`
ClientGetDealInfo func(context.Context, cid.Cid) (*DealInfo, error) `perm:"read"`
ClientListDeals func(ctx context.Context) ([]DealInfo, error) `perm:"write"`
ClientRetrieve func(ctx context.Context, order RetrievalOrder, path string) error `perm:"admin"`
ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"`
ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"`
ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, path string) error `perm:"admin"`
ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*types.SignedStorageAsk, error) `perm:"read"`
StateMinerSectors func(context.Context, address.Address, *types.TipSet) ([]*ChainSectorInfo, error) `perm:"read"`
StateMinerProvingSet func(context.Context, address.Address, *types.TipSet) ([]*ChainSectorInfo, error) `perm:"read"`
StateMinerPower func(context.Context, address.Address, *types.TipSet) (MinerPower, error) `perm:"read"`
StateMinerSectors func(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error) `perm:"read"`
StateMinerProvingSet func(context.Context, address.Address, *types.TipSet) ([]*api.ChainSectorInfo, error) `perm:"read"`
StateMinerPower func(context.Context, address.Address, *types.TipSet) (api.MinerPower, error) `perm:"read"`
StateMinerWorker func(context.Context, address.Address, *types.TipSet) (address.Address, error) `perm:"read"`
StateMinerPeerID func(ctx context.Context, m address.Address, ts *types.TipSet) (peer.ID, error) `perm:"read"`
StateMinerElectionPeriodStart func(ctx context.Context, actor address.Address, ts *types.TipSet) (uint64, error) `perm:"read"`
StateMinerSectorSize func(context.Context, address.Address, *types.TipSet) (uint64, error) `perm:"read"`
StateCall func(context.Context, *types.Message, *types.TipSet) (*types.MessageReceipt, error) `perm:"read"`
StateReplay func(context.Context, *types.TipSet, cid.Cid) (*ReplayResults, error) `perm:"read"`
StateReplay func(context.Context, *types.TipSet, cid.Cid) (*api.ReplayResults, error) `perm:"read"`
StateGetActor func(context.Context, address.Address, *types.TipSet) (*types.Actor, error) `perm:"read"`
StateReadState func(context.Context, *types.Actor, *types.TipSet) (*ActorState, error) `perm:"read"`
StateReadState func(context.Context, *types.Actor, *types.TipSet) (*api.ActorState, error) `perm:"read"`
StatePledgeCollateral func(context.Context, *types.TipSet) (types.BigInt, error) `perm:"read"`
StateWaitMsg func(context.Context, cid.Cid) (*MsgWait, error) `perm:"read"`
StateWaitMsg func(context.Context, cid.Cid) (*api.MsgWait, error) `perm:"read"`
StateListMiners func(context.Context, *types.TipSet) ([]address.Address, error) `perm:"read"`
StateListActors func(context.Context, *types.TipSet) ([]address.Address, error) `perm:"read"`
StateMarketBalance func(context.Context, address.Address, *types.TipSet) (actors.StorageParticipantBalance, error) `perm:"read"`
@ -111,19 +112,19 @@ type FullNodeStruct struct {
MarketEnsureAvailable func(context.Context, address.Address, types.BigInt) error `perm:"sign"`
PaychGet func(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error) `perm:"sign"`
PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
PaychStatus func(context.Context, address.Address) (*PaychStatus, error) `perm:"read"`
PaychClose func(context.Context, address.Address) (cid.Cid, error) `perm:"sign"`
PaychAllocateLane func(context.Context, address.Address) (uint64, error) `perm:"sign"`
PaychNewPayment func(ctx context.Context, from, to address.Address, vouchers []VoucherSpec) (*PaymentInfo, error) `perm:"sign"`
PaychVoucherCheck func(context.Context, *types.SignedVoucher) error `perm:"read"`
PaychVoucherCheckValid func(context.Context, address.Address, *types.SignedVoucher) error `perm:"read"`
PaychVoucherCheckSpendable func(context.Context, address.Address, *types.SignedVoucher, []byte, []byte) (bool, error) `perm:"read"`
PaychVoucherAdd func(context.Context, address.Address, *types.SignedVoucher, []byte, types.BigInt) (types.BigInt, error) `perm:"write"`
PaychVoucherCreate func(context.Context, address.Address, types.BigInt, uint64) (*types.SignedVoucher, error) `perm:"sign"`
PaychVoucherList func(context.Context, address.Address) ([]*types.SignedVoucher, error) `perm:"write"`
PaychVoucherSubmit func(context.Context, address.Address, *types.SignedVoucher) (cid.Cid, error) `perm:"sign"`
PaychGet func(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*api.ChannelInfo, error) `perm:"sign"`
PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
PaychStatus func(context.Context, address.Address) (*api.PaychStatus, error) `perm:"read"`
PaychClose func(context.Context, address.Address) (cid.Cid, error) `perm:"sign"`
PaychAllocateLane func(context.Context, address.Address) (uint64, error) `perm:"sign"`
PaychNewPayment func(ctx context.Context, from, to address.Address, vouchers []api.VoucherSpec) (*api.PaymentInfo, error) `perm:"sign"`
PaychVoucherCheck func(context.Context, *types.SignedVoucher) error `perm:"read"`
PaychVoucherCheckValid func(context.Context, address.Address, *types.SignedVoucher) error `perm:"read"`
PaychVoucherCheckSpendable func(context.Context, address.Address, *types.SignedVoucher, []byte, []byte) (bool, error) `perm:"read"`
PaychVoucherAdd func(context.Context, address.Address, *types.SignedVoucher, []byte, types.BigInt) (types.BigInt, error) `perm:"write"`
PaychVoucherCreate func(context.Context, address.Address, types.BigInt, uint64) (*types.SignedVoucher, error) `perm:"sign"`
PaychVoucherList func(context.Context, address.Address) ([]*types.SignedVoucher, error) `perm:"write"`
PaychVoucherSubmit func(context.Context, address.Address, *types.SignedVoucher) (cid.Cid, error) `perm:"sign"`
}
}
@ -136,10 +137,10 @@ type StorageMinerStruct struct {
PledgeSector func(context.Context) error `perm:"write"`
SectorsStatus func(context.Context, uint64) (SectorInfo, error) `perm:"read"`
SectorsList func(context.Context) ([]uint64, error) `perm:"read"`
SectorsRefs func(context.Context) (map[string][]SealedRef, error) `perm:"read"`
SectorsUpdate func(context.Context, uint64, SectorState) error `perm:"write"`
SectorsStatus func(context.Context, uint64) (api.SectorInfo, error) `perm:"read"`
SectorsList func(context.Context) ([]uint64, error) `perm:"read"`
SectorsRefs func(context.Context) (map[string][]api.SealedRef, error) `perm:"read"`
SectorsUpdate func(context.Context, uint64, api.SectorState) error `perm:"write"`
WorkerStats func(context.Context) (sectorbuilder.WorkerStats, error) `perm:"read"`
@ -148,11 +149,11 @@ type StorageMinerStruct struct {
}
}
func (c *CommonStruct) AuthVerify(ctx context.Context, token string) ([]Permission, error) {
func (c *CommonStruct) AuthVerify(ctx context.Context, token string) ([]api.Permission, error) {
return c.Internal.AuthVerify(ctx, token)
}
func (c *CommonStruct) AuthNew(ctx context.Context, perms []Permission) ([]byte, error) {
func (c *CommonStruct) AuthNew(ctx context.Context, perms []api.Permission) ([]byte, error) {
return c.Internal.AuthNew(ctx, perms)
}
@ -182,11 +183,11 @@ func (c *CommonStruct) ID(ctx context.Context) (peer.ID, error) {
}
// Version implements API.Version
func (c *CommonStruct) Version(ctx context.Context) (Version, error) {
func (c *CommonStruct) Version(ctx context.Context) (api.Version, error) {
return c.Internal.Version(ctx)
}
func (c *FullNodeStruct) ClientListImports(ctx context.Context) ([]Import, error) {
func (c *FullNodeStruct) ClientListImports(ctx context.Context) ([]api.Import, error) {
return c.Internal.ClientListImports(ctx)
}
@ -198,22 +199,22 @@ func (c *FullNodeStruct) ClientHasLocal(ctx context.Context, root cid.Cid) (bool
return c.Internal.ClientHasLocal(ctx, root)
}
func (c *FullNodeStruct) ClientFindData(ctx context.Context, root cid.Cid) ([]QueryOffer, error) {
func (c *FullNodeStruct) ClientFindData(ctx context.Context, root cid.Cid) ([]api.QueryOffer, error) {
return c.Internal.ClientFindData(ctx, root)
}
func (c *FullNodeStruct) ClientStartDeal(ctx context.Context, data cid.Cid, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) {
return c.Internal.ClientStartDeal(ctx, data, miner, price, blocksDuration)
}
func (c *FullNodeStruct) ClientGetDealInfo(ctx context.Context, deal cid.Cid) (*DealInfo, error) {
func (c *FullNodeStruct) ClientGetDealInfo(ctx context.Context, deal cid.Cid) (*api.DealInfo, error) {
return c.Internal.ClientGetDealInfo(ctx, deal)
}
func (c *FullNodeStruct) ClientListDeals(ctx context.Context) ([]DealInfo, error) {
func (c *FullNodeStruct) ClientListDeals(ctx context.Context) ([]api.DealInfo, error) {
return c.Internal.ClientListDeals(ctx)
}
func (c *FullNodeStruct) ClientRetrieve(ctx context.Context, order RetrievalOrder, path string) error {
func (c *FullNodeStruct) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, path string) error {
return c.Internal.ClientRetrieve(ctx, order, path)
}
@ -233,7 +234,7 @@ func (c *FullNodeStruct) MpoolPushMessage(ctx context.Context, msg *types.Messag
return c.Internal.MpoolPushMessage(ctx, msg)
}
func (c *FullNodeStruct) MpoolSub(ctx context.Context) (<-chan MpoolUpdate, error) {
func (c *FullNodeStruct) MpoolSub(ctx context.Context) (<-chan api.MpoolUpdate, error) {
return c.Internal.MpoolSub(ctx)
}
@ -305,7 +306,7 @@ func (c *FullNodeStruct) ChainGetTipSet(ctx context.Context, key types.TipSetKey
return c.Internal.ChainGetTipSet(ctx, key)
}
func (c *FullNodeStruct) ChainGetBlockMessages(ctx context.Context, b cid.Cid) (*BlockMessages, error) {
func (c *FullNodeStruct) ChainGetBlockMessages(ctx context.Context, b cid.Cid) (*api.BlockMessages, error) {
return c.Internal.ChainGetBlockMessages(ctx, b)
}
@ -313,7 +314,7 @@ func (c *FullNodeStruct) ChainGetParentReceipts(ctx context.Context, b cid.Cid)
return c.Internal.ChainGetParentReceipts(ctx, b)
}
func (c *FullNodeStruct) ChainGetParentMessages(ctx context.Context, b cid.Cid) ([]Message, error) {
func (c *FullNodeStruct) ChainGetParentMessages(ctx context.Context, b cid.Cid) ([]api.Message, error) {
return c.Internal.ChainGetParentMessages(ctx, b)
}
@ -337,7 +338,7 @@ func (c *FullNodeStruct) ChainTipSetWeight(ctx context.Context, ts *types.TipSet
return c.Internal.ChainTipSetWeight(ctx, ts)
}
func (c *FullNodeStruct) SyncState(ctx context.Context) (*SyncState, error) {
func (c *FullNodeStruct) SyncState(ctx context.Context) (*api.SyncState, error) {
return c.Internal.SyncState(ctx)
}
@ -349,15 +350,15 @@ func (c *FullNodeStruct) SyncIncomingBlocks(ctx context.Context) (<-chan *types.
return c.Internal.SyncIncomingBlocks(ctx)
}
func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address, ts *types.TipSet) ([]*ChainSectorInfo, error) {
func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address, ts *types.TipSet) ([]*api.ChainSectorInfo, error) {
return c.Internal.StateMinerSectors(ctx, addr, ts)
}
func (c *FullNodeStruct) StateMinerProvingSet(ctx context.Context, addr address.Address, ts *types.TipSet) ([]*ChainSectorInfo, error) {
func (c *FullNodeStruct) StateMinerProvingSet(ctx context.Context, addr address.Address, ts *types.TipSet) ([]*api.ChainSectorInfo, error) {
return c.Internal.StateMinerProvingSet(ctx, addr, ts)
}
func (c *FullNodeStruct) StateMinerPower(ctx context.Context, a address.Address, ts *types.TipSet) (MinerPower, error) {
func (c *FullNodeStruct) StateMinerPower(ctx context.Context, a address.Address, ts *types.TipSet) (api.MinerPower, error) {
return c.Internal.StateMinerPower(ctx, a, ts)
}
@ -381,7 +382,7 @@ func (c *FullNodeStruct) StateCall(ctx context.Context, msg *types.Message, ts *
return c.Internal.StateCall(ctx, msg, ts)
}
func (c *FullNodeStruct) StateReplay(ctx context.Context, ts *types.TipSet, mc cid.Cid) (*ReplayResults, error) {
func (c *FullNodeStruct) StateReplay(ctx context.Context, ts *types.TipSet, mc cid.Cid) (*api.ReplayResults, error) {
return c.Internal.StateReplay(ctx, ts, mc)
}
@ -389,7 +390,7 @@ func (c *FullNodeStruct) StateGetActor(ctx context.Context, actor address.Addres
return c.Internal.StateGetActor(ctx, actor, ts)
}
func (c *FullNodeStruct) StateReadState(ctx context.Context, act *types.Actor, ts *types.TipSet) (*ActorState, error) {
func (c *FullNodeStruct) StateReadState(ctx context.Context, act *types.Actor, ts *types.TipSet) (*api.ActorState, error) {
return c.Internal.StateReadState(ctx, act, ts)
}
@ -397,7 +398,7 @@ func (c *FullNodeStruct) StatePledgeCollateral(ctx context.Context, ts *types.Ti
return c.Internal.StatePledgeCollateral(ctx, ts)
}
func (c *FullNodeStruct) StateWaitMsg(ctx context.Context, msgc cid.Cid) (*MsgWait, error) {
func (c *FullNodeStruct) StateWaitMsg(ctx context.Context, msgc cid.Cid) (*api.MsgWait, error) {
return c.Internal.StateWaitMsg(ctx, msgc)
}
func (c *FullNodeStruct) StateListMiners(ctx context.Context, ts *types.TipSet) ([]address.Address, error) {
@ -440,7 +441,7 @@ func (c *FullNodeStruct) MarketEnsureAvailable(ctx context.Context, addr address
return c.Internal.MarketEnsureAvailable(ctx, addr, amt)
}
func (c *FullNodeStruct) PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error) {
func (c *FullNodeStruct) PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*api.ChannelInfo, error) {
return c.Internal.PaychGet(ctx, from, to, ensureFunds)
}
@ -448,7 +449,7 @@ func (c *FullNodeStruct) PaychList(ctx context.Context) ([]address.Address, erro
return c.Internal.PaychList(ctx)
}
func (c *FullNodeStruct) PaychStatus(ctx context.Context, pch address.Address) (*PaychStatus, error) {
func (c *FullNodeStruct) PaychStatus(ctx context.Context, pch address.Address) (*api.PaychStatus, error) {
return c.Internal.PaychStatus(ctx, pch)
}
@ -480,7 +481,7 @@ func (c *FullNodeStruct) PaychAllocateLane(ctx context.Context, ch address.Addre
return c.Internal.PaychAllocateLane(ctx, ch)
}
func (c *FullNodeStruct) PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []VoucherSpec) (*PaymentInfo, error) {
func (c *FullNodeStruct) PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []api.VoucherSpec) (*api.PaymentInfo, error) {
return c.Internal.PaychNewPayment(ctx, from, to, vouchers)
}
@ -501,7 +502,7 @@ func (c *StorageMinerStruct) PledgeSector(ctx context.Context) error {
}
// Get the status of a given sector by ID
func (c *StorageMinerStruct) SectorsStatus(ctx context.Context, sid uint64) (SectorInfo, error) {
func (c *StorageMinerStruct) SectorsStatus(ctx context.Context, sid uint64) (api.SectorInfo, error) {
return c.Internal.SectorsStatus(ctx, sid)
}
@ -510,11 +511,11 @@ func (c *StorageMinerStruct) SectorsList(ctx context.Context) ([]uint64, error)
return c.Internal.SectorsList(ctx)
}
func (c *StorageMinerStruct) SectorsRefs(ctx context.Context) (map[string][]SealedRef, error) {
func (c *StorageMinerStruct) SectorsRefs(ctx context.Context) (map[string][]api.SealedRef, error) {
return c.Internal.SectorsRefs(ctx)
}
func (c *StorageMinerStruct) SectorsUpdate(ctx context.Context, id uint64, state SectorState) error {
func (c *StorageMinerStruct) SectorsUpdate(ctx context.Context, id uint64, state api.SectorState) error {
return c.Internal.SectorsUpdate(ctx, id, state)
}
@ -530,6 +531,6 @@ func (c *StorageMinerStruct) WorkerDone(ctx context.Context, task uint64, res se
return c.Internal.WorkerDone(ctx, task, res)
}
var _ Common = &CommonStruct{}
var _ FullNode = &FullNodeStruct{}
var _ StorageMiner = &StorageMinerStruct{}
var _ api.Common = &CommonStruct{}
var _ api.FullNode = &FullNodeStruct{}
var _ api.StorageMiner = &StorageMinerStruct{}

View File

@ -18,16 +18,29 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{131}); err != nil {
if _, err := w.Write([]byte{163}); err != nil {
return err
}
// t.Channel (address.Address) (struct)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Channel")))); err != nil {
return err
}
if _, err := w.Write([]byte("Channel")); err != nil {
return err
}
// t.t.Channel (address.Address) (struct)
if err := t.Channel.MarshalCBOR(w); err != nil {
return err
}
// t.t.ChannelMessage (cid.Cid) (struct)
// t.ChannelMessage (cid.Cid) (struct)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("ChannelMessage")))); err != nil {
return err
}
if _, err := w.Write([]byte("ChannelMessage")); err != nil {
return err
}
if t.ChannelMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
@ -39,7 +52,14 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error {
}
}
// t.t.Vouchers ([]*types.SignedVoucher) (slice)
// t.Vouchers ([]*types.SignedVoucher) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Vouchers")))); err != nil {
return err
}
if _, err := w.Write([]byte("Vouchers")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Vouchers)))); err != nil {
return err
}
@ -58,15 +78,30 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra != 3 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Channel (address.Address) (struct)
var name string
// t.Channel (address.Address) (struct)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Channel" {
return fmt.Errorf("expected struct map entry %s to be Channel", name)
}
{
@ -75,7 +110,20 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.ChannelMessage (cid.Cid) (struct)
// t.ChannelMessage (cid.Cid) (struct)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "ChannelMessage" {
return fmt.Errorf("expected struct map entry %s to be ChannelMessage", name)
}
{
@ -99,7 +147,20 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Vouchers ([]*types.SignedVoucher) (slice)
// t.Vouchers ([]*types.SignedVoucher) (slice)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Vouchers" {
return fmt.Errorf("expected struct map entry %s to be Vouchers", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -134,21 +195,42 @@ func (t *SealedRef) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{131}); err != nil {
if _, err := w.Write([]byte{163}); err != nil {
return err
}
// t.SectorID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("SectorID")))); err != nil {
return err
}
if _, err := w.Write([]byte("SectorID")); err != nil {
return err
}
// t.t.SectorID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorID))); err != nil {
return err
}
// t.t.Offset (uint64) (uint64)
// t.Offset (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Offset")))); err != nil {
return err
}
if _, err := w.Write([]byte("Offset")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Offset))); err != nil {
return err
}
// t.t.Size (uint64) (uint64)
// t.Size (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Size")))); err != nil {
return err
}
if _, err := w.Write([]byte("Size")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil {
return err
}
@ -162,15 +244,30 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error {
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra != 3 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.SectorID (uint64) (uint64)
var name string
// t.SectorID (uint64) (uint64)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "SectorID" {
return fmt.Errorf("expected struct map entry %s to be SectorID", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -180,7 +277,20 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.SectorID = uint64(extra)
// t.t.Offset (uint64) (uint64)
// t.Offset (uint64) (uint64)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Offset" {
return fmt.Errorf("expected struct map entry %s to be Offset", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -190,7 +300,20 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Offset = uint64(extra)
// t.t.Size (uint64) (uint64)
// t.Size (uint64) (uint64)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Size" {
return fmt.Errorf("expected struct map entry %s to be Size", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -208,11 +331,18 @@ func (t *SealedRefs) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{129}); err != nil {
if _, err := w.Write([]byte{161}); err != nil {
return err
}
// t.Refs ([]api.SealedRef) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Refs")))); err != nil {
return err
}
if _, err := w.Write([]byte("Refs")); err != nil {
return err
}
// t.t.Refs ([]api.SealedRef) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Refs)))); err != nil {
return err
}
@ -231,15 +361,30 @@ func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error {
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra != 1 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Refs ([]api.SealedRef) (slice)
var name string
// t.Refs ([]api.SealedRef) (slice)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Refs" {
return fmt.Errorf("expected struct map entry %s to be Refs", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {

View File

@ -1,6 +1,7 @@
package client
import (
"github.com/filecoin-project/lotus/api/apistruct"
"net/http"
"github.com/filecoin-project/lotus/api"
@ -9,7 +10,7 @@ import (
// NewCommonRPC creates a new http jsonrpc client.
func NewCommonRPC(addr string, requestHeader http.Header) (api.Common, jsonrpc.ClientCloser, error) {
var res api.CommonStruct
var res apistruct.CommonStruct
closer, err := jsonrpc.NewMergeClient(addr, "Filecoin",
[]interface{}{
&res.Internal,
@ -20,7 +21,7 @@ func NewCommonRPC(addr string, requestHeader http.Header) (api.Common, jsonrpc.C
// NewFullNodeRPC creates a new http jsonrpc client.
func NewFullNodeRPC(addr string, requestHeader http.Header) (api.FullNode, jsonrpc.ClientCloser, error) {
var res api.FullNodeStruct
var res apistruct.FullNodeStruct
closer, err := jsonrpc.NewMergeClient(addr, "Filecoin",
[]interface{}{
&res.CommonStruct.Internal,
@ -32,7 +33,7 @@ func NewFullNodeRPC(addr string, requestHeader http.Header) (api.FullNode, jsonr
// NewStorageMinerRPC creates a new http jsonrpc client for storage miner
func NewStorageMinerRPC(addr string, requestHeader http.Header) (api.StorageMiner, jsonrpc.ClientCloser, error) {
var res api.StorageMinerStruct
var res apistruct.StorageMinerStruct
closer, err := jsonrpc.NewMergeClient(addr, "Filecoin",
[]interface{}{
&res.CommonStruct.Internal,

View File

@ -1,2 +1,6 @@
/ip4/147.75.80.29/tcp/1347/p2p/12D3KooWDzb12XyoKT4uJAqmRVsSYqY9EZczXeWJ7WqehugBTVAT
/ip4/147.75.80.17/tcp/1347/p2p/12D3KooWDsfpmaYPouFT2RxvSf8eCuUS63T4dAKvDPqzWKdv7Qc7
/dns4/lotus-bootstrap-0.dfw.fil-test.net/tcp/1347/p2p/12D3KooWHwGBSiLR5ts7KW9MgH4BMzC2iXe18kwAQ8Ee3LUd1jeR
/dns4/lotus-bootstrap-1.dfw.fil-test.net/tcp/1347/p2p/12D3KooWCLFaawdhLGcSpiqg43DtZ9QzPQ6HcB8Vvyu2Cnta8UWc
/dns4/lotus-bootstrap-0.fra.fil-test.net/tcp/1347/p2p/12D3KooWMmaL7eaUCF6tVAghVmgozxz4uztbuFUQv6dyFpHRarHR
/dns4/lotus-bootstrap-1.fra.fil-test.net/tcp/1347/p2p/12D3KooWLLpNYoKdf9NgcWudBhXLdTcXncqAsTzozw1scMMu6nS5
/dns4/lotus-bootstrap-0.sin.fil-test.net/tcp/1347/p2p/12D3KooWCNL9vXaXwNs3Bu8uRAJK4pxpCyPeM7jZLSDpJma1wrV8
/dns4/lotus-bootstrap-1.sin.fil-test.net/tcp/1347/p2p/12D3KooWNGGxFda1eC5U2YKAgs4ypoFHn3Z3xHCsjmFdrCcytoxm

Binary file not shown.

View File

@ -25,6 +25,7 @@ var log = logging.Logger("build")
//const gateway = "http://198.211.99.118/ipfs/"
const gateway = "https://ipfs.io/ipfs/"
const paramdir = "/var/tmp/filecoin-proof-parameters"
const dirEnv = "FIL_PROOFS_PARAMETER_CACHE"
type paramFile struct {
Cid string `json:"cid"`
@ -39,8 +40,15 @@ type fetch struct {
errs []error
}
func getParamDir() string {
if os.Getenv(dirEnv) == "" {
return paramdir
}
return os.Getenv(dirEnv)
}
func GetParams(storageSize uint64) error {
if err := os.Mkdir(paramdir, 0755); err != nil && !os.IsExist(err) {
if err := os.Mkdir(getParamDir(), 0755); err != nil && !os.IsExist(err) {
return err
}
@ -70,7 +78,7 @@ func (ft *fetch) maybeFetchAsync(name string, info paramFile) {
go func() {
defer ft.wg.Done()
path := filepath.Join(paramdir, name)
path := filepath.Join(getParamDir(), name)
err := ft.checkFile(path, info)
if !os.IsNotExist(err) && err != nil {

View File

@ -29,6 +29,9 @@ const InteractivePoRepDelay = 2
// Epochs
const InteractivePoRepConfidence = 6
// Bytes
var MinimumMinerPower uint64 = 2 << 10 // 2KiB
func init() {
os.Setenv("TRUST_PARAMS", "1")
}

View File

@ -25,7 +25,7 @@ func SupportedSectorSize(ssize uint64) bool {
// Payments
// Epochs
const PaymentChannelClosingDelay = 6 * 60 * 2 // six hours
const PaymentChannelClosingDelay = 6 * 60 * 60 / BlockDelay // six hours
// /////
// Consensus / Network
@ -83,10 +83,6 @@ var InitialReward *big.Int
const FilecoinPrecision = 1_000_000_000_000_000_000
// six years
// Epochs
const HalvingPeriodEpochs = 6 * 365 * 24 * 60 * 2
// TODO: Move other important consts here
func init() {

View File

@ -3,16 +3,14 @@
package build
var SectorSizes = []uint64{
16 << 20,
256 << 20,
1 << 30,
32 << 30,
}
// Seconds
const BlockDelay = 30
const BlockDelay = 45
const PropagationDelay = 5
const PropagationDelay = 6
// FallbackPoStDelay is the number of epochs the miner needs to wait after
// ElectionPeriodStart before starting fallback post computation
@ -31,3 +29,6 @@ const InteractivePoRepDelay = 8
// Epochs
const InteractivePoRepConfidence = 6
// Bytes
var MinimumMinerPower uint64 = 512 << 30 // 512GB

View File

@ -1,54 +1,54 @@
{
"v20-proof-of-spacetime-election-09ae025de08399327e14f0cb6b4c907b6fe1e8b77046e31de8921bde588de900.params": {
"cid": "QmbbP455Dmu4GvEYgJTJjDvN8pj98cAKBQWgo4wmzUQhHM",
"digest": "34ecd0781d730a78f905c93dc35f107b",
"sector_size": 268435456
},
"v20-proof-of-spacetime-election-09ae025de08399327e14f0cb6b4c907b6fe1e8b77046e31de8921bde588de900.vk": {
"cid": "QmUEsQPP46mjiZkFoVdgJMBt8yhDxrzGTdqExWHAMA2eAX",
"digest": "cb5096105e25070e4894f682a0e7ce7e",
"sector_size": 268435456
},
"v20-proof-of-spacetime-election-4a2342062706429612fac099694f77294e355c6c9265b80feaff12a0268b0a92.params": {
"cid": "QmNegxzrsuFT9Z44B1zyxYGsxjUn5zVTCAqyBU6fp4X1Lw",
"digest": "1d3e2add91e31a4c7ad7f985d758e844",
"sector_size": 1024
},
"v20-proof-of-spacetime-election-4a2342062706429612fac099694f77294e355c6c9265b80feaff12a0268b0a92.vk": {
"cid": "QmSDyi3BQrYXTQp4vSVAjZSF2RfU5iZJzzJ8jM5WSMTgjd",
"digest": "21f6b4c8fb316c41a7b2ffd0e2bf39ca",
"sector_size": 1024
},
"v20-proof-of-spacetime-election-512f5e6dc00a37fa13c8b0e468188f85957b7bf1ab36d17fb9fe9ed49ae8d657.params": {
"cid": "QmQQhB1g98j3bPQLTnvUcMLzqhAaFjpE6giwMZp4BkLSkj",
"digest": "54c4ef0dffee9b3f52319ae0a13e0ed0",
"sector_size": 1073741824
},
"v20-proof-of-spacetime-election-512f5e6dc00a37fa13c8b0e468188f85957b7bf1ab36d17fb9fe9ed49ae8d657.vk": {
"cid": "QmcDgvf8B7LNNG1UD9JQ9srbmGCqWQ3SpYnSt11Q7M6N6o",
"digest": "f3cd7afac7b4635c7d90ce7108539649",
"sector_size": 1073741824
},
"v20-proof-of-spacetime-election-6c7cbfe7eed40b6c0b23a213a70648770aed65d9ca03ae85451573c18532304b.params": {
"cid": "QmX2Tfu49qnSUbz42s9jPf7WTVjmAPNAXFzqroAAWXN4ms",
"digest": "5078bde58986f57f4393e96be9623536",
"sector_size": 16777216
},
"v20-proof-of-spacetime-election-6c7cbfe7eed40b6c0b23a213a70648770aed65d9ca03ae85451573c18532304b.vk": {
"cid": "QmaTM9V7AguRAHbjsadVKtHdVvXS8k18qt8rh1S1JPPyJT",
"digest": "2a1d0da743c8162a937ca21e15424d3f",
"sector_size": 16777216
},
"v20-proof-of-spacetime-election-7e98e29a3b6fd661ce53507e168a8194bc7c8a29aa069b5c057d95462a8fcf9f.params": {
"cid": "QmRkidQgNyNiG39ikHrQ4pWv6VzVuSNT8f6JG5i6W2BfJG",
"digest": "81906993f9e4525345074c88c6238f61",
"v20-proof-of-spacetime-election-5f585aca354eb68e411c8582ed0efd800792430e4e76d73468c4fc03f1a8d6d2.params": {
"cid": "QmX7tYeNPWae2fjZ3Am6GB9dmHvLqvoz8dKo3PR98VYxH9",
"digest": "39a9edec3355516674f0d12b926be493",
"sector_size": 34359738368
},
"v20-proof-of-spacetime-election-7e98e29a3b6fd661ce53507e168a8194bc7c8a29aa069b5c057d95462a8fcf9f.vk": {
"cid": "QmTcr7okdprbf2rak2t9S7DZEN4i6sKzJSiSigL36d7Qb5",
"digest": "95638189775b411a489980cb3839cf3d",
"v20-proof-of-spacetime-election-5f585aca354eb68e411c8582ed0efd800792430e4e76d73468c4fc03f1a8d6d2.vk": {
"cid": "QmbNGx7pNbGiEr8ykoHxVXHW2LNSmGdsxKtj1onZCyguCX",
"digest": "0227ae7df4f2affe529ebafbbc7540ee",
"sector_size": 34359738368
},
"v20-proof-of-spacetime-election-a4e18190d4b4657ba1b4d08a341871b2a6f398e327cb9951b28ab141fbdbf49d.params": {
"cid": "QmRGZsNp4mp1cZshcXqt3VMuWscAEsiMa2iepF4CsWWoiv",
"digest": "991041a354b12c280542741f58c7f2ca",
"sector_size": 1024
},
"v20-proof-of-spacetime-election-a4e18190d4b4657ba1b4d08a341871b2a6f398e327cb9951b28ab141fbdbf49d.vk": {
"cid": "QmWpmrhCGVcfqLyqp5oGAnhPmCE5hGTPaauHi25mpQwRSU",
"digest": "91fac550e1f9bccab213830bb0c85bd6",
"sector_size": 1024
},
"v20-proof-of-spacetime-election-a9eb6d90b896a282ec2d3a875c6143e3fcff778f0da1460709e051833651559b.params": {
"cid": "QmenSZXh1EsSyHiSRvA6wb8yaPhYBTjrKehJw96Px5HnN4",
"digest": "6322eacd2773163ddd51f9ca7d645fc4",
"sector_size": 1073741824
},
"v20-proof-of-spacetime-election-a9eb6d90b896a282ec2d3a875c6143e3fcff778f0da1460709e051833651559b.vk": {
"cid": "QmPvZoMKofw6eDhDg5ESJA2QAZP8HvM6qMQk7fw4pq9bQf",
"digest": "0df62745fceac922e3e70847cfc70b52",
"sector_size": 1073741824
},
"v20-proof-of-spacetime-election-bf872523641b1de33553db2a177df13e412d7b3b0103e6696ae0a1cf5d525259.params": {
"cid": "QmVibFqzkZoL8cwQmzj8njPokCQGCCx4pBcUH77bzgJgV9",
"digest": "de9d71e672f286706a1673bd57abdaac",
"sector_size": 16777216
},
"v20-proof-of-spacetime-election-bf872523641b1de33553db2a177df13e412d7b3b0103e6696ae0a1cf5d525259.vk": {
"cid": "QmZa5FX27XyiEXQQLQpHqtMJKLzrcY8wMuj3pxzmSimSyu",
"digest": "7f796d3a0f13499181e44b5eee0cc744",
"sector_size": 16777216
},
"v20-proof-of-spacetime-election-ffc3fb192364238b60977839d14e3154d4a98313e30d46694a12af54b6874975.params": {
"cid": "Qmbt2SWWAmMcYoY3DAiRDXA8fAuqdqRLWucJMSxYmzBCmN",
"digest": "151ae0ae183fc141e8c2bebc28e5cc10",
"sector_size": 268435456
},
"v20-proof-of-spacetime-election-ffc3fb192364238b60977839d14e3154d4a98313e30d46694a12af54b6874975.vk": {
"cid": "QmUxvPu4xdVmjMFihUKoYyEdXBqxsXkvmxRweU7KouWHji",
"digest": "95eb89588e9d1832aca044c3a13178af",
"sector_size": 268435456
},
"v20-stacked-proof-of-replication-117839dacd1ef31e5968a6fd13bcd6fa86638d85c40c9241a1d07c2a954eb89b.params": {
"cid": "QmQZe8eLo2xXbhSDxtyYZNqEjqjdcWGdADywECRvNEZQdX",
"digest": "fcd50e2e08a8560a6bb3418e883567ed",
@ -99,4 +99,5 @@
"digest": "834408e5c3fce6ec5d1bf64e64cee94e",
"sector_size": 16777216
}
}
}

View File

@ -1,7 +1,7 @@
package build
// Version is the local build version, set by build system
const Version = "0.11.0"
const Version = "0.1.0"
// APIVersion is a hex semver version of the rpc api exposed
//
@ -12,15 +12,19 @@ const Version = "0.11.0"
// R R H
// |\vv/|
// vv vv
const APIVersion = 0x000b01
const APIVersion = 0x000100
const (
MajorMask = 0xff0000
MinorMask = 0xffff00
PatchMask = 0xffffff
MajorOnlyMask = 0xff0000
MinorOnlyMask = 0x00ff00
PatchOnlyMask = 0x0000ff
)
// VersionInts returns (major, minor, patch) versions
func VersionInts(version uint32) (uint32, uint32, uint32) {
return (version & MajorMask) >> 16, (version & MinorMask) >> 8, version & PatchMask
return (version & MajorOnlyMask) >> 16, (version & MinorOnlyMask) >> 8, version & PatchOnlyMask
}

View File

@ -53,14 +53,10 @@ type StorageMinerActorState struct {
// Contains mostly static info about this miner
Info cid.Cid
// Faulty sectors reported since last SubmitPost,
// up to the current proving period's challenge time.
CurrentFaultSet types.BitField
// Faulty sectors reported since last SubmitPost
FaultSet types.BitField
// Faults submitted after the current proving period's challenge time,
// but before the PoSt for that period is submitted.
// These become the currentFaultSet when a PoSt is submitted.
NextFaultSet types.BitField
LastFaultSubmission uint64
// Amount of power this miner has.
Power types.BigInt
@ -340,7 +336,7 @@ func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMC
return nil, aerrors.Wrapf(err, "failed to compute data commitment (sector %d, deals: %v)", params.SectorID, params.DealIDs)
}
if ok, err := ValidatePoRep(ctx, maddr, mi.SectorSize, commD, us.Info.CommR, ticket, params.Proof, seed, params.SectorID); err != nil {
if ok, err := vmctx.Sys().ValidatePoRep(ctx, maddr, mi.SectorSize, commD, us.Info.CommR, ticket, params.Proof, seed, params.SectorID); err != nil {
return nil, err
} else if !ok {
return nil, aerrors.Newf(2, "porep proof was invalid (t:%x; s:%x(%d); p:%s)", ticket, seed, us.ReceivedEpoch+build.InteractivePoRepDelay, truncateHexPrint(params.Proof))
@ -463,8 +459,17 @@ func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VM
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
}
faults, nerr := self.FaultSet.AllMap()
if nerr != nil {
return nil, aerrors.Absorb(err, 5, "RLE+ invalid")
}
var sectorInfos []ffi.PublicSectorInfo
if err := pss.ForEach(func(id uint64, v *cbg.Deferred) error {
if faults[id] {
return nil
}
var comms [][]byte
if err := cbor.DecodeInto(v.Raw, &comms); err != nil {
return xerrors.New("could not decode comms")
@ -485,12 +490,6 @@ func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VM
return nil, aerrors.Absorb(err, 3, "could not decode sectorset")
}
faults, nerr := self.CurrentFaultSet.All()
if nerr != nil {
return nil, aerrors.Absorb(err, 5, "RLE+ invalid")
}
_ = faults
proverID := vmctx.Message().To // TODO: normalize to ID address
var candidates []sectorbuilder.EPostCandidate
@ -598,6 +597,25 @@ func GetFromSectorSet(ctx context.Context, s types.Storage, ss cid.Cid, sectorID
return true, comms[0], comms[1], nil
}
func RemoveFromSectorSet(ctx context.Context, s types.Storage, ss cid.Cid, ids []uint64) (cid.Cid, aerrors.ActorError) {
ssr, err := amt.LoadAMT(types.WrapStorage(s), ss)
if err != nil {
return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node")
}
if err := ssr.BatchDelete(ids); err != nil {
return cid.Undef, aerrors.HandleExternalError(err, "failed to delete from sector set")
}
ncid, err := ssr.Flush()
if err != nil {
return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set")
}
return ncid, nil
}
func ValidatePoRep(ctx context.Context, maddr address.Address, ssize uint64, commD, commR, ticket, proof, seed []byte, sectorID uint64) (bool, ActorError) {
_, span := trace.StartSpan(ctx, "ValidatePoRep")
defer span.End()
@ -787,34 +805,28 @@ type DeclareFaultsParams struct {
}
func (sma StorageMinerActor) DeclareFaults(act *types.Actor, vmctx types.VMContext, params *DeclareFaultsParams) ([]byte, ActorError) {
/*
oldstate, self, aerr := loadState(vmctx)
if aerr != nil {
return nil, aerr
}
oldstate, self, aerr := loadState(vmctx)
if aerr != nil {
return nil, aerr
}
challengeHeight := self.ProvingPeriodEnd - build.PoStChallangeTime
nfaults, err := types.MergeBitFields(params.Faults, self.FaultSet)
if err != nil {
return nil, aerrors.Absorb(err, 1, "failed to merge bitfields")
}
if vmctx.BlockHeight() < challengeHeight {
// TODO: optimized bitfield methods
for _, v := range params.Faults.All() {
self.CurrentFaultSet.Set(v)
}
} else {
for _, v := range params.Faults.All() {
self.NextFaultSet.Set(v)
}
}
self.FaultSet = nfaults
nstate, err := vmctx.Storage().Put(self)
if err != nil {
return nil, err
}
if err := vmctx.Storage().Commit(oldstate, nstate); err != nil {
return nil, err
}
self.LastFaultSubmission = vmctx.BlockHeight()
nstate, aerr := vmctx.Storage().Put(self)
if err != nil {
return nil, aerr
}
if err := vmctx.Storage().Commit(oldstate, nstate); err != nil {
return nil, err
}
*/
return nil, nil
}
@ -906,14 +918,22 @@ func onSuccessfulPoSt(self *StorageMinerActorState, vmctx types.VMContext) aerro
return aerrors.HandleExternalError(nerr, "failed to load proving set")
}
self.CurrentFaultSet = self.NextFaultSet
self.NextFaultSet = types.NewBitField()
faults, nerr := self.FaultSet.All()
if nerr != nil {
return aerrors.Absorb(nerr, 1, "invalid bitfield (fatal?)")
}
faults := []uint64{} // TODO
self.FaultSet = types.NewBitField()
oldPower := self.Power
self.Power = types.BigMul(types.NewInt(pss.Count-uint64(len(faults))),
types.NewInt(mi.SectorSize))
newPower := types.BigMul(types.NewInt(pss.Count-uint64(len(faults))), types.NewInt(mi.SectorSize))
// If below the minimum size requirement, miners have zero power
if newPower.LessThan(types.NewInt(build.MinimumMinerPower)) {
newPower = types.NewInt(0)
}
self.Power = newPower
delta := types.BigSub(self.Power, oldPower)
if self.SlashedAt != 0 {
@ -922,26 +942,34 @@ func onSuccessfulPoSt(self *StorageMinerActorState, vmctx types.VMContext) aerro
}
prevSlashingDeadline := self.ElectionPeriodStart + build.SlashablePowerDelay
if !self.Active {
if !self.Active && newPower.GreaterThan(types.NewInt(0)) {
self.Active = true
prevSlashingDeadline = 0
}
enc, err := SerializeParams(&UpdateStorageParams{
Delta: delta,
NextProvingPeriodEnd: vmctx.BlockHeight() + build.SlashablePowerDelay,
PreviousProvingPeriodEnd: prevSlashingDeadline,
})
if !(oldPower.IsZero() && newPower.IsZero()) {
enc, err := SerializeParams(&UpdateStorageParams{
Delta: delta,
NextProvingPeriodEnd: vmctx.BlockHeight() + build.SlashablePowerDelay,
PreviousProvingPeriodEnd: prevSlashingDeadline,
})
if err != nil {
return err
}
_, err = vmctx.Send(StoragePowerAddress, SPAMethods.UpdateStorage, types.NewInt(0), enc)
if err != nil {
return err
}
}
ncid, err := RemoveFromSectorSet(vmctx.Context(), vmctx.Storage(), self.Sectors, faults)
if err != nil {
return err
}
_, err = vmctx.Send(StoragePowerAddress, SPAMethods.UpdateStorage, types.NewInt(0), enc)
if err != nil {
return err
}
self.ProvingSet = self.Sectors
self.Sectors = ncid
self.ProvingSet = ncid
self.ElectionPeriodStart = vmctx.BlockHeight()
return nil
}

View File

@ -0,0 +1,157 @@
package actors_test
import (
"bytes"
"context"
"math/rand"
"testing"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/aerrors"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/sectorbuilder"
hamt "github.com/ipfs/go-hamt-ipld"
blockstore "github.com/ipfs/go-ipfs-blockstore"
cbg "github.com/whyrusleeping/cbor-gen"
)
func TestMinerCommitSectors(t *testing.T) {
var worker, client address.Address
var minerAddr address.Address
opts := []HarnessOpt{
HarnessAddr(&worker, 1000000),
HarnessAddr(&client, 1000000),
HarnessActor(&minerAddr, &worker, actors.StorageMinerCodeCid,
func() cbg.CBORMarshaler {
return &actors.StorageMinerConstructorParams{
Owner: worker,
Worker: worker,
SectorSize: 1024,
PeerID: "fakepeerid",
}
}),
}
h := NewHarness(t, opts...)
h.vm.Syscalls.ValidatePoRep = func(ctx context.Context, maddr address.Address, ssize uint64, commD, commR, ticket, proof, seed []byte, sectorID uint64) (bool, aerrors.ActorError) {
// all proofs are valid
return true, nil
}
ret, _ := h.SendFunds(t, worker, minerAddr, types.NewInt(100000))
ApplyOK(t, ret)
ret, _ = h.InvokeWithValue(t, client, actors.StorageMarketAddress, actors.SMAMethods.AddBalance, types.NewInt(2000), nil)
ApplyOK(t, ret)
addSectorToMiner(h, t, minerAddr, worker, client, 1)
assertSectorIDs(h, t, minerAddr, []uint64{1})
}
func addSectorToMiner(h *Harness, t *testing.T, minerAddr, worker, client address.Address, sid uint64) {
t.Helper()
s := sectorbuilder.UserBytesForSectorSize(1024)
deal := h.makeFakeDeal(t, minerAddr, worker, client, s)
ret, _ := h.Invoke(t, worker, actors.StorageMarketAddress, actors.SMAMethods.PublishStorageDeals,
&actors.PublishStorageDealsParams{
Deals: []actors.StorageDealProposal{*deal},
})
ApplyOK(t, ret)
var dealIds actors.PublishStorageDealResponse
if err := dealIds.UnmarshalCBOR(bytes.NewReader(ret.Return)); err != nil {
t.Fatal(err)
}
dealid := dealIds.DealIDs[0]
ret, _ = h.Invoke(t, worker, minerAddr, actors.MAMethods.PreCommitSector,
&actors.SectorPreCommitInfo{
SectorNumber: sid,
CommR: []byte("cats"),
SealEpoch: 10,
DealIDs: []uint64{dealid},
})
ApplyOK(t, ret)
h.BlockHeight += 100
ret, _ = h.Invoke(t, worker, minerAddr, actors.MAMethods.ProveCommitSector,
&actors.SectorProveCommitInfo{
Proof: []byte("prooofy"),
SectorID: sid,
DealIDs: []uint64{dealid}, // TODO: weird that i have to pass this again
})
ApplyOK(t, ret)
}
func assertSectorIDs(h *Harness, t *testing.T, maddr address.Address, ids []uint64) {
t.Helper()
sectors, err := getMinerSectorSet(context.TODO(), h.vm.StateTree(), h.bs, maddr)
if err != nil {
t.Fatal(err)
}
if len(sectors) != len(ids) {
t.Fatal("miner has wrong number of sectors in their sector set")
}
all := make(map[uint64]bool)
for _, s := range sectors {
all[s.SectorID] = true
}
for _, id := range ids {
if !all[id] {
t.Fatal("expected to find sector ID: ", id)
}
}
}
func getMinerSectorSet(ctx context.Context, st types.StateTree, bs blockstore.Blockstore, maddr address.Address) ([]*api.ChainSectorInfo, error) {
mact, err := st.GetActor(maddr)
if err != nil {
return nil, err
}
cst := hamt.CSTFromBstore(bs)
var mstate actors.StorageMinerActorState
if err := cst.Get(ctx, mact.Head, &mstate); err != nil {
return nil, err
}
return stmgr.LoadSectorsFromSet(ctx, bs, mstate.Sectors)
}
func (h *Harness) makeFakeDeal(t *testing.T, miner, worker, client address.Address, size uint64) *actors.StorageDealProposal {
data := make([]byte, size)
rand.Read(data)
commP, err := sectorbuilder.GeneratePieceCommitment(bytes.NewReader(data), size)
if err != nil {
t.Fatal(err)
}
prop := actors.StorageDealProposal{
PieceRef: commP[:],
PieceSize: size,
//PieceSerialization SerializationMode // Needs to be here as it tells how data in the sector maps to PieceRef cid
Client: client,
Provider: miner,
ProposalExpiration: 10000,
Duration: 150,
StoragePricePerEpoch: types.NewInt(1),
StorageCollateral: types.NewInt(0),
}
if err := api.SignWith(context.TODO(), h.w.Sign, client, &prop); err != nil {
t.Fatal(err)
}
return &prop
}

View File

@ -83,7 +83,7 @@ func TestPaychUpdate(t *testing.T) {
ApplyOK(t, ret)
// now we have to 'wait' for the chain to advance.
h.vm.SetBlockHeight(1000)
h.BlockHeight = 1000
ret, _ = h.Invoke(t, targetAddr, pch, actors.PCAMethods.Collect, nil)
ApplyOK(t, ret)

View File

@ -3,6 +3,8 @@ package actors
import (
"bytes"
"context"
"sort"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-amt-ipld"
@ -73,9 +75,8 @@ const (
)
type StorageDealProposal struct {
PieceRef []byte // cid bytes // TODO: spec says to use cid.Cid, probably not a good idea
PieceSize uint64
PieceSerialization SerializationMode // Needs to be here as it tells how data in the sector maps to PieceRef cid
PieceRef []byte // cid bytes // TODO: spec says to use cid.Cid, probably not a good idea
PieceSize uint64
Client address.Address
Provider address.Address
@ -131,36 +132,19 @@ func (sdp *StorageDealProposal) Verify() error {
return sdp.ProposerSignature.Verify(sdp.Client, buf.Bytes())
}
func (d *StorageDeal) Sign(ctx context.Context, sign SignFunc) error {
var buf bytes.Buffer
if err := d.Proposal.MarshalCBOR(&buf); err != nil {
return err
}
sig, err := sign(ctx, buf.Bytes())
if err != nil {
return err
}
d.CounterSignature = sig
return nil
}
func (d *StorageDeal) Verify(proposerWorker address.Address) error {
var buf bytes.Buffer
if err := d.Proposal.MarshalCBOR(&buf); err != nil {
return err
}
return d.CounterSignature.Verify(proposerWorker, buf.Bytes())
}
type StorageDeal struct {
Proposal StorageDealProposal
CounterSignature *types.Signature
}
type OnChainDeal struct {
Deal StorageDeal
ActivationEpoch uint64 // 0 = inactive
PieceRef []byte // cid bytes // TODO: spec says to use cid.Cid, probably not a good idea
PieceSize uint64
Client address.Address
Provider address.Address
ProposalExpiration uint64
Duration uint64 // TODO: spec
StoragePricePerEpoch types.BigInt
StorageCollateral types.BigInt
ActivationEpoch uint64 // 0 = inactive
}
type WithdrawBalanceParams struct {
@ -245,8 +229,15 @@ func (sma StorageMarketActor) AddBalance(act *types.Actor, vmctx types.VMContext
}
func setMarketBalances(vmctx types.VMContext, nd *hamt.Node, set map[address.Address]StorageParticipantBalance) (cid.Cid, ActorError) {
for addr, b := range set {
balance := b // to stop linter complaining
keys := make([]address.Address, 0, len(set))
for k := range set {
keys = append(keys, k)
}
sort.Slice(keys, func(i, j int) bool {
return bytes.Compare(keys[i].Bytes(), keys[j].Bytes()) < 0
})
for _, addr := range keys {
balance := set[addr]
if err := nd.Set(vmctx.Context(), string(addr.Bytes()), &balance); err != nil {
return cid.Undef, aerrors.HandleExternalError(err, "setting new balance")
}
@ -297,7 +288,7 @@ func (sma StorageMarketActor) CheckLockedBalance(act *types.Actor, vmctx types.V
*/
type PublishStorageDealsParams struct {
Deals []StorageDeal
Deals []StorageDealProposal
}
type PublishStorageDealResponse struct {
@ -326,7 +317,7 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
DealIDs: make([]uint64, len(params.Deals)),
}
workerBytes, aerr := vmctx.Send(params.Deals[0].Proposal.Provider, MAMethods.GetWorkerAddr, types.NewInt(0), nil)
workerBytes, aerr := vmctx.Send(params.Deals[0].Provider, MAMethods.GetWorkerAddr, types.NewInt(0), nil)
if aerr != nil {
return nil, aerr
}
@ -342,7 +333,20 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
return nil, err
}
err := deals.Set(self.NextDealID, &OnChainDeal{Deal: deal})
err := deals.Set(self.NextDealID, &OnChainDeal{
PieceRef: deal.PieceRef,
PieceSize: deal.PieceSize,
Client: deal.Client,
Provider: deal.Provider,
ProposalExpiration: deal.ProposalExpiration,
Duration: deal.Duration,
StoragePricePerEpoch: deal.StoragePricePerEpoch,
StorageCollateral: deal.StorageCollateral,
ActivationEpoch: 0,
})
if err != nil {
return nil, aerrors.HandleExternalError(err, "setting deal in deal AMT")
}
@ -376,34 +380,28 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
return outBuf.Bytes(), nil
}
func (st *StorageMarketState) validateDeal(vmctx types.VMContext, deal StorageDeal, providerWorker address.Address) aerrors.ActorError {
if vmctx.BlockHeight() > deal.Proposal.ProposalExpiration {
func (st *StorageMarketState) validateDeal(vmctx types.VMContext, deal StorageDealProposal, providerWorker address.Address) aerrors.ActorError {
if vmctx.BlockHeight() > deal.ProposalExpiration {
return aerrors.New(1, "deal proposal already expired")
}
if err := deal.Proposal.Verify(); err != nil {
return aerrors.Absorb(err, 2, "verifying proposer signature")
if vmctx.Message().From != providerWorker {
return aerrors.New(2, "Deals must be submitted by the miner worker")
}
err := deal.Verify(providerWorker)
if err != nil {
return aerrors.Absorb(err, 2, "verifying provider signature")
}
// TODO: maybe this is actually fine
if vmctx.Message().From != providerWorker && vmctx.Message().From != deal.Proposal.Client {
return aerrors.New(4, "message not sent by deal participant")
if err := deal.Verify(); err != nil {
return aerrors.Absorb(err, 3, "verifying proposer signature")
}
// TODO: do some caching (changes gas so needs to be in spec too)
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), st.Balances, deal.Proposal.Client, providerWorker)
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), st.Balances, deal.Client, providerWorker)
if aerr != nil {
return aerrors.Wrap(aerr, "getting client, and provider balances")
}
clientBalance := b[0]
providerBalance := b[1]
totalPrice := deal.Proposal.TotalStoragePrice()
totalPrice := deal.TotalStoragePrice()
if clientBalance.Available.LessThan(totalPrice) {
return aerrors.Newf(5, "client doesn't have enough available funds to cover storage price; %d < %d", clientBalance.Available, totalPrice)
@ -412,17 +410,17 @@ func (st *StorageMarketState) validateDeal(vmctx types.VMContext, deal StorageDe
clientBalance = lockFunds(clientBalance, totalPrice)
// TODO: REVIEW: Not clear who pays for this
if providerBalance.Available.LessThan(deal.Proposal.StorageCollateral) {
return aerrors.Newf(6, "provider doesn't have enough available funds to cover StorageCollateral; %d < %d", providerBalance.Available, deal.Proposal.StorageCollateral)
if providerBalance.Available.LessThan(deal.StorageCollateral) {
return aerrors.Newf(6, "provider doesn't have enough available funds to cover StorageCollateral; %d < %d", providerBalance.Available, deal.StorageCollateral)
}
providerBalance = lockFunds(providerBalance, deal.Proposal.StorageCollateral)
providerBalance = lockFunds(providerBalance, deal.StorageCollateral)
// TODO: piece checks (e.g. size > sectorSize)?
bcid, aerr := setMarketBalances(vmctx, bnd, map[address.Address]StorageParticipantBalance{
deal.Proposal.Client: clientBalance,
providerWorker: providerBalance,
deal.Client: clientBalance,
providerWorker: providerBalance,
})
if aerr != nil {
return aerr
@ -458,11 +456,11 @@ func (sma StorageMarketActor) ActivateStorageDeals(act *types.Actor, vmctx types
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
}
if vmctx.Message().From != dealInfo.Deal.Proposal.Provider {
if vmctx.Message().From != dealInfo.Provider {
return nil, aerrors.New(1, "ActivateStorageDeals can only be called by the deal provider")
}
if vmctx.BlockHeight() > dealInfo.Deal.Proposal.ProposalExpiration {
if vmctx.BlockHeight() > dealInfo.ProposalExpiration {
return nil, aerrors.New(2, "deal cannot be activated: proposal expired")
}
@ -533,7 +531,7 @@ func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
}
if dealInfo.Deal.Proposal.Provider != vmctx.Message().From {
if dealInfo.Provider != vmctx.Message().From {
return nil, aerrors.New(3, "ProcessStorageDealsPayment can only be called by deal provider")
}
@ -542,15 +540,15 @@ func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx
return nil, aerrors.New(4, "ActivationEpoch lower than block height")
}
if vmctx.BlockHeight() > dealInfo.ActivationEpoch+dealInfo.Deal.Proposal.Duration {
if vmctx.BlockHeight() > dealInfo.ActivationEpoch+dealInfo.Duration {
// Deal expired, miner should drop it
// TODO: process payment for the remainder of last proving period
return nil, nil
}
toPay := types.BigMul(dealInfo.Deal.Proposal.StoragePricePerEpoch, types.NewInt(build.SlashablePowerDelay))
toPay := types.BigMul(dealInfo.StoragePricePerEpoch, types.NewInt(build.SlashablePowerDelay))
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), self.Balances, dealInfo.Deal.Proposal.Client, providerWorker)
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), self.Balances, dealInfo.Client, providerWorker)
if aerr != nil {
return nil, aerr
}
@ -561,8 +559,8 @@ func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx
// TODO: call set once
bcid, aerr := setMarketBalances(vmctx, bnd, map[address.Address]StorageParticipantBalance{
dealInfo.Deal.Proposal.Client: clientBal,
providerWorker: providerBal,
dealInfo.Client: clientBal,
providerWorker: providerBal,
})
if aerr != nil {
return nil, aerr
@ -625,15 +623,15 @@ func (sma StorageMarketActor) ComputeDataCommitment(act *types.Actor, vmctx type
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
}
if dealInfo.Deal.Proposal.Provider != vmctx.Message().From {
if dealInfo.Provider != vmctx.Message().From {
return nil, aerrors.New(5, "referenced deal was not from caller")
}
var commP [32]byte
copy(commP[:], dealInfo.Deal.Proposal.PieceRef)
copy(commP[:], dealInfo.PieceRef)
pieces = append(pieces, sectorbuilder.PublicPieceInfo{
Size: dealInfo.Deal.Proposal.PieceSize,
Size: dealInfo.PieceSize,
CommP: commP,
})
}

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@ package actors_test
import (
"bytes"
"context"
"math/rand"
"testing"
"github.com/ipfs/go-cid"
@ -41,10 +42,12 @@ const (
type HarnessOpt func(testing.TB, *Harness) error
type Harness struct {
HI HarnessInit
Stage HarnessStage
Nonces map[address.Address]uint64
GasCharges map[address.Address]types.BigInt
HI HarnessInit
Stage HarnessStage
Nonces map[address.Address]uint64
GasCharges map[address.Address]types.BigInt
Rand vm.Rand
BlockHeight uint64
lastBalanceCheck map[address.Address]types.BigInt
@ -127,6 +130,7 @@ func NewHarness(t *testing.T, options ...HarnessOpt) *Harness {
h := &Harness{
Stage: HarnessPreInit,
Nonces: make(map[address.Address]uint64),
Rand: &fakeRand{},
HI: HarnessInit{
NAddrs: 1,
Miner: blsaddr(0),
@ -140,6 +144,7 @@ func NewHarness(t *testing.T, options ...HarnessOpt) *Harness {
w: w,
ctx: context.Background(),
bs: bstore.NewBlockstore(dstore.NewMapDatastore()),
BlockHeight: 0,
}
for _, opt := range options {
err := opt(t, h)
@ -157,8 +162,14 @@ func NewHarness(t *testing.T, options ...HarnessOpt) *Harness {
if err != nil {
t.Fatal(err)
}
stateroot, err = gen.SetupStorageMarketActor(h.bs, stateroot, nil)
if err != nil {
t.Fatal(err)
}
h.cs = store.NewChainStore(h.bs, nil)
h.vm, err = vm.NewVM(stateroot, 1, nil, h.HI.Miner, h.cs.Blockstore())
h.vm, err = vm.NewVM(stateroot, 1, h.Rand, h.HI.Miner, h.cs.Blockstore())
if err != nil {
t.Fatal(err)
}
@ -246,6 +257,7 @@ func (h *Harness) Invoke(t testing.TB, from address.Address, to address.Address,
func (h *Harness) InvokeWithValue(t testing.TB, from address.Address, to address.Address,
method uint64, value types.BigInt, params cbg.CBORMarshaler) (*vm.ApplyRet, *state.StateTree) {
t.Helper()
h.vm.SetBlockHeight(h.BlockHeight)
return h.Apply(t, types.Message{
To: to,
From: from,
@ -315,3 +327,11 @@ func DumpObject(t testing.TB, obj cbg.CBORMarshaler) []byte {
}
return b.Bytes()
}
type fakeRand struct{}
func (fr *fakeRand) GetRandomness(ctx context.Context, h int64) ([]byte, error) {
out := make([]byte, 32)
rand.New(rand.NewSource(h)).Read(out)
return out, nil
}

View File

@ -22,6 +22,7 @@ import (
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/cborutil"
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/peermgr"
)
type BlockSync struct {
@ -29,13 +30,15 @@ type BlockSync struct {
host host.Host
syncPeers *bsPeerTracker
peerMgr *peermgr.PeerMgr
}
func NewBlockSyncClient(bserv dtypes.ChainBlockService, h host.Host) *BlockSync {
func NewBlockSyncClient(bserv dtypes.ChainBlockService, h host.Host, pmgr peermgr.MaybePeerMgr) *BlockSync {
return &BlockSync{
bserv: bserv,
host: h,
syncPeers: newPeerTracker(),
syncPeers: newPeerTracker(pmgr.Mgr),
peerMgr: pmgr.Mgr,
}
}
@ -392,11 +395,14 @@ type bsPeerTracker struct {
peers map[peer.ID]*peerStats
avgGlobalTime time.Duration
pmgr *peermgr.PeerMgr
}
func newPeerTracker() *bsPeerTracker {
func newPeerTracker(pmgr *peermgr.PeerMgr) *bsPeerTracker {
return &bsPeerTracker{
peers: make(map[peer.ID]*peerStats),
pmgr: pmgr,
}
}
@ -435,20 +441,31 @@ func (bpt *bsPeerTracker) prefSortedPeers() []peer.ID {
var costI, costJ float64
getPeerInitLat := func(p peer.ID) float64 {
var res float64
if bpt.pmgr != nil {
if lat, ok := bpt.pmgr.GetPeerLatency(out[i]); ok {
res = float64(lat)
}
}
if res == 0 {
res = float64(bpt.avgGlobalTime)
}
return res * newPeerMul
}
if pi.successes+pi.failures > 0 {
failRateI := float64(pi.failures) / float64(pi.failures+pi.successes)
costI = float64(pi.averageTime) + failRateI*float64(bpt.avgGlobalTime)
} else {
// we know nothing about this peer
// make them bit better than average
costI = 0.9 * float64(bpt.avgGlobalTime)
costI = getPeerInitLat(out[i])
}
if pj.successes+pj.failures > 0 {
failRateJ := float64(pj.failures) / float64(pj.failures+pj.successes)
costJ = float64(pj.averageTime) + failRateJ*float64(bpt.avgGlobalTime)
} else {
costJ = 0.9 * float64(bpt.avgGlobalTime)
costI = getPeerInitLat(out[i])
}
return costI < costJ

View File

@ -23,7 +23,7 @@ func (t *BlockSyncRequest) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Start ([]cid.Cid) (slice)
// t.Start ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Start)))); err != nil {
return err
}
@ -33,12 +33,12 @@ func (t *BlockSyncRequest) MarshalCBOR(w io.Writer) error {
}
}
// t.t.RequestLength (uint64) (uint64)
// t.RequestLength (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.RequestLength))); err != nil {
return err
}
// t.t.Options (uint64) (uint64)
// t.Options (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Options))); err != nil {
return err
}
@ -60,7 +60,7 @@ func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Start ([]cid.Cid) (slice)
// t.Start ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -86,7 +86,7 @@ func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error {
t.Start[i] = c
}
// t.t.RequestLength (uint64) (uint64)
// t.RequestLength (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -96,7 +96,7 @@ func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.RequestLength = uint64(extra)
// t.t.Options (uint64) (uint64)
// t.Options (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -118,7 +118,7 @@ func (t *BlockSyncResponse) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Chain ([]*blocksync.BSTipSet) (slice)
// t.Chain ([]*blocksync.BSTipSet) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Chain)))); err != nil {
return err
}
@ -128,12 +128,12 @@ func (t *BlockSyncResponse) MarshalCBOR(w io.Writer) error {
}
}
// t.t.Status (uint64) (uint64)
// t.Status (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
return err
}
// t.t.Message (string) (string)
// t.Message (string) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Message)))); err != nil {
return err
}
@ -158,7 +158,7 @@ func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Chain ([]*blocksync.BSTipSet) (slice)
// t.Chain ([]*blocksync.BSTipSet) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -185,7 +185,7 @@ func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error {
t.Chain[i] = &v
}
// t.t.Status (uint64) (uint64)
// t.Status (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -195,7 +195,7 @@ func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Status = uint64(extra)
// t.t.Message (string) (string)
// t.Message (string) (string)
{
sval, err := cbg.ReadString(br)
@ -217,7 +217,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Blocks ([]*types.BlockHeader) (slice)
// t.Blocks ([]*types.BlockHeader) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Blocks)))); err != nil {
return err
}
@ -227,7 +227,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error {
}
}
// t.t.BlsMessages ([]*types.Message) (slice)
// t.BlsMessages ([]*types.Message) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BlsMessages)))); err != nil {
return err
}
@ -237,7 +237,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error {
}
}
// t.t.BlsMsgIncludes ([][]uint64) (slice)
// t.BlsMsgIncludes ([][]uint64) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BlsMsgIncludes)))); err != nil {
return err
}
@ -252,7 +252,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error {
}
}
// t.t.SecpkMessages ([]*types.SignedMessage) (slice)
// t.SecpkMessages ([]*types.SignedMessage) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.SecpkMessages)))); err != nil {
return err
}
@ -262,7 +262,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error {
}
}
// t.t.SecpkMsgIncludes ([][]uint64) (slice)
// t.SecpkMsgIncludes ([][]uint64) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.SecpkMsgIncludes)))); err != nil {
return err
}
@ -294,7 +294,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Blocks ([]*types.BlockHeader) (slice)
// t.Blocks ([]*types.BlockHeader) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -321,7 +321,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
t.Blocks[i] = &v
}
// t.t.BlsMessages ([]*types.Message) (slice)
// t.BlsMessages ([]*types.Message) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -348,7 +348,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
t.BlsMessages[i] = &v
}
// t.t.BlsMsgIncludes ([][]uint64) (slice)
// t.BlsMsgIncludes ([][]uint64) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -403,7 +403,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.SecpkMessages ([]*types.SignedMessage) (slice)
// t.SecpkMessages ([]*types.SignedMessage) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -430,7 +430,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
t.SecpkMessages[i] = &v
}
// t.t.SecpkMsgIncludes ([][]uint64) (slice)
// t.SecpkMsgIncludes ([][]uint64) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {

View File

@ -24,7 +24,7 @@ func (t *AskRequest) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Miner (address.Address) (struct)
// t.Miner (address.Address) (struct)
if err := t.Miner.MarshalCBOR(w); err != nil {
return err
}
@ -46,7 +46,7 @@ func (t *AskRequest) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Miner (address.Address) (struct)
// t.Miner (address.Address) (struct)
{
@ -67,7 +67,7 @@ func (t *AskResponse) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Ask (types.SignedStorageAsk) (struct)
// t.Ask (types.SignedStorageAsk) (struct)
if err := t.Ask.MarshalCBOR(w); err != nil {
return err
}
@ -89,7 +89,7 @@ func (t *AskResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Ask (types.SignedStorageAsk) (struct)
// t.Ask (types.SignedStorageAsk) (struct)
{
@ -122,12 +122,12 @@ func (t *Proposal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.DealProposal (actors.StorageDealProposal) (struct)
// t.DealProposal (actors.StorageDealProposal) (struct)
if err := t.DealProposal.MarshalCBOR(w); err != nil {
return err
}
// t.t.Piece (cid.Cid) (struct)
// t.Piece (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Piece); err != nil {
return xerrors.Errorf("failed to write cid field t.Piece: %w", err)
@ -151,7 +151,7 @@ func (t *Proposal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.DealProposal (actors.StorageDealProposal) (struct)
// t.DealProposal (actors.StorageDealProposal) (struct)
{
@ -172,7 +172,7 @@ func (t *Proposal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Piece (cid.Cid) (struct)
// t.Piece (cid.Cid) (struct)
{
@ -192,16 +192,16 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{133}); err != nil {
if _, err := w.Write([]byte{132}); err != nil {
return err
}
// t.t.State (uint64) (uint64)
// t.State (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil {
return err
}
// t.t.Message (string) (string)
// t.Message (string) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Message)))); err != nil {
return err
}
@ -209,29 +209,16 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Proposal (cid.Cid) (struct)
// t.Proposal (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Proposal); err != nil {
return xerrors.Errorf("failed to write cid field t.Proposal: %w", err)
}
// t.t.StorageDeal (actors.StorageDeal) (struct)
if err := t.StorageDeal.MarshalCBOR(w); err != nil {
// t.StorageDealSubmission (types.SignedMessage) (struct)
if err := t.StorageDealSubmission.MarshalCBOR(w); err != nil {
return err
}
// t.t.PublishMessage (cid.Cid) (struct)
if t.PublishMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
return err
}
} else {
if err := cbg.WriteCid(w, *t.PublishMessage); err != nil {
return xerrors.Errorf("failed to write cid field t.PublishMessage: %w", err)
}
}
return nil
}
@ -246,11 +233,11 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 5 {
if extra != 4 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.State (uint64) (uint64)
// t.State (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -260,7 +247,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.State = uint64(extra)
// t.t.Message (string) (string)
// t.Message (string) (string)
{
sval, err := cbg.ReadString(br)
@ -270,7 +257,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
t.Message = string(sval)
}
// t.t.Proposal (cid.Cid) (struct)
// t.Proposal (cid.Cid) (struct)
{
@ -282,7 +269,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
t.Proposal = c
}
// t.t.StorageDeal (actors.StorageDeal) (struct)
// t.StorageDealSubmission (types.SignedMessage) (struct)
{
@ -296,36 +283,12 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
return err
}
} else {
t.StorageDeal = new(actors.StorageDeal)
if err := t.StorageDeal.UnmarshalCBOR(br); err != nil {
t.StorageDealSubmission = new(types.SignedMessage)
if err := t.StorageDealSubmission.UnmarshalCBOR(br); err != nil {
return err
}
}
}
// t.t.PublishMessage (cid.Cid) (struct)
{
pb, err := br.PeekByte()
if err != nil {
return err
}
if pb == cbg.CborNull[0] {
var nbuf [1]byte
if _, err := br.Read(nbuf[:]); err != nil {
return err
}
} else {
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.PublishMessage: %w", err)
}
t.PublishMessage = &c
}
}
return nil
}
@ -339,12 +302,12 @@ func (t *SignedResponse) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Response (deals.Response) (struct)
// t.Response (deals.Response) (struct)
if err := t.Response.MarshalCBOR(w); err != nil {
return err
}
// t.t.Signature (types.Signature) (struct)
// t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil {
return err
}
@ -366,7 +329,7 @@ func (t *SignedResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Response (deals.Response) (struct)
// t.Response (deals.Response) (struct)
{
@ -375,7 +338,7 @@ func (t *SignedResponse) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Signature (types.Signature) (struct)
// t.Signature (types.Signature) (struct)
{
@ -408,43 +371,43 @@ func (t *ClientDealProposal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Data (cid.Cid) (struct)
// t.Data (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Data); err != nil {
return xerrors.Errorf("failed to write cid field t.Data: %w", err)
}
// t.t.PricePerEpoch (types.BigInt) (struct)
// t.PricePerEpoch (types.BigInt) (struct)
if err := t.PricePerEpoch.MarshalCBOR(w); err != nil {
return err
}
// t.t.ProposalExpiration (uint64) (uint64)
// t.ProposalExpiration (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ProposalExpiration))); err != nil {
return err
}
// t.t.Duration (uint64) (uint64)
// t.Duration (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Duration))); err != nil {
return err
}
// t.t.ProviderAddress (address.Address) (struct)
// t.ProviderAddress (address.Address) (struct)
if err := t.ProviderAddress.MarshalCBOR(w); err != nil {
return err
}
// t.t.Client (address.Address) (struct)
// t.Client (address.Address) (struct)
if err := t.Client.MarshalCBOR(w); err != nil {
return err
}
// t.t.MinerWorker (address.Address) (struct)
// t.MinerWorker (address.Address) (struct)
if err := t.MinerWorker.MarshalCBOR(w); err != nil {
return err
}
// t.t.MinerID (peer.ID) (string)
// t.MinerID (peer.ID) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.MinerID)))); err != nil {
return err
}
@ -469,7 +432,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Data (cid.Cid) (struct)
// t.Data (cid.Cid) (struct)
{
@ -481,7 +444,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
t.Data = c
}
// t.t.PricePerEpoch (types.BigInt) (struct)
// t.PricePerEpoch (types.BigInt) (struct)
{
@ -490,7 +453,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.ProposalExpiration (uint64) (uint64)
// t.ProposalExpiration (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -500,7 +463,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.ProposalExpiration = uint64(extra)
// t.t.Duration (uint64) (uint64)
// t.Duration (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -510,7 +473,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Duration = uint64(extra)
// t.t.ProviderAddress (address.Address) (struct)
// t.ProviderAddress (address.Address) (struct)
{
@ -519,7 +482,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Client (address.Address) (struct)
// t.Client (address.Address) (struct)
{
@ -528,7 +491,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.MinerWorker (address.Address) (struct)
// t.MinerWorker (address.Address) (struct)
{
@ -537,7 +500,7 @@ func (t *ClientDealProposal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.MinerID (peer.ID) (string)
// t.MinerID (peer.ID) (string)
{
sval, err := cbg.ReadString(br)
@ -559,23 +522,23 @@ func (t *ClientDeal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.ProposalCid (cid.Cid) (struct)
// t.ProposalCid (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ProposalCid); err != nil {
return xerrors.Errorf("failed to write cid field t.ProposalCid: %w", err)
}
// t.t.Proposal (actors.StorageDealProposal) (struct)
// t.Proposal (actors.StorageDealProposal) (struct)
if err := t.Proposal.MarshalCBOR(w); err != nil {
return err
}
// t.t.State (uint64) (uint64)
// t.State (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil {
return err
}
// t.t.Miner (peer.ID) (string)
// t.Miner (peer.ID) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Miner)))); err != nil {
return err
}
@ -583,28 +546,20 @@ func (t *ClientDeal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.MinerWorker (address.Address) (struct)
// t.MinerWorker (address.Address) (struct)
if err := t.MinerWorker.MarshalCBOR(w); err != nil {
return err
}
// t.t.DealID (uint64) (uint64)
// t.DealID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.DealID))); err != nil {
return err
}
// t.t.PublishMessage (cid.Cid) (struct)
if t.PublishMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
return err
}
} else {
if err := cbg.WriteCid(w, *t.PublishMessage); err != nil {
return xerrors.Errorf("failed to write cid field t.PublishMessage: %w", err)
}
// t.PublishMessage (types.SignedMessage) (struct)
if err := t.PublishMessage.MarshalCBOR(w); err != nil {
return err
}
return nil
}
@ -623,7 +578,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.ProposalCid (cid.Cid) (struct)
// t.ProposalCid (cid.Cid) (struct)
{
@ -635,7 +590,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
t.ProposalCid = c
}
// t.t.Proposal (actors.StorageDealProposal) (struct)
// t.Proposal (actors.StorageDealProposal) (struct)
{
@ -644,7 +599,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.State (uint64) (uint64)
// t.State (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -654,7 +609,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.State = uint64(extra)
// t.t.Miner (peer.ID) (string)
// t.Miner (peer.ID) (string)
{
sval, err := cbg.ReadString(br)
@ -664,7 +619,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
t.Miner = peer.ID(sval)
}
// t.t.MinerWorker (address.Address) (struct)
// t.MinerWorker (address.Address) (struct)
{
@ -673,7 +628,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.DealID (uint64) (uint64)
// t.DealID (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -683,7 +638,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.DealID = uint64(extra)
// t.t.PublishMessage (cid.Cid) (struct)
// t.PublishMessage (types.SignedMessage) (struct)
{
@ -697,13 +652,10 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
return err
}
} else {
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.PublishMessage: %w", err)
t.PublishMessage = new(types.SignedMessage)
if err := t.PublishMessage.UnmarshalCBOR(br); err != nil {
return err
}
t.PublishMessage = &c
}
}
@ -719,7 +671,7 @@ func (t *MinerDeal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Client (peer.ID) (string)
// t.Client (peer.ID) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Client)))); err != nil {
return err
}
@ -727,34 +679,34 @@ func (t *MinerDeal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Proposal (actors.StorageDealProposal) (struct)
// t.Proposal (actors.StorageDealProposal) (struct)
if err := t.Proposal.MarshalCBOR(w); err != nil {
return err
}
// t.t.ProposalCid (cid.Cid) (struct)
// t.ProposalCid (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ProposalCid); err != nil {
return xerrors.Errorf("failed to write cid field t.ProposalCid: %w", err)
}
// t.t.State (uint64) (uint64)
// t.State (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil {
return err
}
// t.t.Ref (cid.Cid) (struct)
// t.Ref (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Ref); err != nil {
return xerrors.Errorf("failed to write cid field t.Ref: %w", err)
}
// t.t.DealID (uint64) (uint64)
// t.DealID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.DealID))); err != nil {
return err
}
// t.t.SectorID (uint64) (uint64)
// t.SectorID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorID))); err != nil {
return err
}
@ -776,7 +728,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Client (peer.ID) (string)
// t.Client (peer.ID) (string)
{
sval, err := cbg.ReadString(br)
@ -786,7 +738,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
t.Client = peer.ID(sval)
}
// t.t.Proposal (actors.StorageDealProposal) (struct)
// t.Proposal (actors.StorageDealProposal) (struct)
{
@ -795,7 +747,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.ProposalCid (cid.Cid) (struct)
// t.ProposalCid (cid.Cid) (struct)
{
@ -807,7 +759,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
t.ProposalCid = c
}
// t.t.State (uint64) (uint64)
// t.State (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -817,7 +769,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.State = uint64(extra)
// t.t.Ref (cid.Cid) (struct)
// t.Ref (cid.Cid) (struct)
{
@ -829,7 +781,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
t.Ref = c
}
// t.t.DealID (uint64) (uint64)
// t.DealID (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -839,7 +791,7 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.DealID = uint64(extra)
// t.t.SectorID (uint64) (uint64)
// t.SectorID (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -861,13 +813,13 @@ func (t *StorageDataTransferVoucher) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Proposal (cid.Cid) (struct)
// t.Proposal (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Proposal); err != nil {
return xerrors.Errorf("failed to write cid field t.Proposal: %w", err)
}
// t.t.DealID (uint64) (uint64)
// t.DealID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.DealID))); err != nil {
return err
}
@ -889,7 +841,7 @@ func (t *StorageDataTransferVoucher) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Proposal (cid.Cid) (struct)
// t.Proposal (cid.Cid) (struct)
{
@ -901,7 +853,7 @@ func (t *StorageDataTransferVoucher) UnmarshalCBOR(r io.Reader) error {
t.Proposal = c
}
// t.t.DealID (uint64) (uint64)
// t.DealID (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {

View File

@ -36,7 +36,7 @@ type ClientDeal struct {
MinerWorker address.Address
DealID uint64
PublishMessage *cid.Cid
PublishMessage *types.SignedMessage
s inet.Stream
}
@ -206,7 +206,6 @@ func (c *Client) Start(ctx context.Context, p ClientDealProposal) (cid.Cid, erro
dealProposal := &actors.StorageDealProposal{
PieceRef: commP,
PieceSize: uint64(pieceSize),
PieceSerialization: actors.SerializationUnixFSv0,
Client: p.Client,
Provider: p.ProviderAddress,
ProposalExpiration: p.ProposalExpiration,

View File

@ -44,6 +44,9 @@ func (c *Client) new(ctx context.Context, deal ClientDeal) (func(*ClientDeal), e
if err != nil {
return nil, err
}
// TODO: verify StorageDealSubmission
if err := c.disconnect(deal); err != nil {
return nil, err
}
@ -54,18 +57,14 @@ func (c *Client) new(ctx context.Context, deal ClientDeal) (func(*ClientDeal), e
}
return func(info *ClientDeal) {
info.PublishMessage = resp.PublishMessage
info.PublishMessage = resp.StorageDealSubmission
}, nil
}
func (c *Client) accepted(ctx context.Context, deal ClientDeal) (func(*ClientDeal), error) {
log.Infow("DEAL ACCEPTED!")
pubmsg, err := c.chain.GetMessage(*deal.PublishMessage)
if err != nil {
return nil, xerrors.Errorf("getting deal pubsish message: %w", err)
}
pubmsg := deal.PublishMessage.Message
pw, err := stmgr.GetMinerWorker(ctx, c.sm, nil, deal.Proposal.Provider)
if err != nil {
return nil, xerrors.Errorf("getting miner worker failed: %w", err)
@ -91,7 +90,8 @@ func (c *Client) accepted(ctx context.Context, deal ClientDeal) (func(*ClientDea
dealIdx := -1
for i, storageDeal := range params.Deals {
// TODO: make it less hacky
eq, err := cborutil.Equals(&deal.Proposal, &storageDeal.Proposal)
sd := storageDeal
eq, err := cborutil.Equals(&deal.Proposal, &sd)
if err != nil {
return nil, err
}
@ -102,11 +102,11 @@ func (c *Client) accepted(ctx context.Context, deal ClientDeal) (func(*ClientDea
}
if dealIdx == -1 {
return nil, xerrors.Errorf("deal publish didn't contain our deal (message cid: %s)", deal.PublishMessage)
return nil, xerrors.Errorf("deal publish didn't contain our deal (message cid: %s)", deal.PublishMessage.Cid())
}
// TODO: timeout
_, ret, err := c.sm.WaitForMessage(ctx, *deal.PublishMessage)
_, ret, err := c.sm.WaitForMessage(ctx, deal.PublishMessage.Cid())
if err != nil {
return nil, xerrors.Errorf("waiting for deal publish message: %w", err)
}

View File

@ -42,13 +42,6 @@ func (p *Provider) handle(ctx context.Context, deal MinerDeal, cb providerHandle
// ACCEPTED
func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal), error) {
switch deal.Proposal.PieceSerialization {
//case SerializationRaw:
//case SerializationIPLD:
case actors.SerializationUnixFSv0:
default:
return nil, xerrors.Errorf("deal proposal with unsupported serialization: %s", deal.Proposal.PieceSerialization)
}
head, err := p.full.ChainHead(ctx)
if err != nil {
@ -93,15 +86,8 @@ func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal)
log.Info("publishing deal")
storageDeal := actors.StorageDeal{
Proposal: deal.Proposal,
}
if err := api.SignWith(ctx, p.full.WalletSign, waddr, &storageDeal); err != nil {
return nil, xerrors.Errorf("signing storage deal failed: ", err)
}
params, err := actors.SerializeParams(&actors.PublishStorageDealsParams{
Deals: []actors.StorageDeal{storageDeal},
Deals: []actors.StorageDealProposal{deal.Proposal},
})
if err != nil {
return nil, xerrors.Errorf("serializing PublishStorageDeals params failed: ", err)
@ -136,13 +122,11 @@ func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal)
}
log.Infof("fetching data for a deal %d", resp.DealIDs[0])
mcid := smsg.Cid()
err = p.sendSignedResponse(&Response{
State: api.DealAccepted,
Proposal: deal.ProposalCid,
PublishMessage: &mcid,
StorageDeal: &storageDeal,
Proposal: deal.ProposalCid,
StorageDealSubmission: smsg,
})
if err != nil {
return nil, err

View File

@ -58,8 +58,7 @@ type Response struct {
Proposal cid.Cid
// DealAccepted
StorageDeal *actors.StorageDeal
PublishMessage *cid.Cid
StorageDealSubmission *types.SignedMessage
}
// TODO: Do we actually need this to be signed?

View File

@ -528,7 +528,7 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round int64, miner add
var winners []sectorbuilder.EPostCandidate
for _, c := range candidates {
if types.IsTicketWinner(c.PartialTicket[:], ssize, pow.TotalPower) {
if types.IsTicketWinner(c.PartialTicket[:], ssize, uint64(len(sinfos)), pow.TotalPower) {
winners = append(winners, c)
}
}

View File

@ -8,6 +8,7 @@ import (
func init() {
build.SectorSizes = []uint64{1024}
build.MinimumMinerPower = 1024
}
func testGeneration(t testing.TB, n int, msgs int) {

View File

@ -197,7 +197,7 @@ func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
}, nil
}
func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors.StorageDeal) (cid.Cid, error) {
func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors.StorageDealProposal) (cid.Cid, error) {
cst := hamt.CSTFromBstore(bs)
nd := hamt.NewNode(cst)
emptyHAMT, err := cst.Put(context.TODO(), nd)
@ -210,8 +210,15 @@ func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors
cdeals := make([]cbg.CBORMarshaler, len(deals))
for i, deal := range deals {
cdeals[i] = &actors.OnChainDeal{
Deal: deal,
ActivationEpoch: 1,
PieceRef: deal.PieceRef,
PieceSize: deal.PieceSize,
Client: deal.Client,
Provider: deal.Provider,
ProposalExpiration: deal.ProposalExpiration,
Duration: deal.Duration,
StoragePricePerEpoch: deal.StoragePricePerEpoch,
StorageCollateral: deal.StorageCollateral,
ActivationEpoch: 1,
}
}
@ -267,7 +274,7 @@ func mustEnc(i cbg.CBORMarshaler) []byte {
return enc
}
func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid, gmcfg *GenMinerCfg) (cid.Cid, []actors.StorageDeal, error) {
func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid, gmcfg *GenMinerCfg) (cid.Cid, []actors.StorageDealProposal, error) {
vm, err := vm.NewVM(sroot, 0, nil, actors.NetworkAddress, cs.Blockstore())
if err != nil {
return cid.Undef, nil, xerrors.Errorf("failed to create NewVM: %w", err)
@ -281,7 +288,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
return cid.Undef, nil, xerrors.Errorf("miner address list, and preseal count doesn't match (%d != %d)", len(gmcfg.MinerAddrs), len(gmcfg.PreSeals))
}
var deals []actors.StorageDeal
var deals []actors.StorageDealProposal
for i, maddr := range gmcfg.MinerAddrs {
ps, psok := gmcfg.PreSeals[maddr.String()]
@ -344,7 +351,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
if err := cst.Get(ctx, mact.Head, &mstate); err != nil {
return cid.Undef, nil, xerrors.Errorf("getting miner actor state failed: %w", err)
}
mstate.Power = types.BigMul(types.NewInt(build.SectorSizes[0]), types.NewInt(uint64(len(ps.Sectors))))
mstate.Power = types.BigMul(types.NewInt(ps.SectorSize), types.NewInt(uint64(len(ps.Sectors))))
blks := amt.WrapBlockstore(cs.Blockstore())

View File

@ -166,7 +166,7 @@ func New(api Provider, ds dtypes.MetadataDS) (*MessagePool, error) {
}
if err := mp.loadLocal(); err != nil {
return nil, xerrors.Errorf("loading local messages: %w", err)
log.Errorf("loading local messages: %+v", err)
}
go mp.repubLocal()
@ -192,14 +192,43 @@ func (mp *MessagePool) repubLocal() {
select {
case <-mp.repubTk.C:
mp.lk.Lock()
msgs := make([]*types.SignedMessage, 0)
msgsForAddr := make(map[address.Address][]*types.SignedMessage)
for a := range mp.localAddrs {
msgs = append(msgs, mp.pendingFor(a)...)
msgsForAddr[a] = mp.pendingFor(a)
}
mp.lk.Unlock()
var errout error
for _, msg := range msgs {
outputMsgs := []*types.SignedMessage{}
for a, msgs := range msgsForAddr {
a, err := mp.api.StateGetActor(a, nil)
if err != nil {
errout = multierr.Append(errout, xerrors.Errorf("could not get actor state: %w", err))
continue
}
curNonce := a.Nonce
for _, m := range msgs {
if m.Message.Nonce < curNonce {
continue
}
if m.Message.Nonce != curNonce {
break
}
outputMsgs = append(outputMsgs, m)
curNonce++
}
}
if len(outputMsgs) != 0 {
log.Infow("republishing local messages", "n", len(outputMsgs))
}
for _, msg := range outputMsgs {
msgb, err := msg.Serialize()
if err != nil {
errout = multierr.Append(errout, xerrors.Errorf("could not serialize: %w", err))
@ -683,7 +712,7 @@ func (mp *MessagePool) loadLocal() error {
continue // todo: drop the message from local cache (if above certain confidence threshold)
}
return xerrors.Errorf("adding local message: %w", err)
log.Errorf("adding local message: %+v", err)
}
}

View File

@ -138,7 +138,7 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get network actor: %w", err)
}
reward := vm.MiningReward(netact.Balance)
for _, b := range blks {
for tsi, b := range blks {
netact, err = vmi.StateTree().GetActor(actors.NetworkAddress)
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get network actor: %w", err)
@ -171,10 +171,10 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
}
ret, err := vmi.ApplyMessage(ctx, postSubmitMsg)
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("submit election post message invocation failed: %w", err)
return cid.Undef, cid.Undef, xerrors.Errorf("submit election post message for block %s (miner %s) invocation failed: %w", b.Cid(), b.Miner, err)
}
if ret.ExitCode != 0 {
return cid.Undef, cid.Undef, xerrors.Errorf("submit election post invocation returned nonzero exit code: %d", ret.ExitCode)
return cid.Undef, cid.Undef, xerrors.Errorf("submit election post invocation returned nonzero exit code: %d (err = %s, block = %s, miner = %s, tsi = %d)", ret.ExitCode, ret.ActorErr, b.Cid(), b.Miner, tsi)
}
}

View File

@ -155,6 +155,8 @@ func (cs *ChainStore) SubHeadChanges(ctx context.Context) chan []*HeadChange {
go func() {
defer close(out)
var unsubOnce sync.Once
for {
select {
case val, ok := <-subch:
@ -170,7 +172,9 @@ func (cs *ChainStore) SubHeadChanges(ctx context.Context) chan []*HeadChange {
case <-ctx.Done():
}
case <-ctx.Done():
go cs.bestTips.Unsub(subch)
unsubOnce.Do(func() {
go cs.bestTips.Unsub(subch)
})
}
}
}()
@ -490,6 +494,7 @@ func (cs *ChainStore) expandTipset(b *types.BlockHeader) (*types.TipSet, error)
return types.NewTipSet(all)
}
inclMiners := map[address.Address]bool{b.Miner: true}
for _, bhc := range tsets {
if bhc == b.Cid() {
continue
@ -500,8 +505,14 @@ func (cs *ChainStore) expandTipset(b *types.BlockHeader) (*types.TipSet, error)
return nil, xerrors.Errorf("failed to load block (%s) for tipset expansion: %w", bhc, err)
}
if inclMiners[h.Miner] {
log.Warnf("Have multiple blocks from miner %s at height %d in our tipset cache", h.Miner, h.Height)
continue
}
if types.CidArrsEqual(h.Parents, b.Parents) {
all = append(all, h)
inclMiners[h.Miner] = true
}
}

View File

@ -492,7 +492,16 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
}
winnerCheck := async.Err(func() error {
_, tpow, err := stmgr.GetPower(ctx, syncer.sm, baseTs, h.Miner)
slashedAt, 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)
}
mpow, tpow, err := stmgr.GetPower(ctx, syncer.sm, baseTs, h.Miner)
if err != nil {
return xerrors.Errorf("failed getting power: %w", err)
}
@ -502,8 +511,10 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
return xerrors.Errorf("failed to get sector size for block miner: %w", err)
}
snum := types.BigDiv(mpow, types.NewInt(ssize))
for _, t := range h.EPostProof.Candidates {
if !types.IsTicketWinner(t.Partial, ssize, tpow) {
if !types.IsTicketWinner(t.Partial, ssize, snum.Uint64(), tpow) {
return xerrors.Errorf("miner created a block but was not a winner")
}
}
@ -930,6 +941,12 @@ func (syncer *Syncer) syncFork(ctx context.Context, from *types.TipSet, to *type
}
for cur := 0; cur < len(tips); {
if nts.Height() == 0 {
if !syncer.Genesis.Equals(nts) {
return nil, xerrors.Errorf("somehow synced chain that linked back to a different genesis (bad genesis: %s)", nts.Key())
}
return nil, xerrors.Errorf("synced chain forked at genesis, refusing to sync")
}
if nts.Equals(tips[cur]) {
return tips[:cur+1], nil

View File

@ -28,6 +28,7 @@ func init() {
build.InsecurePoStValidation = true
os.Setenv("TRUST_PARAMS", "1")
build.SectorSizes = []uint64{1024}
build.MinimumMinerPower = 1024
}
const source = 0

View File

@ -237,3 +237,7 @@ func (bi *BigInt) UnmarshalCBOR(br io.Reader) error {
return nil
}
func (bi *BigInt) IsZero() bool {
return bi.Int.Sign() == 0
}

View File

@ -34,6 +34,38 @@ func BitFieldFromSet(setBits []uint64) BitField {
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()
@ -86,7 +118,26 @@ func (bf BitField) All() ([]uint64, error) {
return nil, err
}
return res, err
return res, nil
}
func (bf BitField) AllMap() (map[uint64]bool, error) {
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 {

View File

@ -174,9 +174,9 @@ var blocksPerEpoch = NewInt(build.BlocksPerEpoch)
const sha256bits = 256
func IsTicketWinner(partialTicket []byte, ssizeI uint64, totpow BigInt) bool {
func IsTicketWinner(partialTicket []byte, ssizeI uint64, snum uint64, totpow BigInt) bool {
ssize := NewInt(ssizeI)
ssampled := ElectionPostChallengeCount(snum)
/*
Need to check that
(h(vrfout) + 1) / (max(h) + 1) <= e * sectorSize / totalPower
@ -185,23 +185,42 @@ func IsTicketWinner(partialTicket []byte, ssizeI uint64, totpow BigInt) bool {
(h(vrfout) + 1) * totalPower <= e * sectorSize * 2^256
in 2^256 space, it is equivalent to:
h(vrfout) * totalPower < e * sectorSize * 2^256
Because of SectorChallengeRatioDiv sampling for proofs
we need to scale this appropriately.
Let c = ceil(numSectors/SectorChallengeRatioDiv)
(c is the number of tickets a miner requests)
Accordingly we check
(h(vrfout) + 1) / 2^256 <= e * sectorSize / totalPower * snum / c
or
h(vrfout) * totalPower * c < e * sectorSize * 2^256 * snum
*/
h := sha256.Sum256(partialTicket)
lhs := BigFromBytes(h[:]).Int
lhs = lhs.Mul(lhs, totpow.Int)
lhs = lhs.Mul(lhs, new(big.Int).SetUint64(ssampled))
// rhs = sectorSize * 2^256
// rhs = sectorSize << 256
rhs := new(big.Int).Lsh(ssize.Int, sha256bits)
rhs = rhs.Mul(rhs, big.NewInt(build.SectorChallengeRatioDiv))
rhs = rhs.Mul(rhs, new(big.Int).SetUint64(snum))
rhs = rhs.Mul(rhs, blocksPerEpoch.Int)
// h(vrfout) * totalPower < e * sectorSize * 2^256?
return lhs.Cmp(rhs) < 0
}
func ElectionPostChallengeCount(sectors uint64) uint64 {
if sectors == 0 {
return 0
}
// ceil(sectors / build.SectorChallengeRatioDiv)
return (sectors-1)/build.SectorChallengeRatioDiv + 1
}
func (t *Ticket) Equals(ot *Ticket) bool {
return bytes.Equal(t.VRFProof, ot.VRFProof)
}

View File

@ -23,22 +23,22 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Miner (address.Address) (struct)
// t.Miner (address.Address) (struct)
if err := t.Miner.MarshalCBOR(w); err != nil {
return err
}
// t.t.Ticket (types.Ticket) (struct)
// t.Ticket (types.Ticket) (struct)
if err := t.Ticket.MarshalCBOR(w); err != nil {
return err
}
// t.t.EPostProof (types.EPostProof) (struct)
// t.EPostProof (types.EPostProof) (struct)
if err := t.EPostProof.MarshalCBOR(w); err != nil {
return err
}
// t.t.Parents ([]cid.Cid) (slice)
// t.Parents ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Parents)))); err != nil {
return err
}
@ -48,45 +48,45 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
}
}
// t.t.ParentWeight (types.BigInt) (struct)
// t.ParentWeight (types.BigInt) (struct)
if err := t.ParentWeight.MarshalCBOR(w); err != nil {
return err
}
// t.t.Height (uint64) (uint64)
// t.Height (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Height))); err != nil {
return err
}
// t.t.ParentStateRoot (cid.Cid) (struct)
// t.ParentStateRoot (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ParentStateRoot); err != nil {
return xerrors.Errorf("failed to write cid field t.ParentStateRoot: %w", err)
}
// t.t.ParentMessageReceipts (cid.Cid) (struct)
// t.ParentMessageReceipts (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ParentMessageReceipts); err != nil {
return xerrors.Errorf("failed to write cid field t.ParentMessageReceipts: %w", err)
}
// t.t.Messages (cid.Cid) (struct)
// t.Messages (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Messages); err != nil {
return xerrors.Errorf("failed to write cid field t.Messages: %w", err)
}
// t.t.BLSAggregate (types.Signature) (struct)
// t.BLSAggregate (types.Signature) (struct)
if err := t.BLSAggregate.MarshalCBOR(w); err != nil {
return err
}
// t.t.Timestamp (uint64) (uint64)
// t.Timestamp (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Timestamp))); err != nil {
return err
}
// t.t.BlockSig (types.Signature) (struct)
// t.BlockSig (types.Signature) (struct)
if err := t.BlockSig.MarshalCBOR(w); err != nil {
return err
}
@ -108,7 +108,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Miner (address.Address) (struct)
// t.Miner (address.Address) (struct)
{
@ -117,7 +117,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Ticket (types.Ticket) (struct)
// t.Ticket (types.Ticket) (struct)
{
@ -138,7 +138,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.EPostProof (types.EPostProof) (struct)
// t.EPostProof (types.EPostProof) (struct)
{
@ -147,7 +147,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Parents ([]cid.Cid) (slice)
// t.Parents ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -173,7 +173,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.Parents[i] = c
}
// t.t.ParentWeight (types.BigInt) (struct)
// t.ParentWeight (types.BigInt) (struct)
{
@ -182,7 +182,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Height (uint64) (uint64)
// t.Height (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -192,7 +192,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Height = uint64(extra)
// t.t.ParentStateRoot (cid.Cid) (struct)
// t.ParentStateRoot (cid.Cid) (struct)
{
@ -204,7 +204,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.ParentStateRoot = c
}
// t.t.ParentMessageReceipts (cid.Cid) (struct)
// t.ParentMessageReceipts (cid.Cid) (struct)
{
@ -216,7 +216,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.ParentMessageReceipts = c
}
// t.t.Messages (cid.Cid) (struct)
// t.Messages (cid.Cid) (struct)
{
@ -228,7 +228,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
t.Messages = c
}
// t.t.BLSAggregate (types.Signature) (struct)
// t.BLSAggregate (types.Signature) (struct)
{
@ -237,7 +237,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Timestamp (uint64) (uint64)
// t.Timestamp (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -247,7 +247,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Timestamp = uint64(extra)
// t.t.BlockSig (types.Signature) (struct)
// t.BlockSig (types.Signature) (struct)
{
@ -280,7 +280,7 @@ func (t *Ticket) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.VRFProof ([]uint8) (slice)
// t.VRFProof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.VRFProof)))); err != nil {
return err
}
@ -305,7 +305,7 @@ func (t *Ticket) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.VRFProof ([]uint8) (slice)
// t.VRFProof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -334,7 +334,7 @@ func (t *EPostProof) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Proof ([]uint8) (slice)
// t.Proof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil {
return err
}
@ -342,7 +342,7 @@ func (t *EPostProof) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.PostRand ([]uint8) (slice)
// t.PostRand ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.PostRand)))); err != nil {
return err
}
@ -350,7 +350,7 @@ func (t *EPostProof) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Candidates ([]types.EPostTicket) (slice)
// t.Candidates ([]types.EPostTicket) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Candidates)))); err != nil {
return err
}
@ -377,7 +377,7 @@ func (t *EPostProof) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Proof ([]uint8) (slice)
// t.Proof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -394,7 +394,7 @@ func (t *EPostProof) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.Proof); err != nil {
return err
}
// t.t.PostRand ([]uint8) (slice)
// t.PostRand ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -411,7 +411,7 @@ func (t *EPostProof) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.PostRand); err != nil {
return err
}
// t.t.Candidates ([]types.EPostTicket) (slice)
// t.Candidates ([]types.EPostTicket) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -450,7 +450,7 @@ func (t *EPostTicket) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Partial ([]uint8) (slice)
// t.Partial ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Partial)))); err != nil {
return err
}
@ -458,12 +458,12 @@ func (t *EPostTicket) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.SectorID (uint64) (uint64)
// t.SectorID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorID))); err != nil {
return err
}
// t.t.ChallengeIndex (uint64) (uint64)
// t.ChallengeIndex (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ChallengeIndex))); err != nil {
return err
}
@ -485,7 +485,7 @@ func (t *EPostTicket) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Partial ([]uint8) (slice)
// t.Partial ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -502,7 +502,7 @@ func (t *EPostTicket) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.Partial); err != nil {
return err
}
// t.t.SectorID (uint64) (uint64)
// t.SectorID (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -512,7 +512,7 @@ func (t *EPostTicket) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.SectorID = uint64(extra)
// t.t.ChallengeIndex (uint64) (uint64)
// t.ChallengeIndex (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -534,42 +534,42 @@ func (t *Message) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.To (address.Address) (struct)
// t.To (address.Address) (struct)
if err := t.To.MarshalCBOR(w); err != nil {
return err
}
// t.t.From (address.Address) (struct)
// t.From (address.Address) (struct)
if err := t.From.MarshalCBOR(w); err != nil {
return err
}
// t.t.Nonce (uint64) (uint64)
// t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err
}
// t.t.Value (types.BigInt) (struct)
// t.Value (types.BigInt) (struct)
if err := t.Value.MarshalCBOR(w); err != nil {
return err
}
// t.t.GasPrice (types.BigInt) (struct)
// t.GasPrice (types.BigInt) (struct)
if err := t.GasPrice.MarshalCBOR(w); err != nil {
return err
}
// t.t.GasLimit (types.BigInt) (struct)
// t.GasLimit (types.BigInt) (struct)
if err := t.GasLimit.MarshalCBOR(w); err != nil {
return err
}
// t.t.Method (uint64) (uint64)
// t.Method (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Method))); err != nil {
return err
}
// t.t.Params ([]uint8) (slice)
// t.Params ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Params)))); err != nil {
return err
}
@ -594,7 +594,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.To (address.Address) (struct)
// t.To (address.Address) (struct)
{
@ -603,7 +603,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.From (address.Address) (struct)
// t.From (address.Address) (struct)
{
@ -612,7 +612,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Nonce (uint64) (uint64)
// t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -622,7 +622,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Nonce = uint64(extra)
// t.t.Value (types.BigInt) (struct)
// t.Value (types.BigInt) (struct)
{
@ -631,7 +631,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.GasPrice (types.BigInt) (struct)
// t.GasPrice (types.BigInt) (struct)
{
@ -640,7 +640,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.GasLimit (types.BigInt) (struct)
// t.GasLimit (types.BigInt) (struct)
{
@ -649,7 +649,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Method (uint64) (uint64)
// t.Method (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -659,7 +659,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Method = uint64(extra)
// t.t.Params ([]uint8) (slice)
// t.Params ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -688,12 +688,12 @@ func (t *SignedMessage) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Message (types.Message) (struct)
// t.Message (types.Message) (struct)
if err := t.Message.MarshalCBOR(w); err != nil {
return err
}
// t.t.Signature (types.Signature) (struct)
// t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil {
return err
}
@ -715,7 +715,7 @@ func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Message (types.Message) (struct)
// t.Message (types.Message) (struct)
{
@ -724,7 +724,7 @@ func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Signature (types.Signature) (struct)
// t.Signature (types.Signature) (struct)
{
@ -745,13 +745,13 @@ func (t *MsgMeta) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.BlsMessages (cid.Cid) (struct)
// t.BlsMessages (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.BlsMessages); err != nil {
return xerrors.Errorf("failed to write cid field t.BlsMessages: %w", err)
}
// t.t.SecpkMessages (cid.Cid) (struct)
// t.SecpkMessages (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.SecpkMessages); err != nil {
return xerrors.Errorf("failed to write cid field t.SecpkMessages: %w", err)
@ -775,7 +775,7 @@ func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.BlsMessages (cid.Cid) (struct)
// t.BlsMessages (cid.Cid) (struct)
{
@ -787,7 +787,7 @@ func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error {
t.BlsMessages = c
}
// t.t.SecpkMessages (cid.Cid) (struct)
// t.SecpkMessages (cid.Cid) (struct)
{
@ -811,12 +811,12 @@ func (t *SignedVoucher) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.TimeLock (uint64) (uint64)
// t.TimeLock (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.TimeLock))); err != nil {
return err
}
// t.t.SecretPreimage ([]uint8) (slice)
// t.SecretPreimage ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.SecretPreimage)))); err != nil {
return err
}
@ -824,32 +824,32 @@ func (t *SignedVoucher) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Extra (types.ModVerifyParams) (struct)
// t.Extra (types.ModVerifyParams) (struct)
if err := t.Extra.MarshalCBOR(w); err != nil {
return err
}
// t.t.Lane (uint64) (uint64)
// t.Lane (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Lane))); err != nil {
return err
}
// t.t.Nonce (uint64) (uint64)
// t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err
}
// t.t.Amount (types.BigInt) (struct)
// t.Amount (types.BigInt) (struct)
if err := t.Amount.MarshalCBOR(w); err != nil {
return err
}
// t.t.MinCloseHeight (uint64) (uint64)
// t.MinCloseHeight (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.MinCloseHeight))); err != nil {
return err
}
// t.t.Merges ([]types.Merge) (slice)
// t.Merges ([]types.Merge) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Merges)))); err != nil {
return err
}
@ -859,7 +859,7 @@ func (t *SignedVoucher) MarshalCBOR(w io.Writer) error {
}
}
// t.t.Signature (types.Signature) (struct)
// t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil {
return err
}
@ -881,7 +881,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.TimeLock (uint64) (uint64)
// t.TimeLock (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -891,7 +891,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.TimeLock = uint64(extra)
// t.t.SecretPreimage ([]uint8) (slice)
// t.SecretPreimage ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -908,7 +908,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.SecretPreimage); err != nil {
return err
}
// t.t.Extra (types.ModVerifyParams) (struct)
// t.Extra (types.ModVerifyParams) (struct)
{
@ -929,7 +929,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Lane (uint64) (uint64)
// t.Lane (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -939,7 +939,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Lane = uint64(extra)
// t.t.Nonce (uint64) (uint64)
// t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -949,7 +949,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Nonce = uint64(extra)
// t.t.Amount (types.BigInt) (struct)
// t.Amount (types.BigInt) (struct)
{
@ -958,7 +958,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.MinCloseHeight (uint64) (uint64)
// t.MinCloseHeight (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -968,7 +968,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.MinCloseHeight = uint64(extra)
// t.t.Merges ([]types.Merge) (slice)
// t.Merges ([]types.Merge) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -995,7 +995,7 @@ func (t *SignedVoucher) UnmarshalCBOR(r io.Reader) error {
t.Merges[i] = v
}
// t.t.Signature (types.Signature) (struct)
// t.Signature (types.Signature) (struct)
{
@ -1028,17 +1028,17 @@ func (t *ModVerifyParams) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Actor (address.Address) (struct)
// t.Actor (address.Address) (struct)
if err := t.Actor.MarshalCBOR(w); err != nil {
return err
}
// t.t.Method (uint64) (uint64)
// t.Method (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Method))); err != nil {
return err
}
// t.t.Data ([]uint8) (slice)
// t.Data ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Data)))); err != nil {
return err
}
@ -1063,7 +1063,7 @@ func (t *ModVerifyParams) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Actor (address.Address) (struct)
// t.Actor (address.Address) (struct)
{
@ -1072,7 +1072,7 @@ func (t *ModVerifyParams) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Method (uint64) (uint64)
// t.Method (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1082,7 +1082,7 @@ func (t *ModVerifyParams) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Method = uint64(extra)
// t.t.Data ([]uint8) (slice)
// t.Data ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1111,12 +1111,12 @@ func (t *Merge) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Lane (uint64) (uint64)
// t.Lane (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Lane))); err != nil {
return err
}
// t.t.Nonce (uint64) (uint64)
// t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err
}
@ -1138,7 +1138,7 @@ func (t *Merge) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Lane (uint64) (uint64)
// t.Lane (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1148,7 +1148,7 @@ func (t *Merge) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Lane = uint64(extra)
// t.t.Nonce (uint64) (uint64)
// t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1170,24 +1170,24 @@ func (t *Actor) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Code (cid.Cid) (struct)
// t.Code (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Code); err != nil {
return xerrors.Errorf("failed to write cid field t.Code: %w", err)
}
// t.t.Head (cid.Cid) (struct)
// t.Head (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Head); err != nil {
return xerrors.Errorf("failed to write cid field t.Head: %w", err)
}
// t.t.Nonce (uint64) (uint64)
// t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err
}
// t.t.Balance (types.BigInt) (struct)
// t.Balance (types.BigInt) (struct)
if err := t.Balance.MarshalCBOR(w); err != nil {
return err
}
@ -1209,7 +1209,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Code (cid.Cid) (struct)
// t.Code (cid.Cid) (struct)
{
@ -1221,7 +1221,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
t.Code = c
}
// t.t.Head (cid.Cid) (struct)
// t.Head (cid.Cid) (struct)
{
@ -1233,7 +1233,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
t.Head = c
}
// t.t.Nonce (uint64) (uint64)
// t.Nonce (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1243,7 +1243,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Nonce = uint64(extra)
// t.t.Balance (types.BigInt) (struct)
// t.Balance (types.BigInt) (struct)
{
@ -1264,12 +1264,12 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.ExitCode (uint8) (uint8)
// t.ExitCode (uint8) (uint8)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ExitCode))); err != nil {
return err
}
// t.t.Return ([]uint8) (slice)
// t.Return ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Return)))); err != nil {
return err
}
@ -1277,7 +1277,7 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.GasUsed (types.BigInt) (struct)
// t.GasUsed (types.BigInt) (struct)
if err := t.GasUsed.MarshalCBOR(w); err != nil {
return err
}
@ -1299,7 +1299,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.ExitCode (uint8) (uint8)
// t.ExitCode (uint8) (uint8)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1312,7 +1312,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("integer in input was too large for uint8 field")
}
t.ExitCode = uint8(extra)
// t.t.Return ([]uint8) (slice)
// t.Return ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1329,7 +1329,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.Return); err != nil {
return err
}
// t.t.GasUsed (types.BigInt) (struct)
// t.GasUsed (types.BigInt) (struct)
{
@ -1350,12 +1350,12 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Header (types.BlockHeader) (struct)
// t.Header (types.BlockHeader) (struct)
if err := t.Header.MarshalCBOR(w); err != nil {
return err
}
// t.t.BlsMessages ([]cid.Cid) (slice)
// t.BlsMessages ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BlsMessages)))); err != nil {
return err
}
@ -1365,7 +1365,7 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error {
}
}
// t.t.SecpkMessages ([]cid.Cid) (slice)
// t.SecpkMessages ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.SecpkMessages)))); err != nil {
return err
}
@ -1392,7 +1392,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Header (types.BlockHeader) (struct)
// t.Header (types.BlockHeader) (struct)
{
@ -1413,7 +1413,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.BlsMessages ([]cid.Cid) (slice)
// t.BlsMessages ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1439,7 +1439,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error {
t.BlsMessages[i] = c
}
// t.t.SecpkMessages ([]cid.Cid) (slice)
// t.SecpkMessages ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1477,12 +1477,12 @@ func (t *SignedStorageAsk) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Ask (types.StorageAsk) (struct)
// t.Ask (types.StorageAsk) (struct)
if err := t.Ask.MarshalCBOR(w); err != nil {
return err
}
// t.t.Signature (types.Signature) (struct)
// t.Signature (types.Signature) (struct)
if err := t.Signature.MarshalCBOR(w); err != nil {
return err
}
@ -1504,7 +1504,7 @@ func (t *SignedStorageAsk) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Ask (types.StorageAsk) (struct)
// t.Ask (types.StorageAsk) (struct)
{
@ -1525,7 +1525,7 @@ func (t *SignedStorageAsk) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Signature (types.Signature) (struct)
// t.Signature (types.Signature) (struct)
{
@ -1558,32 +1558,32 @@ func (t *StorageAsk) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Price (types.BigInt) (struct)
// t.Price (types.BigInt) (struct)
if err := t.Price.MarshalCBOR(w); err != nil {
return err
}
// t.t.MinPieceSize (uint64) (uint64)
// t.MinPieceSize (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.MinPieceSize))); err != nil {
return err
}
// t.t.Miner (address.Address) (struct)
// t.Miner (address.Address) (struct)
if err := t.Miner.MarshalCBOR(w); err != nil {
return err
}
// t.t.Timestamp (uint64) (uint64)
// t.Timestamp (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Timestamp))); err != nil {
return err
}
// t.t.Expiry (uint64) (uint64)
// t.Expiry (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Expiry))); err != nil {
return err
}
// t.t.SeqNo (uint64) (uint64)
// t.SeqNo (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SeqNo))); err != nil {
return err
}
@ -1605,7 +1605,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Price (types.BigInt) (struct)
// t.Price (types.BigInt) (struct)
{
@ -1614,7 +1614,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.MinPieceSize (uint64) (uint64)
// t.MinPieceSize (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1624,7 +1624,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.MinPieceSize = uint64(extra)
// t.t.Miner (address.Address) (struct)
// t.Miner (address.Address) (struct)
{
@ -1633,7 +1633,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Timestamp (uint64) (uint64)
// t.Timestamp (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1643,7 +1643,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Timestamp = uint64(extra)
// t.t.Expiry (uint64) (uint64)
// t.Expiry (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1653,7 +1653,7 @@ func (t *StorageAsk) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Expiry = uint64(extra)
// t.t.SeqNo (uint64) (uint64)
// t.SeqNo (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1675,7 +1675,7 @@ func (t *ExpTipSet) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Cids ([]cid.Cid) (slice)
// t.Cids ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Cids)))); err != nil {
return err
}
@ -1685,7 +1685,7 @@ func (t *ExpTipSet) MarshalCBOR(w io.Writer) error {
}
}
// t.t.Blocks ([]*types.BlockHeader) (slice)
// t.Blocks ([]*types.BlockHeader) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Blocks)))); err != nil {
return err
}
@ -1695,7 +1695,7 @@ func (t *ExpTipSet) MarshalCBOR(w io.Writer) error {
}
}
// t.t.Height (uint64) (uint64)
// t.Height (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Height))); err != nil {
return err
}
@ -1717,7 +1717,7 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Cids ([]cid.Cid) (slice)
// t.Cids ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1743,7 +1743,7 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error {
t.Cids[i] = c
}
// t.t.Blocks ([]*types.BlockHeader) (slice)
// t.Blocks ([]*types.BlockHeader) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -1770,7 +1770,7 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error {
t.Blocks[i] = &v
}
// t.t.Height (uint64) (uint64)
// t.Height (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {

View File

@ -10,6 +10,7 @@ import (
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
)
var log = logging.Logger("types")
@ -95,6 +96,10 @@ func tipsetSortFunc(blks []*BlockHeader) func(i, j int) bool {
}
func NewTipSet(blks []*BlockHeader) (*TipSet, error) {
if len(blks) == 0 {
return nil, xerrors.Errorf("NewTipSet called with zero length array of blocks")
}
sort.Slice(blks, tipsetSortFunc(blks))
var ts TipSet

View File

@ -40,10 +40,15 @@ type VMContext interface {
ChargeGas(uint64) aerrors.ActorError
GetRandomness(height uint64) ([]byte, aerrors.ActorError)
GetBalance(address.Address) (BigInt, aerrors.ActorError)
Sys() *VMSyscalls
Context() context.Context
}
type VMSyscalls struct {
ValidatePoRep func(context.Context, address.Address, uint64, []byte, []byte, []byte, []byte, []byte, uint64) (bool, aerrors.ActorError)
}
type storageWrapper struct {
s Storage
}

View File

@ -48,7 +48,7 @@ func makeActor(st *state.StateTree, addr address.Address) (*types.Actor, aerrors
case address.SECP256K1:
return NewSecp256k1AccountActor(st, addr)
case address.ID:
return nil, aerrors.New(1, "no actor with given ID")
return nil, aerrors.Newf(1, "no actor with given ID: %s", addr)
case address.Actor:
return nil, aerrors.Newf(1, "no such actor: %s", addr)
default:

14
chain/vm/syscalls.go Normal file
View File

@ -0,0 +1,14 @@
package vm
import (
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
)
// Actual type is defined in chain/types/vmcontext.go because the VMContext interface is there
func DefaultSyscalls() *types.VMSyscalls {
return &types.VMSyscalls{
ValidatePoRep: actors.ValidatePoRep,
}
}

View File

@ -54,6 +54,8 @@ type VMContext struct {
gasAvailable types.BigInt
gasUsed types.BigInt
sys *types.VMSyscalls
// root cid of the state of the actor this invocation will be on
sroot cid.Cid
@ -75,6 +77,10 @@ func (vmc *VMContext) GetRandomness(height uint64) ([]byte, aerrors.ActorError)
return res, nil
}
func (vmc *VMContext) Sys() *types.VMSyscalls {
return vmc.sys
}
// Storage interface
func (vmc *VMContext) Put(i cbg.CBORMarshaler) (cid.Cid, aerrors.ActorError) {
@ -284,6 +290,7 @@ func (vm *VM) makeVMContext(ctx context.Context, sroot cid.Cid, msg *types.Messa
msg: msg,
origin: origin,
height: vm.blockHeight,
sys: vm.Syscalls,
gasUsed: usedGas,
gasAvailable: msg.GasLimit,
@ -304,6 +311,8 @@ type VM struct {
blockMiner address.Address
inv *invoker
rand Rand
Syscalls *types.VMSyscalls
}
func NewVM(base cid.Cid, height uint64, r Rand, maddr address.Address, cbs blockstore.Blockstore) (*VM, error) {
@ -323,6 +332,7 @@ func NewVM(base cid.Cid, height uint64, r Rand, maddr address.Address, cbs block
blockMiner: maddr,
inv: newInvoker(),
rand: r,
Syscalls: DefaultSyscalls(),
}, nil
}

View File

@ -9,10 +9,12 @@ import (
"github.com/filecoin-project/lotus/chain/types"
)
const HalvingPeriodEpochs = 6 * 365 * 24 * 60 * 2
func TestBlockReward(t *testing.T) {
coffer := types.FromFil(build.MiningRewardTotal).Int
sum := new(big.Int)
N := build.HalvingPeriodEpochs
N := HalvingPeriodEpochs
for i := 0; i < N; i++ {
a := MiningReward(types.BigInt{coffer})
sum = sum.Add(sum, a.Int)

View File

@ -6,7 +6,7 @@ import (
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/apistruct"
)
var authCmd = &cli.Command{
@ -42,18 +42,18 @@ var authCreateAdminToken = &cli.Command{
perm := cctx.String("perm")
idx := 0
for i, p := range api.AllPermissions {
for i, p := range apistruct.AllPermissions {
if perm == p {
idx = i + 1
}
}
if idx == 0 {
return fmt.Errorf("--perm flag has to be one of: %s", api.AllPermissions)
return fmt.Errorf("--perm flag has to be one of: %s", apistruct.AllPermissions)
}
// slice on [:idx] so for example: 'sign' gives you [read, write, sign]
token, err := napi.AuthNew(ctx, api.AllPermissions[:idx])
token, err := napi.AuthNew(ctx, apistruct.AllPermissions[:idx])
if err != nil {
return err
}

View File

@ -236,7 +236,7 @@ var clientRetrieveCmd = &cli.Command{
}
if err := api.ClientRetrieve(ctx, offers[0].Order(payer), cctx.Args().Get(1)); err != nil {
return err
return xerrors.Errorf("Retrieval Failed: %w", err)
}
fmt.Println("Success")

View File

@ -1,6 +1,7 @@
package cli
import (
"github.com/docker/go-units"
"github.com/filecoin-project/lotus/build"
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
@ -10,13 +11,18 @@ var fetchParamCmd = &cli.Command{
Name: "fetch-params",
Usage: "Fetch proving parameters",
Flags: []cli.Flag{
&cli.Uint64Flag{
&cli.StringFlag{
Name: "proving-params",
Usage: "download params used creating proofs for given size",
Usage: "download params used creating proofs for given size, i.e. 32GiB",
},
},
Action: func(cctx *cli.Context) error {
err := build.GetParams(cctx.Uint64("proving-params"))
sectorSizeInt, err := units.FromHumanSize(cctx.String("proving-params"))
if err != nil {
return err
}
sectorSize := uint64(sectorSizeInt)
err = build.GetParams(sectorSize)
if err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err)
}

24
cli/utils.go Normal file
View File

@ -0,0 +1,24 @@
package cli
import (
"fmt"
"math/big"
"github.com/filecoin-project/lotus/chain/types"
)
var Units = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"}
func SizeStr(size types.BigInt) string {
r := new(big.Rat).SetInt(size.Int)
den := big.NewRat(1, 1024)
var i int
for f, _ := r.Float64(); f >= 1024 && 1 < len(Units); f, _ = r.Float64() {
i++
r = r.Mul(r, den)
}
f, _ := r.Float64()
return fmt.Sprintf("%.3g %s", f, Units[i])
}

27
cli/utils_test.go Normal file
View File

@ -0,0 +1,27 @@
package cli
import (
"testing"
types "github.com/filecoin-project/lotus/chain/types"
"github.com/stretchr/testify/assert"
)
func TestSizeStr(t *testing.T) {
cases := []struct {
in uint64
out string
}{
{0, "0 B"},
{1, "1 B"},
{1024, "1 KiB"},
{2000, "1.95 KiB"},
{5 << 20, "5 MiB"},
{11 << 60, "11 EiB"},
}
for _, c := range cases {
assert.Equal(t, c.out, SizeStr(types.NewInt(c.in)), "input %+v, produced wrong result", c)
}
}

View File

@ -19,7 +19,11 @@ var versionCmd = &cli.Command{
ctx := ReqContext(cctx)
// TODO: print more useful things
fmt.Println(api.Version(ctx))
v, err := api.Version(ctx)
if err != nil {
return err
}
fmt.Println(v)
cli.VersionPrinter(cctx)
return nil
},

View File

@ -4,14 +4,18 @@ import (
"bytes"
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"github.com/docker/go-units"
"io/ioutil"
"math/big"
"math/rand"
"os"
"path/filepath"
"time"
ffi "github.com/filecoin-project/filecoin-ffi"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log"
"github.com/mitchellh/go-homedir"
@ -20,6 +24,8 @@ import (
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/genesis"
"github.com/filecoin-project/lotus/lib/sectorbuilder"
)
@ -60,56 +66,91 @@ func main() {
Value: "~/.lotus-bench",
Usage: "Path to the storage directory that will store sectors long term",
},
&cli.Uint64Flag{
&cli.StringFlag{
Name: "sector-size",
Value: 1024,
Value: "1GiB",
Usage: "size of the sectors in bytes, i.e. 32GiB",
},
&cli.BoolFlag{
Name: "no-gpu",
Usage: "disable gpu usage for the benchmark run",
},
&cli.StringFlag{
Name: "miner-addr",
Usage: "pass miner address (only necessary if using existing sectorbuilder)",
Value: "t0101",
},
&cli.StringFlag{
Name: "benchmark-existing-sectorbuilder",
Usage: "pass a directory to run election-post timings on an existing sectorbuilder",
},
&cli.BoolFlag{
Name: "json-out",
Usage: "output results in json format",
},
},
Action: func(c *cli.Context) error {
if c.Bool("no-gpu") {
os.Setenv("BELLMAN_NO_GPU", "1")
}
sdir, err := homedir.Expand(c.String("storage-dir"))
if err != nil {
return err
}
os.MkdirAll(sdir, 0775)
robench := c.String("benchmark-existing-sectorbuilder")
tsdir, err := ioutil.TempDir(sdir, "bench")
if err != nil {
return err
}
defer func() {
if err := os.RemoveAll(tsdir); err != nil {
log.Warn("remove all: ", err)
var sbdir string
if robench == "" {
sdir, err := homedir.Expand(c.String("storage-dir"))
if err != nil {
return err
}
}()
maddr, err := address.NewFromString("t0101")
os.MkdirAll(sdir, 0775)
tsdir, err := ioutil.TempDir(sdir, "bench")
if err != nil {
return err
}
defer func() {
if err := os.RemoveAll(tsdir); err != nil {
log.Warn("remove all: ", err)
}
}()
sbdir = tsdir
} else {
exp, err := homedir.Expand(robench)
if err != nil {
return err
}
sbdir = exp
}
maddr, err := address.NewFromString(c.String("miner-addr"))
if err != nil {
return err
}
sectorSize := c.Uint64("sector-size")
sectorSizeInt, err := units.FromHumanSize(c.String("sector-size"))
if err != nil {
return err
}
sectorSize := uint64(sectorSizeInt)
mds := datastore.NewMapDatastore()
cfg := &sectorbuilder.Config{
Miner: maddr,
SectorSize: sectorSize,
WorkerThreads: 2,
CacheDir: filepath.Join(tsdir, "cache"),
SealedDir: filepath.Join(tsdir, "sealed"),
StagedDir: filepath.Join(tsdir, "staged"),
UnsealedDir: filepath.Join(tsdir, "unsealed"),
CacheDir: filepath.Join(sbdir, "cache"),
SealedDir: filepath.Join(sbdir, "sealed"),
StagedDir: filepath.Join(sbdir, "staged"),
UnsealedDir: filepath.Join(sbdir, "unsealed"),
}
for _, d := range []string{cfg.CacheDir, cfg.SealedDir, cfg.StagedDir, cfg.UnsealedDir} {
if err := os.MkdirAll(d, 0775); err != nil {
return err
if robench == "" {
for _, d := range []string{cfg.CacheDir, cfg.SealedDir, cfg.StagedDir, cfg.UnsealedDir} {
if err := os.MkdirAll(d, 0775); err != nil {
return err
}
}
}
@ -126,7 +167,7 @@ func main() {
var sealTimings []SealingResult
var sealedSectors []ffi.PublicSectorInfo
numSectors := uint64(1)
for i := uint64(1); i <= numSectors; i++ {
for i := uint64(1); i <= numSectors && robench == ""; i++ {
start := time.Now()
log.Info("Writing piece into sector...")
@ -207,6 +248,34 @@ func main() {
var challenge [32]byte
rand.Read(challenge[:])
if robench != "" {
// TODO: this assumes we only ever benchmark a preseal
// sectorbuilder directory... we need a better way to handle
// this in other cases
fdata, err := ioutil.ReadFile(filepath.Join(sbdir, "pre-seal-"+maddr.String()+".json"))
if err != nil {
return err
}
var genmm map[string]genesis.GenesisMiner
if err := json.Unmarshal(fdata, &genmm); err != nil {
return err
}
genm, ok := genmm[maddr.String()]
if !ok {
return xerrors.Errorf("preseal file didnt have expected miner in it")
}
for _, s := range genm.Sectors {
sealedSectors = append(sealedSectors, ffi.PublicSectorInfo{
CommR: s.CommR,
SectorID: s.SectorID,
})
}
}
log.Info("generating election post candidates")
sinfos := sectorbuilder.NewSortedPublicSectorInfo(sealedSectors)
candidates, err := sb.GenerateEPostCandidates(sinfos, challenge, []uint64{})
@ -255,7 +324,7 @@ func main() {
}
verifypost2 := time.Now()
benchout := BenchResults{
bo := BenchResults{
SectorSize: cfg.SectorSize,
SealingResults: sealTimings,
@ -266,17 +335,28 @@ func main() {
VerifyEPostHot: verifypost2.Sub(verifypost1),
} // TODO: optionally write this as json to a file
fmt.Println("results")
fmt.Printf("seal: addPiece: %s\n", benchout.SealingResults[0].AddPiece) // TODO: average across multiple sealings
fmt.Printf("seal: preCommit: %s\n", benchout.SealingResults[0].PreCommit)
fmt.Printf("seal: Commit: %s\n", benchout.SealingResults[0].Commit)
fmt.Printf("seal: Verify: %s\n", benchout.SealingResults[0].Verify)
fmt.Printf("unseal: %s\n", benchout.SealingResults[0].Unseal)
fmt.Printf("generate candidates: %s\n", benchout.PostGenerateCandidates)
fmt.Printf("compute epost proof (cold): %s\n", benchout.PostEProofCold)
fmt.Printf("compute epost proof (hot): %s\n", benchout.PostEProofHot)
fmt.Printf("verify epost proof (cold): %s\n", benchout.VerifyEPostCold)
fmt.Printf("verify epost proof (hot): %s\n", benchout.VerifyEPostHot)
if c.Bool("json-out") {
data, err := json.MarshalIndent(bo, "", " ")
if err != nil {
return err
}
fmt.Println(string(data))
} else {
fmt.Printf("results (%d)\n", sectorSize)
if robench == "" {
fmt.Printf("seal: addPiece: %s (%s)\n", bo.SealingResults[0].AddPiece, bps(bo.SectorSize, bo.SealingResults[0].AddPiece)) // TODO: average across multiple sealings
fmt.Printf("seal: preCommit: %s (%s)\n", bo.SealingResults[0].PreCommit, bps(bo.SectorSize, bo.SealingResults[0].PreCommit))
fmt.Printf("seal: commit: %s (%s)\n", bo.SealingResults[0].Commit, bps(bo.SectorSize, bo.SealingResults[0].Commit))
fmt.Printf("seal: verify: %s\n", bo.SealingResults[0].Verify)
fmt.Printf("unseal: %s (%s)\n", bo.SealingResults[0].Unseal, bps(bo.SectorSize, bo.SealingResults[0].Unseal))
}
fmt.Printf("generate candidates: %s (%s)\n", bo.PostGenerateCandidates, bps(bo.SectorSize*uint64(len(bo.SealingResults)), bo.PostGenerateCandidates))
fmt.Printf("compute epost proof (cold): %s\n", bo.PostEProofCold)
fmt.Printf("compute epost proof (hot): %s\n", bo.PostEProofHot)
fmt.Printf("verify epost proof (cold): %s\n", bo.VerifyEPostCold)
fmt.Printf("verify epost proof (hot): %s\n", bo.VerifyEPostHot)
}
return nil
},
}
@ -286,3 +366,10 @@ func main() {
return
}
}
func bps(data uint64, d time.Duration) string {
bdata := new(big.Int).SetUint64(data)
bdata = bdata.Mul(bdata, big.NewInt(time.Second.Nanoseconds()))
bps := bdata.Div(bdata, big.NewInt(d.Nanoseconds()))
return lcli.SizeStr(types.BigInt{bps}) + "/s"
}

View File

@ -100,7 +100,7 @@ var runCmd = &cli.Command{
IPRate: time.Minute,
IPBurst: 5,
WalletRate: 15 * time.Minute,
WalletBurst: 1,
WalletBurst: 2,
}),
minerLimiter: NewLimiter(LimiterConfig{
TotalRate: time.Second,
@ -108,7 +108,7 @@ var runCmd = &cli.Command{
IPRate: 10 * time.Minute,
IPBurst: 2,
WalletRate: 1 * time.Hour,
WalletBurst: 1,
WalletBurst: 2,
}),
}
@ -150,7 +150,7 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) {
// Limit based on wallet address
limiter := h.limiter.GetWalletLimiter(to.String())
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
http.Error(w, http.StatusText(http.StatusTooManyRequests)+": wallet limit", http.StatusTooManyRequests)
return
}
@ -170,13 +170,13 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) {
limiter = h.limiter.GetIPLimiter(reqIP)
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
http.Error(w, http.StatusText(http.StatusTooManyRequests)+": IP limit", http.StatusTooManyRequests)
return
}
// General limiter to allow throttling all messages that can make it into the mpool
if !h.limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
http.Error(w, http.StatusText(http.StatusTooManyRequests)+": global limit", http.StatusTooManyRequests)
return
}
@ -221,20 +221,20 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
// Limit based on wallet address
limiter := h.minerLimiter.GetWalletLimiter(owner.String())
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
http.Error(w, http.StatusText(http.StatusTooManyRequests)+": wallet limit", http.StatusTooManyRequests)
return
}
// Limit based on IP
limiter = h.minerLimiter.GetIPLimiter(r.RemoteAddr)
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
http.Error(w, http.StatusText(http.StatusTooManyRequests)+": IP limit", http.StatusTooManyRequests)
return
}
// General limiter owner allow throttling all messages that can make it into the mpool
if !h.minerLimiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
http.Error(w, http.StatusText(http.StatusTooManyRequests)+": global limit", http.StatusTooManyRequests)
return
}

View File

@ -17,8 +17,6 @@
<select name="sectorSize">
<option selected value="1073741824">1GiB sectors</option>
<option value="34359738368">32GiB sectors</option>
<option value="268435456">256MiB sectors</option>
<option value="16777216">16MiB sectors</option>
</select>
<button type='submit'>Create Miner</button>
</form>

View File

@ -179,7 +179,7 @@ var aggregateSectorDirsCmd = &cli.Command{
return err
}
if err := os.MkdirAll(cctx.String("dest"), 0755); err != nil {
if err := os.MkdirAll(destdir, 0755); err != nil {
return err
}
@ -204,6 +204,7 @@ var aggregateSectorDirsCmd = &cli.Command{
return err
}
var aggrGenMiner genesis.GenesisMiner
var highestSectorID uint64
for _, dir := range cctx.Args().Slice() {
dir, err := homedir.Expand(dir)
@ -244,6 +245,8 @@ var aggregateSectorDirsCmd = &cli.Command{
}
}
aggrGenMiner = mergeGenMiners(aggrGenMiner, genm)
opts := badger.DefaultOptions
opts.ReadOnly = true
mds, err := badger.NewDatastore(filepath.Join(dir, "badger"), &opts)
@ -265,7 +268,7 @@ var aggregateSectorDirsCmd = &cli.Command{
return err
}
if err := agsb.ImportFrom(sb); err != nil {
if err := agsb.ImportFrom(sb, false); err != nil {
return xerrors.Errorf("importing sectors from %q failed: %w", dir, err)
}
}
@ -274,6 +277,10 @@ var aggregateSectorDirsCmd = &cli.Command{
return err
}
if err := seed.WriteGenesisMiner(maddr, destdir, &aggrGenMiner); err != nil {
return err
}
return nil
},
}

View File

@ -2,11 +2,11 @@ package seed
import (
"context"
"crypto/rand"
"crypto/sha256"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
@ -53,7 +53,6 @@ func PreSeal(maddr address.Address, ssize uint64, offset uint64, sectors int, sb
return nil, err
}
r := rand.New(rand.NewSource(101))
size := sectorbuilder.UserBytesForSectorSize(ssize)
var sealedSectors []*genesis.PreSeal
@ -63,7 +62,7 @@ func PreSeal(maddr address.Address, ssize uint64, offset uint64, sectors int, sb
return nil, err
}
pi, err := sb.AddPiece(size, sid, r, nil)
pi, err := sb.AddPiece(size, sid, rand.Reader, nil)
if err != nil {
return nil, err
}
@ -143,7 +142,6 @@ func createDeals(m *genesis.GenesisMiner, k *wallet.Key, maddr address.Address,
proposal := &actors.StorageDealProposal{
PieceRef: pref, // just one deal so this == CommP
PieceSize: sectorbuilder.UserBytesForSectorSize(ssize),
PieceSerialization: actors.SerializationUnixFSv0,
Client: k.Address,
Provider: maddr,
ProposalExpiration: 9000, // TODO: allow setting
@ -153,20 +151,12 @@ func createDeals(m *genesis.GenesisMiner, k *wallet.Key, maddr address.Address,
ProposerSignature: nil,
}
// TODO: pretty sure we don't even need to sign this
if err := api.SignWith(context.TODO(), wallet.KeyWallet(k).Sign, k.Address, proposal); err != nil {
return err
}
deal := &actors.StorageDeal{
Proposal: *proposal,
CounterSignature: nil,
}
if err := api.SignWith(context.TODO(), wallet.KeyWallet(k).Sign, k.Address, deal); err != nil {
return err
}
sector.Deal = *deal
sector.Deal = *proposal
}
return nil

52
cmd/lotus-shed/base16.go Normal file
View File

@ -0,0 +1,52 @@
package main
import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"gopkg.in/urfave/cli.v2"
)
var base16Cmd = &cli.Command{
Name: "base16",
Description: "standard hex",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "decode",
Value: false,
Usage: "Decode the value",
},
},
Action: func(cctx *cli.Context) error {
var input io.Reader
if cctx.Args().Len() == 0 {
input = os.Stdin
} else {
input = strings.NewReader(cctx.Args().First())
}
bytes, err := ioutil.ReadAll(input)
if err != nil {
return nil
}
if cctx.Bool("decode") {
decoded, err := hex.DecodeString(strings.TrimSpace(string(bytes)))
if err != nil {
return err
}
fmt.Println(string(decoded))
} else {
encoded := hex.EncodeToString(bytes)
fmt.Println(encoded)
}
return nil
},
}

53
cmd/lotus-shed/base32.go Normal file
View File

@ -0,0 +1,53 @@
package main
import (
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"gopkg.in/urfave/cli.v2"
"github.com/multiformats/go-base32"
)
var base32Cmd = &cli.Command{
Name: "base32",
Description: "multiformats base32",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "decode",
Value: false,
Usage: "Decode the multiformats base32",
},
},
Action: func(cctx *cli.Context) error {
var input io.Reader
if cctx.Args().Len() == 0 {
input = os.Stdin
} else {
input = strings.NewReader(cctx.Args().First())
}
bytes, err := ioutil.ReadAll(input)
if err != nil {
return nil
}
if cctx.Bool("decode") {
decoded, err := base32.RawStdEncoding.DecodeString(strings.TrimSpace(string(bytes)))
if err != nil {
return err
}
fmt.Println(string(decoded))
} else {
encoded := base32.RawStdEncoding.EncodeToString(bytes)
fmt.Println(encoded)
}
return nil
},
}

84
cmd/lotus-shed/keyinfo.go Normal file
View File

@ -0,0 +1,84 @@
package main
import (
"encoding/hex"
"encoding/json"
"io"
"io/ioutil"
"os"
"strings"
"text/template"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
)
type walletInfo struct {
Type string
Address string
PublicKey string
}
func (wi walletInfo) String() string {
bs, _ := json.Marshal(wi)
return string(bs)
}
var keyinfoCmd = &cli.Command{
Name: "keyinfo",
Description: "decode a keyinfo",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "format",
Value: "{{.Address}}",
Usage: "Format to output",
},
},
Action: func(cctx *cli.Context) error {
format := cctx.String("format")
var input io.Reader
if cctx.Args().Len() == 0 {
input = os.Stdin
} else {
input = strings.NewReader(cctx.Args().First())
}
bytes, err := ioutil.ReadAll(input)
data, err := hex.DecodeString(strings.TrimSpace(string(bytes)))
if err != nil {
return err
}
var ki types.KeyInfo
if err := json.Unmarshal(data, &ki); err != nil {
return err
}
key, err := wallet.NewKey(ki)
if err != nil {
return err
}
bs, err := json.Marshal(key)
if err != nil {
return err
}
var wi walletInfo
if err := json.Unmarshal(bs, &wi); err != nil {
return err
}
tmpl, err := template.New("").Parse(format)
if err != nil {
return err
}
return tmpl.Execute(os.Stdout, wi)
},
}

36
cmd/lotus-shed/main.go Normal file
View File

@ -0,0 +1,36 @@
package main
import (
"os"
logging "github.com/ipfs/go-log"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/lotus/build"
)
var log = logging.Logger("lotus-shed")
func main() {
logging.SetLogLevel("*", "INFO")
local := []*cli.Command{
base32Cmd,
base16Cmd,
keyinfoCmd,
peerkeyCmd,
}
app := &cli.App{
Name: "lotus-shed",
Usage: "A place for all the lotus tools",
Version: build.Version,
Commands: local,
}
if err := app.Run(os.Args); err != nil {
log.Warnf("%+v", err)
os.Exit(1)
return
}
}

105
cmd/lotus-shed/peerkey.go Normal file
View File

@ -0,0 +1,105 @@
package main
import (
"encoding/json"
"fmt"
"os"
"strings"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/modules/lp2p"
"github.com/libp2p/go-libp2p-core/peer"
)
type keystore struct {
set bool
info types.KeyInfo
}
func (ks *keystore) Put(name string, info types.KeyInfo) error {
ks.info = info
ks.set = true
return nil
}
func (ks *keystore) Get(name string) (types.KeyInfo, error) {
if !ks.set {
return types.KeyInfo{}, types.ErrKeyInfoNotFound
}
return ks.info, nil
}
func (ks *keystore) Delete(name string) error {
panic("Implement me")
return nil
}
func (ks *keystore) List() ([]string, error) {
panic("Implement me")
return []string{}, nil
}
var peerkeyCmd = &cli.Command{
Name: "peerkey",
Description: "create libp2p host key",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "output",
Value: "<peerid>.peerkey",
Usage: "Output file format",
},
&cli.BoolFlag{
Name: "silent",
Value: false,
Usage: "Do not print peerid at end",
},
},
Action: func(cctx *cli.Context) error {
output := cctx.String("output")
ks := keystore{}
sk, err := lp2p.PrivKey(&ks)
if err != nil {
return err
}
bs, err := json.Marshal(ks.info)
if err != nil {
return err
}
peerid, err := peer.IDFromPrivateKey(sk)
if err != nil {
return err
}
output = strings.ReplaceAll(output, "<peerid>", peerid.String())
f, err := os.Create(output)
if err != nil {
return err
}
defer func() {
if err := f.Close(); err != nil {
log.Warnf("failed to close output file: %w", err)
}
}()
if _, err := f.Write(bs); err != nil {
return err
}
if !cctx.Bool("silent") {
fmt.Println(peerid.String())
}
return nil
},
}

View File

@ -43,7 +43,7 @@ var infoCmd = &cli.Command{
return err
}
fmt.Printf("Sector Size: %s\n", sizeStr(types.NewInt(sizeByte)))
fmt.Printf("Sector Size: %s\n", lcli.SizeStr(types.NewInt(sizeByte)))
pow, err := api.StateMinerPower(ctx, maddr, nil)
if err != nil {
@ -51,7 +51,7 @@ var infoCmd = &cli.Command{
}
percI := types.BigDiv(types.BigMul(pow.MinerPower, types.NewInt(1000)), pow.TotalPower)
fmt.Printf("Power: %s / %s (%0.4f%%)\n", sizeStr(pow.MinerPower), sizeStr(pow.TotalPower), float64(percI.Int64())/100000*10000)
fmt.Printf("Power: %s / %s (%0.4f%%)\n", lcli.SizeStr(pow.MinerPower), lcli.SizeStr(pow.TotalPower), float64(percI.Int64())/100000*10000)
// TODO: indicate whether the post worker is in use
wstat, err := nodeApi.WorkerStats(ctx)
@ -110,18 +110,6 @@ var infoCmd = &cli.Command{
},
}
var Units = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"}
func sizeStr(size types.BigInt) string {
size = types.BigMul(size, types.NewInt(100))
i := 0
for types.BigCmp(size, types.NewInt(102400)) >= 0 && i < len(Units)-1 {
size = types.BigDiv(size, types.NewInt(1024))
i++
}
return fmt.Sprintf("%s.%s %s", types.BigDiv(size, types.NewInt(100)), types.BigMod(size, types.NewInt(100)), Units[i])
}
func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[string]int, error) {
sectors, err := napi.SectorsList(ctx)
if err != nil {

View File

@ -1,6 +1,7 @@
package main
import (
"bytes"
"context"
"crypto/rand"
"encoding/json"
@ -75,12 +76,21 @@ var initCmd = &cli.Command{
Name: "nosync",
Usage: "don't check full-node sync status",
},
&cli.BoolFlag{
Name: "symlink-imported-sectors",
Usage: "attempt to symlink to presealed sectors instead of copying them into place",
},
},
Action: func(cctx *cli.Context) error {
log.Info("Initializing lotus storage miner")
ssize := cctx.Uint64("sector-size")
symlink := cctx.Bool("symlink-imported-sectors")
if symlink {
log.Info("will attempt to symlink to imported sectors")
}
log.Info("Checking proof parameters")
if err := build.GetParams(ssize); err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err)
@ -152,7 +162,9 @@ var initCmd = &cli.Command{
return err
}
oldmds, err := badger.NewDatastore(filepath.Join(pssb, "badger"), nil)
bopts := badger.DefaultOptions
bopts.ReadOnly = true
oldmds, err := badger.NewDatastore(filepath.Join(pssb, "badger"), &bopts)
if err != nil {
return err
}
@ -181,7 +193,7 @@ var initCmd = &cli.Command{
return xerrors.Errorf("failed to open up sectorbuilder: %w", err)
}
if err := nsb.ImportFrom(oldsb); err != nil {
if err := nsb.ImportFrom(oldsb, symlink); err != nil {
return err
}
if err := lr.Close(); err != nil {
@ -267,7 +279,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
return err
}
proposalCid, err := sector.Deal.Proposal.Cid()
proposalCid, err := sector.Deal.Cid()
if err != nil {
return err
}
@ -275,7 +287,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
dealKey := datastore.NewKey(deals.ProviderDsPrefix).ChildString(proposalCid.String())
deal := &deals.MinerDeal{
Proposal: sector.Deal.Proposal,
Proposal: sector.Deal,
ProposalCid: proposalCid,
State: lapi.DealComplete,
Ref: proposalCid, // TODO: This is super wrong, but there
@ -298,7 +310,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
return nil
}
func findMarketDealID(ctx context.Context, api lapi.FullNode, deal actors.StorageDeal) (uint64, error) {
func findMarketDealID(ctx context.Context, api lapi.FullNode, deal actors.StorageDealProposal) (uint64, error) {
// TODO: find a better way
// (this is only used by genesis miners)
@ -308,11 +320,7 @@ func findMarketDealID(ctx context.Context, api lapi.FullNode, deal actors.Storag
}
for k, v := range deals {
eq, err := cborutil.Equals(&v.Deal, &deal)
if err != nil {
return 0, err
}
if eq {
if bytes.Equal(v.PieceRef, deal.PieceRef) {
return strconv.ParseUint(k, 10, 64)
}
}

View File

@ -15,6 +15,7 @@ import (
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/apistruct"
"github.com/filecoin-project/lotus/build"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/lib/auth"
@ -131,7 +132,7 @@ var runCmd = &cli.Command{
mux := mux.NewRouter()
rpcServer := jsonrpc.NewServer()
rpcServer.Register("Filecoin", api.PermissionedStorMinerAPI(minerapi))
rpcServer.Register("Filecoin", apistruct.PermissionedStorMinerAPI(minerapi))
mux.Handle("/rpc/v0", rpcServer)
mux.PathPrefix("/remote").HandlerFunc(minerapi.(*impl.StorageMinerAPI).ServeRemote)

View File

@ -47,6 +47,11 @@ var DaemonCmd = &cli.Command{
Name: "genesis",
Usage: "genesis file to use for first node run",
},
&cli.StringFlag{
Name: "genesis-timestamp",
Hidden: true,
Usage: "set the timestamp for the genesis block that will be created",
},
&cli.BoolFlag{
Name: "bootstrap",
Value: true,
@ -84,7 +89,7 @@ var DaemonCmd = &cli.Command{
if cctx.String(preSealedSectorsFlag) == "" {
return xerrors.Errorf("must also pass file with miner preseal info to `--%s`", preSealedSectorsFlag)
}
genesis = node.Override(new(modules.Genesis), testing.MakeGenesis(cctx.String(makeGenFlag), cctx.String(preSealedSectorsFlag)))
genesis = node.Override(new(modules.Genesis), testing.MakeGenesis(cctx.String(makeGenFlag), cctx.String(preSealedSectorsFlag), cctx.String("genesis-timestamp")))
}
var api api.FullNode

View File

@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
"github.com/filecoin-project/lotus/api/apistruct"
"net/http"
_ "net/http/pprof"
"os"
@ -26,7 +27,7 @@ var log = logging.Logger("main")
func serveRPC(a api.FullNode, stop node.StopFunc, addr multiaddr.Multiaddr) error {
rpcServer := jsonrpc.NewServer()
rpcServer.Register("Filecoin", api.PermissionedFullAPI(a))
rpcServer.Register("Filecoin", apistruct.PermissionedFullAPI(a))
ah := &auth.Handler{
Verify: a.AuthVerify,
@ -70,7 +71,7 @@ func handleImport(a *impl.FullNodeAPI) func(w http.ResponseWriter, r *http.Reque
w.WriteHeader(404)
return
}
if !api.HasPerm(r.Context(), api.PermWrite) {
if !apistruct.HasPerm(r.Context(), apistruct.PermWrite) {
w.WriteHeader(401)
json.NewEncoder(w).Encode(struct{ Error string }{"unauthorized: missing write permission"})
return

2
extern/filecoin-ffi vendored

@ -1 +1 @@
Subproject commit 16a8b663ec61339d3d8736e85eddd3e4a1c190b7
Subproject commit e32f5efc808b92560f9d7f92a5d312b5ac403b7d

View File

@ -49,7 +49,7 @@ func main() {
os.Exit(1)
}
err = gen.WriteTupleEncodersToFile("./api/cbor_gen.go", "api",
err = gen.WriteMapEncodersToFile("./api/cbor_gen.go", "api",
api.PaymentInfo{},
api.SealedRef{},
api.SealedRefs{},
@ -96,6 +96,7 @@ func main() {
actors.SubmitFallbackPoStParams{},
actors.PaymentVerifyParams{},
actors.UpdatePeerIDParams{},
actors.DeclareFaultsParams{},
actors.MultiSigActorState{},
actors.MultiSigConstructorParams{},
actors.MultiSigProposeParams{},
@ -122,7 +123,6 @@ func main() {
actors.StorageMarketState{},
actors.WithdrawBalanceParams{},
actors.StorageDealProposal{},
actors.StorageDeal{},
actors.PublishStorageDealsParams{},
actors.PublishStorageDealResponse{},
actors.ActivateStorageDealsParams{},
@ -154,7 +154,7 @@ func main() {
os.Exit(1)
}
err = gen.WriteTupleEncodersToFile("./storage/cbor_gen.go", "storage",
err = gen.WriteMapEncodersToFile("./storage/cbor_gen.go", "storage",
storage.SealTicket{},
storage.SealSeed{},
storage.Piece{},

View File

@ -10,7 +10,7 @@ type PreSeal struct {
CommR [32]byte
CommD [32]byte
SectorID uint64
Deal actors.StorageDeal
Deal actors.StorageDealProposal
}
type GenesisMiner struct {

3
go.mod
View File

@ -8,6 +8,7 @@ require (
github.com/GeertJohan/go.rice v1.0.0
github.com/Gurpartap/async v0.0.0-20180927173644-4f7f499dd9ee
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/docker/go-units v0.4.0
github.com/fatih/color v1.7.0 // indirect
github.com/filecoin-project/chain-validation v0.0.3
github.com/filecoin-project/filecoin-ffi v0.0.0-20191204125133-ebb3e13addf1
@ -86,7 +87,7 @@ require (
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
github.com/stretchr/testify v1.4.0
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba
github.com/whyrusleeping/cbor-gen v0.0.0-20191208220313-d43e400b4942
github.com/whyrusleeping/cbor-gen v0.0.0-20191209162422-1c55bd7cf8aa
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d
go.opencensus.io v0.22.1

6
go.sum
View File

@ -68,6 +68,8 @@ github.com/dgraph-io/badger v1.6.0-rc1/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhY
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
@ -586,8 +588,8 @@ github.com/whyrusleeping/cbor-gen v0.0.0-20190910031516-c1cbffdb01bb/go.mod h1:x
github.com/whyrusleeping/cbor-gen v0.0.0-20190917003517-d78d67427694/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20191116002219-891f55cd449d h1:NRa/Vs7+b91GdXrp0AqsG7pspWV6CLk5Gk7i46L4tGo=
github.com/whyrusleeping/cbor-gen v0.0.0-20191116002219-891f55cd449d/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20191208220313-d43e400b4942 h1:EIKesTogdQi76lVOmZleTRQtNNIXSy037QVBVMZ8rug=
github.com/whyrusleeping/cbor-gen v0.0.0-20191208220313-d43e400b4942/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/cbor-gen v0.0.0-20191209162422-1c55bd7cf8aa h1:iuIvC21JR4TcHtdCtkXz2jG8KCAK9ZJQQQxbDkFxkNE=
github.com/whyrusleeping/cbor-gen v0.0.0-20191209162422-1c55bd7cf8aa/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E=
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k=

View File

@ -5,8 +5,10 @@ import (
"net/http"
"strings"
"github.com/filecoin-project/lotus/api"
logging "github.com/ipfs/go-log"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/apistruct"
)
var log = logging.Logger("auth")
@ -42,7 +44,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
ctx = api.WithPerm(ctx, allow)
ctx = apistruct.WithPerm(ctx, allow)
}
h.Next(w, r.WithContext(ctx))

View File

@ -31,12 +31,7 @@ func (sb *SectorBuilder) stagedSectorFile(sectorID uint64) (*os.File, error) {
func (sb *SectorBuilder) SealedSectorPath(sectorID uint64) (string, error) {
path := filepath.Join(sb.sealedDir, sb.SectorName(sectorID))
e, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return "", err
}
return path, e.Close()
return path, nil
}
func (sb *SectorBuilder) sectorCacheDir(sectorID uint64) (string, error) {

View File

@ -3,7 +3,9 @@ package sectorbuilder
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"sync"
"sync/atomic"
@ -16,6 +18,7 @@ import (
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/modules/dtypes"
)
@ -480,6 +483,14 @@ func (sb *SectorBuilder) SealPreCommit(sectorID uint64, ticket SealTicket, piece
return RawSealPreCommitOutput{}, xerrors.Errorf("getting sealed sector path: %w", err)
}
e, err := os.OpenFile(sealedPath, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return RawSealPreCommitOutput{}, xerrors.Errorf("ensuring sealed file exists: %w", err)
}
if err := e.Close(); err != nil {
return RawSealPreCommitOutput{}, err
}
var sum uint64
for _, piece := range pieces {
sum += piece.Size
@ -506,8 +517,6 @@ func (sb *SectorBuilder) SealPreCommit(sectorID uint64, ticket SealTicket, piece
return RawSealPreCommitOutput{}, xerrors.Errorf("presealing sector %d (%s): %w", sectorID, stagedPath, err)
}
log.Infof("PRECOMMIT FFI RSPCO %v", rspco)
return RawSealPreCommitOutput(rspco), nil
}
@ -623,7 +632,7 @@ func (sb *SectorBuilder) GenerateEPostCandidates(sectorInfo SortedPublicSectorIn
return nil, err
}
challengeCount := ElectionPostChallengeCount(uint64(len(sectorInfo.Values())))
challengeCount := types.ElectionPostChallengeCount(uint64(len(sectorInfo.Values())))
proverID := addressToProverID(sb.Miner)
return sectorbuilder.GenerateCandidates(sb.ssize, proverID, challengeSeed, challengeCount, privsectors)
@ -674,29 +683,24 @@ func (sb *SectorBuilder) Stop() {
close(sb.stopping)
}
func ElectionPostChallengeCount(sectors uint64) uint64 {
// ceil(sectors / build.SectorChallengeRatioDiv)
return (sectors + build.SectorChallengeRatioDiv - 1) / build.SectorChallengeRatioDiv
}
func fallbackPostChallengeCount(sectors uint64) uint64 {
challengeCount := ElectionPostChallengeCount(sectors)
challengeCount := types.ElectionPostChallengeCount(sectors)
if challengeCount > build.MaxFallbackPostChallengeCount {
return build.MaxFallbackPostChallengeCount
}
return challengeCount
}
func (sb *SectorBuilder) ImportFrom(osb *SectorBuilder) error {
if err := dcopy.Copy(osb.cacheDir, sb.cacheDir); err != nil {
func (sb *SectorBuilder) ImportFrom(osb *SectorBuilder, symlink bool) error {
if err := migrate(osb.cacheDir, sb.cacheDir, symlink); err != nil {
return err
}
if err := dcopy.Copy(osb.sealedDir, sb.sealedDir); err != nil {
if err := migrate(osb.sealedDir, sb.sealedDir, symlink); err != nil {
return err
}
if err := dcopy.Copy(osb.stagedDir, sb.stagedDir); err != nil {
if err := migrate(osb.stagedDir, sb.stagedDir, symlink); err != nil {
return err
}
@ -722,3 +726,58 @@ func (sb *SectorBuilder) SetLastSectorID(id uint64) error {
sb.lastID = id
return nil
}
func migrate(from, to string, symlink bool) error {
st, err := os.Stat(from)
if err != nil {
return err
}
if st.IsDir() {
return migrateDir(from, to, symlink)
}
return migrateFile(from, to, symlink)
}
func migrateDir(from, to string, symlink bool) error {
tost, err := os.Stat(to)
if err != nil {
if !os.IsNotExist(err) {
return err
}
if err := os.MkdirAll(to, 0755); err != nil {
return err
}
} else if !tost.IsDir() {
return xerrors.Errorf("target %q already exists and is a file (expected directory)")
}
dirents, err := ioutil.ReadDir(from)
if err != nil {
return err
}
for _, inf := range dirents {
n := inf.Name()
if inf.IsDir() {
if err := migrate(filepath.Join(from, n), filepath.Join(to, n), symlink); err != nil {
return err
}
} else {
if err := migrate(filepath.Join(from, n), filepath.Join(to, n), symlink); err != nil {
return err
}
}
}
return nil
}
func migrateFile(from, to string, symlink bool) error {
if symlink {
return os.Symlink(from, to)
}
return dcopy.Copy(from, to)
}

View File

@ -8,6 +8,7 @@ import (
"go.opencensus.io/trace"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/types"
)
func (sb *SectorBuilder) SectorSize() uint64 {
@ -36,7 +37,7 @@ func NewSortedPublicSectorInfo(sectors []sectorbuilder.PublicSectorInfo) SortedP
}
func VerifyElectionPost(ctx context.Context, sectorSize uint64, sectorInfo SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []EPostCandidate, proverID address.Address) (bool, error) {
challengeCount := ElectionPostChallengeCount(uint64(len(sectorInfo.Values())))
challengeCount := types.ElectionPostChallengeCount(uint64(len(sectorInfo.Values())))
return verifyPost(ctx, sectorSize, sectorInfo, challengeCount, challengeSeed, proof, candidates, proverID)
}

View File

@ -8,6 +8,7 @@ import (
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/query"
cbg "github.com/whyrusleeping/cbor-gen"
"go.uber.org/multierr"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/lib/cborutil"
@ -139,6 +140,8 @@ func (st *StateStore) List(out interface{}) error {
outT := reflect.TypeOf(out).Elem().Elem()
rout := reflect.ValueOf(out)
var errs error
for {
res, ok := res.NextSync()
if !ok {
@ -151,7 +154,8 @@ func (st *StateStore) List(out interface{}) error {
elem := reflect.New(outT)
err := cborutil.ReadCborRPC(bytes.NewReader(res.Value), elem.Interface())
if err != nil {
return err
errs = multierr.Append(errs, xerrors.Errorf("decoding state for key '%s': %w", res.Key, err))
continue
}
rout.Elem().Set(reflect.Append(rout.Elem(), elem.Elem()))

View File

@ -15,6 +15,7 @@ let sealCodes = [
"PreCommitting",
"PreCommitted",
"Committing",
"CommitWait",
"Proving",
"SealFailed",

View File

@ -17,6 +17,10 @@ import (
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
)
func init() {
build.SectorSizes = []uint64{1024}
}
func (api *api) Spawn() (nodeInfo, error) {
dir, err := ioutil.TempDir(os.TempDir(), "lotus-")
if err != nil {
@ -36,7 +40,7 @@ func (api *api) Spawn() (nodeInfo, error) {
}
sbroot := filepath.Join(dir, "preseal")
genm, err := seed.PreSeal(genMiner, build.SectorSizes[0], 0, 1, sbroot, []byte("8"))
genm, err := seed.PreSeal(genMiner, build.SectorSizes[0], 0, 2, sbroot, []byte("8"))
if err != nil {
return nodeInfo{}, xerrors.Errorf("preseal failed: %w", err)
}

View File

@ -170,8 +170,6 @@ eventLoop:
}
lastBase = *base
log.Infof("Time delta between now and our mining base: %ds", uint64(time.Now().Unix())-base.ts.MinTimestamp())
blks := make([]*types.BlockMsg, 0)
for _, addr := range addrs {
@ -272,6 +270,8 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB
return nil, nil
}
log.Infof("Time delta between now and our mining base: %ds", uint64(time.Now().Unix())-base.ts.MinTimestamp())
ticket, err := m.computeTicket(ctx, addr, base)
if err != nil {
return nil, xerrors.Errorf("scratching ticket failed: %w", err)

View File

@ -217,7 +217,6 @@ func Online() Option {
Override(RunBlockSyncKey, modules.RunBlockSync),
Override(RunPeerMgrKey, modules.RunPeerMgr),
Override(HandleIncomingBlocksKey, modules.HandleIncomingBlocks),
Override(HeadMetricsKey, metrics.SendHeadNotifs("")),
Override(new(*discovery.Local), discovery.NewLocal),
Override(new(discovery.PeerResolver), modules.RetrievalResolver),
@ -313,7 +312,9 @@ func ConfigFullNode(c interface{}) Option {
return Options(
ConfigCommon(&cfg.Common),
Override(HeadMetricsKey, metrics.SendHeadNotifs(cfg.Metrics.Nickname)),
If(cfg.Metrics.HeadNotifs,
Override(HeadMetricsKey, metrics.SendHeadNotifs(cfg.Metrics.Nickname)),
),
If(cfg.Metrics.PubsubTracing,
Override(new(*pubsub.PubSub), lp2p.GossipSub(lp2p.PubsubTracer())),
),

View File

@ -42,6 +42,7 @@ type Libp2p struct {
type Metrics struct {
Nickname string
HeadNotifs bool
PubsubTracing bool
}

View File

@ -2,8 +2,7 @@ package hello
import (
"context"
"go.uber.org/fx"
"time"
"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
@ -32,6 +31,9 @@ type Message struct {
HeaviestTipSet []cid.Cid
HeaviestTipSetWeight types.BigInt
GenesisHash cid.Cid
TArrial int64
TSent int64
}
type NewStreamFunc func(context.Context, peer.ID, ...protocol.ID) (inet.Stream, error)
@ -43,13 +45,7 @@ type Service struct {
pmgr *peermgr.PeerMgr
}
type MaybePeerMgr struct {
fx.In
Mgr *peermgr.PeerMgr `optional:"true"`
}
func NewHelloService(h host.Host, cs *store.ChainStore, syncer *chain.Syncer, pmgr MaybePeerMgr) *Service {
func NewHelloService(h host.Host, cs *store.ChainStore, syncer *chain.Syncer, pmgr peermgr.MaybePeerMgr) *Service {
if pmgr.Mgr == nil {
log.Warn("running without peer manager")
}
@ -68,9 +64,12 @@ func (hs *Service) HandleStream(s inet.Stream) {
var hmsg Message
if err := cborutil.ReadCborRPC(s, &hmsg); err != nil {
log.Infow("failed to read hello message", "error", err)
log.Infow("failed to read hello message, diconnecting", "error", err)
s.Conn().Close()
return
}
arrived := time.Now()
log.Debugw("genesis from hello",
"tipset", hmsg.HeaviestTipSet,
"peer", s.Conn().RemotePeer(),
@ -81,6 +80,16 @@ func (hs *Service) HandleStream(s inet.Stream) {
s.Conn().Close()
return
}
go func() {
sent := time.Now()
msg := &Message{
TArrial: arrived.UnixNano(),
TSent: sent.UnixNano(),
}
if err := cborutil.WriteCborRPC(s, msg); err != nil {
log.Debugf("error while responding to latency: %v", err)
}
}()
ts, err := hs.syncer.FetchTipSet(context.Background(), s.Conn().RemotePeer(), hmsg.HeaviestTipSet)
if err != nil {
@ -93,6 +102,7 @@ func (hs *Service) HandleStream(s inet.Stream) {
if hs.pmgr != nil {
hs.pmgr.AddFilecoinPeer(s.Conn().RemotePeer())
}
}
func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
@ -120,9 +130,34 @@ func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
}
log.Info("Sending hello message: ", hts.Cids(), hts.Height(), gen.Cid())
t0 := time.Now()
if err := cborutil.WriteCborRPC(s, hmsg); err != nil {
return err
}
go func() {
hmsg = &Message{}
s.SetReadDeadline(time.Now().Add(10 * time.Second))
err := cborutil.ReadCborRPC(s, hmsg) // ignore error
ok := err == nil
t3 := time.Now()
lat := t3.Sub(t0)
// add to peer tracker
if hs.pmgr != nil {
hs.pmgr.SetPeerLatency(pid, lat)
}
if ok {
if hmsg.TArrial != 0 && hmsg.TSent != 0 {
t1 := time.Unix(0, hmsg.TArrial)
t2 := time.Unix(0, hmsg.TSent)
offset := t0.Sub(t1) + t3.Sub(t2)
offset /= 2
log.Infow("time offset", "offset", offset.Seconds(), "peerid", pid.String())
}
}
}()
return nil
}

View File

@ -2,7 +2,6 @@ package impl
import (
"context"
"github.com/gbrlsnchs/jwt/v3"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"

View File

@ -148,7 +148,7 @@ func (a *StateAPI) stateForTs(ctx context.Context, ts *types.TipSet) (*state.Sta
func (a *StateAPI) StateGetActor(ctx context.Context, actor address.Address, ts *types.TipSet) (*types.Actor, error) {
state, err := a.stateForTs(ctx, ts)
if err != nil {
return nil, err
return nil, xerrors.Errorf("computing tipset state failed: %w", err)
}
return state.GetActor(actor)

View File

@ -3,6 +3,7 @@ package impl
import (
"context"
"encoding/json"
"github.com/filecoin-project/lotus/api/apistruct"
"io"
"mime"
"net/http"
@ -33,7 +34,7 @@ type StorageMinerAPI struct {
}
func (sm *StorageMinerAPI) ServeRemote(w http.ResponseWriter, r *http.Request) {
if !api.HasPerm(r.Context(), api.PermAdmin) {
if !apistruct.HasPerm(r.Context(), apistruct.PermAdmin) {
w.WriteHeader(401)
json.NewEncoder(w).Encode(struct{ Error string }{"unauthorized: missing write permission"})
return
@ -167,7 +168,7 @@ func (sm *StorageMinerAPI) SectorsStatus(ctx context.Context, sid uint64) (api.S
Deals: deals,
Ticket: info.Ticket.SB(),
Seed: info.Seed.SB(),
Retries: info.Nonce,
Retries: info.Nonce,
LastErr: info.LastErr,
}, nil

View File

@ -3,10 +3,10 @@ package modules
import (
"context"
"crypto/rand"
"github.com/filecoin-project/lotus/api/apistruct"
"io"
"io/ioutil"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/addrutil"
@ -57,7 +57,7 @@ func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, err
// TODO: make this configurable
p := jwtPayload{
Allow: api.AllPermissions,
Allow: apistruct.AllPermissions,
}
cliToken, err := jwt.Sign(&p, jwt.NewHS256(key.PrivateKey))

View File

@ -8,7 +8,7 @@ import (
pnet "github.com/libp2p/go-libp2p-pnet"
)
var LotusKey = "/key/swarm/psk/1.0.0/\n/base16/\n20c72398e6299c7bbc1b501fdcc8abe4f89f798e9b93b2d2bc02e3c29b6a088e"
var LotusKey = "/key/swarm/psk/1.0.0/\n/base16/\n20c72388e6299c7bbc1b501fdcc8abe4f89f798e9b93b2d2bc02e3c29b6a088e"
type PNetFingerprint []byte

View File

@ -68,7 +68,7 @@ func MakeGenesisMem(out io.Writer, gmc *gen.GenMinerCfg) func(bs dtypes.ChainBlo
}
}
func MakeGenesis(outFile, presealInfo string) func(bs dtypes.ChainBlockstore, w *wallet.Wallet) modules.Genesis {
func MakeGenesis(outFile, presealInfo, timestamp string) func(bs dtypes.ChainBlockstore, w *wallet.Wallet) modules.Genesis {
return func(bs dtypes.ChainBlockstore, w *wallet.Wallet) modules.Genesis {
return func() (*types.BlockHeader, error) {
glog.Warn("Generating new random genesis block, note that this SHOULD NOT happen unless you are setting up new network")
@ -87,6 +87,7 @@ func MakeGenesis(outFile, presealInfo string) func(bs dtypes.ChainBlockstore, w
return nil, err
}
var fakePeerIDs []peer.ID
minerAddresses := make([]address.Address, 0, len(preseals))
for s := range preseals {
a, err := address.NewFromString(s)
@ -97,10 +98,11 @@ func MakeGenesis(outFile, presealInfo string) func(bs dtypes.ChainBlockstore, w
return nil, xerrors.New("expected ID address")
}
minerAddresses = append(minerAddresses, a)
fakePeerIDs = append(fakePeerIDs, peer.ID("peer"+a.String()))
}
gmc := &gen.GenMinerCfg{
PeerIDs: []peer.ID{"peer ID 1"},
PeerIDs: fakePeerIDs,
PreSeals: preseals,
MinerAddrs: minerAddresses,
}
@ -117,7 +119,18 @@ func MakeGenesis(outFile, presealInfo string) func(bs dtypes.ChainBlockstore, w
addrs[miner.Worker] = types.FromFil(100000)
}
b, err := gen.MakeGenesisBlock(bs, addrs, gmc, uint64(time.Now().Unix()))
ts := uint64(time.Now().Unix())
if timestamp != "" {
t, err := time.Parse(time.RFC3339, timestamp)
if err != nil {
return nil, xerrors.Errorf("parsing input genesis timestamp: %w", err)
}
glog.Infof("will use %s as the genesis timestamp", t)
ts = uint64(t.Unix())
}
b, err := gen.MakeGenesisBlock(bs, addrs, gmc, ts)
if err != nil {
return nil, err
}

View File

@ -43,6 +43,7 @@ func init() {
_ = logging.SetLogLevel("*", "INFO")
build.SectorSizes = []uint64{1024}
build.MinimumMinerPower = 1024
}
func testStorageNode(ctx context.Context, t *testing.T, waddr address.Address, act address.Address, pk crypto.PrivKey, tnd test.TestNode, mn mocknet.Mocknet) test.TestStorageNode {
@ -237,7 +238,7 @@ func builder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []test.Te
t.Fatal(err)
}
if err := sma.SectorBuilder.ImportFrom(osb); err != nil {
if err := sma.SectorBuilder.ImportFrom(osb, false); err != nil {
t.Fatal(err)
}

View File

@ -22,12 +22,12 @@ func (t *VoucherInfo) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Voucher (types.SignedVoucher) (struct)
// t.Voucher (types.SignedVoucher) (struct)
if err := t.Voucher.MarshalCBOR(w); err != nil {
return err
}
// t.t.Proof ([]uint8) (slice)
// t.Proof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil {
return err
}
@ -52,7 +52,7 @@ func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Voucher (types.SignedVoucher) (struct)
// t.Voucher (types.SignedVoucher) (struct)
{
@ -73,7 +73,7 @@ func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Proof ([]uint8) (slice)
// t.Proof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -102,27 +102,27 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Channel (address.Address) (struct)
// t.Channel (address.Address) (struct)
if err := t.Channel.MarshalCBOR(w); err != nil {
return err
}
// t.t.Control (address.Address) (struct)
// t.Control (address.Address) (struct)
if err := t.Control.MarshalCBOR(w); err != nil {
return err
}
// t.t.Target (address.Address) (struct)
// t.Target (address.Address) (struct)
if err := t.Target.MarshalCBOR(w); err != nil {
return err
}
// t.t.Direction (uint64) (uint64)
// t.Direction (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Direction))); err != nil {
return err
}
// t.t.Vouchers ([]*paych.VoucherInfo) (slice)
// t.Vouchers ([]*paych.VoucherInfo) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Vouchers)))); err != nil {
return err
}
@ -132,7 +132,7 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error {
}
}
// t.t.NextLane (uint64) (uint64)
// t.NextLane (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.NextLane))); err != nil {
return err
}
@ -154,7 +154,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Channel (address.Address) (struct)
// t.Channel (address.Address) (struct)
{
@ -163,7 +163,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Control (address.Address) (struct)
// t.Control (address.Address) (struct)
{
@ -172,7 +172,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Target (address.Address) (struct)
// t.Target (address.Address) (struct)
{
@ -181,7 +181,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Direction (uint64) (uint64)
// t.Direction (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -191,7 +191,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Direction = uint64(extra)
// t.t.Vouchers ([]*paych.VoucherInfo) (slice)
// t.Vouchers ([]*paych.VoucherInfo) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -218,7 +218,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error {
t.Vouchers[i] = &v
}
// t.t.NextLane (uint64) (uint64)
// t.NextLane (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {

View File

@ -6,6 +6,7 @@ import (
"time"
"github.com/filecoin-project/lotus/node/modules/dtypes"
"go.uber.org/fx"
host "github.com/libp2p/go-libp2p-core/host"
net "github.com/libp2p/go-libp2p-core/network"
@ -22,6 +23,12 @@ const (
MinFilPeers = 8
)
type MaybePeerMgr struct {
fx.In
Mgr *PeerMgr `optional:"true"`
}
type PeerMgr struct {
bootstrappers []peer.AddrInfo
@ -30,7 +37,7 @@ type PeerMgr struct {
//peerLeads map[peer.ID]time.Time // TODO: unused
peersLk sync.Mutex
peers map[peer.ID]struct{}
peers map[peer.ID]time.Duration
maxFilPeers int
minFilPeers int
@ -49,7 +56,7 @@ func NewPeerMgr(h host.Host, dht *dht.IpfsDHT, bootstrap dtypes.BootstrapPeers)
dht: dht,
bootstrappers: bootstrap,
peers: make(map[peer.ID]struct{}),
peers: make(map[peer.ID]time.Duration),
maxFilPeers: MaxFilPeers,
minFilPeers: MinFilPeers,
@ -69,7 +76,23 @@ func NewPeerMgr(h host.Host, dht *dht.IpfsDHT, bootstrap dtypes.BootstrapPeers)
func (pmgr *PeerMgr) AddFilecoinPeer(p peer.ID) {
pmgr.peersLk.Lock()
defer pmgr.peersLk.Unlock()
pmgr.peers[p] = struct{}{}
pmgr.peers[p] = time.Duration(0)
}
func (pmgr *PeerMgr) GetPeerLatency(p peer.ID) (time.Duration, bool) {
pmgr.peersLk.Lock()
defer pmgr.peersLk.Unlock()
dur, ok := pmgr.peers[p]
return dur, ok
}
func (pmgr *PeerMgr) SetPeerLatency(p peer.ID, latency time.Duration) {
pmgr.peersLk.Lock()
defer pmgr.peersLk.Unlock()
if _, ok := pmgr.peers[p]; ok {
pmgr.peers[p] = latency
}
}
func (pmgr *PeerMgr) Disconnect(p peer.ID) {

View File

@ -21,7 +21,7 @@ func (t *RetParams) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
// t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
if err := t.Unixfs0.MarshalCBOR(w); err != nil {
return err
}
@ -43,7 +43,7 @@ func (t *RetParams) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
// t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
{
@ -76,7 +76,7 @@ func (t *Query) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Piece (cid.Cid) (struct)
// t.Piece (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Piece); err != nil {
return xerrors.Errorf("failed to write cid field t.Piece: %w", err)
@ -100,7 +100,7 @@ func (t *Query) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Piece (cid.Cid) (struct)
// t.Piece (cid.Cid) (struct)
{
@ -124,17 +124,17 @@ func (t *QueryResponse) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Status (retrieval.QueryResponseStatus) (uint64)
// t.Status (retrieval.QueryResponseStatus) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
return err
}
// t.t.Size (uint64) (uint64)
// t.Size (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil {
return err
}
// t.t.MinPrice (types.BigInt) (struct)
// t.MinPrice (types.BigInt) (struct)
if err := t.MinPrice.MarshalCBOR(w); err != nil {
return err
}
@ -156,7 +156,7 @@ func (t *QueryResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Status (retrieval.QueryResponseStatus) (uint64)
// t.Status (retrieval.QueryResponseStatus) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -166,7 +166,7 @@ func (t *QueryResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Status = QueryResponseStatus(extra)
// t.t.Size (uint64) (uint64)
// t.Size (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -176,7 +176,7 @@ func (t *QueryResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Size = uint64(extra)
// t.t.MinPrice (types.BigInt) (struct)
// t.MinPrice (types.BigInt) (struct)
{
@ -197,12 +197,12 @@ func (t *Unixfs0Offer) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Offset (uint64) (uint64)
// t.Offset (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Offset))); err != nil {
return err
}
// t.t.Size (uint64) (uint64)
// t.Size (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil {
return err
}
@ -224,7 +224,7 @@ func (t *Unixfs0Offer) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Offset (uint64) (uint64)
// t.Offset (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -234,7 +234,7 @@ func (t *Unixfs0Offer) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Offset = uint64(extra)
// t.t.Size (uint64) (uint64)
// t.Size (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -256,18 +256,18 @@ func (t *DealProposal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Payment (api.PaymentInfo) (struct)
// t.Payment (api.PaymentInfo) (struct)
if err := t.Payment.MarshalCBOR(w); err != nil {
return err
}
// t.t.Ref (cid.Cid) (struct)
// t.Ref (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Ref); err != nil {
return xerrors.Errorf("failed to write cid field t.Ref: %w", err)
}
// t.t.Params (retrieval.RetParams) (struct)
// t.Params (retrieval.RetParams) (struct)
if err := t.Params.MarshalCBOR(w); err != nil {
return err
}
@ -289,7 +289,7 @@ func (t *DealProposal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Payment (api.PaymentInfo) (struct)
// t.Payment (api.PaymentInfo) (struct)
{
@ -298,7 +298,7 @@ func (t *DealProposal) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Ref (cid.Cid) (struct)
// t.Ref (cid.Cid) (struct)
{
@ -310,7 +310,7 @@ func (t *DealProposal) UnmarshalCBOR(r io.Reader) error {
t.Ref = c
}
// t.t.Params (retrieval.RetParams) (struct)
// t.Params (retrieval.RetParams) (struct)
{
@ -331,12 +331,12 @@ func (t *DealResponse) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Status (uint64) (uint64)
// t.Status (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
return err
}
// t.t.Message (string) (string)
// t.Message (string) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Message)))); err != nil {
return err
}
@ -361,7 +361,7 @@ func (t *DealResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Status (uint64) (uint64)
// t.Status (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -371,7 +371,7 @@ func (t *DealResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Status = uint64(extra)
// t.t.Message (string) (string)
// t.Message (string) (string)
{
sval, err := cbg.ReadString(br)
@ -393,7 +393,7 @@ func (t *Block) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Prefix ([]uint8) (slice)
// t.Prefix ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Prefix)))); err != nil {
return err
}
@ -401,7 +401,7 @@ func (t *Block) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Data ([]uint8) (slice)
// t.Data ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Data)))); err != nil {
return err
}
@ -426,7 +426,7 @@ func (t *Block) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Prefix ([]uint8) (slice)
// t.Prefix ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -443,7 +443,7 @@ func (t *Block) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.Prefix); err != nil {
return err
}
// t.t.Data ([]uint8) (slice)
// t.Data ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {

View File

@ -100,7 +100,7 @@ type clientStream struct {
func (c *Client) RetrieveUnixfs(ctx context.Context, root cid.Cid, size uint64, total types.BigInt, miner peer.ID, client, minerAddr address.Address, out io.Writer) error {
s, err := c.h.NewStream(ctx, miner, ProtocolID)
if err != nil {
return err
return xerrors.Errorf("failed to open stream to miner for retrieval query: %w", err)
}
defer s.Close()
@ -149,7 +149,6 @@ func (c *Client) RetrieveUnixfs(ctx context.Context, root cid.Cid, size uint64,
cst.offset += toFetch
}
log.Info("RETRIEVE SUCCESSFUL")
return nil
}
@ -173,13 +172,12 @@ func (cst *clientStream) doOneExchange(ctx context.Context, toFetch uint64, out
}
if err := cborutil.WriteCborRPC(cst.stream, deal); err != nil {
return err
return xerrors.Errorf("sending incremental retrieval request: %w", err)
}
var resp DealResponse
if err := cborutil.ReadCborRPC(cst.peeker, &resp); err != nil {
log.Error(err)
return err
return xerrors.Errorf("reading retrieval response: %w", err)
}
if resp.Status != Accepted {

View File

@ -1,109 +0,0 @@
#!/usr/bin/env bash
############
## Settings
GENESIS_HOST=root@147.75.80.29
BOOTSTRAPPERS=( root@147.75.80.17 )
############
read -p "You are about to deploy new DevNet, killing bootstrap nodes. Proceed? (y/n)? " r
case "$r" in
y|Y ) echo "Proceding";;
n|N ) exit 0;;
* ) exit 1;;
esac
log() {
echo -e "\e[33m$1\e[39m"
}
rm -f build/bootstrap/*.pi
log '> Generating genesis'
make
GENPATH=$(mktemp -d)
log 'staring temp daemon'
./lotus --repo="${GENPATH}" daemon --lotus-make-random-genesis="${GENPATH}/devnet.car" &
GDPID=$!
sleep 3
log 'Extracting genesis miner prvate key'
ADDR=$(./lotus --repo="${GENPATH}" wallet list)
./lotus --repo="${GENPATH}" wallet export "$ADDR" > "${GENPATH}/wallet.key"
kill "$GDPID"
wait
log '> Creating genesis binary'
cp "${GENPATH}/devnet.car" build/genesis/devnet.car
rm -f build/bootstrap/*.pi
make
log '> Deploying and starting genesis miner'
ssh $GENESIS_HOST 'systemctl stop lotus-daemon' &
ssh $GENESIS_HOST 'systemctl stop lotus-storage-miner' &
wait
ssh $GENESIS_HOST 'rm -rf .lotus' &
ssh $GENESIS_HOST 'rm -rf .lotusstorage' &
scp -C lotus "${GENESIS_HOST}":/usr/local/bin/lotus &
scp -C lotus-storage-miner "${GENESIS_HOST}":/usr/local/bin/lotus-storage-miner &
wait
log 'Initializing genesis miner repo'
ssh $GENESIS_HOST 'systemctl start lotus-daemon'
scp scripts/bootstrap.toml "${GENESIS_HOST}:.lotus/config.toml" &
ssh < "${GENPATH}/wallet.key" $GENESIS_HOST '/usr/local/bin/lotus wallet import' &
wait
ssh $GENESIS_HOST "echo -e '[Metrics]\nNickname=\"Boot-genesis\"' >> .lotus/config.toml"
ssh $GENESIS_HOST 'systemctl restart lotus-daemon'
log 'Starting genesis mining'
ssh $GENESIS_HOST '/usr/local/bin/lotus-storage-miner init --genesis-miner --actor=t0101'
ssh $GENESIS_HOST 'systemctl start lotus-storage-miner'
log 'Getting genesis addr info'
ssh $GENESIS_HOST 'lotus net listen' | grep -v '/10' | grep -v '/127' > build/bootstrap/root.pi
log '> Creating bootstrap binaries'
make
for host in "${BOOTSTRAPPERS[@]}"
do
./scripts/deploy-bootstrapper.sh $host
done
log 'Updating genesis node with bootstrapable binaries'
ssh "$GENESIS_HOST" 'systemctl stop lotus-daemon' &
ssh "$GENESIS_HOST" 'systemctl stop lotus-storage-miner' &
wait
scp -C lotus "${GENESIS_HOST}":/usr/local/bin/lotus &
scp -C lotus-storage-miner "${GENESIS_HOST}":/usr/local/bin/lotus-storage-miner &
wait
ssh "$GENESIS_HOST" 'systemctl start lotus-daemon' &
ssh "$GENESIS_HOST" 'systemctl start lotus-storage-miner' &
wait

117
scripts/init-network.sh Executable file
View File

@ -0,0 +1,117 @@
#!/usr/bin/env bash
set -xeo
NUM_SECTORS=2
SECTOR_SIZE=1024
sdt0111=$(mktemp -d)
sdt0222=$(mktemp -d)
sdt0333=$(mktemp -d)
staging=$(mktemp -d)
make debug
./lotus-seed --sectorbuilder-dir="${sdt0111}" pre-seal --miner-addr=t0111 --sector-offset=0 --sector-size=${SECTOR_SIZE} --num-sectors=${NUM_SECTORS} &
./lotus-seed --sectorbuilder-dir="${sdt0222}" pre-seal --miner-addr=t0222 --sector-offset=0 --sector-size=${SECTOR_SIZE} --num-sectors=${NUM_SECTORS} &
./lotus-seed --sectorbuilder-dir="${sdt0333}" pre-seal --miner-addr=t0333 --sector-offset=0 --sector-size=${SECTOR_SIZE} --num-sectors=${NUM_SECTORS} &
wait
./lotus-seed aggregate-manifests "${sdt0111}/pre-seal-t0111.json" "${sdt0222}/pre-seal-t0222.json" "${sdt0333}/pre-seal-t0333.json" > "${staging}/genesis.json"
lotus_path=$(mktemp -d)
./lotus --repo="${lotus_path}" daemon --lotus-make-random-genesis="${staging}/devnet.car" --genesis-presealed-sectors="${staging}/genesis.json" --bootstrap=false &
lpid=$!
sleep 3
kill "$lpid"
wait
cp "${staging}/devnet.car" build/genesis/devnet.car
make debug
ldt0111=$(mktemp -d)
ldt0222=$(mktemp -d)
ldt0333=$(mktemp -d)
sdlist=( "$sdt0111" "$sdt0222" "$sdt0333" )
ldlist=( "$ldt0111" "$ldt0222" "$ldt0333" )
for (( i=0; i<${#sdlist[@]}; i++ )); do
preseal=${sdlist[$i]}
fullpath=$(find ${preseal} -type f -iname 'pre-seal-*.json')
filefull=$(basename ${fullpath})
filename=${filefull%%.*}
mineraddr=$(echo $filename | sed 's/pre-seal-//g')
wallet_raw=$(jq -rc ".${mineraddr}.Key" < ${preseal}/${filefull})
wallet_b16=$(./lotus-shed base16 "${wallet_raw}")
wallet_adr=$(./lotus-shed keyinfo --format="{{.Address}}" "${wallet_b16}")
wallet_adr_enc=$(./lotus-shed base32 "wallet-${wallet_adr}")
mkdir -p "${ldlist[$i]}/keystore"
cat > "${ldlist[$i]}/keystore/${wallet_adr_enc}" <<EOF
${wallet_raw}
EOF
chmod 0700 "${ldlist[$i]}/keystore/${wallet_adr_enc}"
done
pids=()
for (( i=0; i<${#ldlist[@]}; i++ )); do
repo=${ldlist[$i]}
./lotus --repo="${repo}" daemon --api "3000$i" --bootstrap=false &
pids+=($!)
done
sleep 10
boot=$(./lotus --repo="${ldlist[0]}" net listen)
for (( i=1; i<${#ldlist[@]}; i++ )); do
repo=${ldlist[$i]}
./lotus --repo="${repo}" net connect ${boot}
done
sleep 3
mdt0111=$(mktemp -d)
mdt0222=$(mktemp -d)
mdt0333=$(mktemp -d)
env LOTUS_PATH="${ldt0111}" LOTUS_STORAGE_PATH="${mdt0111}" ./lotus-storage-miner init --genesis-miner --actor=t0111 --pre-sealed-sectors="${sdt0111}" --nosync=true --sector-size="${SECTOR_SIZE}" || true
env LOTUS_PATH="${ldt0111}" LOTUS_STORAGE_PATH="${mdt0111}" ./lotus-storage-miner run --nosync &
mpid=$!
env LOTUS_PATH="${ldt0222}" LOTUS_STORAGE_PATH="${mdt0222}" ./lotus-storage-miner init --actor=t0222 --pre-sealed-sectors="${sdt0222}" --nosync=true --sector-size="${SECTOR_SIZE}" || true
env LOTUS_PATH="${ldt0333}" LOTUS_STORAGE_PATH="${mdt0333}" ./lotus-storage-miner init --actor=t0333 --pre-sealed-sectors="${sdt0333}" --nosync=true --sector-size="${SECTOR_SIZE}" || true
kill $mpid
wait $mpid
for (( i=0; i<${#pids[@]}; i++ )); do
kill ${pids[$i]}
done
wait
rm -rf $mdt0111
rm -rf $mdt0222
rm -rf $mdt0333
rm -rf $ldt0111
rm -rf $ldt0222
rm -rf $ldt0333
rm -rf $sdt0111
rm -rf $sdt0222
rm -rf $sdt0333
rm -rf $staging

View File

@ -17,16 +17,30 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
if _, err := w.Write([]byte{162}); err != nil {
return err
}
// t.BlockHeight (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("BlockHeight")))); err != nil {
return err
}
if _, err := w.Write([]byte("BlockHeight")); err != nil {
return err
}
// t.t.BlockHeight (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.BlockHeight))); err != nil {
return err
}
// t.t.TicketBytes ([]uint8) (slice)
// t.TicketBytes ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("TicketBytes")))); err != nil {
return err
}
if _, err := w.Write([]byte("TicketBytes")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.TicketBytes)))); err != nil {
return err
}
@ -43,15 +57,30 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error {
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.BlockHeight (uint64) (uint64)
var name string
// t.BlockHeight (uint64) (uint64)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "BlockHeight" {
return fmt.Errorf("expected struct map entry %s to be BlockHeight", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -61,7 +90,20 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.BlockHeight = uint64(extra)
// t.t.TicketBytes ([]uint8) (slice)
// t.TicketBytes ([]uint8) (slice)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "TicketBytes" {
return fmt.Errorf("expected struct map entry %s to be TicketBytes", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -86,16 +128,30 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
if _, err := w.Write([]byte{162}); err != nil {
return err
}
// t.BlockHeight (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("BlockHeight")))); err != nil {
return err
}
if _, err := w.Write([]byte("BlockHeight")); err != nil {
return err
}
// t.t.BlockHeight (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.BlockHeight))); err != nil {
return err
}
// t.t.TicketBytes ([]uint8) (slice)
// t.TicketBytes ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("TicketBytes")))); err != nil {
return err
}
if _, err := w.Write([]byte("TicketBytes")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.TicketBytes)))); err != nil {
return err
}
@ -112,15 +168,30 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error {
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.BlockHeight (uint64) (uint64)
var name string
// t.BlockHeight (uint64) (uint64)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "BlockHeight" {
return fmt.Errorf("expected struct map entry %s to be BlockHeight", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -130,7 +201,20 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.BlockHeight = uint64(extra)
// t.t.TicketBytes ([]uint8) (slice)
// t.TicketBytes ([]uint8) (slice)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "TicketBytes" {
return fmt.Errorf("expected struct map entry %s to be TicketBytes", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -155,21 +239,42 @@ func (t *Piece) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{131}); err != nil {
if _, err := w.Write([]byte{163}); err != nil {
return err
}
// t.DealID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("DealID")))); err != nil {
return err
}
if _, err := w.Write([]byte("DealID")); err != nil {
return err
}
// t.t.DealID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.DealID))); err != nil {
return err
}
// t.t.Size (uint64) (uint64)
// t.Size (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Size")))); err != nil {
return err
}
if _, err := w.Write([]byte("Size")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil {
return err
}
// t.t.CommP ([]uint8) (slice)
// t.CommP ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("CommP")))); err != nil {
return err
}
if _, err := w.Write([]byte("CommP")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommP)))); err != nil {
return err
}
@ -186,15 +291,30 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error {
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra != 3 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.DealID (uint64) (uint64)
var name string
// t.DealID (uint64) (uint64)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "DealID" {
return fmt.Errorf("expected struct map entry %s to be DealID", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -204,7 +324,20 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.DealID = uint64(extra)
// t.t.Size (uint64) (uint64)
// t.Size (uint64) (uint64)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Size" {
return fmt.Errorf("expected struct map entry %s to be Size", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -214,7 +347,20 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Size = uint64(extra)
// t.t.CommP ([]uint8) (slice)
// t.CommP ([]uint8) (slice)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "CommP" {
return fmt.Errorf("expected struct map entry %s to be CommP", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -239,26 +385,54 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{142}); err != nil {
if _, err := w.Write([]byte{173}); err != nil {
return err
}
// t.State (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("State")))); err != nil {
return err
}
if _, err := w.Write([]byte("State")); err != nil {
return err
}
// t.t.State (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil {
return err
}
// t.t.SectorID (uint64) (uint64)
// t.SectorID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("SectorID")))); err != nil {
return err
}
if _, err := w.Write([]byte("SectorID")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorID))); err != nil {
return err
}
// t.t.Nonce (uint64) (uint64)
// t.Nonce (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Nonce")))); err != nil {
return err
}
if _, err := w.Write([]byte("Nonce")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil {
return err
}
// t.t.Pieces ([]storage.Piece) (slice)
// t.Pieces ([]storage.Piece) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Pieces")))); err != nil {
return err
}
if _, err := w.Write([]byte("Pieces")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Pieces)))); err != nil {
return err
}
@ -268,15 +442,14 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
}
// t.t.Pad0 ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Pad0)))); err != nil {
// t.CommD ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("CommD")))); err != nil {
return err
}
if _, err := w.Write(t.Pad0); err != nil {
if _, err := w.Write([]byte("CommD")); err != nil {
return err
}
// t.t.CommD ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommD)))); err != nil {
return err
}
@ -284,7 +457,14 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.CommR ([]uint8) (slice)
// t.CommR ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("CommR")))); err != nil {
return err
}
if _, err := w.Write([]byte("CommR")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommR)))); err != nil {
return err
}
@ -292,15 +472,14 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Pad1 ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Pad1)))); err != nil {
// t.Proof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Proof")))); err != nil {
return err
}
if _, err := w.Write(t.Pad1); err != nil {
if _, err := w.Write([]byte("Proof")); err != nil {
return err
}
// t.t.Proof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil {
return err
}
@ -308,12 +487,25 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Ticket (storage.SealTicket) (struct)
// t.Ticket (storage.SealTicket) (struct)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Ticket")))); err != nil {
return err
}
if _, err := w.Write([]byte("Ticket")); err != nil {
return err
}
if err := t.Ticket.MarshalCBOR(w); err != nil {
return err
}
// t.t.PreCommitMessage (cid.Cid) (struct)
// t.PreCommitMessage (cid.Cid) (struct)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("PreCommitMessage")))); err != nil {
return err
}
if _, err := w.Write([]byte("PreCommitMessage")); err != nil {
return err
}
if t.PreCommitMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
@ -325,12 +517,25 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
}
// t.t.Seed (storage.SealSeed) (struct)
// t.Seed (storage.SealSeed) (struct)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Seed")))); err != nil {
return err
}
if _, err := w.Write([]byte("Seed")); err != nil {
return err
}
if err := t.Seed.MarshalCBOR(w); err != nil {
return err
}
// t.t.CommitMessage (cid.Cid) (struct)
// t.CommitMessage (cid.Cid) (struct)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("CommitMessage")))); err != nil {
return err
}
if _, err := w.Write([]byte("CommitMessage")); err != nil {
return err
}
if t.CommitMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
@ -342,7 +547,32 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
}
// t.t.LastErr (string) (string)
// t.FaultReportMsg (cid.Cid) (struct)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("FaultReportMsg")))); err != nil {
return err
}
if _, err := w.Write([]byte("FaultReportMsg")); err != nil {
return err
}
if t.FaultReportMsg == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
return err
}
} else {
if err := cbg.WriteCid(w, *t.FaultReportMsg); err != nil {
return xerrors.Errorf("failed to write cid field t.FaultReportMsg: %w", err)
}
}
// t.LastErr (string) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("LastErr")))); err != nil {
return err
}
if _, err := w.Write([]byte("LastErr")); err != nil {
return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.LastErr)))); err != nil {
return err
}
@ -359,15 +589,30 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra != 14 {
if extra != 13 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.State (uint64) (uint64)
var name string
// t.State (uint64) (uint64)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "State" {
return fmt.Errorf("expected struct map entry %s to be State", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -377,7 +622,20 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.State = uint64(extra)
// t.t.SectorID (uint64) (uint64)
// t.SectorID (uint64) (uint64)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "SectorID" {
return fmt.Errorf("expected struct map entry %s to be SectorID", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -387,7 +645,20 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.SectorID = uint64(extra)
// t.t.Nonce (uint64) (uint64)
// t.Nonce (uint64) (uint64)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Nonce" {
return fmt.Errorf("expected struct map entry %s to be Nonce", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -397,7 +668,20 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Nonce = uint64(extra)
// t.t.Pieces ([]storage.Piece) (slice)
// t.Pieces ([]storage.Piece) (slice)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Pieces" {
return fmt.Errorf("expected struct map entry %s to be Pieces", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -424,24 +708,20 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
t.Pieces[i] = v
}
// t.t.Pad0 ([]uint8) (slice)
// t.CommD ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.Pad0: byte array too large (%d)", extra)
if name != "CommD" {
return fmt.Errorf("expected struct map entry %s to be CommD", name)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Pad0 = make([]byte, extra)
if _, err := io.ReadFull(br, t.Pad0); err != nil {
return err
}
// t.t.CommD ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -458,7 +738,20 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.CommD); err != nil {
return err
}
// t.t.CommR ([]uint8) (slice)
// t.CommR ([]uint8) (slice)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "CommR" {
return fmt.Errorf("expected struct map entry %s to be CommR", name)
}
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -475,24 +768,20 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.CommR); err != nil {
return err
}
// t.t.Pad1 ([]uint8) (slice)
// t.Proof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.Pad1: byte array too large (%d)", extra)
if name != "Proof" {
return fmt.Errorf("expected struct map entry %s to be Proof", name)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Pad1 = make([]byte, extra)
if _, err := io.ReadFull(br, t.Pad1); err != nil {
return err
}
// t.t.Proof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -509,7 +798,20 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.Proof); err != nil {
return err
}
// t.t.Ticket (storage.SealTicket) (struct)
// t.Ticket (storage.SealTicket) (struct)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Ticket" {
return fmt.Errorf("expected struct map entry %s to be Ticket", name)
}
{
@ -518,7 +820,20 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.PreCommitMessage (cid.Cid) (struct)
// t.PreCommitMessage (cid.Cid) (struct)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "PreCommitMessage" {
return fmt.Errorf("expected struct map entry %s to be PreCommitMessage", name)
}
{
@ -542,7 +857,20 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.Seed (storage.SealSeed) (struct)
// t.Seed (storage.SealSeed) (struct)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "Seed" {
return fmt.Errorf("expected struct map entry %s to be Seed", name)
}
{
@ -551,7 +879,20 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.CommitMessage (cid.Cid) (struct)
// t.CommitMessage (cid.Cid) (struct)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "CommitMessage" {
return fmt.Errorf("expected struct map entry %s to be CommitMessage", name)
}
{
@ -575,7 +916,57 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.LastErr (string) (string)
// t.FaultReportMsg (cid.Cid) (struct)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "FaultReportMsg" {
return fmt.Errorf("expected struct map entry %s to be FaultReportMsg", name)
}
{
pb, err := br.PeekByte()
if err != nil {
return err
}
if pb == cbg.CborNull[0] {
var nbuf [1]byte
if _, err := br.Read(nbuf[:]); err != nil {
return err
}
} else {
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.FaultReportMsg: %w", err)
}
t.FaultReportMsg = &c
}
}
// t.LastErr (string) (string)
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
if name != "LastErr" {
return fmt.Errorf("expected struct map entry %s to be LastErr", name)
}
{
sval, err := cbg.ReadString(br)

View File

@ -20,7 +20,7 @@ func (m *Miner) pledgeSector(ctx context.Context, sectorID uint64, existingPiece
return nil, nil
}
deals := make([]actors.StorageDeal, len(sizes))
deals := make([]actors.StorageDealProposal, len(sizes))
for i, size := range sizes {
release := m.sb.RateLimit()
commP, err := sectorbuilder.GeneratePieceCommitment(io.LimitReader(rand.New(rand.NewSource(42)), int64(size)), size)
@ -33,7 +33,6 @@ func (m *Miner) pledgeSector(ctx context.Context, sectorID uint64, existingPiece
sdp := actors.StorageDealProposal{
PieceRef: commP[:],
PieceSize: size,
PieceSerialization: actors.SerializationUnixFSv0,
Client: m.worker,
Provider: m.maddr,
ProposalExpiration: math.MaxUint64,
@ -47,14 +46,7 @@ func (m *Miner) pledgeSector(ctx context.Context, sectorID uint64, existingPiece
return nil, xerrors.Errorf("signing storage deal failed: ", err)
}
storageDeal := actors.StorageDeal{
Proposal: sdp,
}
if err := api.SignWith(ctx, m.api.WalletSign, m.worker, &storageDeal); err != nil {
return nil, xerrors.Errorf("signing storage deal failed: ", err)
}
deals[i] = storageDeal
deals[i] = sdp
}
params, aerr := actors.SerializeParams(&actors.PublishStorageDealsParams{

Some files were not shown because too many files have changed in this diff Show More