Merge pull request #1299 from filecoin-project/feat/update-sectorbuilder

Update lotus to use v23 proofs
This commit is contained in:
Łukasz Magiera 2020-02-29 03:14:19 +01:00 committed by GitHub
commit fa245c1e53
86 changed files with 1399 additions and 2079 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/ipfs/go-filestore" "github.com/ipfs/go-filestore"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
xerrors "golang.org/x/xerrors"
"github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
@ -135,7 +136,7 @@ type FullNode interface {
MsigGetAvailableBalance(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) MsigGetAvailableBalance(context.Context, address.Address, types.TipSetKey) (types.BigInt, error)
MarketEnsureAvailable(context.Context, address.Address, types.BigInt) error MarketEnsureAvailable(context.Context, address.Address, address.Address, types.BigInt) error
// MarketFreeBalance // MarketFreeBalance
PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error) PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error)
@ -228,9 +229,10 @@ type PaymentInfo struct {
} }
type VoucherSpec struct { type VoucherSpec struct {
Amount types.BigInt Amount types.BigInt
TimeLock abi.ChainEpoch TimeLockMin abi.ChainEpoch
MinSettle abi.ChainEpoch TimeLockMax abi.ChainEpoch
MinSettle abi.ChainEpoch
Extra *paych.ModVerifyParams Extra *paych.ModVerifyParams
} }
@ -339,3 +341,18 @@ type MpoolUpdate struct {
Type MpoolChange Type MpoolChange
Message *types.SignedMessage Message *types.SignedMessage
} }
func ProofTypeFromSectorSize(ssize abi.SectorSize) (abi.RegisteredProof, abi.RegisteredProof, error) {
switch ssize {
case 2 << 10:
return abi.RegisteredProof_StackedDRG2KiBPoSt, abi.RegisteredProof_StackedDRG2KiBSeal, nil
case 8 << 20:
return abi.RegisteredProof_StackedDRG8MiBPoSt, abi.RegisteredProof_StackedDRG8MiBSeal, nil
case 512 << 20:
return abi.RegisteredProof_StackedDRG512MiBPoSt, abi.RegisteredProof_StackedDRG512MiBSeal, nil
case 32 << 30:
return abi.RegisteredProof_StackedDRG32GiBPoSt, abi.RegisteredProof_StackedDRG32GiBSeal, nil
default:
return 0, 0, xerrors.Errorf("unsupported sector size for miner: %v", ssize)
}
}

View File

@ -1,10 +1,12 @@
package api package api
import ( import (
"bytes"
"context" "context"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
) )
@ -123,12 +125,12 @@ type SectorLog struct {
type SectorInfo struct { type SectorInfo struct {
SectorID abi.SectorNumber SectorID abi.SectorNumber
State SectorState State SectorState
CommD []byte CommD *cid.Cid
CommR []byte CommR *cid.Cid
Proof []byte Proof []byte
Deals []abi.DealID Deals []abi.DealID
Ticket sectorbuilder.SealTicket Ticket SealTicket
Seed sectorbuilder.SealSeed Seed SealSeed
Retries uint64 Retries uint64
LastErr string LastErr string
@ -145,3 +147,21 @@ type SealedRef struct {
type SealedRefs struct { type SealedRefs struct {
Refs []SealedRef Refs []SealedRef
} }
type SealTicket struct {
Value abi.SealRandomness
Epoch abi.ChainEpoch
}
type SealSeed struct {
Value abi.InteractiveSealRandomness
Epoch abi.ChainEpoch
}
func (st *SealTicket) Equals(ost *SealTicket) bool {
return bytes.Equal(st.Value, ost.Value) && st.Epoch == ost.Epoch
}
func (st *SealSeed) Equals(ost *SealSeed) bool {
return bytes.Equal(st.Value, ost.Value) && st.Epoch == ost.Epoch
}

View File

@ -101,7 +101,7 @@ type FullNodeStruct struct {
ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"` ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"`
ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"` ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"`
ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, path string) error `perm:"admin"` ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, path string) error `perm:"admin"`
ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"` ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"`
StateMinerSectors func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` StateMinerSectors func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"`
StateMinerProvingSet func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` StateMinerProvingSet func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"`
@ -132,7 +132,7 @@ type FullNodeStruct struct {
MsigGetAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"` MsigGetAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"`
MarketEnsureAvailable func(context.Context, address.Address, types.BigInt) error `perm:"sign"` MarketEnsureAvailable func(context.Context, address.Address, address.Address, types.BigInt) error `perm:"sign"`
PaychGet func(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*api.ChannelInfo, 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"` PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
@ -144,7 +144,7 @@ type FullNodeStruct struct {
PaychVoucherCheckValid func(context.Context, address.Address, *paych.SignedVoucher) error `perm:"read"` PaychVoucherCheckValid func(context.Context, address.Address, *paych.SignedVoucher) error `perm:"read"`
PaychVoucherCheckSpendable func(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (bool, error) `perm:"read"` PaychVoucherCheckSpendable func(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (bool, error) `perm:"read"`
PaychVoucherAdd func(context.Context, address.Address, *paych.SignedVoucher, []byte, types.BigInt) (types.BigInt, error) `perm:"write"` PaychVoucherAdd func(context.Context, address.Address, *paych.SignedVoucher, []byte, types.BigInt) (types.BigInt, error) `perm:"write"`
PaychVoucherCreate func(context.Context, address.Address, big.Int, uint64) (*paych.SignedVoucher, error) `perm:"sign"` PaychVoucherCreate func(context.Context, address.Address, big.Int, uint64) (*paych.SignedVoucher, error) `perm:"sign"`
PaychVoucherList func(context.Context, address.Address) ([]*paych.SignedVoucher, error) `perm:"write"` PaychVoucherList func(context.Context, address.Address) ([]*paych.SignedVoucher, error) `perm:"write"`
PaychVoucherSubmit func(context.Context, address.Address, *paych.SignedVoucher) (cid.Cid, error) `perm:"sign"` PaychVoucherSubmit func(context.Context, address.Address, *paych.SignedVoucher) (cid.Cid, error) `perm:"sign"`
} }
@ -519,8 +519,8 @@ func (c *FullNodeStruct) MsigGetAvailableBalance(ctx context.Context, a address.
return c.Internal.MsigGetAvailableBalance(ctx, a, tsk) return c.Internal.MsigGetAvailableBalance(ctx, a, tsk)
} }
func (c *FullNodeStruct) MarketEnsureAvailable(ctx context.Context, addr address.Address, amt types.BigInt) error { func (c *FullNodeStruct) MarketEnsureAvailable(ctx context.Context, addr, wallet address.Address, amt types.BigInt) error {
return c.Internal.MarketEnsureAvailable(ctx, addr, amt) return c.Internal.MarketEnsureAvailable(ctx, addr, wallet, amt)
} }
func (c *FullNodeStruct) PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*api.ChannelInfo, error) { func (c *FullNodeStruct) PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*api.ChannelInfo, error) {

View File

@ -432,3 +432,279 @@ func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error {
return nil return nil
} }
func (t *SealTicket) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{162}); err != nil {
return err
}
// t.Value (abi.SealRandomness) (slice)
if len("Value") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Value\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Value")))); err != nil {
return err
}
if _, err := w.Write([]byte("Value")); err != nil {
return err
}
if len(t.Value) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.Value was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Value)))); err != nil {
return err
}
if _, err := w.Write(t.Value); err != nil {
return err
}
// t.Epoch (abi.ChainEpoch) (int64)
if len("Epoch") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Epoch\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Epoch")))); err != nil {
return err
}
if _, err := w.Write([]byte("Epoch")); err != nil {
return err
}
if t.Epoch >= 0 {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Epoch))); err != nil {
return err
}
} else {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.Epoch)-1)); err != nil {
return err
}
}
return nil
}
func (t *SealTicket) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra > cbg.MaxLength {
return fmt.Errorf("SealTicket: map struct too large (%d)", extra)
}
var name string
n := extra
for i := uint64(0); i < n; i++ {
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
switch name {
// t.Value (abi.SealRandomness) (slice)
case "Value":
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.Value: byte array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Value = make([]byte, extra)
if _, err := io.ReadFull(br, t.Value); err != nil {
return err
}
// t.Epoch (abi.ChainEpoch) (int64)
case "Epoch":
{
maj, extra, err := cbg.CborReadHeader(br)
var extraI int64
if err != nil {
return err
}
switch maj {
case cbg.MajUnsignedInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 positive overflow")
}
case cbg.MajNegativeInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 negative oveflow")
}
extraI = -1 - extraI
default:
return fmt.Errorf("wrong type for int64 field: %d", maj)
}
t.Epoch = abi.ChainEpoch(extraI)
}
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
}
return nil
}
func (t *SealSeed) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{162}); err != nil {
return err
}
// t.Value (abi.InteractiveSealRandomness) (slice)
if len("Value") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Value\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Value")))); err != nil {
return err
}
if _, err := w.Write([]byte("Value")); err != nil {
return err
}
if len(t.Value) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.Value was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Value)))); err != nil {
return err
}
if _, err := w.Write(t.Value); err != nil {
return err
}
// t.Epoch (abi.ChainEpoch) (int64)
if len("Epoch") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Epoch\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Epoch")))); err != nil {
return err
}
if _, err := w.Write([]byte("Epoch")); err != nil {
return err
}
if t.Epoch >= 0 {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Epoch))); err != nil {
return err
}
} else {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.Epoch)-1)); err != nil {
return err
}
}
return nil
}
func (t *SealSeed) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra > cbg.MaxLength {
return fmt.Errorf("SealSeed: map struct too large (%d)", extra)
}
var name string
n := extra
for i := uint64(0); i < n; i++ {
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
switch name {
// t.Value (abi.InteractiveSealRandomness) (slice)
case "Value":
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.Value: byte array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Value = make([]byte, extra)
if _, err := io.ReadFull(br, t.Value); err != nil {
return err
}
// t.Epoch (abi.ChainEpoch) (int64)
case "Epoch":
{
maj, extra, err := cbg.CborReadHeader(br)
var extraI int64
if err != nil {
return err
}
switch maj {
case cbg.MajUnsignedInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 positive overflow")
}
case cbg.MajNegativeInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 negative oveflow")
}
extraI = -1 - extraI
default:
return fmt.Errorf("wrong type for int64 field: %d", maj)
}
t.Epoch = abi.ChainEpoch(extraI)
}
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
}
return nil
}

View File

@ -42,7 +42,7 @@ func TestDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration) {
} }
time.Sleep(time.Second) time.Sleep(time.Second)
data := make([]byte, 800) data := make([]byte, 1600)
rand.New(rand.NewSource(5)).Read(data) rand.New(rand.NewSource(5)).Read(data)
r := bytes.NewReader(data) r := bytes.NewReader(data)

View File

@ -10,7 +10,7 @@ func init() {
InsecurePoStValidation = true InsecurePoStValidation = true
} }
var SectorSizes = []abi.SectorSize{1024} var SectorSizes = []abi.SectorSize{2048}
// Seconds // Seconds
const BlockDelay = 6 const BlockDelay = 6

View File

@ -1,103 +1,83 @@
{ {
"v20-proof-of-spacetime-election-5f585aca354eb68e411c8582ed0efd800792430e4e76d73468c4fc03f1a8d6d2.params": { "v23-proof-of-spacetime-election-PoseidonHasher-0b0b9781bcb153efbb3cab4be3a792c4f555d4ab6f8dd62b27e1dcad08a34f22.params": {
"cid": "QmX7tYeNPWae2fjZ3Am6GB9dmHvLqvoz8dKo3PR98VYxH9", "cid": "Qmcqu1sgXs8p1mn8n9bCYovGgarCK5LvqFWbrCnYDxxjnq",
"digest": "39a9edec3355516674f0d12b926be493", "digest": "558ff029bef32ed76d87f5e448a03bd3",
"sector_size": 34359738368 "sector_size": 34359738368
}, },
"v20-proof-of-spacetime-election-5f585aca354eb68e411c8582ed0efd800792430e4e76d73468c4fc03f1a8d6d2.vk": { "v23-proof-of-spacetime-election-PoseidonHasher-0b0b9781bcb153efbb3cab4be3a792c4f555d4ab6f8dd62b27e1dcad08a34f22.vk": {
"cid": "QmbNGx7pNbGiEr8ykoHxVXHW2LNSmGdsxKtj1onZCyguCX", "cid": "QmS1SdHpnipjjcbnEG6b9T2q4rF6h8hc1jtZgEn5XBXW4o",
"digest": "0227ae7df4f2affe529ebafbbc7540ee", "digest": "2eca950d71d47b54125446f58d997035",
"sector_size": 34359738368 "sector_size": 34359738368
}, },
"v20-proof-of-spacetime-election-a4e18190d4b4657ba1b4d08a341871b2a6f398e327cb9951b28ab141fbdbf49d.params": { "v23-proof-of-spacetime-election-PoseidonHasher-0b499a953f1a9dcab420b3ba1e6b1f3952dc7f17cf67ed10406ae9a43e2b8ec5.params": {
"cid": "QmRGZsNp4mp1cZshcXqt3VMuWscAEsiMa2iepF4CsWWoiv", "cid": "QmbuwgxzqLKKutGBR4ay7jfPWATNynYUMGrwj8jCMG2pwN",
"digest": "991041a354b12c280542741f58c7f2ca", "digest": "7f9c06a57c8f2c029de378d63ba0b4c8",
"sector_size": 1024 "sector_size": 8388608
}, },
"v20-proof-of-spacetime-election-a4e18190d4b4657ba1b4d08a341871b2a6f398e327cb9951b28ab141fbdbf49d.vk": { "v23-proof-of-spacetime-election-PoseidonHasher-0b499a953f1a9dcab420b3ba1e6b1f3952dc7f17cf67ed10406ae9a43e2b8ec5.vk": {
"cid": "QmWpmrhCGVcfqLyqp5oGAnhPmCE5hGTPaauHi25mpQwRSU", "cid": "QmXt3hXJR4XjdE3uLyhTYvRuCLhCkmfGnK9sbYXmGZ4mgs",
"digest": "91fac550e1f9bccab213830bb0c85bd6", "digest": "2565ed8c01783d1fc8c6b1814a84dfbb",
"sector_size": 1024 "sector_size": 8388608
}, },
"v20-proof-of-spacetime-election-a9eb6d90b896a282ec2d3a875c6143e3fcff778f0da1460709e051833651559b.params": { "v23-proof-of-spacetime-election-PoseidonHasher-27a7fc680a47e4821f40cf1676fb80b9888820ef6867a71a175b4c9ae068ad3f.params": {
"cid": "QmenSZXh1EsSyHiSRvA6wb8yaPhYBTjrKehJw96Px5HnN4", "cid": "QmXn1SNAERUJWXkkdEUcYLTpsde6KStUPWpG5jCZNjDphy",
"digest": "6322eacd2773163ddd51f9ca7d645fc4", "digest": "21b612f054cead6cb7416932c98ad93d",
"sector_size": 1073741824 "sector_size": 536870912
}, },
"v20-proof-of-spacetime-election-a9eb6d90b896a282ec2d3a875c6143e3fcff778f0da1460709e051833651559b.vk": { "v23-proof-of-spacetime-election-PoseidonHasher-27a7fc680a47e4821f40cf1676fb80b9888820ef6867a71a175b4c9ae068ad3f.vk": {
"cid": "QmPvZoMKofw6eDhDg5ESJA2QAZP8HvM6qMQk7fw4pq9bQf", "cid": "QmS2b2157k1MgyAtdC8cP4wAxau4PbJPCLzaqx9hxgpbe7",
"digest": "0df62745fceac922e3e70847cfc70b52", "digest": "4a198ab9cf20245e1783d346d0ba7fe5",
"sector_size": 1073741824 "sector_size": 536870912
}, },
"v20-proof-of-spacetime-election-bf872523641b1de33553db2a177df13e412d7b3b0103e6696ae0a1cf5d525259.params": { "v23-proof-of-spacetime-election-PoseidonHasher-5916054ae98e28fc2f0470d1fb58eb875a6865be86f0b8c4e302d55f13217fef.params": {
"cid": "QmVibFqzkZoL8cwQmzj8njPokCQGCCx4pBcUH77bzgJgV9", "cid": "QmPY3BG7gZmQKnprsepGfgHdS5MwjV9Cqqi4YrYJZyvRuv",
"digest": "de9d71e672f286706a1673bd57abdaac", "digest": "386a70fe0e4ce16942b99e0694a3ce84",
"sector_size": 16777216 "sector_size": 2048
}, },
"v20-proof-of-spacetime-election-bf872523641b1de33553db2a177df13e412d7b3b0103e6696ae0a1cf5d525259.vk": { "v23-proof-of-spacetime-election-PoseidonHasher-5916054ae98e28fc2f0470d1fb58eb875a6865be86f0b8c4e302d55f13217fef.vk": {
"cid": "QmZa5FX27XyiEXQQLQpHqtMJKLzrcY8wMuj3pxzmSimSyu", "cid": "QmTikzLJfqC1izpbZP2BEw5GWAEJrUiKzWj4EyCPBtqgVT",
"digest": "7f796d3a0f13499181e44b5eee0cc744", "digest": "c1750423edbd09ec94fcbc8538209f1a",
"sector_size": 16777216 "sector_size": 2048
}, },
"v20-proof-of-spacetime-election-ffc3fb192364238b60977839d14e3154d4a98313e30d46694a12af54b6874975.params": { "v23-stacked-proof-of-replication-PoseidonHasher-Sha256Hasher-49442c8ce7545579cbd689d578301d0cc1e46e94e2499a0ec36de7ff4f4694a2.params": {
"cid": "Qmbt2SWWAmMcYoY3DAiRDXA8fAuqdqRLWucJMSxYmzBCmN", "cid": "QmdkRUVf7iBA5qYv5WFKdBN5fzsmGrKLRJs3F8PtR3azAc",
"digest": "151ae0ae183fc141e8c2bebc28e5cc10", "digest": "d8a4f1ff91b7b0395bae850d1277fc74",
"sector_size": 268435456 "sector_size": 8388608
}, },
"v20-proof-of-spacetime-election-ffc3fb192364238b60977839d14e3154d4a98313e30d46694a12af54b6874975.vk": { "v23-stacked-proof-of-replication-PoseidonHasher-Sha256Hasher-49442c8ce7545579cbd689d578301d0cc1e46e94e2499a0ec36de7ff4f4694a2.vk": {
"cid": "QmUxvPu4xdVmjMFihUKoYyEdXBqxsXkvmxRweU7KouWHji", "cid": "Qmdmrp75NToB9b6vxh5gZcECEHiGxxP8NRLhcVt7B9SjqQ",
"digest": "95eb89588e9d1832aca044c3a13178af", "digest": "ad2d7a1931ffb996278245cda162a2ea",
"sector_size": 268435456 "sector_size": 8388608
}, },
"v20-stacked-proof-of-replication-117839dacd1ef31e5968a6fd13bcd6fa86638d85c40c9241a1d07c2a954eb89b.params": { "v23-stacked-proof-of-replication-PoseidonHasher-Sha256Hasher-d84aa4581c74190f845596893ebe5b71da32ecf16e1d151b9fff74ee8f94d77c.params": {
"cid": "QmQZe8eLo2xXbhSDxtyYZNqEjqjdcWGdADywECRvNEZQdX", "cid": "QmcAn3A6iBPAcvHZWv4CG2KDg73T9kE5VvLYe9XrEmVQQd",
"digest": "fcd50e2e08a8560a6bb3418e883567ed", "digest": "dccdeb3bed61a7ca0184241c290970c9",
"sector_size": 268435456 "sector_size": 536870912
}, },
"v20-stacked-proof-of-replication-117839dacd1ef31e5968a6fd13bcd6fa86638d85c40c9241a1d07c2a954eb89b.vk": { "v23-stacked-proof-of-replication-PoseidonHasher-Sha256Hasher-d84aa4581c74190f845596893ebe5b71da32ecf16e1d151b9fff74ee8f94d77c.vk": {
"cid": "Qme1hn6QT1covfoUFGDZkqoE1pMTax9FNW3nWWmTNqFe7y", "cid": "QmWwLsV5wrkoWhrTmQCE62J5o3tmdvFDTznEy4N1Wsknqg",
"digest": "872e244d86499fd659082e3bcf3f13e7", "digest": "ce3d9951ebde0b10419339f26d604ba7",
"sector_size": 268435456 "sector_size": 536870912
}, },
"v20-stacked-proof-of-replication-b46f3a1051afbb67f70aae7082da95def62eee943662f3e1bf69837fb08aaae4.params": { "v23-stacked-proof-of-replication-PoseidonHasher-Sha256Hasher-fc32be6028c2398175466f36fa36810842ae8948fae15c84454af5b61ca99e15.params": {
"cid": "QmSfrPDC9jwY4MKrjzhCqDBBAG44wSDM8oE5NuDwWSh2xN", "cid": "Qmama5rJYTHFQbjamAuv3nyrJ8TYwg38hyKTs5rHM4F1s5",
"digest": "0a338b941c5f17946340de5fc95cab30", "digest": "d600e36f91e0ec5d1e44aa9de0cc2901",
"sector_size": 34359738368 "sector_size": 34359738368
}, },
"v20-stacked-proof-of-replication-b46f3a1051afbb67f70aae7082da95def62eee943662f3e1bf69837fb08aaae4.vk": { "v23-stacked-proof-of-replication-PoseidonHasher-Sha256Hasher-fc32be6028c2398175466f36fa36810842ae8948fae15c84454af5b61ca99e15.vk": {
"cid": "QmTDGynCmnbaZNBP3Bv3F3duC3ecKRubCKeMUiQQZYbGpF", "cid": "QmXnCBjLn8mJhQibrmdzwD8LKWVJf8MZvqTNSYYBZnfC7M",
"digest": "c752e070a6b7aa8b79aa661a6b600b55", "digest": "5fdf47c8b367f9dfa4d763eb70bef759",
"sector_size": 34359738368 "sector_size": 34359738368
}, },
"v20-stacked-proof-of-replication-e71093863cadc71de61f38311ee45816633973bbf34849316b147f8d2e66f199.params": { "v23-stacked-proof-of-replication-PoseidonHasher-Sha256Hasher-fe437922fe766f61b112750506d6be0e4ad5daa85ff9ce96549d99253ba61cbe.params": {
"cid": "QmXjSSnMUnc7EjQBYtTHhvLU3kXJTbUyhVhJRSTRehh186", "cid": "QmPUL7h51m671KGZaKB6nruAXtzFbMVwHousSnrPP4QtCH",
"digest": "efa407fd09202dffd15799a8518e73d3", "digest": "fcd772f59cdb2d1124fe0edc8b402bda",
"sector_size": 1024 "sector_size": 2048
}, },
"v20-stacked-proof-of-replication-e71093863cadc71de61f38311ee45816633973bbf34849316b147f8d2e66f199.vk": { "v23-stacked-proof-of-replication-PoseidonHasher-Sha256Hasher-fe437922fe766f61b112750506d6be0e4ad5daa85ff9ce96549d99253ba61cbe.vk": {
"cid": "QmYHW3zhQouDP4okFbXSsRMcZ8bokKGvzxqbv7ZrunPMiG", "cid": "QmaBZ83AuRzWkAT3QNtt5H7kQMnf5YT66ah6Q7DDMy6N9K",
"digest": "b2f09a0ccb62da28c890d5b881c8dcd2", "digest": "4ce2e879f537d085d872cae46f0b3365",
"sector_size": 1024 "sector_size": 2048
},
"v20-stacked-proof-of-replication-e99a585174b6a45b254ba4780d72c89ad808c305c6d11711009ade4f39dba8e9.params": {
"cid": "QmUhyfNeLb32LfSkjsUwTFYLXQGMj6JQ8daff4DdVMt79q",
"digest": "b53c1916a63839ec345aa2224e9198b7",
"sector_size": 1073741824
},
"v20-stacked-proof-of-replication-e99a585174b6a45b254ba4780d72c89ad808c305c6d11711009ade4f39dba8e9.vk": {
"cid": "QmWReGfbuoozNErbskmFvqV4q36BY6F2WWb4cVFc3zoYkA",
"digest": "20d58a3fae7343481f8298a2dd493dd7",
"sector_size": 1073741824
},
"v20-stacked-proof-of-replication-f571ee2386f4c65a68e802747f2d78691006fc81a67971c4d9641403fffece16.params": {
"cid": "QmSAHu14Pe8iav6BYCt9XkpHJ73XM7tcpY4d9JK9BST9HU",
"digest": "7698426202c7e07b26ef056d31485b3a",
"sector_size": 16777216
},
"v20-stacked-proof-of-replication-f571ee2386f4c65a68e802747f2d78691006fc81a67971c4d9641403fffece16.vk": {
"cid": "QmaKtFLShnhMGVn7P9UsHjkgqtqRFSwCStqqykBN7u8dax",
"digest": "834408e5c3fce6ec5d1bf64e64cee94e",
"sector_size": 16777216
} }
} }

View File

@ -1,101 +0,0 @@
package actors_test
import (
"testing"
"github.com/filecoin-project/specs-actors/actors/builtin"
samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/stretchr/testify/assert"
cbg "github.com/whyrusleeping/cbor-gen"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/specs-actors/actors/abi/big"
)
func TestMultiSigCreate(t *testing.T) {
var creatorAddr, sig1Addr, sig2Addr, outsideAddr address.Address
opts := []HarnessOpt{
HarnessAddr(&creatorAddr, 100000),
HarnessAddr(&sig1Addr, 100000),
HarnessAddr(&sig2Addr, 100000),
HarnessAddr(&outsideAddr, 100000),
}
h := NewHarness(t, opts...)
ret, _ := h.CreateActor(t, creatorAddr, builtin.MultisigActorCodeID,
&samsig.ConstructorParams{
Signers: []address.Address{creatorAddr, sig1Addr, sig2Addr},
NumApprovalsThreshold: 2,
})
ApplyOK(t, ret)
}
func ApplyOK(t testing.TB, ret *vm.ApplyRet) {
t.Helper()
if ret.ExitCode != 0 {
t.Fatalf("exit code should be 0, got %d, actorErr: %+v", ret.ExitCode, ret.ActorErr)
}
if ret.ActorErr != nil {
t.Fatalf("somehow got an error with exit == 0: %s", ret.ActorErr)
}
}
func TestMultiSigOps(t *testing.T) {
var creatorAddr, sig1Addr, sig2Addr, outsideAddr address.Address
var multSigAddr address.Address
opts := []HarnessOpt{
HarnessAddr(&creatorAddr, 100000),
HarnessAddr(&sig1Addr, 100000),
HarnessAddr(&sig2Addr, 100000),
HarnessAddr(&outsideAddr, 100000),
HarnessActor(&multSigAddr, &creatorAddr, builtin.MultisigActorCodeID,
func() cbg.CBORMarshaler {
return &samsig.ConstructorParams{
Signers: []address.Address{creatorAddr, sig1Addr, sig2Addr},
NumApprovalsThreshold: 2,
}
}),
}
h := NewHarness(t, opts...)
{
const chargeVal = 2000
// Send funds into the multisig
ret, _ := h.SendFunds(t, creatorAddr, multSigAddr, types.NewInt(chargeVal))
ApplyOK(t, ret)
h.AssertBalanceChange(t, creatorAddr, -chargeVal)
h.AssertBalanceChange(t, multSigAddr, chargeVal)
}
{
// Transfer funds outside of multsig
const sendVal = 1000
ret, _ := h.Invoke(t, creatorAddr, multSigAddr, uint64(builtin.MethodsMultisig.Propose),
&samsig.ProposeParams{
To: outsideAddr,
Value: big.NewInt(sendVal),
})
ApplyOK(t, ret)
var txIDParam samsig.TxnIDParams
err := cbor.DecodeInto(ret.Return, &txIDParam.ID)
assert.NoError(t, err, "decoding txid")
ret, _ = h.Invoke(t, outsideAddr, multSigAddr, uint64(builtin.MethodsMultisig.Approve),
&txIDParam)
assert.Equal(t, uint8(18), ret.ExitCode, "outsideAddr should not approve")
h.AssertBalanceChange(t, multSigAddr, 0)
ret2, _ := h.Invoke(t, sig1Addr, multSigAddr, uint64(builtin.MethodsMultisig.Approve),
&txIDParam)
ApplyOK(t, ret2)
h.AssertBalanceChange(t, outsideAddr, sendVal)
h.AssertBalanceChange(t, multSigAddr, -sendVal)
}
}

View File

@ -1,98 +0,0 @@
package actors_test
import (
"context"
"testing"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
)
func TestPaychCreate(t *testing.T) {
var creatorAddr, targetAddr address.Address
opts := []HarnessOpt{
HarnessAddr(&creatorAddr, 100000),
HarnessAddr(&targetAddr, 100000),
}
h := NewHarness(t, opts...)
ret, _ := h.CreateActor(t, creatorAddr, builtin.PaymentChannelActorCodeID,
&paych.ConstructorParams{
To: targetAddr,
})
ApplyOK(t, ret)
}
func signVoucher(t *testing.T, w *wallet.Wallet, addr address.Address, sv *paych.SignedVoucher) {
vb, err := sv.SigningBytes()
if err != nil {
t.Fatal(err)
}
sig, err := w.Sign(context.TODO(), addr, vb)
if err != nil {
t.Fatal(err)
}
sv.Signature = sig
}
func TestPaychUpdate(t *testing.T) {
var creatorAddr, targetAddr address.Address
opts := []HarnessOpt{
HarnessAddr(&creatorAddr, 100000),
HarnessAddr(&targetAddr, 100000),
}
h := NewHarness(t, opts...)
ret, _ := h.CreateActor(t, creatorAddr, builtin.PaymentChannelActorCodeID,
&paych.ConstructorParams{
To: targetAddr,
})
ApplyOK(t, ret)
pch, err := address.NewFromBytes(ret.Return)
if err != nil {
t.Fatal(err)
}
ret, _ = h.SendFunds(t, creatorAddr, pch, types.NewInt(5000))
ApplyOK(t, ret)
sv := &paych.SignedVoucher{
Amount: types.NewInt(100),
Nonce: 1,
}
signVoucher(t, h.w, creatorAddr, sv)
ret, _ = h.Invoke(t, targetAddr, pch, uint64(builtin.MethodsPaych.UpdateChannelState), &paych.UpdateChannelStateParams{
Sv: *sv,
})
ApplyOK(t, ret)
ret, _ = h.Invoke(t, targetAddr, pch, builtin.MethodsPaych.GetToSend, nil)
ApplyOK(t, ret)
bi := types.BigFromBytes(ret.Return)
if bi.String() != "100" {
t.Fatal("toSend amount was wrong: ", bi.String())
}
// TODO settle
ret, _ = h.Invoke(t, targetAddr, pch, uint64(builtin.MethodsPaych.Settle), nil)
ApplyOK(t, ret)
// now we have to 'wait' for the chain to advance.
h.BlockHeight = 1000
ret, _ = h.Invoke(t, targetAddr, pch, uint64(builtin.MethodsPaych.Settle), nil)
ApplyOK(t, ret)
h.AssertBalanceChange(t, targetAddr, 100)
h.AssertBalanceChange(t, creatorAddr, -100)
}

View File

@ -1,182 +0,0 @@
package actors_test
import (
"context"
"fmt"
"testing"
"github.com/filecoin-project/lotus/build"
cbg "github.com/whyrusleeping/cbor-gen"
"github.com/filecoin-project/go-address"
. "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/chain/wallet"
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
cid "github.com/ipfs/go-cid"
bstore "github.com/ipfs/go-ipfs-blockstore"
cbor "github.com/ipfs/go-ipld-cbor"
mh "github.com/multiformats/go-multihash"
"github.com/stretchr/testify/assert"
)
func TestStorageMarketCreateAndSlashMiner(t *testing.T) {
var ownerAddr, workerAddr address.Address
opts := []HarnessOpt{
HarnessAddr(&ownerAddr, 1000000),
HarnessAddr(&workerAddr, 100000),
}
h := NewHarness(t, opts...)
var minerAddr address.Address
{
// cheating the bootstrapping problem
cheatStorageMarketTotal(t, h.vm, h.cs.Blockstore())
ret, _ := h.InvokeWithValue(t, ownerAddr, StoragePowerAddress, SPAMethods.CreateStorageMiner,
types.NewInt(500000),
&CreateStorageMinerParams{
Owner: ownerAddr,
Worker: workerAddr,
SectorSize: build.SectorSizes[0],
PeerID: "fakepeerid",
})
ApplyOK(t, ret)
var err error
minerAddr, err = address.NewFromBytes(ret.Return)
assert.NoError(t, err)
}
{
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.IsValidMiner,
&IsValidMinerParam{Addr: minerAddr})
ApplyOK(t, ret)
var output bool
err := cbor.DecodeInto(ret.Return, &output)
if err != nil {
t.Fatalf("error decoding: %+v", err)
}
if !output {
t.Fatalf("%s is miner but IsValidMiner call returned false", minerAddr)
}
}
{
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.PowerLookup,
&PowerLookupParams{Miner: minerAddr})
ApplyOK(t, ret)
power := types.BigFromBytes(ret.Return)
if types.BigCmp(power, types.NewInt(0)) != 0 {
t.Fatalf("power should be zero, is: %s", power)
}
}
{
ret, _ := h.Invoke(t, ownerAddr, minerAddr, MAMethods.GetOwner, nil)
ApplyOK(t, ret)
oA, err := address.NewFromBytes(ret.Return)
assert.NoError(t, err)
assert.Equal(t, ownerAddr, oA, "return from GetOwner should be equal to the owner")
}
{
b1 := fakeBlock(t, minerAddr, 100)
b2 := fakeBlock(t, minerAddr, 101)
signBlock(t, h.w, workerAddr, b1)
signBlock(t, h.w, workerAddr, b2)
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.ArbitrateConsensusFault,
&ArbitrateConsensusFaultParams{
Block1: b1,
Block2: b1,
})
assert.Equal(t, uint8(3), ret.ExitCode, "should have failed with exit 3")
ret, _ = h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.ArbitrateConsensusFault,
&ArbitrateConsensusFaultParams{
Block1: b1,
Block2: b2,
})
ApplyOK(t, ret)
}
{
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.PowerLookup,
&PowerLookupParams{Miner: minerAddr})
assert.Equal(t, ret.ExitCode, byte(1))
}
{
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.IsValidMiner, &IsValidMinerParam{minerAddr})
ApplyOK(t, ret)
assert.Equal(t, ret.Return, cbg.CborBoolFalse)
}
}
func cheatStorageMarketTotal(t *testing.T, vm *vm.VM, bs bstore.Blockstore) {
t.Helper()
sma, err := vm.StateTree().GetActor(StoragePowerAddress)
if err != nil {
t.Fatal(err)
}
cst := cbor.NewCborStore(bs)
var smastate StoragePowerState
if err := cst.Get(context.TODO(), sma.Head, &smastate); err != nil {
t.Fatal(err)
}
smastate.TotalStorage = types.NewInt(10000)
c, err := cst.Put(context.TODO(), &smastate)
if err != nil {
t.Fatal(err)
}
sma.Head = c
if err := vm.StateTree().SetActor(StoragePowerAddress, sma); err != nil {
t.Fatal(err)
}
}
func fakeBlock(t *testing.T, minerAddr address.Address, ts uint64) *types.BlockHeader {
c := fakeCid(t, 1)
return &types.BlockHeader{Height: 8000, Miner: minerAddr, Timestamp: ts, ParentStateRoot: c, Messages: c, ParentMessageReceipts: c, BLSAggregate: types.Signature{Type: types.KTBLS}}
}
func fakeCid(t *testing.T, s int) cid.Cid {
t.Helper()
c, err := cid.NewPrefixV1(cid.Raw, mh.IDENTITY).Sum([]byte(fmt.Sprintf("%d", s)))
if err != nil {
t.Fatal(err)
}
return c
}
func signBlock(t *testing.T, w *wallet.Wallet, worker address.Address, blk *types.BlockHeader) {
t.Helper()
sb, err := blk.SigningBytes()
if err != nil {
t.Fatal(err)
}
sig, err := w.Sign(context.TODO(), worker, sb)
if err != nil {
t.Fatal(err)
}
blk.BlockSig = sig
}

View File

@ -1,159 +0,0 @@
package actors_test
import (
"context"
"encoding/binary"
"fmt"
"testing"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/gen/genesis"
"github.com/filecoin-project/go-address"
dstore "github.com/ipfs/go-datastore"
bstore "github.com/ipfs/go-ipfs-blockstore"
. "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
)
func blsaddr(n uint64) address.Address {
buf := make([]byte, 48)
binary.PutUvarint(buf, n)
addr, err := address.NewBLSAddress(buf)
if err != nil {
panic(err) // ok
}
return addr
}
func setupVMTestEnv(t *testing.T) (*vm.VM, []address.Address, bstore.Blockstore) {
bs := bstore.NewBlockstore(dstore.NewMapDatastore())
from := blsaddr(0)
maddr := blsaddr(1)
actors := map[address.Address]types.BigInt{
from: types.NewInt(1000000),
maddr: types.NewInt(0),
}
st, err := genesis.MakeInitialStateTree(bs, actors)
if err != nil {
t.Fatal(err)
}
stateroot, err := st.Flush(context.TODO())
if err != nil {
t.Fatal(err)
}
cs := store.NewChainStore(bs, nil, nil)
// TODO: should probabaly mock out the randomness bit, nil works for now
vm, err := vm.NewVM(stateroot, 1, nil, maddr, cs.Blockstore(), cs.VMSys())
if err != nil {
t.Fatal(err)
}
return vm, []address.Address{from, maddr}, bs
}
func TestVMInvokeMethod(t *testing.T) {
vm, addrs, _ := setupVMTestEnv(t)
from := addrs[0]
var err error
cenc, err := SerializeParams(&StorageMinerConstructorParams{Owner: from, Worker: from})
if err != nil {
t.Fatal(err)
}
execparams := &ExecParams{
Code: StorageMinerCodeCid,
Params: cenc,
}
enc, err := SerializeParams(execparams)
if err != nil {
t.Fatal(err)
}
msg := &types.Message{
To: InitAddress,
From: from,
Method: IAMethods.Exec,
Params: enc,
GasPrice: types.NewInt(1),
GasLimit: types.NewInt(10000),
Value: types.NewInt(0),
}
ret, err := vm.ApplyMessage(context.TODO(), msg)
if err != nil {
t.Fatal(err)
}
if ret.ExitCode != 0 {
t.Fatal("invocation failed")
}
outaddr, err := address.NewFromBytes(ret.Return)
if err != nil {
t.Fatal(err)
}
if outaddr.String() != "t0102" {
t.Fatal("hold up")
}
}
func TestStorageMarketActorCreateMiner(t *testing.T) {
vm, addrs, bs := setupVMTestEnv(t)
from := addrs[0]
maddr := addrs[1]
cheatStorageMarketTotal(t, vm, bs)
params := &StorageMinerConstructorParams{
Owner: maddr,
Worker: maddr,
SectorSize: build.SectorSizes[0],
PeerID: "fakepeerid",
}
var err error
enc, err := SerializeParams(params)
if err != nil {
t.Fatal(err)
}
msg := &types.Message{
To: StoragePowerAddress,
From: from,
Method: SPAMethods.CreateStorageMiner,
Params: enc,
GasPrice: types.NewInt(1),
GasLimit: types.NewInt(10000),
Value: types.NewInt(50000),
}
ret, err := vm.ApplyMessage(context.TODO(), msg)
if err != nil {
t.Fatal(err)
}
if ret.ExitCode != 0 {
fmt.Println(ret.ActorErr)
t.Fatal("invocation failed: ", ret.ExitCode)
}
outaddr, err := address.NewFromBytes(ret.Return)
if err != nil {
t.Fatal(err)
}
if outaddr.String() != "t0102" {
t.Fatal("hold up")
}
}

View File

@ -1,368 +0,0 @@
package actors_test
import (
"bytes"
"context"
"math/rand"
"testing"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/go-sectorbuilder"
"github.com/ipfs/go-cid"
dstore "github.com/ipfs/go-datastore"
blockstore "github.com/ipfs/go-ipfs-blockstore"
bstore "github.com/ipfs/go-ipfs-blockstore"
cbor "github.com/ipfs/go-ipld-cbor"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/gen/genesis"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/chain/wallet"
)
const testGasLimit = 10000
type HarnessInit struct {
NAddrs uint64
Addrs map[address.Address]types.BigInt
Miner address.Address
}
type HarnessStage int
const (
HarnessPreInit HarnessStage = iota
HarnessPostInit
)
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
Rand vm.Rand
BlockHeight abi.ChainEpoch
lastBalanceCheck map[address.Address]types.BigInt
ctx context.Context
bs blockstore.Blockstore
vm *vm.VM
cs *store.ChainStore
w *wallet.Wallet
}
var HarnessMinerFunds = types.NewInt(1000000)
func HarnessAddr(addr *address.Address, value uint64) HarnessOpt {
return func(t testing.TB, h *Harness) error {
if h.Stage != HarnessPreInit {
return nil
}
hi := &h.HI
if addr.Empty() {
k, err := h.w.GenerateKey(types.KTSecp256k1)
if err != nil {
t.Fatal(err)
}
*addr = k
}
hi.Addrs[*addr] = types.NewInt(value)
return nil
}
}
func HarnessMiner(addr *address.Address) HarnessOpt {
return func(_ testing.TB, h *Harness) error {
if h.Stage != HarnessPreInit {
return nil
}
hi := &h.HI
if addr.Empty() {
*addr = hi.Miner
return nil
}
delete(hi.Addrs, hi.Miner)
hi.Miner = *addr
return nil
}
}
func HarnessActor(actor *address.Address, creator *address.Address, code cid.Cid, params func() cbg.CBORMarshaler) HarnessOpt {
return func(t testing.TB, h *Harness) error {
if h.Stage != HarnessPostInit {
return nil
}
if !actor.Empty() {
return xerrors.New("actor address should be empty")
}
ret, _ := h.CreateActor(t, *creator, code, params())
if ret.ExitCode != 0 {
return xerrors.Errorf("creating actor: %w", ret.ActorErr)
}
var err error
*actor, err = address.NewFromBytes(ret.Return)
return err
}
}
func HarnessAddMiner(addr *address.Address, creator *address.Address) HarnessOpt {
return func(t testing.TB, h *Harness) error {
if h.Stage != HarnessPostInit {
return nil
}
if !addr.Empty() {
return xerrors.New("actor address should be empty")
}
ret, _ := h.InvokeWithValue(t, *creator, actors.StoragePowerAddress,
actors.SPAMethods.CreateStorageMiner, types.NewInt(3000), &actors.StorageMinerConstructorParams{
Owner: *creator,
Worker: *creator,
SectorSize: 1024,
PeerID: "fakepeerid",
})
if ret.ExitCode != 0 {
return xerrors.Errorf("creating actor: %w", ret.ActorErr)
}
var err error
*addr, err = address.NewFromBytes(ret.Return)
return err
}
}
func HarnessCtx(ctx context.Context) HarnessOpt {
return func(t testing.TB, h *Harness) error {
h.ctx = ctx
return nil
}
}
func NewHarness(t *testing.T, options ...HarnessOpt) *Harness {
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
if err != nil {
t.Fatal(err)
}
h := &Harness{
Stage: HarnessPreInit,
Nonces: make(map[address.Address]uint64),
Rand: &fakeRand{},
HI: HarnessInit{
NAddrs: 1,
Miner: blsaddr(0),
Addrs: map[address.Address]types.BigInt{
blsaddr(0): HarnessMinerFunds,
},
},
GasCharges: make(map[address.Address]types.BigInt),
lastBalanceCheck: make(map[address.Address]types.BigInt),
w: w,
ctx: context.Background(),
bs: bstore.NewBlockstore(dstore.NewMapDatastore()),
BlockHeight: 0,
}
for _, opt := range options {
err := opt(t, h)
if err != nil {
t.Fatalf("Applying options: %v", err)
}
}
st, err := genesis.MakeInitialStateTree(h.bs, h.HI.Addrs)
if err != nil {
t.Fatal(err)
}
stateroot, err := st.Flush(context.TODO())
if err != nil {
t.Fatal(err)
}
stateroot, err = genesis.SetupStorageMarketActor(h.bs, stateroot, nil)
if err != nil {
t.Fatal(err)
}
h.cs = store.NewChainStore(h.bs, nil, vm.Syscalls(sectorbuilder.ProofVerifier))
h.vm, err = vm.NewVM(stateroot, 1, h.Rand, h.HI.Miner, h.cs.Blockstore(), h.cs.VMSys())
if err != nil {
t.Fatal(err)
}
h.Stage = HarnessPostInit
for _, opt := range options {
err := opt(t, h)
if err != nil {
t.Fatalf("Applying options: %+v", err)
}
}
return h
}
func (h *Harness) Apply(t testing.TB, msg types.Message) (*vm.ApplyRet, *state.StateTree) {
t.Helper()
if msg.Nonce == 0 {
msg.Nonce, _ = h.Nonces[msg.From]
h.Nonces[msg.From] = msg.Nonce + 1
}
ret, err := h.vm.ApplyMessage(h.ctx, &msg)
if err != nil {
t.Fatalf("Applying message: %+v", err)
}
if ret != nil {
if prev, ok := h.GasCharges[msg.From]; ok {
h.GasCharges[msg.From] = types.BigAdd(prev, ret.GasUsed)
} else {
h.GasCharges[msg.From] = ret.GasUsed
}
}
stateroot, err := h.vm.Flush(context.TODO())
if err != nil {
t.Fatalf("Flushing VM: %+v", err)
}
cst := cbor.NewCborStore(h.bs)
state, err := state.LoadStateTree(cst, stateroot)
if err != nil {
t.Fatalf("Loading state tree: %+v", err)
}
return ret, state
}
func (h *Harness) CreateActor(t testing.TB, from address.Address,
code cid.Cid, params cbg.CBORMarshaler) (*vm.ApplyRet, *state.StateTree) {
t.Helper()
return h.Apply(t, types.Message{
To: actors.InitAddress,
From: from,
Method: actors.IAMethods.Exec,
Params: DumpObject(t,
&actors.ExecParams{
Code: code,
Params: DumpObject(t, params),
}),
GasPrice: types.NewInt(1),
GasLimit: types.NewInt(testGasLimit),
Value: types.NewInt(0),
})
}
func (h *Harness) SendFunds(t testing.TB, from address.Address, to address.Address,
value types.BigInt) (*vm.ApplyRet, *state.StateTree) {
t.Helper()
return h.Apply(t, types.Message{
To: to,
From: from,
Method: 0,
Value: value,
GasPrice: types.NewInt(1),
GasLimit: types.NewInt(testGasLimit),
})
}
func (h *Harness) Invoke(t testing.TB, from address.Address, to address.Address,
method uint64, params cbg.CBORMarshaler) (*vm.ApplyRet, *state.StateTree) {
t.Helper()
return h.InvokeWithValue(t, from, to, method, types.NewInt(0), params)
}
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,
Method: method,
Value: value,
Params: DumpObject(t, params),
GasPrice: types.NewInt(1),
GasLimit: types.NewInt(testGasLimit),
})
}
func (h *Harness) AssertBalance(t testing.TB, addr address.Address, amt uint64) {
t.Helper()
b, err := h.vm.ActorBalance(addr)
if err != nil {
t.Fatalf("%+v", err)
}
if types.BigCmp(types.NewInt(amt), b) != 0 {
t.Errorf("expected %s to have balanced of %d. Instead has %s", addr, amt, b)
}
}
func (h *Harness) AssertBalanceChange(t testing.TB, addr address.Address, amt int64) {
t.Helper()
lastBalance, ok := h.lastBalanceCheck[addr]
if !ok {
lastBalance, ok = h.HI.Addrs[addr]
if !ok {
lastBalance = types.NewInt(0)
}
}
var expected types.BigInt
if amt >= 0 {
expected = types.BigAdd(lastBalance, types.NewInt(uint64(amt)))
} else {
expected = types.BigSub(lastBalance, types.NewInt(uint64(-amt)))
}
h.lastBalanceCheck[addr] = expected
if gasUsed, ok := h.GasCharges[addr]; ok {
expected = types.BigSub(expected, gasUsed)
}
b, err := h.vm.ActorBalance(addr)
if err != nil {
t.Fatalf("%+v", err)
}
if types.BigCmp(expected, b) != 0 {
t.Errorf("expected %s to have balanced of %d. Instead has %s", addr, amt, b)
}
}
func DumpObject(t testing.TB, obj cbg.CBORMarshaler) []byte {
if obj == nil {
return nil
}
t.Helper()
b := new(bytes.Buffer)
if err := obj.MarshalCBOR(b); err != nil {
t.Fatalf("dumping params: %+v", err)
}
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

@ -7,7 +7,7 @@ import (
"io" "io"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
cid "github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors" xerrors "golang.org/x/xerrors"
) )

View File

@ -130,7 +130,7 @@ func (e *calledEvents) checkNewCalls(ts *types.TipSet) {
for _, matchFn := range matchFns { for _, matchFn := range matchFns {
ok, err := matchFn(msg) ok, err := matchFn(msg)
if err != nil { if err != nil {
log.Warnf("event matcher failed: %s", err) log.Errorf("event matcher failed: %s", err)
continue continue
} }
matched = ok matched = ok

View File

@ -8,6 +8,7 @@ import (
"io/ioutil" "io/ioutil"
"sync/atomic" "sync/atomic"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
commcid "github.com/filecoin-project/go-fil-commcid" commcid "github.com/filecoin-project/go-fil-commcid"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder" sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
@ -23,7 +24,6 @@ import (
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
"github.com/ipfs/go-merkledag" "github.com/ipfs/go-merkledag"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis" genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis"
@ -136,7 +136,7 @@ func NewGenerator() (*ChainGen, error) {
return nil, err return nil, err
} }
genm1, k1, err := seed.PreSeal(maddr1, 1024, 0, 1, m1temp, []byte("some randomness"), nil) genm1, k1, err := seed.PreSeal(maddr1, abi.RegisteredProof_StackedDRG2KiBPoSt, 0, 1, m1temp, []byte("some randomness"), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -148,7 +148,7 @@ func NewGenerator() (*ChainGen, error) {
return nil, err return nil, err
} }
genm2, k2, err := seed.PreSeal(maddr2, 1024, 0, 1, m2temp, []byte("some randomness"), nil) genm2, k2, err := seed.PreSeal(maddr2, abi.RegisteredProof_StackedDRG2KiBPoSt, 0, 1, m2temp, []byte("some randomness"), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -514,32 +514,37 @@ func (mca mca) WalletSign(ctx context.Context, a address.Address, v []byte) (*cr
} }
type ElectionPoStProver interface { type ElectionPoStProver interface {
GenerateCandidates(context.Context, sectorbuilder.SortedPublicSectorInfo, []byte) ([]sectorbuilder.EPostCandidate, error) GenerateCandidates(context.Context, []abi.SectorInfo, abi.PoStRandomness) ([]ffi.PoStCandidateWithTicket, error)
ComputeProof(context.Context, sectorbuilder.SortedPublicSectorInfo, []byte, []sectorbuilder.EPostCandidate) ([]byte, error) ComputeProof(context.Context, []abi.SectorInfo, []byte, []ffi.PoStCandidateWithTicket) ([]abi.PoStProof, error)
} }
type eppProvider struct{} type eppProvider struct{}
func (epp *eppProvider) GenerateCandidates(ctx context.Context, _ sectorbuilder.SortedPublicSectorInfo, eprand []byte) ([]sectorbuilder.EPostCandidate, error) { func (epp *eppProvider) GenerateCandidates(ctx context.Context, _ []abi.SectorInfo, eprand abi.PoStRandomness) ([]ffi.PoStCandidateWithTicket, error) {
return []sectorbuilder.EPostCandidate{ return []ffi.PoStCandidateWithTicket{
{ {
SectorNum: 1, Candidate: abi.PoStCandidate{
PartialTicket: [32]byte{}, RegisteredProof: abi.RegisteredProof_StackedDRG2KiBPoSt,
Ticket: [32]byte{}, SectorID: abi.SectorID{Number: 1},
SectorChallengeIndex: 1, PartialTicket: abi.PartialTicket{},
PrivateProof: abi.PrivatePoStCandidateProof{},
ChallengeIndex: 1,
},
}, },
}, nil }, nil
} }
func (epp *eppProvider) ComputeProof(ctx context.Context, _ sectorbuilder.SortedPublicSectorInfo, eprand []byte, winners []sectorbuilder.EPostCandidate) ([]byte, error) { func (epp *eppProvider) ComputeProof(ctx context.Context, _ []abi.SectorInfo, eprand []byte, winners []ffi.PoStCandidateWithTicket) ([]abi.PoStProof, error) {
return []byte("valid proof"), nil return []abi.PoStProof{{
ProofBytes: []byte("valid proof"),
}}, nil
} }
type ProofInput struct { type ProofInput struct {
sectors sectorbuilder.SortedPublicSectorInfo sectors []abi.SectorInfo
hvrf []byte hvrf []byte
winners []sectorbuilder.EPostCandidate winners []ffi.PoStCandidateWithTicket
vrfout []byte vrfout []byte
} }
@ -567,23 +572,20 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round int64, miner add
return nil, nil return nil, nil
} }
var sinfos []ffi.PublicSectorInfo var sinfos []abi.SectorInfo
for _, s := range pset { for _, s := range pset {
cr, err := commcid.CIDToReplicaCommitmentV1(s.Info.Info.SealedCID) if s.Info.Info.RegisteredProof == 0 {
if err != nil { return nil, xerrors.Errorf("sector %d in proving set had registered type of zero", s.ID)
return nil, xerrors.Errorf("get sealed cid: %w", err)
} }
var commRa [32]byte sinfos = append(sinfos, abi.SectorInfo{
copy(commRa[:], cr) SectorNumber: s.ID,
sinfos = append(sinfos, ffi.PublicSectorInfo{ SealedCID: s.Info.Info.SealedCID,
SectorNum: s.ID, RegisteredProof: s.Info.Info.RegisteredProof,
CommR: commRa,
}) })
} }
sectors := sectorbuilder.NewSortedPublicSectorInfo(sinfos)
hvrf := sha256.Sum256(vrfout) hvrf := sha256.Sum256(vrfout)
candidates, err := epp.GenerateCandidates(ctx, sectors, hvrf[:]) candidates, err := epp.GenerateCandidates(ctx, sinfos, hvrf[:])
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to generate electionPoSt candidates: %w", err) return nil, xerrors.Errorf("failed to generate electionPoSt candidates: %w", err)
} }
@ -598,9 +600,9 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round int64, miner add
return nil, xerrors.Errorf("failed to look up miners sector size: %w", err) return nil, xerrors.Errorf("failed to look up miners sector size: %w", err)
} }
var winners []sectorbuilder.EPostCandidate var winners []ffi.PoStCandidateWithTicket
for _, c := range candidates { for _, c := range candidates {
if types.IsTicketWinner(c.PartialTicket[:], ssize, uint64(len(sinfos)), pow.TotalPower) { if types.IsTicketWinner(c.Candidate.PartialTicket, ssize, uint64(len(sinfos)), pow.TotalPower) {
winners = append(winners, c) winners = append(winners, c)
} }
} }
@ -611,7 +613,7 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round int64, miner add
} }
return &ProofInput{ return &ProofInput{
sectors: sectors, sectors: sinfos,
hvrf: hvrf[:], hvrf: hvrf[:],
winners: winners, winners: winners,
vrfout: vrfout, vrfout: vrfout,
@ -625,16 +627,16 @@ func ComputeProof(ctx context.Context, epp ElectionPoStProver, pi *ProofInput) (
} }
ept := types.EPostProof{ ept := types.EPostProof{
Proof: proof, Proofs: proof,
PostRand: pi.vrfout, PostRand: pi.vrfout,
} }
for _, win := range pi.winners { for _, win := range pi.winners {
part := make([]byte, 32) part := make([]byte, 32)
copy(part, win.PartialTicket[:]) copy(part, win.Candidate.PartialTicket)
ept.Candidates = append(ept.Candidates, types.EPostTicket{ ept.Candidates = append(ept.Candidates, types.EPostTicket{
Partial: part, Partial: part,
SectorID: win.SectorNum, SectorID: win.Candidate.SectorID.Number,
ChallengeIndex: win.SectorChallengeIndex, ChallengeIndex: uint64(win.Candidate.ChallengeIndex),
}) })
} }
@ -676,17 +678,17 @@ type genFakeVerifier struct{}
var _ sectorbuilder.Verifier = (*genFakeVerifier)(nil) var _ sectorbuilder.Verifier = (*genFakeVerifier)(nil)
func (m genFakeVerifier) VerifyElectionPost(ctx context.Context, sectorSize abi.SectorSize, sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []sectorbuilder.EPostCandidate, proverID address.Address) (bool, error) { func (m genFakeVerifier) VerifyElectionPost(ctx context.Context, pvi abi.PoStVerifyInfo) (bool, error) {
panic("nyi") panic("nyi")
} }
func (m genFakeVerifier) GenerateDataCommitment(ssize abi.PaddedPieceSize, pieces []ffi.PublicPieceInfo) ([sectorbuilder.CommLen]byte, error) { func (m genFakeVerifier) GenerateDataCommitment(ssize abi.PaddedPieceSize, pieces []abi.PieceInfo) (cid.Cid, error) {
return sbmock.MockVerifier.GenerateDataCommitment(ssize, pieces) return sbmock.MockVerifier.GenerateDataCommitment(ssize, pieces)
} }
func (m genFakeVerifier) VerifySeal(sectorSize abi.SectorSize, commR, commD []byte, proverID address.Address, ticket []byte, seed []byte, sectorID abi.SectorNumber, proof []byte) (bool, error) { func (m genFakeVerifier) VerifySeal(svi abi.SealVerifyInfo) (bool, error) {
return true, nil return true, nil
} }
func (m genFakeVerifier) VerifyFallbackPost(ctx context.Context, sectorSize abi.SectorSize, sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []sectorbuilder.EPostCandidate, proverID address.Address, faults uint64) (bool, error) { func (m genFakeVerifier) VerifyFallbackPost(ctx context.Context, pvi abi.PoStVerifyInfo) (bool, error) {
panic("nyi") panic("nyi")
} }

View File

@ -14,8 +14,8 @@ import (
) )
func init() { func init() {
build.SectorSizes = []abi.SectorSize{1024} build.SectorSizes = []abi.SectorSize{2048}
build.MinimumMinerPower = 1024 build.MinimumMinerPower = 2048
} }
func testGeneration(t testing.TB, n int, msgs int) { func testGeneration(t testing.TB, n int, msgs int) {

View File

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"github.com/filecoin-project/go-amt-ipld/v2" "github.com/filecoin-project/go-amt-ipld/v2"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/account" "github.com/filecoin-project/specs-actors/actors/builtin/account"
@ -257,7 +258,7 @@ func MakeGenesisBlock(ctx context.Context, bs bstore.Blockstore, sys runtime.Sys
Miner: builtin.InitActorAddr, Miner: builtin.InitActorAddr,
Ticket: genesisticket, Ticket: genesisticket,
EPostProof: types.EPostProof{ EPostProof: types.EPostProof{
Proof: []byte("not a real proof"), Proofs: []abi.PoStProof{{ProofBytes: []byte("not a real proof")}},
PostRand: []byte("i guess this is kinda random"), PostRand: []byte("i guess this is kinda random"),
}, },
Parents: []cid.Cid{}, Parents: []cid.Cid{},

View File

@ -7,7 +7,6 @@ import (
"math/rand" "math/rand"
cborutil "github.com/filecoin-project/go-cbor-util" cborutil "github.com/filecoin-project/go-cbor-util"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/power"
cbor "github.com/ipfs/go-ipld-cbor" cbor "github.com/ipfs/go-ipld-cbor"
@ -62,6 +61,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
var maddr address.Address var maddr address.Address
{ {
constructorParams := &power.CreateMinerParams{ constructorParams := &power.CreateMinerParams{
Owner: m.Worker,
Worker: m.Worker, Worker: m.Worker,
SectorSize: m.SectorSize, SectorSize: m.SectorSize,
Peer: m.PeerId, Peer: m.PeerId,
@ -201,11 +201,12 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
{ {
newSectorInfo := &miner.SectorOnChainInfo{ newSectorInfo := &miner.SectorOnChainInfo{
Info: miner.SectorPreCommitInfo{ Info: miner.SectorPreCommitInfo{
SectorNumber: preseal.SectorID, RegisteredProof: preseal.ProofType,
SealedCID: commcid.ReplicaCommitmentV1ToCID(preseal.CommR[:]), SectorNumber: preseal.SectorID,
SealRandEpoch: 0, SealedCID: preseal.CommR,
DealIDs: []abi.DealID{dealIDs[pi]}, SealRandEpoch: 0,
Expiration: preseal.Deal.EndEpoch, DealIDs: []abi.DealID{dealIDs[pi]},
Expiration: preseal.Deal.EndEpoch,
}, },
ActivationEpoch: 0, ActivationEpoch: 0,
DealWeight: dealWeight, DealWeight: dealWeight,

View File

@ -5,6 +5,7 @@ import (
"sync" "sync"
"github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin"
logging "github.com/ipfs/go-log"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
@ -14,6 +15,8 @@ import (
"github.com/filecoin-project/lotus/node/impl/full" "github.com/filecoin-project/lotus/node/impl/full"
) )
var log = logging.Logger("market_adapter")
type FundMgr struct { type FundMgr struct {
sm *stmgr.StateManager sm *stmgr.StateManager
mpool full.MpoolAPI mpool full.MpoolAPI
@ -31,7 +34,7 @@ func NewFundMgr(sm *stmgr.StateManager, mpool full.MpoolAPI) *FundMgr {
} }
} }
func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr address.Address, amt types.BigInt) error { func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Address, amt types.BigInt) error {
fm.lk.Lock() fm.lk.Lock()
avail, ok := fm.available[addr] avail, ok := fm.available[addr]
if !ok { if !ok {
@ -64,7 +67,7 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr address.Address, am
smsg, err := fm.mpool.MpoolPushMessage(ctx, &types.Message{ smsg, err := fm.mpool.MpoolPushMessage(ctx, &types.Message{
To: builtin.StorageMarketActorAddr, To: builtin.StorageMarketActorAddr,
From: addr, From: wallet,
Value: toAdd, Value: toAdd,
GasPrice: types.NewInt(0), GasPrice: types.NewInt(0),
GasLimit: types.NewInt(1000000), GasLimit: types.NewInt(1000000),
@ -77,7 +80,7 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr address.Address, am
_, r, err := fm.sm.WaitForMessage(ctx, smsg.Cid()) _, r, err := fm.sm.WaitForMessage(ctx, smsg.Cid())
if err != nil { if err != nil {
return err return xerrors.Errorf("failed waiting for market AddBalance message: %w", err)
} }
if r.ExitCode != 0 { if r.ExitCode != 0 {

View File

@ -12,6 +12,7 @@ import (
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
"github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/specs-actors/actors/runtime"
"github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/specs-actors/actors/util/adt"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors"
@ -34,8 +35,8 @@ import (
) )
func init() { func init() {
build.SectorSizes = []abi.SectorSize{1024} build.SectorSizes = []abi.SectorSize{2048}
build.MinimumMinerPower = 1024 build.MinimumMinerPower = 2048
} }
const testForkHeight = 40 const testForkHeight = 40
@ -57,7 +58,7 @@ func (tas *testActorState) UnmarshalCBOR(r io.Reader) error {
return err return err
} }
if t != cbg.MajUnsignedInt { if t != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type in test actor state") return fmt.Errorf("wrong type in test actor state (got %d)", t)
} }
tas.HasUpgraded = v tas.HasUpgraded = v
return nil return nil
@ -70,38 +71,29 @@ func (ta *testActor) Exports() []interface{} {
} }
} }
func (ta *testActor) Constructor(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) { func (ta *testActor) Constructor(rt runtime.Runtime, params *adt.EmptyValue) *adt.EmptyValue {
c, err := vmctx.Storage().Put(&testActorState{11})
if err != nil {
return nil, err
}
empty, err := vmctx.Storage().Put(&adt.EmptyValue{})
if err != nil {
return nil, err
}
fmt.Println("NEW ACTOR ADDRESS IS: ", vmctx.Message().To.String()) rt.State().Create(&testActorState{11})
fmt.Println("NEW ACTOR ADDRESS IS: ", rt.Message().Receiver())
return nil, vmctx.Storage().Commit(empty, c) return &adt.EmptyValue{}
} }
func (ta *testActor) TestMethod(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) { func (ta *testActor) TestMethod(rt runtime.Runtime, params *adt.EmptyValue) *adt.EmptyValue {
var st testActorState var st testActorState
if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &st); err != nil { rt.State().Readonly(&st)
return nil, err
}
if vmctx.BlockHeight() > testForkHeight { if rt.CurrEpoch() > testForkHeight {
if st.HasUpgraded != 55 { if st.HasUpgraded != 55 {
return nil, aerrors.Fatal("fork updating applied in wrong order") panic(aerrors.Fatal("fork updating applied in wrong order"))
} }
} else { } else {
if st.HasUpgraded != 11 { if st.HasUpgraded != 11 {
return nil, aerrors.Fatal("fork updating happened too early") panic(aerrors.Fatal("fork updating happened too early"))
} }
} }
return nil, nil return &adt.EmptyValue{}
} }
func TestForkHeightTriggers(t *testing.T) { func TestForkHeightTriggers(t *testing.T) {
@ -125,7 +117,7 @@ func TestForkHeightTriggers(t *testing.T) {
} }
// predicting the address here... may break if other assumptions change // predicting the address here... may break if other assumptions change
taddr, err := address.NewIDAddress(1000) taddr, err := address.NewIDAddress(1002)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -144,7 +136,7 @@ func TestForkHeightTriggers(t *testing.T) {
var tas testActorState var tas testActorState
if err := cst.Get(ctx, act.Head, &tas); err != nil { if err := cst.Get(ctx, act.Head, &tas); err != nil {
return cid.Undef, err return cid.Undef, xerrors.Errorf("in fork handler, failed to run get: %w", err)
} }
tas.HasUpgraded = 55 tas.HasUpgraded = 55

View File

@ -2,6 +2,7 @@ package stmgr
import ( import (
"context" "context"
"github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/state"
amt "github.com/filecoin-project/go-amt-ipld/v2" amt "github.com/filecoin-project/go-amt-ipld/v2"
@ -16,10 +17,6 @@ import (
"github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/actors/aerrors"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
@ -155,13 +152,13 @@ func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet,
return LoadSectorsFromSet(ctx, sm.ChainStore().Blockstore(), mas.Sectors) return LoadSectorsFromSet(ctx, sm.ChainStore().Blockstore(), mas.Sectors)
} }
func GetSectorsForElectionPost(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (*sectorbuilder.SortedPublicSectorInfo, error) { func GetSectorsForElectionPost(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) ([]abi.SectorInfo, error) {
sectors, err := GetMinerProvingSet(ctx, sm, ts, maddr) sectors, err := GetMinerProvingSet(ctx, sm, ts, maddr)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to get sector set for miner: %w", err) return nil, xerrors.Errorf("failed to get sector set for miner: %w", err)
} }
var uselessOtherArray []ffi.PublicSectorInfo var uselessOtherArray []abi.SectorInfo
for _, s := range sectors { for _, s := range sectors {
cr, err := commcid.CIDToReplicaCommitmentV1(s.Info.Info.SealedCID) cr, err := commcid.CIDToReplicaCommitmentV1(s.Info.Info.SealedCID)
if err != nil { if err != nil {
@ -169,14 +166,14 @@ func GetSectorsForElectionPost(ctx context.Context, sm *StateManager, ts *types.
} }
var uselessBuffer [32]byte var uselessBuffer [32]byte
copy(uselessBuffer[:], cr) copy(uselessBuffer[:], cr)
uselessOtherArray = append(uselessOtherArray, ffi.PublicSectorInfo{ uselessOtherArray = append(uselessOtherArray, abi.SectorInfo{
SectorNum: s.ID, RegisteredProof: s.Info.Info.RegisteredProof,
CommR: uselessBuffer, SectorNumber: s.ID,
SealedCID: s.Info.Info.SealedCID,
}) })
} }
ssi := sectorbuilder.NewSortedPublicSectorInfo(uselessOtherArray) return uselessOtherArray, nil
return &ssi, nil
} }
func GetMinerSectorSize(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (abi.SectorSize, error) { func GetMinerSectorSize(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (abi.SectorSize, error) {

View File

@ -5,11 +5,12 @@ import (
"context" "context"
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/minio/blake2b-simd"
"io" "io"
"sync" "sync"
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/minio/blake2b-simd"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/specs-actors/actors/runtime"
@ -909,9 +910,11 @@ func (cs *ChainStore) GetRandomness(ctx context.Context, blks []cid.Cid, pers cr
defer span.End() defer span.End()
span.AddAttributes(trace.Int64Attribute("round", round)) span.AddAttributes(trace.Int64Attribute("round", round))
defer func() { /*
log.Infof("getRand %v %d %d %x -> %x", blks, pers, round, entropy, out) defer func() {
}() log.Infof("getRand %v %d %d %x -> %x", blks, pers, round, entropy, out)
}()
*/
for { for {
nts, err := cs.LoadTipSet(types.NewTipSetKey(blks...)) nts, err := cs.LoadTipSet(types.NewTipSetKey(blks...))

View File

@ -15,8 +15,8 @@ import (
) )
func init() { func init() {
build.SectorSizes = []abi.SectorSize{1024} build.SectorSizes = []abi.SectorSize{2048}
build.MinimumMinerPower = 1024 build.MinimumMinerPower = 2048
} }
func BenchmarkGetRandomness(b *testing.B) { func BenchmarkGetRandomness(b *testing.B) {

View File

@ -2,13 +2,14 @@ package chain
import ( import (
"context" "context"
"crypto/sha256"
"errors" "errors"
"fmt" "fmt"
"github.com/filecoin-project/specs-actors/actors/builtin"
"sync" "sync"
"time" "time"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/Gurpartap/async" "github.com/Gurpartap/async"
amt "github.com/filecoin-project/go-amt-ipld/v2" amt "github.com/filecoin-project/go-amt-ipld/v2"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder" sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
@ -666,14 +667,20 @@ func (syncer *Syncer) VerifyElectionPoStProof(ctx context.Context, h *types.Bloc
return xerrors.Errorf("failed to get sector size for miner: %w", err) return xerrors.Errorf("failed to get sector size for miner: %w", err)
} }
var winners []sectorbuilder.EPostCandidate mid, err := address.IDFromAddress(h.Miner)
if err != nil {
return xerrors.Errorf("failed to get ID from miner address %s: %w", h.Miner, err)
}
var winners []abi.PoStCandidate
for _, t := range h.EPostProof.Candidates { for _, t := range h.EPostProof.Candidates {
var partial [32]byte winners = append(winners, abi.PoStCandidate{
copy(partial[:], t.Partial) PartialTicket: t.Partial,
winners = append(winners, sectorbuilder.EPostCandidate{ SectorID: abi.SectorID{
PartialTicket: partial, Number: t.SectorID,
SectorNum: t.SectorID, Miner: abi.ActorID(mid),
SectorChallengeIndex: t.ChallengeIndex, },
ChallengeIndex: int64(t.ChallengeIndex),
}) })
} }
@ -687,14 +694,44 @@ func (syncer *Syncer) VerifyElectionPoStProof(ctx context.Context, h *types.Bloc
} }
if build.InsecurePoStValidation { if build.InsecurePoStValidation {
if string(h.EPostProof.Proof) == "valid proof" { if len(h.EPostProof.Proofs) == 0 {
return xerrors.Errorf("[TESTING] No election post proof given")
}
if string(h.EPostProof.Proofs[0].ProofBytes) == "valid proof" {
return nil return nil
} }
return xerrors.Errorf("[TESTING] election post was invalid") return xerrors.Errorf("[TESTING] election post was invalid")
} }
hvrf := sha256.Sum256(h.EPostProof.PostRand)
ok, err := sectorbuilder.ProofVerifier.VerifyElectionPost(ctx, ssize, *sectorInfo, hvrf[:], h.EPostProof.Proof, winners, h.Miner) rt, _, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
return err
}
candidates := make([]abi.PoStCandidate, 0, len(h.EPostProof.Candidates))
for _, c := range h.EPostProof.Candidates {
candidates = append(candidates, abi.PoStCandidate{
RegisteredProof: rt,
PartialTicket: c.Partial,
SectorID: abi.SectorID{Number: c.SectorID}, // this should not be an ID, we already know who the miner is...
ChallengeIndex: int64(c.ChallengeIndex),
})
}
// TODO: why do we need this here?
challengeCount := sectorbuilder.ElectionPostChallengeCount(uint64(len(sectorInfo)), 0)
pvi := abi.PoStVerifyInfo{
Randomness: h.EPostProof.PostRand,
Candidates: candidates,
Proofs: h.EPostProof.Proofs,
EligibleSectors: sectorInfo,
Prover: abi.ActorID(mid),
ChallengeCount: challengeCount,
}
ok, err := sectorbuilder.ProofVerifier.VerifyElectionPost(ctx, pvi)
if err != nil { if err != nil {
return xerrors.Errorf("failed to verify election post: %w", err) return xerrors.Errorf("failed to verify election post: %w", err)
} }

View File

@ -28,8 +28,8 @@ import (
func init() { func init() {
build.InsecurePoStValidation = true build.InsecurePoStValidation = true
os.Setenv("TRUST_PARAMS", "1") os.Setenv("TRUST_PARAMS", "1")
build.SectorSizes = []abi.SectorSize{1024} build.SectorSizes = []abi.SectorSize{2048}
build.MinimumMinerPower = 1024 build.MinimumMinerPower = 2048
} }
const source = 0 const source = 0

View File

@ -29,7 +29,7 @@ type EPostTicket struct {
} }
type EPostProof struct { type EPostProof struct {
Proof []byte Proofs []abi.PoStProof
PostRand []byte PostRand []byte
Candidates []EPostTicket Candidates []EPostTicket
} }

View File

@ -7,6 +7,7 @@ import (
"testing" "testing"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/crypto"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
) )
@ -27,7 +28,7 @@ func testBlockHeader(t testing.TB) *BlockHeader {
return &BlockHeader{ return &BlockHeader{
Miner: addr, Miner: addr,
EPostProof: EPostProof{ EPostProof: EPostProof{
Proof: []byte("pruuf"), Proofs: []abi.PoStProof{{ProofBytes: []byte("pruuf")}},
PostRand: []byte("random"), PostRand: []byte("random"),
}, },
Ticket: &Ticket{ Ticket: &Ticket{

View File

@ -9,7 +9,7 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/crypto"
cid "github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors" xerrors "golang.org/x/xerrors"
) )
@ -391,16 +391,18 @@ func (t *EPostProof) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.Proof ([]uint8) (slice) // t.Proofs ([]abi.PoStProof) (slice)
if len(t.Proof) > cbg.ByteArrayMaxLen { if len(t.Proofs) > cbg.MaxLength {
return xerrors.Errorf("Byte array in field t.Proof was too long") return xerrors.Errorf("Slice value in field t.Proofs was too long")
} }
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Proofs)))); err != nil {
return err return err
} }
if _, err := w.Write(t.Proof); err != nil { for _, v := range t.Proofs {
return err if err := v.MarshalCBOR(w); err != nil {
return err
}
} }
// t.PostRand ([]uint8) (slice) // t.PostRand ([]uint8) (slice)
@ -446,23 +448,33 @@ func (t *EPostProof) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.Proof ([]uint8) (slice) // t.Proofs ([]abi.PoStProof) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
return err return err
} }
if extra > cbg.ByteArrayMaxLen { if extra > cbg.MaxLength {
return fmt.Errorf("t.Proof: byte array too large (%d)", extra) return fmt.Errorf("t.Proofs: array too large (%d)", extra)
} }
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array") if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
} }
t.Proof = make([]byte, extra) if extra > 0 {
if _, err := io.ReadFull(br, t.Proof); err != nil { t.Proofs = make([]abi.PoStProof, extra)
return err
} }
for i := 0; i < int(extra); i++ {
var v abi.PoStProof
if err := v.UnmarshalCBOR(br); err != nil {
return err
}
t.Proofs[i] = v
}
// t.PostRand ([]uint8) (slice) // t.PostRand ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)

View File

@ -61,7 +61,7 @@ func MkBlock(parents *types.TipSet, weightInc uint64, ticketNonce uint64) *types
return &types.BlockHeader{ return &types.BlockHeader{
Miner: addr, Miner: addr,
EPostProof: types.EPostProof{ EPostProof: types.EPostProof{
Proof: []byte("election post proof proof"), Proofs: []abi.PoStProof{{ProofBytes: []byte("election post proof proof")}},
}, },
Ticket: &types.Ticket{ Ticket: &types.Ticket{
VRFProof: []byte(fmt.Sprintf("====%d=====", ticketNonce)), VRFProof: []byte(fmt.Sprintf("====%d=====", ticketNonce)),

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
@ -64,6 +65,6 @@ type vmRand struct {
eCtx *vchain.ExecutionContext eCtx *vchain.ExecutionContext
} }
func (*vmRand) GetRandomness(ctx context.Context, h int64) ([]byte, error) { func (*vmRand) GetRandomness(ctx context.Context, dst crypto.DomainSeparationTag, h int64, input []byte) ([]byte, error) {
panic("implement me") panic("implement me")
} }

View File

@ -5,7 +5,6 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"reflect" "reflect"
"strings"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
@ -89,17 +88,7 @@ type Invokee interface {
var tVMContext = reflect.TypeOf((*types.VMContext)(nil)).Elem() var tVMContext = reflect.TypeOf((*types.VMContext)(nil)).Elem()
var tAError = reflect.TypeOf((*aerrors.ActorError)(nil)).Elem() var tAError = reflect.TypeOf((*aerrors.ActorError)(nil)).Elem()
func (i *invoker) transform(instance Invokee) (nativeCode, error) { func (*invoker) transform(instance Invokee) (nativeCode, error) {
itype := reflect.TypeOf(instance)
if strings.Contains(itype.PkgPath(), "github.com/filecoin-project/specs-actors/") {
return i.transformSpec(instance)
} else {
return i.transformLotus(instance)
}
}
func (*invoker) transformSpec(instance Invokee) (nativeCode, error) {
itype := reflect.TypeOf(instance) itype := reflect.TypeOf(instance)
exports := instance.Exports() exports := instance.Exports()
for i, m := range exports { for i, m := range exports {
@ -178,81 +167,6 @@ func (*invoker) transformSpec(instance Invokee) (nativeCode, error) {
return code, nil return code, nil
} }
func (*invoker) transformLotus(instance Invokee) (nativeCode, error) {
itype := reflect.TypeOf(instance)
exports := instance.Exports()
for i, m := range exports {
i := i
newErr := func(format string, args ...interface{}) error {
str := fmt.Sprintf(format, args...)
return fmt.Errorf("transform(%s) export(%d): %s", itype.Name(), i, str)
}
if m == nil {
continue
}
meth := reflect.ValueOf(m)
t := meth.Type()
if t.Kind() != reflect.Func {
return nil, newErr("is not a function")
}
if t.NumIn() != 3 {
return nil, newErr("wrong number of inputs should be: " +
"*types.Actor, *VMContext, <type of parameter>")
}
if t.In(0) != reflect.TypeOf(&types.Actor{}) {
return nil, newErr("first arguemnt should be *types.Actor")
}
if t.In(1) != tVMContext {
return nil, newErr("second argument should be types.VMContext")
}
if t.In(2).Kind() != reflect.Ptr {
return nil, newErr("parameter has to be a pointer to parameter, is: %s",
t.In(2).Kind())
}
if t.NumOut() != 2 {
return nil, newErr("wrong number of outputs should be: " +
"(InvokeRet, error)")
}
if t.Out(0) != reflect.TypeOf([]byte{}) {
return nil, newErr("first output should be slice of bytes")
}
if !t.Out(1).Implements(tAError) {
return nil, newErr("second output should be ActorError type")
}
}
code := make(nativeCode, len(exports))
for id, m := range exports {
meth := reflect.ValueOf(m)
code[id] = reflect.MakeFunc(reflect.TypeOf((invokeFunc)(nil)),
func(in []reflect.Value) []reflect.Value {
paramT := meth.Type().In(2).Elem()
param := reflect.New(paramT)
inBytes := in[2].Interface().([]byte)
if len(inBytes) > 0 {
if err := DecodeParams(inBytes, param.Interface()); err != nil {
aerr := aerrors.Absorb(err, 1, "failed to decode parameters")
return []reflect.Value{
reflect.ValueOf([]byte{}),
// Below is a hack, fixed in Go 1.13
// https://git.io/fjXU6
reflect.ValueOf(&aerr).Elem(),
}
}
}
return meth.Call([]reflect.Value{
in[0], in[1], param,
})
}).Interface().(invokeFunc)
}
return code, nil
}
func DecodeParams(b []byte, out interface{}) error { func DecodeParams(b []byte, out interface{}) error {
um, ok := out.(cbg.CBORUnmarshaler) um, ok := out.(cbg.CBORUnmarshaler)
if !ok { if !ok {

View File

@ -257,6 +257,7 @@ func (rs *runtimeShim) Send(to address.Address, method abi.MethodNum, m vmr.CBOR
if err.IsFatal() { if err.IsFatal() {
panic(err) panic(err)
} }
log.Warnf("vmctx send failed: to: %s, method: %d: ret: %d, err: %s", to, method, ret, err)
return nil, exitcode.ExitCode(err.RetCode()) return nil, exitcode.ExitCode(err.RetCode())
} }
return &dumbWrapperType{ret}, 0 return &dumbWrapperType{ret}, 0

View File

@ -1,9 +1,11 @@
package vm package vm
import ( import (
ffi "github.com/filecoin-project/filecoin-ffi" "context"
"fmt"
"math/bits"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/lotus/lib/zerocomm" "github.com/filecoin-project/lotus/lib/zerocomm"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
@ -12,7 +14,6 @@ import (
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash" mh "github.com/multiformats/go-multihash"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"math/bits"
) )
func init() { func init() {
@ -29,18 +30,17 @@ type syscallShim struct {
verifier sectorbuilder.Verifier verifier sectorbuilder.Verifier
} }
func (ss *syscallShim) ComputeUnsealedSectorCID(ssize abi.SectorSize, pieces []abi.PieceInfo) (cid.Cid, error) { func (ss *syscallShim) ComputeUnsealedSectorCID(st abi.RegisteredProof, pieces []abi.PieceInfo) (cid.Cid, error) {
// TODO: does this pull in unwanted dependencies?
var ffipieces []ffi.PublicPieceInfo
var sum abi.PaddedPieceSize var sum abi.PaddedPieceSize
for _, p := range pieces { for _, p := range pieces {
ffipieces = append(ffipieces, ffi.PublicPieceInfo{
Size: p.Size.Unpadded(),
CommP: cidToCommD(p.PieceCID),
})
sum += p.Size sum += p.Size
} }
ssize, err := st.SectorSize()
if err != nil {
return cid.Undef, err
}
{ {
// pad remaining space with 0 CommPs // pad remaining space with 0 CommPs
toFill := uint64(abi.PaddedPieceSize(ssize) - sum) toFill := uint64(abi.PaddedPieceSize(ssize) - sum)
@ -51,32 +51,39 @@ func (ss *syscallShim) ComputeUnsealedSectorCID(ssize abi.SectorSize, pieces []a
toFill ^= psize toFill ^= psize
unpadded := abi.PaddedPieceSize(psize).Unpadded() unpadded := abi.PaddedPieceSize(psize).Unpadded()
ffipieces = append(ffipieces, ffi.PublicPieceInfo{ pieces = append(pieces, abi.PieceInfo{
Size: unpadded, Size: unpadded.Padded(),
CommP: zerocomm.ForSize(unpadded), PieceCID: zerocomm.ForSize(unpadded),
}) })
} }
} }
commd, err := sectorbuilder.GenerateDataCommitment(ssize, ffipieces) commd, err := sectorbuilder.GenerateUnsealedCID(st, pieces)
if err != nil { if err != nil {
log.Errorf("generate data commitment failed: %s", err) log.Errorf("generate data commitment failed: %s", err)
return cid.Undef, err return cid.Undef, err
} }
return commcid.DataCommitmentV1ToCID(commd[:]), nil return commd, nil
} }
func (ss *syscallShim) HashBlake2b(data []byte) [32]byte { func (ss *syscallShim) HashBlake2b(data []byte) [32]byte {
panic("NYI") panic("NYI")
} }
func (ss *syscallShim) VerifyConsensusFault(a, b []byte) bool { func (ss *syscallShim) VerifyConsensusFault(a, b []byte) error {
panic("NYI") panic("NYI")
} }
func (ss *syscallShim) VerifyPoSt(ssize abi.SectorSize, proof abi.PoStVerifyInfo) (bool, error) { func (ss *syscallShim) VerifyPoSt(proof abi.PoStVerifyInfo) error {
panic("NYI") ok, err := ss.verifier.VerifyFallbackPost(context.TODO(), proof)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("proof was invalid")
}
return nil
} }
func cidToCommD(c cid.Cid) [32]byte { func cidToCommD(c cid.Cid) [32]byte {
@ -93,35 +100,35 @@ func cidToCommR(c cid.Cid) [32]byte {
return out return out
} }
func (ss *syscallShim) VerifySeal(ssize abi.SectorSize, info abi.SealVerifyInfo) (bool, error) { func (ss *syscallShim) VerifySeal(info abi.SealVerifyInfo) error {
//_, span := trace.StartSpan(ctx, "ValidatePoRep") //_, span := trace.StartSpan(ctx, "ValidatePoRep")
//defer span.End() //defer span.End()
commD := cidToCommD(info.UnsealedCID)
commR := cidToCommR(info.OnChain.SealedCID)
miner, err := address.NewIDAddress(uint64(info.Miner)) miner, err := address.NewIDAddress(uint64(info.Miner))
if err != nil { if err != nil {
return false, xerrors.Errorf("weirdly failed to construct address: %w", err) return xerrors.Errorf("weirdly failed to construct address: %w", err)
} }
ticket := []byte(info.Randomness) ticket := []byte(info.Randomness)
proof := []byte(info.OnChain.Proof) proof := []byte(info.OnChain.Proof)
seed := []byte(info.InteractiveRandomness) seed := []byte(info.InteractiveRandomness)
log.Infof("Werif %d r:%x; d:%x; m:%s; t:%x; s:%x; N:%d; p:%x", ssize, commR, commD, miner, ticket, seed, info.SectorID.Number, proof) log.Infof("Verif r:%x; d:%x; m:%s; t:%x; s:%x; N:%d; p:%x", info.OnChain.SealedCID, info.UnsealedCID, miner, ticket, seed, info.SectorID.Number, proof)
//func(ctx context.Context, maddr address.Address, ssize abi.SectorSize, commD, commR, ticket, proof, seed []byte, sectorID abi.SectorNumber) //func(ctx context.Context, maddr address.Address, ssize abi.SectorSize, commD, commR, ticket, proof, seed []byte, sectorID abi.SectorNumber)
ok, err := ss.verifier.VerifySeal(ssize, commR[:], commD[:], miner, ticket, seed, info.SectorID.Number, proof) ok, err := ss.verifier.VerifySeal(info)
if err != nil { if err != nil {
return false, xerrors.Errorf("failed to validate PoRep: %w", err) return xerrors.Errorf("failed to validate PoRep: %w", err)
}
if !ok {
return fmt.Errorf("invalid proof")
} }
return ok, nil return nil
} }
func (ss *syscallShim) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) bool { func (ss *syscallShim) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) error {
return true return nil
/* // TODO: in genesis setup, we are currently faking signatures /* // TODO: in genesis setup, we are currently faking signatures
if err := ss.rt.vmctx.VerifySignature(&sig, addr, input); err != nil { if err := ss.rt.vmctx.VerifySignature(&sig, addr, input); err != nil {
return false return false

View File

@ -4,10 +4,11 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"github.com/filecoin-project/specs-actors/actors/builtin"
"math/big" "math/big"
"reflect" "reflect"
"github.com/filecoin-project/specs-actors/actors/builtin"
block "github.com/ipfs/go-block-format" block "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
hamt "github.com/ipfs/go-hamt-ipld" hamt "github.com/ipfs/go-hamt-ipld"

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"bytes"
"context" "context"
"crypto/sha256" "crypto/sha256"
"encoding/json" "encoding/json"
@ -14,7 +13,6 @@ import (
"time" "time"
"github.com/docker/go-units" "github.com/docker/go-units"
ffi "github.com/filecoin-project/filecoin-ffi"
paramfetch "github.com/filecoin-project/go-paramfetch" paramfetch "github.com/filecoin-project/go-paramfetch"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
@ -25,6 +23,7 @@ import (
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/genesis" "github.com/filecoin-project/lotus/genesis"
@ -57,7 +56,7 @@ func main() {
log.Info("Starting lotus-bench") log.Info("Starting lotus-bench")
build.SectorSizes = append(build.SectorSizes, 1024) build.SectorSizes = append(build.SectorSizes, 2048)
app := &cli.App{ app := &cli.App{
Name: "lotus-bench", Name: "lotus-bench",
@ -142,10 +141,16 @@ func main() {
} }
sectorSize := abi.SectorSize(sectorSizeInt) sectorSize := abi.SectorSize(sectorSizeInt)
ppt, spt, err := lapi.ProofTypeFromSectorSize(sectorSize)
if err != nil {
return err
}
mds := datastore.NewMapDatastore() mds := datastore.NewMapDatastore()
cfg := &sectorbuilder.Config{ cfg := &sectorbuilder.Config{
Miner: maddr, Miner: maddr,
SectorSize: sectorSize, SealProofType: spt,
PoStProofType: ppt,
WorkerThreads: 2, WorkerThreads: 2,
Paths: sectorbuilder.SimplePath(sbdir), Paths: sectorbuilder.SimplePath(sbdir),
} }
@ -164,8 +169,15 @@ func main() {
return err return err
} }
amid, err := address.IDFromAddress(maddr)
if err != nil {
return err
}
mid := abi.ActorID(amid)
var sealTimings []SealingResult var sealTimings []SealingResult
var sealedSectors []ffi.PublicSectorInfo var sealedSectors []abi.SectorInfo
numSectors := abi.SectorNumber(1) numSectors := abi.SectorNumber(1)
for i := abi.SectorNumber(1); i <= numSectors && robench == ""; i++ { for i := abi.SectorNumber(1); i <= numSectors && robench == ""; i++ {
start := time.Now() start := time.Now()
@ -173,7 +185,7 @@ func main() {
r := rand.New(rand.NewSource(100 + int64(i))) r := rand.New(rand.NewSource(100 + int64(i)))
pi, err := sb.AddPiece(context.TODO(), abi.UnpaddedPieceSize(sectorSize), i, r, nil) pi, err := sb.AddPiece(context.TODO(), abi.PaddedPieceSize(sectorSize).Unpadded(), i, r, nil)
if err != nil { if err != nil {
return err return err
} }
@ -181,38 +193,53 @@ func main() {
addpiece := time.Now() addpiece := time.Now()
trand := sha256.Sum256([]byte(c.String("ticket-preimage"))) trand := sha256.Sum256([]byte(c.String("ticket-preimage")))
ticket := sectorbuilder.SealTicket{ ticket := abi.SealRandomness(trand[:])
TicketBytes: trand,
}
log.Info("Running replication...") log.Info("Running replication...")
pieces := []sectorbuilder.PublicPieceInfo{pi} pieces := []abi.PieceInfo{pi}
pco, err := sb.SealPreCommit(context.TODO(), i, ticket, pieces) commR, commD, err := sb.SealPreCommit(context.TODO(), i, ticket, pieces)
if err != nil { if err != nil {
return xerrors.Errorf("commit: %w", err) return xerrors.Errorf("commit: %w", err)
} }
precommit := time.Now() precommit := time.Now()
sealedSectors = append(sealedSectors, ffi.PublicSectorInfo{ sealedSectors = append(sealedSectors, abi.SectorInfo{
CommR: pco.CommR, RegisteredProof: ppt,
SectorNum: i, SectorNumber: i,
SealedCID: commR,
}) })
seed := sectorbuilder.SealSeed{ seed := lapi.SealSeed{
BlockHeight: 101, Epoch: 101,
TicketBytes: [32]byte{1, 2, 3, 4, 5}, Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 255},
} }
log.Info("Generating PoRep for sector") log.Info("Generating PoRep for sector")
proof, err := sb.SealCommit(context.TODO(), i, ticket, seed, pieces, pco) proof, err := sb.SealCommit(context.TODO(), i, ticket, seed.Value, pieces, commR, commD)
if err != nil { if err != nil {
return err return err
} }
sealcommit := time.Now() sealcommit := time.Now()
commD := pi.CommP
ok, err := sectorbuilder.ProofVerifier.VerifySeal(sectorSize, pco.CommR[:], commD[:], maddr, ticket.TicketBytes[:], seed.TicketBytes[:], i, proof) svi := abi.SealVerifyInfo{
SectorID: abi.SectorID{Miner: abi.ActorID(mid), Number: i},
OnChain: abi.OnChainSealVerifyInfo{
SealedCID: commR,
InteractiveEpoch: seed.Epoch,
RegisteredProof: ppt,
Proof: proof,
DealIDs: nil,
SectorNumber: i,
SealRandEpoch: 0,
},
Randomness: ticket,
InteractiveRandomness: seed.Value,
UnsealedCID: commD,
}
ok, err := sectorbuilder.ProofVerifier.VerifySeal(svi)
if err != nil { if err != nil {
return err return err
} }
@ -224,7 +251,7 @@ func main() {
if !c.Bool("skip-unseal") { if !c.Bool("skip-unseal") {
log.Info("Unsealing sector") log.Info("Unsealing sector")
rc, err := sb.ReadPieceFromSealedSector(context.TODO(), 1, 0, abi.UnpaddedPieceSize(sectorSize), ticket.TicketBytes[:], commD[:]) rc, err := sb.ReadPieceFromSealedSector(context.TODO(), 1, 0, abi.UnpaddedPieceSize(sectorSize), ticket, commD)
if err != nil { if err != nil {
return err return err
} }
@ -270,24 +297,28 @@ func main() {
} }
for _, s := range genm.Sectors { for _, s := range genm.Sectors {
sealedSectors = append(sealedSectors, ffi.PublicSectorInfo{ sealedSectors = append(sealedSectors, abi.SectorInfo{
CommR: s.CommR, SealedCID: s.CommR,
SectorNum: s.SectorID, SectorNumber: s.SectorID,
}) })
} }
} }
log.Info("generating election post candidates") log.Info("generating election post candidates")
sinfos := sectorbuilder.NewSortedPublicSectorInfo(sealedSectors) fcandidates, err := sb.GenerateEPostCandidates(sealedSectors, abi.PoStRandomness(challenge[:]), []abi.SectorNumber{})
candidates, err := sb.GenerateEPostCandidates(sinfos, challenge, []abi.SectorNumber{})
if err != nil { if err != nil {
return err return err
} }
var candidates []abi.PoStCandidate
for _, c := range fcandidates {
candidates = append(candidates, c.Candidate)
}
gencandidates := time.Now() gencandidates := time.Now()
log.Info("computing election post snark (cold)") log.Info("computing election post snark (cold)")
proof1, err := sb.ComputeElectionPoSt(sinfos, challenge[:], candidates[:1]) proof1, err := sb.ComputeElectionPoSt(sealedSectors, challenge[:], candidates[:1])
if err != nil { if err != nil {
return err return err
} }
@ -295,18 +326,24 @@ func main() {
epost1 := time.Now() epost1 := time.Now()
log.Info("computing election post snark (hot)") log.Info("computing election post snark (hot)")
proof2, err := sb.ComputeElectionPoSt(sinfos, challenge[:], candidates[:1]) proof2, err := sb.ComputeElectionPoSt(sealedSectors, challenge[:], candidates[:1])
if err != nil { if err != nil {
return err return err
} }
epost2 := time.Now() epost2 := time.Now()
if bytes.Equal(proof1, proof2) { ccount := sectorbuilder.ElectionPostChallengeCount(uint64(len(sealedSectors)), 0)
log.Warn("separate epost calls returned the same proof values (this might be bad)")
}
ok, err := sectorbuilder.ProofVerifier.VerifyElectionPost(context.TODO(), sectorSize, sinfos, challenge[:], proof1, candidates[:1], maddr) pvi1 := abi.PoStVerifyInfo{
Randomness: abi.PoStRandomness(challenge[:]),
Candidates: candidates[:1],
Proofs: proof1,
EligibleSectors: sealedSectors,
Prover: abi.ActorID(mid),
ChallengeCount: ccount,
}
ok, err := sectorbuilder.ProofVerifier.VerifyElectionPost(context.TODO(), pvi1)
if err != nil { if err != nil {
return err return err
} }
@ -316,7 +353,16 @@ func main() {
verifypost1 := time.Now() verifypost1 := time.Now()
ok, err = sectorbuilder.ProofVerifier.VerifyElectionPost(context.TODO(), sectorSize, sinfos, challenge[:], proof2, candidates[:1], maddr) pvi2 := abi.PoStVerifyInfo{
Randomness: abi.PoStRandomness(challenge[:]),
Candidates: candidates[:1],
Proofs: proof2,
EligibleSectors: sealedSectors,
Prover: abi.ActorID(mid),
ChallengeCount: ccount,
}
ok, err = sectorbuilder.ProofVerifier.VerifyElectionPost(context.TODO(), pvi2)
if err != nil { if err != nil {
return err return err
} }
@ -326,7 +372,7 @@ func main() {
verifypost2 := time.Now() verifypost2 := time.Now()
bo := BenchResults{ bo := BenchResults{
SectorSize: cfg.SectorSize, SectorSize: sectorSize,
SealingResults: sealTimings, SealingResults: sealTimings,
PostGenerateCandidates: gencandidates.Sub(beforePost), PostGenerateCandidates: gencandidates.Sub(beforePost),

View File

@ -456,7 +456,7 @@ create temp table mh (like miner_heads excluding constraints) on commit drop;
return xerrors.Errorf("prep temp: %w", err) return xerrors.Errorf("prep temp: %w", err)
} }
stmt, err := tx.Prepare(`copy mh (head, addr, stateroot, sectorset, setsize, provingset, provingsize, owner, worker, peerid, sectorsize, power, active, ppe, slashed_at) from STDIN`) stmt, err := tx.Prepare(`copy mh (head, addr, stateroot, sectorset, setsize, provingset, provingsize, owner, worker, peerid, sectorsize, power, ppe) from STDIN`)
if err != nil { if err != nil {
return err return err
} }
@ -473,10 +473,8 @@ create temp table mh (like miner_heads excluding constraints) on commit drop;
i.info.Worker.String(), i.info.Worker.String(),
i.info.PeerId.String(), i.info.PeerId.String(),
i.info.SectorSize, i.info.SectorSize,
i.state.Power.String(), // TODO: SPA i.power.String(), // TODO: SPA
i.state.Active,
i.state.PoStState.ProvingPeriodStart, i.state.PoStState.ProvingPeriodStart,
i.state.SlashedAt,
); err != nil { ); err != nil {
return err return err
} }
@ -557,7 +555,7 @@ create temp table c (like blocks_challenges excluding constraints) on commit dro
} }
} }
stmt2, err := tx.Prepare(`copy b (cid, parentWeight, parentStateRoot, height, miner, "timestamp", vrfproof, tickets, eprof, prand, ep0partial, ep0sector, ep0challangei) from stdin`) stmt2, err := tx.Prepare(`copy b (cid, parentWeight, parentStateRoot, height, miner, "timestamp", vrfproof, tickets, prand, ep0partial, ep0sector, ep0challangei) from stdin`)
if err != nil { if err != nil {
return err return err
} }
@ -577,7 +575,7 @@ create temp table c (like blocks_challenges excluding constraints) on commit dro
bh.Timestamp, bh.Timestamp,
bh.Ticket.VRFProof, bh.Ticket.VRFProof,
l, l,
bh.EPostProof.Proof, //bh.EPostProof.Proof,
bh.EPostProof.PostRand, bh.EPostProof.PostRand,
bh.EPostProof.Candidates[0].Partial, bh.EPostProof.Candidates[0].Partial,
bh.EPostProof.Candidates[0].SectorID, bh.EPostProof.Candidates[0].SectorID,

View File

@ -5,13 +5,15 @@ import (
"container/list" "container/list"
"context" "context"
"encoding/json" "encoding/json"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"math" "math"
"sync" "sync"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
@ -56,6 +58,7 @@ type minerInfo struct {
state miner.State state miner.State
info miner.MinerInfo info miner.MinerInfo
power big.Int
ssize uint64 ssize uint64
psize uint64 psize uint64
} }
@ -268,6 +271,13 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipS
par(50, kvmaparr(miners), func(it func() (minerKey, *minerInfo)) { par(50, kvmaparr(miners), func(it func() (minerKey, *minerInfo)) {
k, info := it() k, info := it()
pow, err := api.StateMinerPower(ctx, k.addr, types.EmptyTSK)
if err != nil {
log.Error(err)
// Not sure why this would fail, but its probably worth continuing
}
info.power = pow.MinerPower
sszs, err := api.StateMinerSectorCount(ctx, k.addr, types.EmptyTSK) sszs, err := api.StateMinerSectorCount(ctx, k.addr, types.EmptyTSK)
if err != nil { if err != nil {
log.Error(err) log.Error(err)

View File

@ -268,7 +268,7 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
Owner: owner, // TODO: That is useful Owner: owner, // TODO: That is useful
Worker: owner, Worker: owner,
SectorSize: abi.SectorSize(ssize), SectorSize: abi.SectorSize(ssize),
Peer: peer.ID("SETME"), Peer: peer.ID("SETME"),
}) })
if err != nil { if err != nil {
w.WriteHeader(400) w.WriteHeader(400)

View File

@ -138,8 +138,14 @@ var runCmd = &cli.Command{
return xerrors.Errorf("get params: %w", err) return xerrors.Errorf("get params: %w", err)
} }
ppt, spt, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
return err
}
sb, err := sectorbuilder.NewStandalone(&sectorbuilder.Config{ sb, err := sectorbuilder.NewStandalone(&sectorbuilder.Config{
SectorSize: ssize, SealProofType: spt,
PoStProofType: ppt,
Miner: act, Miner: act,
WorkerThreads: workers, WorkerThreads: workers,
Paths: sectorbuilder.SimplePath(r), Paths: sectorbuilder.SimplePath(r),

View File

@ -82,13 +82,14 @@ func (w *worker) processTask(ctx context.Context, task sectorbuilder.WorkerTask)
switch task.Type { switch task.Type {
case sectorbuilder.WorkerPreCommit: case sectorbuilder.WorkerPreCommit:
w.limiter.workLimit <- struct{}{} w.limiter.workLimit <- struct{}{}
rspco, err := w.sb.SealPreCommit(ctx, task.SectorNum, task.SealTicket, task.Pieces) sealedCid, unsealedCid, err := w.sb.SealPreCommit(ctx, task.SectorNum, task.SealTicket, task.Pieces)
<-w.limiter.workLimit <-w.limiter.workLimit
if err != nil { if err != nil {
return errRes(xerrors.Errorf("precomitting: %w", err)) return errRes(xerrors.Errorf("precomitting: %w", err))
} }
res.Rspco = rspco.ToJson() res.Rspco.CommD = unsealedCid
res.Rspco.CommR = sealedCid
if err := w.push("sealed", task.SectorNum); err != nil { if err := w.push("sealed", task.SectorNum); err != nil {
return errRes(xerrors.Errorf("pushing precommited data: %w", err)) return errRes(xerrors.Errorf("pushing precommited data: %w", err))
@ -103,7 +104,7 @@ func (w *worker) processTask(ctx context.Context, task sectorbuilder.WorkerTask)
} }
case sectorbuilder.WorkerCommit: case sectorbuilder.WorkerCommit:
w.limiter.workLimit <- struct{}{} w.limiter.workLimit <- struct{}{}
proof, err := w.sb.SealCommit(ctx, task.SectorNum, task.SealTicket, task.SealSeed, task.Pieces, task.Rspco) proof, err := w.sb.SealCommit(ctx, task.SectorNum, task.SealTicket, task.SealSeed, task.Pieces, task.SealedCID, task.UnsealedCID)
<-w.limiter.workLimit <-w.limiter.workLimit
if err != nil { if err != nil {

View File

@ -21,6 +21,7 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/abi/big"
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed" "github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
@ -119,7 +120,12 @@ var preSealCmd = &cli.Command{
} }
} }
gm, key, err := seed.PreSeal(maddr, abi.SectorSize(c.Uint64("sector-size")), abi.SectorNumber(c.Uint64("sector-offset")), c.Int("num-sectors"), sbroot, []byte(c.String("ticket-preimage")), k) rp, _, err := lapi.ProofTypeFromSectorSize(abi.SectorSize(c.Uint64("sector-size")))
if err != nil {
return err
}
gm, key, err := seed.PreSeal(maddr, rp, abi.SectorNumber(c.Uint64("sector-offset")), c.Int("num-sectors"), sbroot, []byte(c.String("ticket-preimage")), k)
if err != nil { if err != nil {
return err return err
} }
@ -216,9 +222,15 @@ var aggregateSectorDirsCmd = &cli.Command{
ssize := abi.SectorSize(cctx.Uint64("sector-size")) ssize := abi.SectorSize(cctx.Uint64("sector-size"))
ppt, spt, err := lapi.ProofTypeFromSectorSize(abi.SectorSize(cctx.Uint64("sector-size")))
if err != nil {
return err
}
agsb, err := sectorbuilder.New(&sectorbuilder.Config{ agsb, err := sectorbuilder.New(&sectorbuilder.Config{
Miner: maddr, Miner: maddr,
SectorSize: ssize, SealProofType: spt,
PoStProofType: ppt,
Paths: sectorbuilder.SimplePath(destdir), Paths: sectorbuilder.SimplePath(destdir),
WorkerThreads: 2, WorkerThreads: 2,
}, namespace.Wrap(agmds, datastore.NewKey("/sectorbuilder"))) }, namespace.Wrap(agmds, datastore.NewKey("/sectorbuilder")))
@ -279,7 +291,8 @@ var aggregateSectorDirsCmd = &cli.Command{
sb, err := sectorbuilder.New(&sectorbuilder.Config{ sb, err := sectorbuilder.New(&sectorbuilder.Config{
Miner: maddr, Miner: maddr,
SectorSize: genm.SectorSize, SealProofType: spt,
PoStProofType: ppt,
Paths: sectorbuilder.SimplePath(dir), Paths: sectorbuilder.SimplePath(dir),
WorkerThreads: 2, WorkerThreads: 2,
}, namespace.Wrap(mds, datastore.NewKey("/sectorbuilder"))) }, namespace.Wrap(mds, datastore.NewKey("/sectorbuilder")))

View File

@ -34,10 +34,21 @@ import (
var log = logging.Logger("preseal") var log = logging.Logger("preseal")
func PreSeal(maddr address.Address, ssize abi.SectorSize, offset abi.SectorNumber, sectors int, sbroot string, preimage []byte, key *types.KeyInfo) (*genesis.Miner, *types.KeyInfo, error) { func PreSeal(maddr address.Address, pt abi.RegisteredProof, offset abi.SectorNumber, sectors int, sbroot string, preimage []byte, key *types.KeyInfo) (*genesis.Miner, *types.KeyInfo, error) {
ppt, err := pt.RegisteredPoStProof()
if err != nil {
return nil, nil, err
}
spt, err := pt.RegisteredSealProof()
if err != nil {
return nil, nil, err
}
cfg := &sectorbuilder.Config{ cfg := &sectorbuilder.Config{
Miner: maddr, Miner: maddr,
SectorSize: ssize, SealProofType: spt,
PoStProofType: ppt,
FallbackLastNum: offset, FallbackLastNum: offset,
Paths: sectorbuilder.SimplePath(sbroot), Paths: sectorbuilder.SimplePath(sbroot),
WorkerThreads: 2, WorkerThreads: 2,
@ -57,6 +68,11 @@ func PreSeal(maddr address.Address, ssize abi.SectorSize, offset abi.SectorNumbe
return nil, nil, err return nil, nil, err
} }
ssize, err := pt.SectorSize()
if err != nil {
return nil, nil, err
}
var sealedSectors []*genesis.PreSeal var sealedSectors []*genesis.PreSeal
for i := 0; i < sectors; i++ { for i := 0; i < sectors; i++ {
sid, err := sb.AcquireSectorNumber() sid, err := sb.AcquireSectorNumber()
@ -70,13 +86,11 @@ func PreSeal(maddr address.Address, ssize abi.SectorSize, offset abi.SectorNumbe
} }
trand := sha256.Sum256(preimage) trand := sha256.Sum256(preimage)
ticket := sectorbuilder.SealTicket{ ticket := abi.SealRandomness(trand[:])
TicketBytes: trand,
}
fmt.Printf("sector-id: %d, piece info: %v\n", sid, pi) fmt.Printf("sector-id: %d, piece info: %v\n", sid, pi)
pco, err := sb.SealPreCommit(context.TODO(), sid, ticket, []sectorbuilder.PublicPieceInfo{pi}) scid, ucid, err := sb.SealPreCommit(context.TODO(), sid, ticket, []abi.PieceInfo{pi})
if err != nil { if err != nil {
return nil, nil, xerrors.Errorf("commit: %w", err) return nil, nil, xerrors.Errorf("commit: %w", err)
} }
@ -85,11 +99,12 @@ func PreSeal(maddr address.Address, ssize abi.SectorSize, offset abi.SectorNumbe
return nil, nil, xerrors.Errorf("trim cache: %w", err) return nil, nil, xerrors.Errorf("trim cache: %w", err)
} }
log.Warn("PreCommitOutput: ", sid, pco) log.Warn("PreCommitOutput: ", sid, scid, ucid)
sealedSectors = append(sealedSectors, &genesis.PreSeal{ sealedSectors = append(sealedSectors, &genesis.PreSeal{
CommR: pco.CommR, CommR: scid,
CommD: pco.CommD, CommD: ucid,
SectorID: sid, SectorID: sid,
ProofType: pt,
}) })
} }
@ -172,10 +187,8 @@ func commDCID(commd []byte) cid.Cid {
func createDeals(m *genesis.Miner, k *wallet.Key, maddr address.Address, ssize abi.SectorSize) error { func createDeals(m *genesis.Miner, k *wallet.Key, maddr address.Address, ssize abi.SectorSize) error {
for _, sector := range m.Sectors { for _, sector := range m.Sectors {
pref := make([]byte, len(sector.CommD))
copy(pref, sector.CommD[:])
proposal := &market.DealProposal{ proposal := &market.DealProposal{
PieceCID: commDCID(pref), // just one deal so this == CommP PieceCID: sector.CommD,
PieceSize: abi.PaddedPieceSize(ssize), PieceSize: abi.PaddedPieceSize(ssize),
Client: k.Address, Client: k.Address,
Provider: maddr, Provider: maddr,

View File

@ -5,15 +5,16 @@ import (
"crypto/rand" "crypto/rand"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/market"
miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner" miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/power"
crypto2 "github.com/filecoin-project/specs-actors/actors/crypto" crypto2 "github.com/filecoin-project/specs-actors/actors/crypto"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
cborutil "github.com/filecoin-project/go-cbor-util" cborutil "github.com/filecoin-project/go-cbor-util"
@ -181,8 +182,14 @@ var initCmd = &cli.Command{
return err return err
} }
ppt, spt, err := lapi.ProofTypeFromSectorSize(ssize)
if err != nil {
return err
}
oldsb, err := sectorbuilder.New(&sectorbuilder.Config{ oldsb, err := sectorbuilder.New(&sectorbuilder.Config{
SectorSize: ssize, SealProofType: spt,
PoStProofType: ppt,
WorkerThreads: 2, WorkerThreads: 2,
Paths: sectorbuilder.SimplePath(pssb), Paths: sectorbuilder.SimplePath(pssb),
}, namespace.Wrap(oldmds, datastore.NewKey("/sectorbuilder"))) }, namespace.Wrap(oldmds, datastore.NewKey("/sectorbuilder")))
@ -191,7 +198,8 @@ var initCmd = &cli.Command{
} }
nsb, err := sectorbuilder.New(&sectorbuilder.Config{ nsb, err := sectorbuilder.New(&sectorbuilder.Config{
SectorSize: ssize, SealProofType: spt,
PoStProofType: ppt,
WorkerThreads: 2, WorkerThreads: 2,
Paths: sectorbuilder.SimplePath(lr.Path()), Paths: sectorbuilder.SimplePath(lr.Path()),
}, namespace.Wrap(mds, datastore.NewKey("/sectorbuilder"))) }, namespace.Wrap(mds, datastore.NewKey("/sectorbuilder")))
@ -250,6 +258,8 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, metadata string,
if err != nil { if err != nil {
return xerrors.Errorf("finding storage deal for pre-sealed sector %d: %w", sector.SectorID, err) return xerrors.Errorf("finding storage deal for pre-sealed sector %d: %w", sector.SectorID, err)
} }
commD := sector.CommD
commR := sector.CommR
info := &sealing.SectorInfo{ info := &sealing.SectorInfo{
State: lapi.Proving, State: lapi.Proving,
@ -258,15 +268,15 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, metadata string,
{ {
DealID: &dealID, DealID: &dealID,
Size: abi.PaddedPieceSize(meta.SectorSize).Unpadded(), Size: abi.PaddedPieceSize(meta.SectorSize).Unpadded(),
CommP: sector.CommD[:], CommP: sector.CommD,
}, },
}, },
CommD: sector.CommD[:], CommD: &commD,
CommR: sector.CommR[:], CommR: &commR,
Proof: nil, Proof: nil,
Ticket: sealing.SealTicket{}, Ticket: lapi.SealTicket{},
PreCommitMessage: nil, PreCommitMessage: nil,
Seed: sealing.SealSeed{}, Seed: lapi.SealSeed{},
CommitMessage: nil, CommitMessage: nil,
} }

View File

@ -2,13 +2,14 @@ package main
import ( import (
"fmt" "fmt"
"github.com/filecoin-project/lotus/chain/types"
"os" "os"
"sort" "sort"
"strconv" "strconv"
"text/tabwriter" "text/tabwriter"
"time" "time"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
@ -78,10 +79,10 @@ var sectorsStatusCmd = &cli.Command{
fmt.Printf("Status:\t%s\n", api.SectorStates[status.State]) fmt.Printf("Status:\t%s\n", api.SectorStates[status.State])
fmt.Printf("CommD:\t\t%x\n", status.CommD) fmt.Printf("CommD:\t\t%x\n", status.CommD)
fmt.Printf("CommR:\t\t%x\n", status.CommR) fmt.Printf("CommR:\t\t%x\n", status.CommR)
fmt.Printf("Ticket:\t\t%x\n", status.Ticket.TicketBytes) fmt.Printf("Ticket:\t\t%x\n", status.Ticket.Value)
fmt.Printf("TicketH:\t\t%d\n", status.Ticket.BlockHeight) fmt.Printf("TicketH:\t\t%d\n", status.Ticket.Epoch)
fmt.Printf("Seed:\t\t%x\n", status.Seed.TicketBytes) fmt.Printf("Seed:\t\t%x\n", status.Seed.Value)
fmt.Printf("SeedH:\t\t%d\n", status.Seed.BlockHeight) fmt.Printf("SeedH:\t\t%d\n", status.Seed.Epoch)
fmt.Printf("Proof:\t\t%x\n", status.Proof) fmt.Printf("Proof:\t\t%x\n", status.Proof)
fmt.Printf("Deals:\t\t%v\n", status.Deals) fmt.Printf("Deals:\t\t%v\n", status.Deals)
fmt.Printf("Retries:\t\t%d\n", status.Retries) fmt.Printf("Retries:\t\t%d\n", status.Retries)
@ -170,8 +171,8 @@ var sectorsListCmd = &cli.Command{
api.SectorStates[st.State], api.SectorStates[st.State],
yesno(inSSet), yesno(inSSet),
yesno(inPSet), yesno(inPSet),
st.Ticket.BlockHeight, st.Ticket.Epoch,
st.Seed.BlockHeight, st.Seed.Epoch,
st.Deals, st.Deals,
) )
} }

View File

@ -51,7 +51,7 @@ If you suspect that your GPU is not being used, first make sure it is properly c
First, to watch GPU utilization run `nvtop` in one terminal, then in a separate terminal, run: First, to watch GPU utilization run `nvtop` in one terminal, then in a separate terminal, run:
```sh ```sh
lotus-bench --sector-size=1024 lotus-bench --sector-size=2048
``` ```
This process uses a fair amount of GPU, and generally takes ~4 minutes to complete. If you do not see any activity in nvtop from lotus during the entire process, it is likely something is misconfigured with your GPU. This process uses a fair amount of GPU, and generally takes ~4 minutes to complete. If you do not see any activity in nvtop from lotus during the entire process, it is likely something is misconfigured with your GPU.

2
extern/filecoin-ffi vendored

@ -1 +1 @@
Subproject commit cb6019e085428c845dc29c95b9e70569019e619f Subproject commit 4da0bccccefb48df4bce63869d058f9bbf02b686

View File

@ -47,6 +47,8 @@ func main() {
api.PaymentInfo{}, api.PaymentInfo{},
api.SealedRef{}, api.SealedRef{},
api.SealedRefs{}, api.SealedRefs{},
api.SealTicket{},
api.SealSeed{},
) )
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -73,8 +75,6 @@ func main() {
} }
err = gen.WriteMapEncodersToFile("./storage/sealing/cbor_gen.go", "sealing", err = gen.WriteMapEncodersToFile("./storage/sealing/cbor_gen.go", "sealing",
sealing.SealTicket{},
sealing.SealSeed{},
sealing.Piece{}, sealing.Piece{},
sealing.SectorInfo{}, sealing.SectorInfo{},
sealing.Log{}, sealing.Log{},

View File

@ -6,6 +6,7 @@ import (
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
) )
@ -17,10 +18,11 @@ const (
) )
type PreSeal struct { type PreSeal struct {
CommR [32]byte CommR cid.Cid
CommD [32]byte CommD cid.Cid
SectorID abi.SectorNumber SectorID abi.SectorNumber
Deal market.DealProposal Deal market.DealProposal
ProofType abi.RegisteredProof
} }
type Miner struct { type Miner struct {

10
go.mod
View File

@ -11,19 +11,19 @@ require (
github.com/coreos/go-systemd/v22 v22.0.0 github.com/coreos/go-systemd/v22 v22.0.0
github.com/docker/go-units v0.4.0 github.com/docker/go-units v0.4.0
github.com/filecoin-project/chain-validation v0.0.3 github.com/filecoin-project/chain-validation v0.0.3
github.com/filecoin-project/filecoin-ffi v0.0.0-20191219131535-bb699517a590 github.com/filecoin-project/filecoin-ffi v0.0.0-20200226205820-4da0bccccefb
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e
github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2 github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5 github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5
github.com/filecoin-project/go-fil-markets v0.0.0-20200223154807-f7afd8e927f9 github.com/filecoin-project/go-fil-markets v0.0.0-20200228192824-ee51014cc8c6
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6 github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6
github.com/filecoin-project/go-paramfetch v0.0.1 github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200210220012-eb75ec747d6b github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200228181617-f00e2c4cc050
github.com/filecoin-project/go-statestore v0.1.0 github.com/filecoin-project/go-statestore v0.1.0
github.com/filecoin-project/specs-actors v0.0.0-20200223194852-39976038b18d github.com/filecoin-project/specs-actors v0.0.0-20200229011003-1d726e3afd04
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1
github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-ole/go-ole v1.2.4 // indirect
github.com/google/uuid v1.1.1 github.com/google/uuid v1.1.1

27
go.sum
View File

@ -94,13 +94,11 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.8.0 h1:5bzFgL+oy7JITMTxUPJ00n7VxmYd/PdMp5mHFX40/RY= github.com/fatih/color v1.8.0 h1:5bzFgL+oy7JITMTxUPJ00n7VxmYd/PdMp5mHFX40/RY=
github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8= github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8=
github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E= github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E=
github.com/filecoin-project/chain-validation v0.0.3 h1:luT/8kJ0WdMIqQ9Bm31W4JkuYCW0wUb26AvnD4WK59M= github.com/filecoin-project/chain-validation v0.0.3 h1:luT/8kJ0WdMIqQ9Bm31W4JkuYCW0wUb26AvnD4WK59M=
github.com/filecoin-project/chain-validation v0.0.3/go.mod h1:NCEGFjcWRjb8akWFSOXvU6n2efkWIqAeOKU6o5WBGQw= github.com/filecoin-project/chain-validation v0.0.3/go.mod h1:NCEGFjcWRjb8akWFSOXvU6n2efkWIqAeOKU6o5WBGQw=
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5 h1:/MmWluswvDIbuPvBct4q6HeQgVm62O2DzWYTB38kt4A=
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0= github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be h1:TooKBwR/g8jG0hZ3lqe9S5sy2vTUcLOZLlz3M5wGn2E= github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be h1:TooKBwR/g8jG0hZ3lqe9S5sy2vTUcLOZLlz3M5wGn2E=
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0= github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
@ -114,22 +112,25 @@ github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce/go.mod h1:b14UWxhxVCAjrQUYvVGrQRRsjAh79wXYejw9RbUcAww= github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce/go.mod h1:b14UWxhxVCAjrQUYvVGrQRRsjAh79wXYejw9RbUcAww=
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5 h1:yvQJCW9mmi9zy+51xA01Ea2X7/dL7r8eKDPuGUjRmbo= github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5 h1:yvQJCW9mmi9zy+51xA01Ea2X7/dL7r8eKDPuGUjRmbo=
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5/go.mod h1:JbkIgFF/Z9BDlvrJO1FuKkaWsH673/UdFaiVS6uIHlA= github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5/go.mod h1:JbkIgFF/Z9BDlvrJO1FuKkaWsH673/UdFaiVS6uIHlA=
github.com/filecoin-project/go-fil-markets v0.0.0-20200223154807-f7afd8e927f9 h1:uFS5r3K3AgIuR7cGBYY8k+vgwn/UXhin9NR2yCXVe7o= github.com/filecoin-project/go-fil-markets v0.0.0-20200228192824-ee51014cc8c6 h1:xYldVV9fZ+nsykQnEVMwcLU+6R5EshzmOWcyQDpludc=
github.com/filecoin-project/go-fil-markets v0.0.0-20200223154807-f7afd8e927f9/go.mod h1:ftsiBbjLjNLAZ52FVDigkdCp73ltdcvAzAXav6drSLA= github.com/filecoin-project/go-fil-markets v0.0.0-20200228192824-ee51014cc8c6/go.mod h1:rfRwhd3ujcCXnD4N9oEM2wjh8GRZGoeNXME+UPG/9ts=
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6 h1:92PET+sx1Hb4W/8CgFwGuxaKbttwY+UNspYZTvXY0vs= github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6 h1:92PET+sx1Hb4W/8CgFwGuxaKbttwY+UNspYZTvXY0vs=
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6/go.mod h1:0HgYnrkeSU4lu1p+LEOeDpFsNBssa0OGGriWdA4hvaE= github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6/go.mod h1:0HgYnrkeSU4lu1p+LEOeDpFsNBssa0OGGriWdA4hvaE=
github.com/filecoin-project/go-paramfetch v0.0.0-20200102181131-b20d579f2878/go.mod h1:40kI2Gv16mwcRsHptI3OAV4nlOEU7wVDc4RgMylNFjU= github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663 h1:eYxi6vI5CyeXD15X1bB3bledDXbqKxqf0wQzTLgwYwA=
github.com/filecoin-project/go-paramfetch v0.0.1 h1:gV7bs5YaqlgpGFMiLxInGK2L1FyCXUE0rimz4L7ghoE= github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc=
github.com/filecoin-project/go-paramfetch v0.0.1/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc= github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200226210935-4739f8749f56 h1:CqldkHf9HtAsewneyOZdi19Btc6kEvktVVeZsP9N7NQ=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200210220012-eb75ec747d6b h1:ds4TQay8wuV+2ucC6ENAeSYQDdl9CWYXnX0gvxzGKHg= github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200226210935-4739f8749f56/go.mod h1:tzTc9BxxSbjlIzhFwm5h9oBkXKkRuLxeiWspntwnKyw=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200210220012-eb75ec747d6b/go.mod h1:qsuPYsbKTHH2phNk81aUF9VJIilUxFrnxxnryJh4FOM= github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200228181617-f00e2c4cc050 h1:mUr2IegjC5TumVe7opY7CuXS/Ud4VCmDLidJDFeBNJQ=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200228181617-f00e2c4cc050/go.mod h1:tzTc9BxxSbjlIzhFwm5h9oBkXKkRuLxeiWspntwnKyw=
github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9 h1:k9qVR9ItcziSB2rxtlkN/MDWNlbsI6yzec+zjUatLW0=
github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIiWBRilQjQ+5IiwdQ= github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIiWBRilQjQ+5IiwdQ=
github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI=
github.com/filecoin-project/specs-actors v0.0.0-20200210130641-2d1fbd8672cf h1:fbxBG12yrxilPFV1EG2lYqpUyAlRZWkvtqjk2svSeXY=
github.com/filecoin-project/specs-actors v0.0.0-20200210130641-2d1fbd8672cf/go.mod h1:xtDZUB6pe4Pksa/bAJbJ693OilaC5Wbot9jMhLm3cZA= github.com/filecoin-project/specs-actors v0.0.0-20200210130641-2d1fbd8672cf/go.mod h1:xtDZUB6pe4Pksa/bAJbJ693OilaC5Wbot9jMhLm3cZA=
github.com/filecoin-project/specs-actors v0.0.0-20200220011005-b2a2fbf40362/go.mod h1:xtDZUB6pe4Pksa/bAJbJ693OilaC5Wbot9jMhLm3cZA= github.com/filecoin-project/specs-actors v0.0.0-20200226200336-94c9b92b2775/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
github.com/filecoin-project/specs-actors v0.0.0-20200223194852-39976038b18d h1:vukVHqbLQnXc+ZfhK+Cor3kaQx9SQbSZISqSeGjhYcE= github.com/filecoin-project/specs-actors v0.0.0-20200228215954-2c5be7cfad99/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
github.com/filecoin-project/specs-actors v0.0.0-20200223194852-39976038b18d/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU= github.com/filecoin-project/specs-actors v0.0.0-20200229011003-1d726e3afd04 h1:O343OeQLkLWLj5ZqQ5nhevAGBTeB5LioiA53ddScqdY=
github.com/filecoin-project/specs-actors v0.0.0-20200229011003-1d726e3afd04/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 h1:EzDjxMg43q1tA2c0MV3tNbaontnHLplHyFF6M5KiVP0= github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 h1:EzDjxMg43q1tA2c0MV3tNbaontnHLplHyFF6M5KiVP0=

10
lib/nullreader/reader.go Normal file
View File

@ -0,0 +1,10 @@
package nullreader
type Reader struct{}
func (Reader) Read(out []byte) (int, error) {
for i := range out {
out[i] = 0
}
return len(out), nil
}

View File

@ -3,7 +3,9 @@ package zerocomm
import ( import (
"math/bits" "math/bits"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
) )
const levels = 37 const levels = 37
@ -47,7 +49,7 @@ var pieceComms = [levels - skip][32]byte{
{0xaa, 0xaa, 0x8c, 0x4c, 0xb4, 0xa, 0xac, 0xee, 0x1e, 0x2, 0xdc, 0x65, 0x42, 0x4b, 0x2a, 0x6c, 0x8e, 0x99, 0xf8, 0x3, 0xb7, 0x2f, 0x79, 0x29, 0xc4, 0x10, 0x1d, 0x7f, 0xae, 0x6b, 0xff, 0x32}, {0xaa, 0xaa, 0x8c, 0x4c, 0xb4, 0xa, 0xac, 0xee, 0x1e, 0x2, 0xdc, 0x65, 0x42, 0x4b, 0x2a, 0x6c, 0x8e, 0x99, 0xf8, 0x3, 0xb7, 0x2f, 0x79, 0x29, 0xc4, 0x10, 0x1d, 0x7f, 0xae, 0x6b, 0xff, 0x32},
} }
func ForSize(sz abi.UnpaddedPieceSize) [32]byte { func ForSize(sz abi.UnpaddedPieceSize) cid.Cid {
level := bits.TrailingZeros64(uint64(sz.Padded())) - skip - 5 // 2^5 = 32 level := bits.TrailingZeros64(uint64(sz.Padded())) - skip - 5 // 2^5 = 32
return pieceComms[level] return commcid.DataCommitmentV1ToCID(pieceComms[level][:])
} }

View File

@ -3,41 +3,87 @@ package zerocomm
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"testing" "testing"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
abi "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/lib/nullreader"
) )
func TestComms(t *testing.T) { func TestComms(t *testing.T) {
var expPieceComms [levels - skip][32]byte t.Skip("don't have enough ram") // no, but seriously, currently this needs like 3tb of /tmp
var expPieceComms [levels - skip]cid.Cid
{ {
l2, err := sectorbuilder.GeneratePieceCommitment(bytes.NewReader(make([]byte, 127)), 127) l2, err := sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, bytes.NewReader(make([]byte, 127)), 127)
if err != nil { if err != nil {
return t.Fatal(err)
} }
expPieceComms[0] = l2 expPieceComms[0] = l2
} }
for i := 1; i < levels-2; i++ { for i := 1; i < levels-2; i++ {
var err error var err error
expPieceComms[i], err = sectorbuilder.GenerateDataCommitment(128<<i, []sectorbuilder.PublicPieceInfo{ sz := abi.UnpaddedPieceSize(127 << i)
{ fmt.Println(i, sz)
Size: 127 << (i - 1), r := io.LimitReader(&nullreader.Reader{}, int64(sz))
CommP: expPieceComms[i-1],
}, expPieceComms[i], err = sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, r, sz)
{
Size: 127 << (i - 1),
CommP: expPieceComms[i-1],
},
})
if err != nil { if err != nil {
panic(err) t.Fatal(err)
} }
} }
for i, comm := range expPieceComms { for i, comm := range expPieceComms {
if string(comm[:]) != string(pieceComms[i][:]) { c, err := commcid.CIDToPieceCommitmentV1(comm)
if err != nil {
t.Fatal(err)
}
if string(c) != string(pieceComms[i][:]) {
t.Errorf("zero commitment %d didn't match", i)
}
}
for _, comm := range expPieceComms { // Could do codegen, but this is good enough
fmt.Printf("%#v,\n", comm)
}
}
func TestCommsSmall(t *testing.T) {
var expPieceComms [8]cid.Cid
lvls := len(expPieceComms) + skip
{
l2, err := sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, bytes.NewReader(make([]byte, 127)), 127)
if err != nil {
t.Fatal(err)
}
expPieceComms[0] = l2
}
for i := 1; i < lvls-2; i++ {
var err error
sz := abi.UnpaddedPieceSize(127 << i)
fmt.Println(i, sz)
r := io.LimitReader(&nullreader.Reader{}, int64(sz))
expPieceComms[i], err = sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, r, sz)
if err != nil {
t.Fatal(err)
}
}
for i, comm := range expPieceComms {
c, err := commcid.CIDToPieceCommitmentV1(comm)
if err != nil {
t.Fatal(err)
}
if string(c) != string(pieceComms[i][:]) {
t.Errorf("zero commitment %d didn't match", i) t.Errorf("zero commitment %d didn't match", i)
} }
} }
@ -48,13 +94,13 @@ func TestComms(t *testing.T) {
} }
func TestForSise(t *testing.T) { func TestForSise(t *testing.T) {
exp, err := sectorbuilder.GeneratePieceCommitment(bytes.NewReader(make([]byte, 1016)), 1016) exp, err := sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, bytes.NewReader(make([]byte, 1016)), 1016)
if err != nil { if err != nil {
return return
} }
actual := ForSize(1016) actual := ForSize(1016)
if string(exp[:]) != string(actual[:]) { if !exp.Equals(actual) {
t.Errorf("zero commitment didn't match") t.Errorf("zero commitment didn't match")
} }
} }

View File

@ -3,9 +3,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis"
"github.com/filecoin-project/lotus/genesis"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -14,6 +11,10 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis"
"github.com/filecoin-project/lotus/genesis"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -23,7 +24,7 @@ import (
) )
func init() { func init() {
build.SectorSizes = []abi.SectorSize{1024} build.SectorSizes = []abi.SectorSize{2048}
} }
func (api *api) Spawn() (nodeInfo, error) { func (api *api) Spawn() (nodeInfo, error) {
@ -45,7 +46,7 @@ func (api *api) Spawn() (nodeInfo, error) {
} }
sbroot := filepath.Join(dir, "preseal") sbroot := filepath.Join(dir, "preseal")
genm, ki, err := seed.PreSeal(genMiner, build.SectorSizes[0], 0, 2, sbroot, []byte("8"), nil) genm, ki, err := seed.PreSeal(genMiner, abi.RegisteredProof_StackedDRG2KiBSeal, 0, 2, sbroot, []byte("8"), nil)
if err != nil { if err != nil {
return nodeInfo{}, xerrors.Errorf("preseal failed: %w", err) return nodeInfo{}, xerrors.Errorf("preseal failed: %w", err)
} }

View File

@ -31,7 +31,7 @@ func (rpn *retrievalProviderNode) UnsealSector(ctx context.Context, sectorID uin
if err != nil { if err != nil {
return nil, err return nil, err
} }
return rpn.sb.ReadPieceFromSealedSector(ctx, abi.SectorNumber(sectorID), sectorbuilder.UnpaddedByteIndex(offset), abi.UnpaddedPieceSize(length), si.Ticket.TicketBytes, si.CommD) return rpn.sb.ReadPieceFromSealedSector(ctx, abi.SectorNumber(sectorID), sectorbuilder.UnpaddedByteIndex(offset), abi.UnpaddedPieceSize(length), si.Ticket.Value, *si.CommD)
} }
func (rpn *retrievalProviderNode) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paych.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount) (abi.TokenAmount, error) { func (rpn *retrievalProviderNode) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paych.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount) (abi.TokenAmount, error) {

View File

@ -145,8 +145,8 @@ func (n *ClientNodeAdapter) AddFunds(ctx context.Context, addr address.Address,
return nil return nil
} }
func (n *ClientNodeAdapter) EnsureFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) error { func (n *ClientNodeAdapter) EnsureFunds(ctx context.Context, addr, wallet address.Address, amount abi.TokenAmount) error {
return n.fm.EnsureAvailable(ctx, addr, amount) return n.fm.EnsureAvailable(ctx, addr, wallet, amount)
} }
func (n *ClientNodeAdapter) GetBalance(ctx context.Context, addr address.Address) (storagemarket.Balance, error) { func (n *ClientNodeAdapter) GetBalance(ctx context.Context, addr address.Address) (storagemarket.Balance, error) {
@ -276,29 +276,47 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider
return nil return nil
} }
var sectorNumber abi.SectorNumber
var sectorFound bool
matchEvent := func(msg *types.Message) (bool, error) { matchEvent := func(msg *types.Message) (bool, error) {
if msg.To != provider { if msg.To != provider {
return false, nil return false, nil
} }
if msg.Method != builtin.MethodsMiner.ProveCommitSector { switch msg.Method {
case builtin.MethodsMiner.PreCommitSector:
var params miner.SectorPreCommitInfo
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
return false, xerrors.Errorf("unmarshal pre commit: %w", err)
}
for _, did := range params.DealIDs {
if did == abi.DealID(dealId) {
sectorNumber = params.SectorNumber
sectorFound = true
return false, nil
}
}
return false, nil
case builtin.MethodsMiner.ProveCommitSector:
var params miner.ProveCommitSectorParams
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
return false, xerrors.Errorf("failed to unmarshal prove commit sector params: %w", err)
}
if !sectorFound {
return false, nil
}
if params.SectorNumber != sectorNumber {
return false, nil
}
return true, nil
default:
return false, nil return false, nil
} }
var params miner.SectorPreCommitInfo
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
return false, err
}
var found bool
for _, dealID := range params.DealIDs {
if uint64(dealID) == dealId {
found = true
break
}
}
return found, nil
} }
if err := c.ev.Called(checkFunc, called, revert, 3, build.SealRandomnessLookbackLimit, matchEvent); err != nil { if err := c.ev.Called(checkFunc, called, revert, 3, build.SealRandomnessLookbackLimit, matchEvent); err != nil {

View File

@ -144,8 +144,8 @@ func (n *ProviderNodeAdapter) SignBytes(ctx context.Context, signer address.Addr
return localSignature, nil return localSignature, nil
} }
func (n *ProviderNodeAdapter) EnsureFunds(ctx context.Context, addr address.Address, amt abi.TokenAmount) error { func (n *ProviderNodeAdapter) EnsureFunds(ctx context.Context, addr, wallet address.Address, amt abi.TokenAmount) error {
return n.MarketEnsureAvailable(ctx, addr, amt) return n.MarketEnsureAvailable(ctx, addr, wallet, amt)
} }
func (n *ProviderNodeAdapter) MostRecentStateId(ctx context.Context) (storagemarket.StateKey, error) { func (n *ProviderNodeAdapter) MostRecentStateId(ctx context.Context) (storagemarket.StateKey, error) {
@ -269,29 +269,49 @@ func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provide
return nil return nil
} }
var sectorNumber abi.SectorNumber
var sectorFound bool
matchEvent := func(msg *types.Message) (bool, error) { matchEvent := func(msg *types.Message) (bool, error) {
if msg.To != provider { if msg.To != provider {
return false, nil return false, nil
} }
if msg.Method != builtin.MethodsMiner.ProveCommitSector { switch msg.Method {
case builtin.MethodsMiner.PreCommitSector:
var params miner.SectorPreCommitInfo
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
return false, xerrors.Errorf("unmarshal pre commit: %w", err)
}
for _, did := range params.DealIDs {
if did == abi.DealID(dealID) {
sectorNumber = params.SectorNumber
sectorFound = true
return false, nil
}
}
return false, nil
case builtin.MethodsMiner.ProveCommitSector:
var params miner.ProveCommitSectorParams
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
return false, xerrors.Errorf("failed to unmarshal prove commit sector params: %w", err)
}
if !sectorFound {
return false, nil
}
if params.SectorNumber != sectorNumber {
return false, nil
}
return true, nil
default:
return false, nil return false, nil
} }
var params miner.SectorPreCommitInfo
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
return false, err
}
var found bool
for _, did := range params.DealIDs {
if did == abi.DealID(dealID) {
found = true
break
}
}
return found, nil
} }
if err := n.ev.Called(checkFunc, called, revert, 3, build.SealRandomnessLookbackLimit, matchEvent); err != nil { if err := n.ev.Called(checkFunc, called, revert, 3, build.SealRandomnessLookbackLimit, matchEvent); err != nil {

View File

@ -3,9 +3,10 @@ package node
import ( import (
"context" "context"
"errors" "errors"
"github.com/filecoin-project/specs-actors/actors/runtime"
"time" "time"
"github.com/filecoin-project/specs-actors/actors/runtime"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder" sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
blockstore "github.com/ipfs/go-ipfs-blockstore" blockstore "github.com/ipfs/go-ipfs-blockstore"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
@ -428,7 +429,7 @@ func New(ctx context.Context, opts ...Option) (StopFunc, error) {
// apply module options in the right order // apply module options in the right order
if err := Options(Options(defaults()...), Options(opts...))(&settings); err != nil { if err := Options(Options(defaults()...), Options(opts...))(&settings); err != nil {
return nil, err return nil, xerrors.Errorf("applying node options failed: %w", err)
} }
// gather constructors for fx.Options // gather constructors for fx.Options
@ -456,7 +457,7 @@ func New(ctx context.Context, opts ...Option) (StopFunc, error) {
// correctly // correctly
if err := app.Start(ctx); err != nil { if err := app.Start(ctx); err != nil {
// comment fx.NopLogger few lines above for easier debugging // comment fx.NopLogger few lines above for easier debugging
return nil, err return nil, xerrors.Errorf("starting node: %w", err)
} }
return app.Stop, nil return app.Stop, nil

View File

@ -7,7 +7,7 @@ import (
"io" "io"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
cid "github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors" xerrors "golang.org/x/xerrors"
) )

View File

@ -76,6 +76,17 @@ func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, addr address.Ad
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed getting miner worker: %w", err) return nil, xerrors.Errorf("failed getting miner worker: %w", err)
} }
ssize, err := a.StateMinerSectorSize(ctx, miner, types.EmptyTSK)
if err != nil {
return nil, xerrors.Errorf("failed checking miners sector size: %w", err)
}
rt, _, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
return nil, xerrors.Errorf("bad sector size: %w", err)
}
providerInfo := utils.NewStorageProviderInfo(miner, mw, 0, pid) providerInfo := utils.NewStorageProviderInfo(miner, mw, 0, pid)
ts, err := a.ChainHead(ctx) ts, err := a.ChainHead(ctx)
if err != nil { if err != nil {
@ -92,7 +103,9 @@ func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, addr address.Ad
ts.Height()+dealStartBuffer, ts.Height()+dealStartBuffer,
ts.Height()+dealStartBuffer+abi.ChainEpoch(blocksDuration), ts.Height()+dealStartBuffer+abi.ChainEpoch(blocksDuration),
epochPrice, epochPrice,
big.Zero()) big.Zero(),
rt,
)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to start deal: %w", err) return nil, xerrors.Errorf("failed to start deal: %w", err)
@ -287,6 +300,10 @@ func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, path
order.MinerPeerID = pid order.MinerPeerID = pid
} }
if order.Size == 0 {
return xerrors.Errorf("cannot make retrieval deal for zero bytes")
}
retrievalResult := make(chan error, 1) retrievalResult := make(chan error, 1)
unsubscribe := a.Retrieval.SubscribeToEvents(func(event retrievalmarket.ClientEvent, state retrievalmarket.ClientDealState) { unsubscribe := a.Retrieval.SubscribeToEvents(func(event retrievalmarket.ClientEvent, state retrievalmarket.ClientDealState) {
@ -300,10 +317,12 @@ func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, path
} }
}) })
ppb := types.BigDiv(order.Total, types.NewInt(order.Size))
a.Retrieval.Retrieve( a.Retrieval.Retrieve(
ctx, ctx,
order.Root, order.Root,
retrievalmarket.NewParamsV0(types.BigDiv(order.Total, types.NewInt(order.Size)), order.PaymentInterval, order.PaymentIntervalIncrease), retrievalmarket.NewParamsV0(ppb, order.PaymentInterval, order.PaymentIntervalIncrease),
order.Total, order.Total,
order.MinerPeerID, order.MinerPeerID,
order.Client, order.Client,

View File

@ -16,6 +16,6 @@ type MarketAPI struct {
FMgr *market.FundMgr FMgr *market.FundMgr
} }
func (a *MarketAPI) MarketEnsureAvailable(ctx context.Context, addr address.Address, amt types.BigInt) error { func (a *MarketAPI) MarketEnsureAvailable(ctx context.Context, addr, wallet address.Address, amt types.BigInt) error {
return a.FMgr.EnsureAvailable(ctx, addr, amt) return a.FMgr.EnsureAvailable(ctx, addr, wallet, amt)
} }

View File

@ -67,7 +67,8 @@ func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address
Lane: uint64(lane), Lane: uint64(lane),
Extra: v.Extra, Extra: v.Extra,
TimeLock: v.TimeLock, TimeLockMin: v.TimeLockMin,
TimeLockMax: v.TimeLockMax,
MinSettleHeight: v.MinSettle, MinSettleHeight: v.MinSettle,
}) })
if err != nil { if err != nil {

View File

@ -3,13 +3,14 @@ package impl
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"github.com/filecoin-project/lotus/chain/types"
"io" "io"
"mime" "mime"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/gorilla/mux" "github.com/gorilla/mux"
files "github.com/ipfs/go-ipfs-files" files "github.com/ipfs/go-ipfs-files"
@ -209,8 +210,8 @@ func (sm *StorageMinerAPI) SectorsStatus(ctx context.Context, sid abi.SectorNumb
CommR: info.CommR, CommR: info.CommR,
Proof: info.Proof, Proof: info.Proof,
Deals: deals, Deals: deals,
Ticket: info.Ticket.SB(), Ticket: info.Ticket,
Seed: info.Seed.SB(), Seed: info.Seed,
Retries: info.Nonce, Retries: info.Nonce,
LastErr: info.LastErr, LastErr: info.LastErr,

View File

@ -3,6 +3,7 @@ package modules
import ( import (
"bytes" "bytes"
"context" "context"
"github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/specs-actors/actors/runtime"
"github.com/ipfs/go-bitswap" "github.com/ipfs/go-bitswap"
@ -108,17 +109,21 @@ func LoadGenesis(genBytes []byte) func(dtypes.ChainBlockstore) Genesis {
return func() (header *types.BlockHeader, e error) { return func() (header *types.BlockHeader, e error) {
c, err := car.LoadCar(bs, bytes.NewReader(genBytes)) c, err := car.LoadCar(bs, bytes.NewReader(genBytes))
if err != nil { if err != nil {
return nil, err return nil, xerrors.Errorf("loading genesis car file failed: %w", err)
} }
if len(c.Roots) != 1 { if len(c.Roots) != 1 {
return nil, xerrors.New("expected genesis file to have one root") return nil, xerrors.New("expected genesis file to have one root")
} }
root, err := bs.Get(c.Roots[0]) root, err := bs.Get(c.Roots[0])
if err != nil { if err != nil {
return &types.BlockHeader{}, err return nil, err
} }
return types.DecodeBlock(root.RawData()) h, err := types.DecodeBlock(root.RawData())
if err != nil {
return nil, xerrors.Errorf("decoding block failed: %w", err)
}
return h, nil
} }
} }
} }
@ -129,12 +134,12 @@ func SetGenesis(cs *store.ChainStore, g Genesis) error {
return nil // already set, noop return nil // already set, noop
} }
if err != datastore.ErrNotFound { if err != datastore.ErrNotFound {
return err return xerrors.Errorf("getting genesis block failed: %w", err)
} }
genesis, err := g() genesis, err := g()
if err != nil { if err != nil {
return err return xerrors.Errorf("genesis func failed: %w", err)
} }
return cs.SetGenesis(genesis) return cs.SetGenesis(genesis)

View File

@ -14,6 +14,7 @@ import (
deals "github.com/filecoin-project/go-fil-markets/storagemarket/impl" deals "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
storageimpl "github.com/filecoin-project/go-fil-markets/storagemarket/impl" storageimpl "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
smnet "github.com/filecoin-project/go-fil-markets/storagemarket/network" smnet "github.com/filecoin-project/go-fil-markets/storagemarket/network"
"github.com/filecoin-project/go-fil-markets/storedcounter"
"github.com/filecoin-project/go-statestore" "github.com/filecoin-project/go-statestore"
"github.com/ipfs/go-bitswap" "github.com/ipfs/go-bitswap"
"github.com/ipfs/go-bitswap/network" "github.com/ipfs/go-bitswap/network"
@ -117,8 +118,9 @@ func StorageClient(h host.Host, ibs dtypes.ClientBlockstore, r repo.LockedRepo,
} }
// RetrievalClient creates a new retrieval client attached to the client blockstore // RetrievalClient creates a new retrieval client attached to the client blockstore
func RetrievalClient(h host.Host, bs dtypes.ClientBlockstore, pmgr *paychmgr.Manager, payapi payapi.PaychAPI, resolver retrievalmarket.PeerResolver) retrievalmarket.RetrievalClient { func RetrievalClient(h host.Host, bs dtypes.ClientBlockstore, pmgr *paychmgr.Manager, payapi payapi.PaychAPI, resolver retrievalmarket.PeerResolver, ds dtypes.MetadataDS) (retrievalmarket.RetrievalClient, error) {
adapter := retrievaladapter.NewRetrievalClientNode(pmgr, payapi) adapter := retrievaladapter.NewRetrievalClientNode(pmgr, payapi)
network := rmnet.NewFromLibp2pHost(h) network := rmnet.NewFromLibp2pHost(h)
return retrievalimpl.NewClient(network, bs, adapter, resolver) sc := storedcounter.New(ds, datastore.NewKey("/retr"))
return retrievalimpl.NewClient(network, bs, adapter, resolver, ds, sc)
} }

View File

@ -2,10 +2,11 @@ package modules
import ( import (
"context" "context"
"github.com/filecoin-project/lotus/chain/types"
"math" "math"
"reflect" "reflect"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
dtgraphsync "github.com/filecoin-project/go-data-transfer/impl/graphsync" dtgraphsync "github.com/filecoin-project/go-data-transfer/impl/graphsync"
piecefilestore "github.com/filecoin-project/go-fil-markets/filestore" piecefilestore "github.com/filecoin-project/go-fil-markets/filestore"
@ -21,6 +22,7 @@ import (
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/go-sectorbuilder/fs" "github.com/filecoin-project/go-sectorbuilder/fs"
"github.com/filecoin-project/go-statestore" "github.com/filecoin-project/go-statestore"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/ipfs/go-bitswap" "github.com/ipfs/go-bitswap"
"github.com/ipfs/go-bitswap/network" "github.com/ipfs/go-bitswap/network"
@ -61,7 +63,12 @@ func minerAddrFromDS(ds dtypes.MetadataDS) (address.Address, error) {
} }
func GetParams(sbc *sectorbuilder.Config) error { func GetParams(sbc *sectorbuilder.Config) error {
if err := paramfetch.GetParams(build.ParametersJson(), uint64(sbc.SectorSize)); err != nil { ssize, err := sbc.SealProofType.SectorSize()
if err != nil {
return err
}
if err := paramfetch.GetParams(build.ParametersJson(), uint64(ssize)); err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err) return xerrors.Errorf("fetching proof parameters: %w", err)
} }
@ -69,13 +76,13 @@ func GetParams(sbc *sectorbuilder.Config) error {
} }
func SectorBuilderConfig(storage []fs.PathConfig, threads uint, noprecommit, nocommit bool) func(dtypes.MetadataDS, api.FullNode) (*sectorbuilder.Config, error) { func SectorBuilderConfig(storage []fs.PathConfig, threads uint, noprecommit, nocommit bool) func(dtypes.MetadataDS, api.FullNode) (*sectorbuilder.Config, error) {
return func(ds dtypes.MetadataDS, api api.FullNode) (*sectorbuilder.Config, error) { return func(ds dtypes.MetadataDS, fnapi api.FullNode) (*sectorbuilder.Config, error) {
minerAddr, err := minerAddrFromDS(ds) minerAddr, err := minerAddrFromDS(ds)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ssize, err := api.StateMinerSectorSize(context.TODO(), minerAddr, types.EmptyTSK) ssize, err := fnapi.StateMinerSectorSize(context.TODO(), minerAddr, types.EmptyTSK)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -91,9 +98,15 @@ func SectorBuilderConfig(storage []fs.PathConfig, threads uint, noprecommit, noc
return nil, xerrors.Errorf("too many sectorbuilder threads specified: %d, max allowed: %d", threads, math.MaxUint8) return nil, xerrors.Errorf("too many sectorbuilder threads specified: %d, max allowed: %d", threads, math.MaxUint8)
} }
ppt, spt, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
return nil, xerrors.Errorf("bad sector size: %w", err)
}
sb := &sectorbuilder.Config{ sb := &sectorbuilder.Config{
Miner: minerAddr, Miner: minerAddr,
SectorSize: ssize, SealProofType: spt,
PoStProofType: ppt,
WorkerThreads: uint8(threads), WorkerThreads: uint8(threads),
NoPreCommit: noprecommit, NoPreCommit: noprecommit,
@ -267,26 +280,21 @@ func SectorBuilder(cfg *sectorbuilder.Config, ds dtypes.MetadataDS) (*sectorbuil
return sb, nil return sb, nil
} }
func SealTicketGen(api api.FullNode) sealing.TicketFn { func SealTicketGen(fapi api.FullNode) sealing.TicketFn {
return func(ctx context.Context) (*sectorbuilder.SealTicket, error) { return func(ctx context.Context) (*api.SealTicket, error) {
ts, err := api.ChainHead(ctx) ts, err := fapi.ChainHead(ctx)
if err != nil { if err != nil {
return nil, xerrors.Errorf("getting head ts for SealTicket failed: %w", err) return nil, xerrors.Errorf("getting head ts for SealTicket failed: %w", err)
} }
r, err := api.ChainGetRandomness(ctx, ts.Key(), crypto.DomainSeparationTag_SealRandomness, ts.Height()-build.SealRandomnessLookback, nil) r, err := fapi.ChainGetRandomness(ctx, ts.Key(), crypto.DomainSeparationTag_SealRandomness, ts.Height()-build.SealRandomnessLookback, nil)
if err != nil { if err != nil {
return nil, xerrors.Errorf("getting randomness for SealTicket failed: %w", err) return nil, xerrors.Errorf("getting randomness for SealTicket failed: %w", err)
} }
var tkt [sectorbuilder.CommLen]byte return &api.SealTicket{
if n := copy(tkt[:], r); n != sectorbuilder.CommLen { Epoch: ts.Height() - build.SealRandomnessLookback,
return nil, xerrors.Errorf("unexpected randomness len: %d (expected %d)", n, sectorbuilder.CommLen) Value: abi.SealRandomness(r),
}
return &sectorbuilder.SealTicket{
BlockHeight: uint64(ts.Height() - build.SealRandomnessLookback),
TicketBytes: tkt,
}, nil }, nil
} }
} }
@ -295,7 +303,7 @@ func NewProviderRequestValidator(deals dtypes.ProviderDealStore) *storageimpl.Pr
return storageimpl.NewProviderRequestValidator(deals) return storageimpl.NewProviderRequestValidator(deals)
} }
func StorageProvider(h host.Host, ds dtypes.MetadataDS, ibs dtypes.StagingBlockstore, r repo.LockedRepo, pieceStore dtypes.ProviderPieceStore, dataTransfer dtypes.ProviderDataTransfer, spn storagemarket.StorageProviderNode) (storagemarket.StorageProvider, error) { func StorageProvider(ctx helpers.MetricsCtx, fapi api.FullNode, h host.Host, ds dtypes.MetadataDS, ibs dtypes.StagingBlockstore, r repo.LockedRepo, pieceStore dtypes.ProviderPieceStore, dataTransfer dtypes.ProviderDataTransfer, spn storagemarket.StorageProviderNode) (storagemarket.StorageProvider, error) {
store, err := piecefilestore.NewLocalFileStore(piecefilestore.OsPath(r.Path())) store, err := piecefilestore.NewLocalFileStore(piecefilestore.OsPath(r.Path()))
if err != nil { if err != nil {
return nil, err return nil, err
@ -305,11 +313,23 @@ func StorageProvider(h host.Host, ds dtypes.MetadataDS, ibs dtypes.StagingBlocks
if err != nil { if err != nil {
return nil, err return nil, err
} }
minerAddress, err := address.NewFromBytes(addr) minerAddress, err := address.NewFromBytes(addr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return storageimpl.NewProvider(net, ds, ibs, store, pieceStore, dataTransfer, spn, minerAddress)
ssize, err := fapi.StateMinerSectorSize(ctx, minerAddress, types.EmptyTSK)
if err != nil {
return nil, err
}
rt, _, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
return nil, err
}
return storageimpl.NewProvider(net, ds, ibs, store, pieceStore, dataTransfer, spn, minerAddress, rt)
} }
// RetrievalProvider creates a new retrieval provider attached to the provider blockstore // RetrievalProvider creates a new retrieval provider attached to the provider blockstore
@ -320,5 +340,5 @@ func RetrievalProvider(h host.Host, miner *storage.Miner, sb sectorbuilder.Inter
return nil, err return nil, err
} }
network := rmnet.NewFromLibp2pHost(h) network := rmnet.NewFromLibp2pHost(h)
return retrievalimpl.NewProvider(address, adapter, network, pieceStore, ibs), nil return retrievalimpl.NewProvider(address, adapter, network, pieceStore, ibs, ds)
} }

View File

@ -36,14 +36,14 @@ func MakeGenesisMem(out io.Writer, template genesis.Template) func(bs dtypes.Cha
glog.Warn("Generating new random genesis block, note that this SHOULD NOT happen unless you are setting up new network") glog.Warn("Generating new random genesis block, note that this SHOULD NOT happen unless you are setting up new network")
b, err := genesis2.MakeGenesisBlock(context.TODO(), bs, syscalls, template) b, err := genesis2.MakeGenesisBlock(context.TODO(), bs, syscalls, template)
if err != nil { if err != nil {
return nil, err return nil, xerrors.Errorf("make genesis block failed: %w", err)
} }
offl := offline.Exchange(bs) offl := offline.Exchange(bs)
blkserv := blockservice.New(bs, offl) blkserv := blockservice.New(bs, offl)
dserv := merkledag.NewDAGService(blkserv) dserv := merkledag.NewDAGService(blkserv)
if err := car.WriteCarWithWalker(context.TODO(), dserv, []cid.Cid{b.Genesis.Cid()}, out, gen.CarWalkFunc); err != nil { if err := car.WriteCarWithWalker(context.TODO(), dserv, []cid.Cid{b.Genesis.Cid()}, out, gen.CarWalkFunc); err != nil {
return nil, err return nil, xerrors.Errorf("failed to write car file: %w", err)
} }
return b.Genesis, nil return b.Genesis, nil

View File

@ -49,8 +49,8 @@ import (
func init() { func init() {
_ = logging.SetLogLevel("*", "INFO") _ = logging.SetLogLevel("*", "INFO")
build.SectorSizes = []abi.SectorSize{1024} build.SectorSizes = []abi.SectorSize{2048}
build.MinimumMinerPower = 1024 build.MinimumMinerPower = 2048
} }
func testStorageNode(ctx context.Context, t *testing.T, waddr address.Address, act address.Address, pk crypto.PrivKey, tnd test.TestNode, mn mocknet.Mocknet, opts node.Option) test.TestStorageNode { func testStorageNode(ctx context.Context, t *testing.T, waddr address.Address, act address.Address, pk crypto.PrivKey, tnd test.TestNode, mn mocknet.Mocknet, opts node.Option) test.TestStorageNode {
@ -174,7 +174,7 @@ func builder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []test.Te
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
genm, k, err := seed.PreSeal(maddr, 1024, 0, 2, tdir, []byte("make genesis mem random"), nil) genm, k, err := seed.PreSeal(maddr, abi.RegisteredProof_StackedDRG2KiBPoSt, 0, 2, tdir, []byte("make genesis mem random"), nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -260,7 +260,8 @@ func builder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []test.Te
} }
osb, err := sectorbuilder.New(&sectorbuilder.Config{ osb, err := sectorbuilder.New(&sectorbuilder.Config{
SectorSize: 1024, SealProofType: abi.RegisteredProof_StackedDRG2KiBSeal,
PoStProofType: abi.RegisteredProof_StackedDRG2KiBPoSt,
WorkerThreads: 2, WorkerThreads: 2,
Miner: genMiner, Miner: genMiner,
Paths: sectorbuilder.SimplePath(psd), Paths: sectorbuilder.SimplePath(psd),
@ -317,7 +318,7 @@ func mockSbBuilder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []t
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
genm, k, err := sbmock.PreSeal(1024, maddr, 2) genm, k, err := sbmock.PreSeal(2048, maddr, 2)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -3,7 +3,7 @@
set -xeo set -xeo
NUM_SECTORS=2 NUM_SECTORS=2
SECTOR_SIZE=1024 SECTOR_SIZE=2048
sdt0111=$(mktemp -d) sdt0111=$(mktemp -d)

View File

@ -2,12 +2,10 @@ package storage
import ( import (
"context" "context"
"github.com/filecoin-project/specs-actors/actors/crypto"
"time" "time"
ffi "github.com/filecoin-project/filecoin-ffi" "github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/filecoin-project/go-address"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/miner"
@ -91,7 +89,7 @@ func (s *FPoStScheduler) declareFaults(ctx context.Context, fc uint64, params *m
return nil return nil
} }
func (s *FPoStScheduler) checkFaults(ctx context.Context, ssi sectorbuilder.SortedPublicSectorInfo) ([]abi.SectorNumber, error) { func (s *FPoStScheduler) checkFaults(ctx context.Context, ssi []abi.SectorNumber) ([]abi.SectorNumber, error) {
faults := s.sb.Scrub(ssi) faults := s.sb.Scrub(ssi)
declaredFaults := map[abi.SectorNumber]struct{}{} declaredFaults := map[abi.SectorNumber]struct{}{}
@ -160,21 +158,23 @@ func (s *FPoStScheduler) runPost(ctx context.Context, eps abi.ChainEpoch, ts *ty
"eps", eps, "eps", eps,
"height", ts.Height()) "height", ts.Height())
faults, err := s.checkFaults(ctx, ssi) var snums []abi.SectorNumber
for _, si := range ssi {
snums = append(snums, si.SectorNumber)
}
faults, err := s.checkFaults(ctx, snums)
if err != nil { if err != nil {
log.Errorf("Failed to declare faults: %+v", err) log.Errorf("Failed to declare faults: %+v", err)
} }
tsStart := time.Now() tsStart := time.Now()
var seed [32]byte
copy(seed[:], rand)
log.Infow("generating fPoSt", log.Infow("generating fPoSt",
"sectors", len(ssi.Values()), "sectors", len(ssi),
"faults", len(faults)) "faults", len(faults))
scandidates, proof, err := s.sb.GenerateFallbackPoSt(ssi, seed, faults) scandidates, proof, err := s.sb.GenerateFallbackPoSt(ssi, abi.PoStRandomness(rand), faults)
if err != nil { if err != nil {
return nil, xerrors.Errorf("running post failed: %w", err) return nil, xerrors.Errorf("running post failed: %w", err)
} }
@ -182,55 +182,43 @@ func (s *FPoStScheduler) runPost(ctx context.Context, eps abi.ChainEpoch, ts *ty
elapsed := time.Since(tsStart) elapsed := time.Since(tsStart)
log.Infow("submitting PoSt", "pLen", len(proof), "elapsed", elapsed) log.Infow("submitting PoSt", "pLen", len(proof), "elapsed", elapsed)
mid, err := address.IDFromAddress(s.actor)
if err != nil {
return nil, err
}
candidates := make([]abi.PoStCandidate, len(scandidates)) candidates := make([]abi.PoStCandidate, len(scandidates))
for i, sc := range scandidates { for i, sc := range scandidates {
part := make([]byte, 32) part := make([]byte, 32)
copy(part, sc.PartialTicket[:]) copy(part, sc.Candidate.PartialTicket[:])
candidates[i] = abi.PoStCandidate{ candidates[i] = abi.PoStCandidate{
RegisteredProof: abi.RegisteredProof_StackedDRG32GiBPoSt, // TODO: build setting RegisteredProof: abi.RegisteredProof_StackedDRG32GiBPoSt, // TODO: build setting
PartialTicket: part, PartialTicket: part,
SectorID: abi.SectorID{ SectorID: sc.Candidate.SectorID,
Miner: abi.ActorID(mid), ChallengeIndex: sc.Candidate.ChallengeIndex,
Number: sc.SectorNum,
},
ChallengeIndex: int64(sc.SectorChallengeIndex), // TODO: fix spec
} }
} }
return &abi.OnChainPoStVerifyInfo{ return &abi.OnChainPoStVerifyInfo{
ProofType: abi.RegisteredProof_StackedDRG32GiBPoSt, // TODO: build setting Proofs: proof,
Proofs: []abi.PoStProof{{proof}},
Candidates: candidates, Candidates: candidates,
}, nil }, nil
} }
func (s *FPoStScheduler) sortedSectorInfo(ctx context.Context, ts *types.TipSet) (sectorbuilder.SortedPublicSectorInfo, error) { func (s *FPoStScheduler) sortedSectorInfo(ctx context.Context, ts *types.TipSet) ([]abi.SectorInfo, error) {
sset, err := s.api.StateMinerProvingSet(ctx, s.actor, ts.Key()) sset, err := s.api.StateMinerProvingSet(ctx, s.actor, ts.Key())
if err != nil { if err != nil {
return sectorbuilder.SortedPublicSectorInfo{}, xerrors.Errorf("failed to get proving set for miner (tsH: %d): %w", ts.Height(), err) return nil, xerrors.Errorf("failed to get proving set for miner (tsH: %d): %w", ts.Height(), err)
} }
if len(sset) == 0 { if len(sset) == 0 {
log.Warn("empty proving set! (ts.H: %d)", ts.Height()) log.Warn("empty proving set! (ts.H: %d)", ts.Height())
} }
sbsi := make([]ffi.PublicSectorInfo, len(sset)) sbsi := make([]abi.SectorInfo, len(sset))
for k, sector := range sset { for k, sector := range sset {
var commR [sectorbuilder.CommLen]byte
scid := sector.Info.Info.SealedCID.Bytes()
copy(commR[:], scid[len(scid)-32:])
sbsi[k] = ffi.PublicSectorInfo{ sbsi[k] = abi.SectorInfo{
SectorNum: sector.Info.Info.SectorNumber, SectorNumber: sector.Info.Info.SectorNumber,
CommR: commR, SealedCID: sector.Info.Info.SealedCID,
} }
} }
return sectorbuilder.NewSortedPublicSectorInfo(sbsi), nil return sbsi, nil
} }
func (s *FPoStScheduler) submitPost(ctx context.Context, proof *abi.OnChainPoStVerifyInfo) error { func (s *FPoStScheduler) submitPost(ctx context.Context, proof *abi.OnChainPoStVerifyInfo) error {

View File

@ -12,6 +12,7 @@ import (
"github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/host"
"golang.org/x/xerrors" "golang.org/x/xerrors"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/miner"
@ -127,27 +128,31 @@ func NewElectionPoStProver(sb sectorbuilder.Interface) *SectorBuilderEpp {
var _ gen.ElectionPoStProver = (*SectorBuilderEpp)(nil) var _ gen.ElectionPoStProver = (*SectorBuilderEpp)(nil)
func (epp *SectorBuilderEpp) GenerateCandidates(ctx context.Context, ssi sectorbuilder.SortedPublicSectorInfo, rand []byte) ([]sectorbuilder.EPostCandidate, error) { func (epp *SectorBuilderEpp) GenerateCandidates(ctx context.Context, ssi []abi.SectorInfo, rand abi.PoStRandomness) ([]ffi.PoStCandidateWithTicket, error) {
start := time.Now() start := time.Now()
var faults []abi.SectorNumber // TODO var faults []abi.SectorNumber // TODO
var randbuf [32]byte cds, err := epp.sb.GenerateEPostCandidates(ssi, rand, faults)
copy(randbuf[:], rand)
cds, err := epp.sb.GenerateEPostCandidates(ssi, randbuf, faults)
if err != nil { if err != nil {
return nil, err return nil, xerrors.Errorf("failed to generate candidates: %w", err)
} }
log.Infof("Generate candidates took %s", time.Since(start)) log.Infof("Generate candidates took %s", time.Since(start))
return cds, nil return cds, nil
} }
func (epp *SectorBuilderEpp) ComputeProof(ctx context.Context, ssi sectorbuilder.SortedPublicSectorInfo, rand []byte, winners []sectorbuilder.EPostCandidate) ([]byte, error) { func (epp *SectorBuilderEpp) ComputeProof(ctx context.Context, ssi []abi.SectorInfo, rand []byte, winners []ffi.PoStCandidateWithTicket) ([]abi.PoStProof, error) {
if build.InsecurePoStValidation { if build.InsecurePoStValidation {
log.Warn("Generating fake EPost proof! You should only see this while running tests!") log.Warn("Generating fake EPost proof! You should only see this while running tests!")
return []byte("valid proof"), nil return []abi.PoStProof{{ProofBytes: []byte("valid proof")}}, nil
} }
owins := make([]abi.PoStCandidate, 0, len(winners))
for _, w := range winners {
owins = append(owins, w.Candidate)
}
start := time.Now() start := time.Now()
proof, err := epp.sb.ComputeElectionPoSt(ssi, rand, winners) proof, err := epp.sb.ComputeElectionPoSt(ssi, rand, owins)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -8,9 +8,11 @@ import (
"github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet" "github.com/filecoin-project/lotus/chain/wallet"
"github.com/filecoin-project/lotus/genesis" "github.com/filecoin-project/lotus/genesis"
"github.com/filecoin-project/lotus/lib/zerocomm"
) )
func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis.Miner, *types.KeyInfo, error) { func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis.Miner, *types.KeyInfo, error) {
@ -28,15 +30,22 @@ func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis
Sectors: make([]*genesis.PreSeal, sectors), Sectors: make([]*genesis.PreSeal, sectors),
} }
_, st, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
return nil, nil, err
}
for i := range genm.Sectors { for i := range genm.Sectors {
preseal := &genesis.PreSeal{} preseal := &genesis.PreSeal{}
sdata := randB(uint64(abi.PaddedPieceSize(ssize).Unpadded()))
preseal.CommD = commD(sdata) preseal.ProofType = st
preseal.CommR = commDR(preseal.CommD[:]) preseal.CommD = zerocomm.ForSize(abi.PaddedPieceSize(ssize).Unpadded())
d, _ := commcid.CIDToPieceCommitmentV1(preseal.CommD)
r := commDR(d)
preseal.CommR = commcid.ReplicaCommitmentV1ToCID(r[:])
preseal.SectorID = abi.SectorNumber(i + 1) preseal.SectorID = abi.SectorNumber(i + 1)
preseal.Deal = market.DealProposal{ preseal.Deal = market.DealProposal{
PieceCID: commcid.PieceCommitmentV1ToCID(preseal.CommD[:]), PieceCID: preseal.CommD,
PieceSize: abi.PaddedPieceSize(ssize), PieceSize: abi.PaddedPieceSize(ssize),
Client: maddr, Client: maddr,
Provider: maddr, Provider: maddr,

View File

@ -11,10 +11,11 @@ import (
"sync" "sync"
ffi "github.com/filecoin-project/filecoin-ffi" ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address" commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/go-sectorbuilder/fs" "github.com/filecoin-project/go-sectorbuilder/fs"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors" "golang.org/x/xerrors"
) )
@ -45,7 +46,7 @@ const (
) )
type sectorState struct { type sectorState struct {
pieces [][]byte pieces []cid.Cid
failed bool failed bool
state int state int
@ -62,7 +63,7 @@ func (sb *SBMock) RateLimit() func() {
} }
} }
func (sb *SBMock) AddPiece(ctx context.Context, size abi.UnpaddedPieceSize, sectorId abi.SectorNumber, r io.Reader, existingPieces []abi.UnpaddedPieceSize) (sectorbuilder.PublicPieceInfo, error) { func (sb *SBMock) AddPiece(ctx context.Context, size abi.UnpaddedPieceSize, sectorId abi.SectorNumber, r io.Reader, existingPieces []abi.UnpaddedPieceSize) (abi.PieceInfo, error) {
sb.lk.Lock() sb.lk.Lock()
ss, ok := sb.sectors[sectorId] ss, ok := sb.sectors[sectorId]
if !ok { if !ok {
@ -77,13 +78,15 @@ func (sb *SBMock) AddPiece(ctx context.Context, size abi.UnpaddedPieceSize, sect
b, err := ioutil.ReadAll(r) b, err := ioutil.ReadAll(r)
if err != nil { if err != nil {
return sectorbuilder.PublicPieceInfo{}, err return abi.PieceInfo{}, err
} }
ss.pieces = append(ss.pieces, b) c := commcid.DataCommitmentV1ToCID(b[:32]) // hax
return sectorbuilder.PublicPieceInfo{
Size: size, ss.pieces = append(ss.pieces, c)
CommP: commD(b), return abi.PieceInfo{
Size: size.Padded(),
PieceCID: c,
}, nil }, nil
} }
@ -99,7 +102,7 @@ func (sb *SBMock) AcquireSectorNumber() (abi.SectorNumber, error) {
return id, nil return id, nil
} }
func (sb *SBMock) Scrub(sectorbuilder.SortedPublicSectorInfo) []*sectorbuilder.Fault { func (sb *SBMock) Scrub([]abi.SectorNumber) []*sectorbuilder.Fault {
sb.lk.Lock() sb.lk.Lock()
mcopy := make(map[abi.SectorNumber]*sectorState) mcopy := make(map[abi.SectorNumber]*sectorState)
for k, v := range sb.sectors { for k, v := range sb.sectors {
@ -123,16 +126,16 @@ func (sb *SBMock) Scrub(sectorbuilder.SortedPublicSectorInfo) []*sectorbuilder.F
return out return out
} }
func (sb *SBMock) GenerateFallbackPoSt(sectorbuilder.SortedPublicSectorInfo, [sectorbuilder.CommLen]byte, []abi.SectorNumber) ([]sectorbuilder.EPostCandidate, []byte, error) { func (sb *SBMock) GenerateFallbackPoSt([]abi.SectorInfo, abi.PoStRandomness, []abi.SectorNumber) ([]ffi.PoStCandidateWithTicket, []abi.PoStProof, error) {
panic("NYI") panic("NYI")
} }
func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticket sectorbuilder.SealTicket, pieces []sectorbuilder.PublicPieceInfo) (sectorbuilder.RawSealPreCommitOutput, error) { func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticket abi.SealRandomness, pieces []abi.PieceInfo) (cid.Cid, cid.Cid, error) {
sb.lk.Lock() sb.lk.Lock()
ss, ok := sb.sectors[sid] ss, ok := sb.sectors[sid]
sb.lk.Unlock() sb.lk.Unlock()
if !ok { if !ok {
return sectorbuilder.RawSealPreCommitOutput{}, xerrors.Errorf("no sector with id %d in sectorbuilder", sid) return cid.Undef, cid.Undef, xerrors.Errorf("no sector with id %d in sectorbuilder", sid)
} }
ss.lk.Lock() ss.lk.Lock()
@ -144,41 +147,50 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticke
var sum abi.UnpaddedPieceSize var sum abi.UnpaddedPieceSize
for _, p := range pieces { for _, p := range pieces {
sum += p.Size sum += p.Size.Unpadded()
} }
if sum != ussize { if sum != ussize {
return sectorbuilder.RawSealPreCommitOutput{}, xerrors.Errorf("aggregated piece sizes don't match up: %d != %d", sum, ussize) return cid.Undef, cid.Undef, xerrors.Errorf("aggregated piece sizes don't match up: %d != %d", sum, ussize)
} }
if ss.state != statePacking { if ss.state != statePacking {
return sectorbuilder.RawSealPreCommitOutput{}, xerrors.Errorf("cannot call pre-seal on sector not in 'packing' state") return cid.Undef, cid.Undef, xerrors.Errorf("cannot call pre-seal on sector not in 'packing' state")
} }
opFinishWait(ctx) opFinishWait(ctx)
ss.state = statePreCommit ss.state = statePreCommit
pis := make([]ffi.PublicPieceInfo, len(ss.pieces)) pis := make([]abi.PieceInfo, len(ss.pieces))
for i, piece := range ss.pieces { for i, piece := range ss.pieces {
pis[i] = ffi.PublicPieceInfo{ pis[i] = abi.PieceInfo{
Size: abi.UnpaddedPieceSize(len(piece)), Size: pieces[i].Size,
CommP: commD(piece), PieceCID: piece,
} }
} }
commd, err := MockVerifier.GenerateDataCommitment(abi.PaddedPieceSize(sb.sectorSize), pis) commd, err := MockVerifier.GenerateDataCommitment(abi.PaddedPieceSize(sb.sectorSize), pis)
if err != nil { if err != nil {
return sectorbuilder.RawSealPreCommitOutput{}, err return cid.Undef, cid.Undef, err
} }
return sectorbuilder.RawSealPreCommitOutput{ cc, _, err := commcid.CIDToCommitment(commd)
CommD: commd, if err != nil {
CommR: commDR(commd[:]), panic(err)
}, nil }
commr := make([]byte, 32)
for i := range cc {
commr[32-(i+1)] = cc[i]
}
commR := commcid.DataCommitmentV1ToCID(commr)
return commd, commR, nil
} }
func (sb *SBMock) SealCommit(ctx context.Context, sid abi.SectorNumber, ticket sectorbuilder.SealTicket, seed sectorbuilder.SealSeed, pieces []sectorbuilder.PublicPieceInfo, precommit sectorbuilder.RawSealPreCommitOutput) ([]byte, error) { func (sb *SBMock) SealCommit(ctx context.Context, sid abi.SectorNumber, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, sealedCid cid.Cid, unsealed cid.Cid) ([]byte, error) {
sb.lk.Lock() sb.lk.Lock()
ss, ok := sb.sectors[sid] ss, ok := sb.sectors[sid]
sb.lk.Unlock() sb.lk.Unlock()
@ -200,8 +212,9 @@ func (sb *SBMock) SealCommit(ctx context.Context, sid abi.SectorNumber, ticket s
var out [32]byte var out [32]byte
for i := range out { for i := range out {
out[i] = precommit.CommD[i] + precommit.CommR[31-i] - ticket.TicketBytes[i]*seed.TicketBytes[i] out[i] = unsealed.Bytes()[i] + sealedCid.Bytes()[31-i] - ticket[i]*seed[i]
} }
return out[:], nil return out[:], nil
} }
@ -255,45 +268,48 @@ func AddOpFinish(ctx context.Context) (context.Context, func()) {
} }
} }
func (sb *SBMock) ComputeElectionPoSt(sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed []byte, winners []sectorbuilder.EPostCandidate) ([]byte, error) { func (sb *SBMock) ComputeElectionPoSt(sectorInfo []abi.SectorInfo, challengeSeed abi.PoStRandomness, winners []abi.PoStCandidate) ([]abi.PoStProof, error) {
panic("implement me") panic("implement me")
} }
func (sb *SBMock) GenerateEPostCandidates(sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed [sectorbuilder.CommLen]byte, faults []abi.SectorNumber) ([]sectorbuilder.EPostCandidate, error) { func (sb *SBMock) GenerateEPostCandidates(sectorInfo []abi.SectorInfo, challengeSeed abi.PoStRandomness, faults []abi.SectorNumber) ([]ffi.PoStCandidateWithTicket, error) {
if len(faults) > 0 { if len(faults) > 0 {
panic("todo") panic("todo")
} }
n := sectorbuilder.ElectionPostChallengeCount(uint64(len(sectorInfo.Values())), uint64(len(faults))) n := sectorbuilder.ElectionPostChallengeCount(uint64(len(sectorInfo)), uint64(len(faults)))
if n > uint64(len(sectorInfo.Values())) { if n > uint64(len(sectorInfo)) {
n = uint64(len(sectorInfo.Values())) n = uint64(len(sectorInfo))
} }
out := make([]sectorbuilder.EPostCandidate, n) out := make([]ffi.PoStCandidateWithTicket, n)
seed := big.NewInt(0).SetBytes(challengeSeed[:]) seed := big.NewInt(0).SetBytes(challengeSeed[:])
start := seed.Mod(seed, big.NewInt(int64(len(sectorInfo.Values())))).Int64() start := seed.Mod(seed, big.NewInt(int64(len(sectorInfo)))).Int64()
for i := range out { for i := range out {
out[i] = sectorbuilder.EPostCandidate{ out[i] = ffi.PoStCandidateWithTicket{
SectorNum: abi.SectorNumber((int(start) + i) % len(sectorInfo.Values())), Candidate: abi.PoStCandidate{
PartialTicket: challengeSeed, SectorID: abi.SectorID{
Ticket: commDR(challengeSeed[:]), Number: abi.SectorNumber((int(start) + i) % len(sectorInfo)),
SectorChallengeIndex: 0, Miner: 1125125, //TODO
},
PartialTicket: abi.PartialTicket(challengeSeed),
},
} }
} }
return out, nil return out, nil
} }
func (sb *SBMock) ReadPieceFromSealedSector(ctx context.Context, sectorID abi.SectorNumber, offset sectorbuilder.UnpaddedByteIndex, size abi.UnpaddedPieceSize, ticket []byte, commD []byte) (io.ReadCloser, error) { func (sb *SBMock) ReadPieceFromSealedSector(ctx context.Context, sectorID abi.SectorNumber, offset sectorbuilder.UnpaddedByteIndex, size abi.UnpaddedPieceSize, ticket abi.SealRandomness, commD cid.Cid) (io.ReadCloser, error) {
if len(sb.sectors[sectorID].pieces) > 1 { if len(sb.sectors[sectorID].pieces) > 1 {
panic("implme") panic("implme")
} }
return ioutil.NopCloser(io.LimitReader(bytes.NewReader(sb.sectors[sectorID].pieces[0][offset:]), int64(size))), nil return ioutil.NopCloser(io.LimitReader(bytes.NewReader(sb.sectors[sectorID].pieces[0].Bytes()[offset:]), int64(size))), nil
} }
func (sb *SBMock) StageFakeData() (abi.SectorNumber, []sectorbuilder.PublicPieceInfo, error) { func (sb *SBMock) StageFakeData() (abi.SectorNumber, []abi.PieceInfo, error) {
usize := abi.PaddedPieceSize(sb.sectorSize).Unpadded() usize := abi.PaddedPieceSize(sb.sectorSize).Unpadded()
sid, err := sb.AcquireSectorNumber() sid, err := sb.AcquireSectorNumber()
if err != nil { if err != nil {
@ -308,7 +324,7 @@ func (sb *SBMock) StageFakeData() (abi.SectorNumber, []sectorbuilder.PublicPiece
return 0, nil, err return 0, nil, err
} }
return sid, []sectorbuilder.PublicPieceInfo{pi}, nil return sid, []abi.PieceInfo{pi}, nil
} }
func (sb *SBMock) FinalizeSector(context.Context, abi.SectorNumber) error { func (sb *SBMock) FinalizeSector(context.Context, abi.SectorNumber) error {
@ -331,21 +347,21 @@ func (sb *SBMock) ReleaseSector(fs.DataType, fs.SectorPath) {
panic("implement me") panic("implement me")
} }
func (m mockVerif) VerifyElectionPost(ctx context.Context, sectorSize abi.SectorSize, sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []sectorbuilder.EPostCandidate, proverID address.Address) (bool, error) { func (m mockVerif) VerifyElectionPost(ctx context.Context, pvi abi.PoStVerifyInfo) (bool, error) {
panic("implement me") panic("implement me")
} }
func (m mockVerif) VerifyFallbackPost(ctx context.Context, sectorSize abi.SectorSize, sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []sectorbuilder.EPostCandidate, proverID address.Address, faults uint64) (bool, error) { func (m mockVerif) VerifyFallbackPost(ctx context.Context, pvi abi.PoStVerifyInfo) (bool, error) {
panic("implement me") panic("implement me")
} }
func (m mockVerif) VerifySeal(sectorSize abi.SectorSize, commR, commD []byte, proverID address.Address, ticket []byte, seed []byte, sectorID abi.SectorNumber, proof []byte) (bool, error) { func (m mockVerif) VerifySeal(svi abi.SealVerifyInfo) (bool, error) {
if len(proof) != 32 { // Real ones are longer, but this should be fine if len(svi.OnChain.Proof) != 32 { // Real ones are longer, but this should be fine
return false, nil return false, nil
} }
for i, b := range proof { for i, b := range svi.OnChain.Proof {
if b != commD[i]+commR[31-i]-ticket[i]*seed[i] { if b != svi.UnsealedCID.Bytes()[i]+svi.OnChain.SealedCID.Bytes()[31-i]-svi.InteractiveRandomness[i]*svi.Randomness[i] {
return false, nil return false, nil
} }
} }
@ -353,14 +369,15 @@ func (m mockVerif) VerifySeal(sectorSize abi.SectorSize, commR, commD []byte, pr
return true, nil return true, nil
} }
func (m mockVerif) GenerateDataCommitment(ssize abi.PaddedPieceSize, pieces []ffi.PublicPieceInfo) ([sectorbuilder.CommLen]byte, error) { func (m mockVerif) GenerateDataCommitment(ssize abi.PaddedPieceSize, pieces []abi.PieceInfo) (cid.Cid, error) {
if len(pieces) != 1 { if len(pieces) != 1 {
panic("todo") panic("todo")
} }
if pieces[0].Size != ssize.Unpadded() { if pieces[0].Size != ssize {
fmt.Println("wrong sizes? ", pieces[0].Size, ssize)
panic("todo") panic("todo")
} }
return pieces[0].CommP, nil return pieces[0].PieceCID, nil
} }
var MockVerifier = mockVerif{} var MockVerifier = mockVerif{}

View File

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/specs-actors/actors/abi"
) )
func TestOpFinish(t *testing.T) { func TestOpFinish(t *testing.T) {
@ -20,7 +20,7 @@ func TestOpFinish(t *testing.T) {
finished := make(chan struct{}) finished := make(chan struct{})
go func() { go func() {
_, err := sb.SealPreCommit(ctx, sid, sectorbuilder.SealTicket{}, pieces) _, _, err := sb.SealPreCommit(ctx, sid, abi.SealRandomness{}, pieces)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return

View File

@ -1,14 +1,9 @@
package sbmock package sbmock
import ( import (
"bytes"
"crypto/rand" "crypto/rand"
"io" "io"
"io/ioutil" "io/ioutil"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/go-sectorbuilder"
) )
func randB(n uint64) []byte { func randB(n uint64) []byte {
@ -26,11 +21,3 @@ func commDR(in []byte) (out [32]byte) {
return out return out
} }
func commD(b []byte) [32]byte {
c, err := sectorbuilder.GeneratePieceCommitment(bytes.NewReader(b), abi.UnpaddedPieceSize(len(b)))
if err != nil {
panic(err)
}
return c
}

View File

@ -13,282 +13,6 @@ import (
var _ = xerrors.Errorf var _ = xerrors.Errorf
func (t *SealTicket) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{162}); err != nil {
return err
}
// t.BlockHeight (abi.ChainEpoch) (int64)
if len("BlockHeight") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"BlockHeight\" was too long")
}
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
}
if t.BlockHeight >= 0 {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.BlockHeight))); err != nil {
return err
}
} else {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.BlockHeight)-1)); err != nil {
return err
}
}
// t.TicketBytes ([]uint8) (slice)
if len("TicketBytes") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"TicketBytes\" was too long")
}
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 len(t.TicketBytes) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.TicketBytes was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.TicketBytes)))); err != nil {
return err
}
if _, err := w.Write(t.TicketBytes); err != nil {
return err
}
return nil
}
func (t *SealTicket) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra > cbg.MaxLength {
return fmt.Errorf("SealTicket: map struct too large (%d)", extra)
}
var name string
n := extra
for i := uint64(0); i < n; i++ {
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
switch name {
// t.BlockHeight (abi.ChainEpoch) (int64)
case "BlockHeight":
{
maj, extra, err := cbg.CborReadHeader(br)
var extraI int64
if err != nil {
return err
}
switch maj {
case cbg.MajUnsignedInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 positive overflow")
}
case cbg.MajNegativeInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 negative oveflow")
}
extraI = -1 - extraI
default:
return fmt.Errorf("wrong type for int64 field: %d", maj)
}
t.BlockHeight = abi.ChainEpoch(extraI)
}
// t.TicketBytes ([]uint8) (slice)
case "TicketBytes":
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.TicketBytes: byte array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.TicketBytes = make([]byte, extra)
if _, err := io.ReadFull(br, t.TicketBytes); err != nil {
return err
}
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
}
return nil
}
func (t *SealSeed) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{162}); err != nil {
return err
}
// t.BlockHeight (abi.ChainEpoch) (int64)
if len("BlockHeight") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"BlockHeight\" was too long")
}
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
}
if t.BlockHeight >= 0 {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.BlockHeight))); err != nil {
return err
}
} else {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.BlockHeight)-1)); err != nil {
return err
}
}
// t.TicketBytes ([]uint8) (slice)
if len("TicketBytes") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"TicketBytes\" was too long")
}
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 len(t.TicketBytes) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.TicketBytes was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.TicketBytes)))); err != nil {
return err
}
if _, err := w.Write(t.TicketBytes); err != nil {
return err
}
return nil
}
func (t *SealSeed) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra > cbg.MaxLength {
return fmt.Errorf("SealSeed: map struct too large (%d)", extra)
}
var name string
n := extra
for i := uint64(0); i < n; i++ {
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
switch name {
// t.BlockHeight (abi.ChainEpoch) (int64)
case "BlockHeight":
{
maj, extra, err := cbg.CborReadHeader(br)
var extraI int64
if err != nil {
return err
}
switch maj {
case cbg.MajUnsignedInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 positive overflow")
}
case cbg.MajNegativeInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 negative oveflow")
}
extraI = -1 - extraI
default:
return fmt.Errorf("wrong type for int64 field: %d", maj)
}
t.BlockHeight = abi.ChainEpoch(extraI)
}
// t.TicketBytes ([]uint8) (slice)
case "TicketBytes":
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.TicketBytes: byte array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.TicketBytes = make([]byte, extra)
if _, err := io.ReadFull(br, t.TicketBytes); err != nil {
return err
}
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
}
return nil
}
func (t *Piece) MarshalCBOR(w io.Writer) error { func (t *Piece) MarshalCBOR(w io.Writer) error {
if t == nil { if t == nil {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
@ -336,7 +60,7 @@ func (t *Piece) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.CommP ([]uint8) (slice) // t.CommP (cid.Cid) (struct)
if len("CommP") > cbg.MaxLength { if len("CommP") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"CommP\" was too long") return xerrors.Errorf("Value in field \"CommP\" was too long")
} }
@ -348,16 +72,10 @@ func (t *Piece) MarshalCBOR(w io.Writer) error {
return err return err
} }
if len(t.CommP) > cbg.ByteArrayMaxLen { if err := cbg.WriteCid(w, t.CommP); err != nil {
return xerrors.Errorf("Byte array in field t.CommP was too long") return xerrors.Errorf("failed to write cid field t.CommP: %w", err)
} }
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommP)))); err != nil {
return err
}
if _, err := w.Write(t.CommP); err != nil {
return err
}
return nil return nil
} }
@ -433,23 +151,18 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error {
t.Size = abi.UnpaddedPieceSize(extra) t.Size = abi.UnpaddedPieceSize(extra)
} }
// t.CommP ([]uint8) (slice) // t.CommP (cid.Cid) (struct)
case "CommP": case "CommP":
maj, extra, err = cbg.CborReadHeader(br) {
if err != nil {
return err c, err := cbg.ReadCid(br)
} if err != nil {
return xerrors.Errorf("failed to read cid field t.CommP: %w", err)
}
t.CommP = c
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.CommP: byte array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.CommP = make([]byte, extra)
if _, err := io.ReadFull(br, t.CommP); err != nil {
return err
} }
default: default:
@ -464,7 +177,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
return err return err
} }
if _, err := w.Write([]byte{174}); err != nil { if _, err := w.Write([]byte{175}); err != nil {
return err return err
} }
@ -516,6 +229,28 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.SectorType (abi.RegisteredProof) (int64)
if len("SectorType") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"SectorType\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("SectorType")))); err != nil {
return err
}
if _, err := w.Write([]byte("SectorType")); err != nil {
return err
}
if t.SectorType >= 0 {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorType))); err != nil {
return err
}
} else {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.SectorType)-1)); err != nil {
return err
}
}
// t.Pieces ([]sealing.Piece) (slice) // t.Pieces ([]sealing.Piece) (slice)
if len("Pieces") > cbg.MaxLength { if len("Pieces") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Pieces\" was too long") return xerrors.Errorf("Value in field \"Pieces\" was too long")
@ -541,7 +276,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
} }
} }
// t.CommD ([]uint8) (slice) // t.CommD (cid.Cid) (struct)
if len("CommD") > cbg.MaxLength { if len("CommD") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"CommD\" was too long") return xerrors.Errorf("Value in field \"CommD\" was too long")
} }
@ -553,18 +288,17 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err return err
} }
if len(t.CommD) > cbg.ByteArrayMaxLen { if t.CommD == nil {
return xerrors.Errorf("Byte array in field t.CommD was too long") if _, err := w.Write(cbg.CborNull); err != nil {
return err
}
} else {
if err := cbg.WriteCid(w, *t.CommD); err != nil {
return xerrors.Errorf("failed to write cid field t.CommD: %w", err)
}
} }
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommD)))); err != nil { // t.CommR (cid.Cid) (struct)
return err
}
if _, err := w.Write(t.CommD); err != nil {
return err
}
// t.CommR ([]uint8) (slice)
if len("CommR") > cbg.MaxLength { if len("CommR") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"CommR\" was too long") return xerrors.Errorf("Value in field \"CommR\" was too long")
} }
@ -576,15 +310,14 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err return err
} }
if len(t.CommR) > cbg.ByteArrayMaxLen { if t.CommR == nil {
return xerrors.Errorf("Byte array in field t.CommR was too long") if _, err := w.Write(cbg.CborNull); err != nil {
} return err
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommR)))); err != nil { } else {
return err if err := cbg.WriteCid(w, *t.CommR); err != nil {
} return xerrors.Errorf("failed to write cid field t.CommR: %w", err)
if _, err := w.Write(t.CommR); err != nil { }
return err
} }
// t.Proof ([]uint8) (slice) // t.Proof ([]uint8) (slice)
@ -610,7 +343,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.Ticket (sealing.SealTicket) (struct) // t.Ticket (api.SealTicket) (struct)
if len("Ticket") > cbg.MaxLength { if len("Ticket") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Ticket\" was too long") return xerrors.Errorf("Value in field \"Ticket\" was too long")
} }
@ -648,7 +381,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
} }
} }
// t.Seed (sealing.SealSeed) (struct) // t.Seed (api.SealSeed) (struct)
if len("Seed") > cbg.MaxLength { if len("Seed") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Seed\" was too long") return xerrors.Errorf("Value in field \"Seed\" was too long")
} }
@ -833,6 +566,32 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
t.Nonce = uint64(extra) t.Nonce = uint64(extra)
} }
// t.SectorType (abi.RegisteredProof) (int64)
case "SectorType":
{
maj, extra, err := cbg.CborReadHeader(br)
var extraI int64
if err != nil {
return err
}
switch maj {
case cbg.MajUnsignedInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 positive overflow")
}
case cbg.MajNegativeInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 negative oveflow")
}
extraI = -1 - extraI
default:
return fmt.Errorf("wrong type for int64 field: %d", maj)
}
t.SectorType = abi.RegisteredProof(extraI)
}
// t.Pieces ([]sealing.Piece) (slice) // t.Pieces ([]sealing.Piece) (slice)
case "Pieces": case "Pieces":
@ -861,41 +620,55 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
t.Pieces[i] = v t.Pieces[i] = v
} }
// t.CommD ([]uint8) (slice) // t.CommD (cid.Cid) (struct)
case "CommD": case "CommD":
maj, extra, err = cbg.CborReadHeader(br) {
if err != nil {
return err 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.CommD: %w", err)
}
t.CommD = &c
}
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.CommD: byte array too large (%d)", extra)
} }
if maj != cbg.MajByteString { // t.CommR (cid.Cid) (struct)
return fmt.Errorf("expected byte array")
}
t.CommD = make([]byte, extra)
if _, err := io.ReadFull(br, t.CommD); err != nil {
return err
}
// t.CommR ([]uint8) (slice)
case "CommR": case "CommR":
maj, extra, err = cbg.CborReadHeader(br) {
if err != nil {
return err 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.CommR: %w", err)
}
t.CommR = &c
}
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.CommR: byte array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.CommR = make([]byte, extra)
if _, err := io.ReadFull(br, t.CommR); err != nil {
return err
} }
// t.Proof ([]uint8) (slice) // t.Proof ([]uint8) (slice)
case "Proof": case "Proof":
@ -915,7 +688,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.Proof); err != nil { if _, err := io.ReadFull(br, t.Proof); err != nil {
return err return err
} }
// t.Ticket (sealing.SealTicket) (struct) // t.Ticket (api.SealTicket) (struct)
case "Ticket": case "Ticket":
{ {
@ -950,7 +723,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
} }
} }
// t.Seed (sealing.SealSeed) (struct) // t.Seed (api.SealSeed) (struct)
case "Seed": case "Seed":
{ {

View File

@ -5,12 +5,10 @@ import (
"context" "context"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/multiformats/go-multihash"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/market"
@ -45,7 +43,7 @@ func checkPieces(ctx context.Context, si SectorInfo, api sealingApi) error {
for i, piece := range si.Pieces { for i, piece := range si.Pieces {
if piece.DealID == nil { if piece.DealID == nil {
exp := zerocomm.ForSize(piece.Size) exp := zerocomm.ForSize(piece.Size)
if string(piece.CommP) != string(exp[:]) { if piece.CommP != exp {
return &ErrInvalidPiece{xerrors.Errorf("deal %d piece %d had non-zero CommP %+v", piece.DealID, i, piece.CommP)} return &ErrInvalidPiece{xerrors.Errorf("deal %d piece %d had non-zero CommP %+v", piece.DealID, i, piece.CommP)}
} }
continue continue
@ -55,13 +53,8 @@ func checkPieces(ctx context.Context, si SectorInfo, api sealingApi) error {
return &ErrApi{xerrors.Errorf("getting deal %d for piece %d: %w", piece.DealID, i, err)} return &ErrApi{xerrors.Errorf("getting deal %d for piece %d: %w", piece.DealID, i, err)}
} }
h, err := multihash.Decode(deal.Proposal.PieceCID.Hash()) if deal.Proposal.PieceCID != piece.CommP {
if err != nil { return &ErrInvalidDeals{xerrors.Errorf("piece %d (or %d) of sector %d refers deal %d with wrong CommP: %x != %x", i, len(si.Pieces), si.SectorID, piece.DealID, piece.CommP, deal.Proposal.PieceCID)}
return &ErrInvalidDeals{xerrors.Errorf("decoding piece CID: %w", err)}
}
if string(h.Digest) != string(piece.CommP) {
return &ErrInvalidDeals{xerrors.Errorf("piece %d (or %d) of sector %d refers deal %d with wrong CommP: %x != %x", i, len(si.Pieces), si.SectorID, piece.DealID, piece.CommP, h.Digest)}
} }
if piece.Size != deal.Proposal.PieceSize.Unpadded() { if piece.Size != deal.Proposal.PieceSize.Unpadded() {
@ -84,14 +77,9 @@ func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api se
return &ErrApi{xerrors.Errorf("getting chain head: %w", err)} return &ErrApi{xerrors.Errorf("getting chain head: %w", err)}
} }
ssize, err := api.StateMinerSectorSize(ctx, maddr, head.Key())
if err != nil {
return &ErrApi{err}
}
ccparams, err := actors.SerializeParams(&market.ComputeDataCommitmentParams{ ccparams, err := actors.SerializeParams(&market.ComputeDataCommitmentParams{
DealIDs: si.deals(), DealIDs: si.deals(),
SectorSize: ssize, SectorType: si.SectorType,
}) })
if err != nil { if err != nil {
return xerrors.Errorf("computing params for ComputeDataCommitment: %w", err) return xerrors.Errorf("computing params for ComputeDataCommitment: %w", err)
@ -118,17 +106,13 @@ func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api se
if err := c.UnmarshalCBOR(bytes.NewReader(r.Return)); err != nil { if err := c.UnmarshalCBOR(bytes.NewReader(r.Return)); err != nil {
return err return err
} }
cd, err := commcid.CIDToDataCommitmentV1(cid.Cid(c))
if err != nil {
return err
}
if string(cd) != string(si.CommD) { if cid.Cid(c) != *si.CommD {
return &ErrBadCommD{xerrors.Errorf("on chain CommD differs from sector: %x != %x", r.Return, si.CommD)} return &ErrBadCommD{xerrors.Errorf("on chain CommD differs from sector: %x != %x", r.Return, si.CommD)}
} }
if int64(head.Height())-int64(si.Ticket.BlockHeight+build.SealRandomnessLookback) > build.SealRandomnessLookbackLimit { if int64(head.Height())-int64(si.Ticket.Epoch+build.SealRandomnessLookback) > build.SealRandomnessLookbackLimit {
return &ErrExpiredTicket{xerrors.Errorf("ticket expired: seal height: %d, head: %d", si.Ticket.BlockHeight+build.SealRandomnessLookback, head.Height())} return &ErrExpiredTicket{xerrors.Errorf("ticket expired: seal height: %d, head: %d", si.Ticket.Epoch+build.SealRandomnessLookback, head.Height())}
} }
return nil return nil

View File

@ -46,13 +46,15 @@ func (evt SectorForceState) applyGlobal(state *SectorInfo) bool {
// Normal path // Normal path
type SectorStart struct { type SectorStart struct {
id abi.SectorNumber id abi.SectorNumber
pieces []Piece sectorType abi.RegisteredProof
pieces []Piece
} }
func (evt SectorStart) apply(state *SectorInfo) { func (evt SectorStart) apply(state *SectorInfo) {
state.SectorID = evt.id state.SectorID = evt.id
state.Pieces = evt.pieces state.Pieces = evt.pieces
state.SectorType = evt.sectorType
} }
type SectorPacked struct{ pieces []Piece } type SectorPacked struct{ pieces []Piece }
@ -66,14 +68,16 @@ type SectorPackingFailed struct{ error }
func (evt SectorPackingFailed) apply(*SectorInfo) {} func (evt SectorPackingFailed) apply(*SectorInfo) {}
type SectorSealed struct { type SectorSealed struct {
commR []byte commR cid.Cid
commD []byte commD cid.Cid
ticket SealTicket ticket api.SealTicket
} }
func (evt SectorSealed) apply(state *SectorInfo) { func (evt SectorSealed) apply(state *SectorInfo) {
state.CommD = evt.commD commd := evt.commD
state.CommR = evt.commR state.CommD = &commd
commr := evt.commR
state.CommR = &commr
state.Ticket = evt.ticket state.Ticket = evt.ticket
} }
@ -94,7 +98,7 @@ func (evt SectorPreCommitted) apply(state *SectorInfo) {
} }
type SectorSeedReady struct { type SectorSeedReady struct {
seed SealSeed seed api.SealSeed
} }
func (evt SectorSeedReady) apply(state *SectorInfo) { func (evt SectorSeedReady) apply(state *SectorInfo) {

View File

@ -75,12 +75,12 @@ func TestSeedRevert(t *testing.T) {
m.planSingle(SectorSeedReady{}) m.planSingle(SectorSeedReady{})
require.Equal(m.t, m.state.State, api.Committing) require.Equal(m.t, m.state.State, api.Committing)
_, err := m.s.plan([]statemachine.Event{{SectorSeedReady{seed: SealSeed{BlockHeight: 5}}}, {SectorCommitted{}}}, m.state) _, err := m.s.plan([]statemachine.Event{{SectorSeedReady{seed: api.SealSeed{Epoch: 5}}}, {SectorCommitted{}}}, m.state)
require.NoError(t, err) require.NoError(t, err)
require.Equal(m.t, m.state.State, api.Committing) require.Equal(m.t, m.state.State, api.Committing)
// not changing the seed this time // not changing the seed this time
_, err = m.s.plan([]statemachine.Event{{SectorSeedReady{seed: SealSeed{BlockHeight: 5}}}, {SectorCommitted{}}}, m.state) _, err = m.s.plan([]statemachine.Event{{SectorSeedReady{seed: api.SealSeed{Epoch: 5}}}, {SectorCommitted{}}}, m.state)
require.Equal(m.t, m.state.State, api.CommitWait) require.Equal(m.t, m.state.State, api.CommitWait)
m.planSingle(SectorProving{}) m.planSingle(SectorProving{})

View File

@ -7,19 +7,13 @@ import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/lib/nullreader"
) )
type nullReader struct{}
func (nullReader) Read(out []byte) (int, error) {
for i := range out {
out[i] = 0
}
return len(out), nil
}
func (m *Sealing) pledgeReader(size abi.UnpaddedPieceSize) io.Reader { func (m *Sealing) pledgeReader(size abi.UnpaddedPieceSize) io.Reader {
return io.LimitReader(&nullReader{}, int64(size)) return io.LimitReader(&nullreader.Reader{}, int64(size))
} }
func (m *Sealing) pledgeSector(ctx context.Context, sectorID abi.SectorNumber, existingPieceSizes []abi.UnpaddedPieceSize, sizes ...abi.UnpaddedPieceSize) ([]Piece, error) { func (m *Sealing) pledgeSector(ctx context.Context, sectorID abi.SectorNumber, existingPieceSizes []abi.UnpaddedPieceSize, sizes ...abi.UnpaddedPieceSize) ([]Piece, error) {
@ -39,8 +33,8 @@ func (m *Sealing) pledgeSector(ctx context.Context, sectorID abi.SectorNumber, e
existingPieceSizes = append(existingPieceSizes, size) existingPieceSizes = append(existingPieceSizes, size)
out[i] = Piece{ out[i] = Piece{
Size: ppi.Size, Size: ppi.Size.Unpadded(),
CommP: ppi.CommP[:], CommP: ppi.PieceCID,
} }
} }
@ -55,6 +49,12 @@ func (m *Sealing) PledgeSector() error {
size := abi.PaddedPieceSize(m.sb.SectorSize()).Unpadded() size := abi.PaddedPieceSize(m.sb.SectorSize()).Unpadded()
rt, _, err := api.ProofTypeFromSectorSize(m.sb.SectorSize())
if err != nil {
log.Error(err)
return
}
sid, err := m.sb.AcquireSectorNumber() sid, err := m.sb.AcquireSectorNumber()
if err != nil { if err != nil {
log.Errorf("%+v", err) log.Errorf("%+v", err)
@ -67,7 +67,7 @@ func (m *Sealing) PledgeSector() error {
return return
} }
if err := m.newSector(sid, pieces); err != nil { if err := m.newSector(sid, rt, pieces); err != nil {
log.Errorf("%+v", err) log.Errorf("%+v", err)
return return
} }

View File

@ -28,7 +28,7 @@ const SectorStorePrefix = "/sectors"
var log = logging.Logger("sectors") var log = logging.Logger("sectors")
type TicketFn func(context.Context) (*sectorbuilder.SealTicket, error) type TicketFn func(context.Context) (*api.SealTicket, error)
type sealingApi interface { // TODO: trim down type sealingApi interface { // TODO: trim down
// Call a read only method on actors (no interaction with the chain required) // Call a read only method on actors (no interaction with the chain required)
@ -121,20 +121,26 @@ func (m *Sealing) SealPiece(ctx context.Context, size abi.UnpaddedPieceSize, r i
return xerrors.Errorf("adding piece to sector: %w", err) return xerrors.Errorf("adding piece to sector: %w", err)
} }
return m.newSector(sectorID, []Piece{ _, rt, err := api.ProofTypeFromSectorSize(m.sb.SectorSize())
if err != nil {
return xerrors.Errorf("bad sector size: %w", err)
}
return m.newSector(sectorID, rt, []Piece{
{ {
DealID: &dealID, DealID: &dealID,
Size: ppi.Size, Size: ppi.Size.Unpadded(),
CommP: ppi.CommP[:], CommP: ppi.PieceCID,
}, },
}) })
} }
func (m *Sealing) newSector(sid abi.SectorNumber, pieces []Piece) error { func (m *Sealing) newSector(sid abi.SectorNumber, rt abi.RegisteredProof, pieces []Piece) error {
log.Infof("Start sealing %d", sid) log.Infof("Start sealing %d", sid)
return m.sectors.Send(uint64(sid), SectorStart{ return m.sectors.Send(uint64(sid), SectorStart{
id: sid, id: sid,
pieces: pieces, pieces: pieces,
sectorType: rt,
}) })
} }

View File

@ -2,15 +2,16 @@ package sealing
import ( import (
"context" "context"
"github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/crypto"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-sectorbuilder/fs" "github.com/filecoin-project/go-sectorbuilder/fs"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/miner"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
@ -69,18 +70,15 @@ func (m *Sealing) handleUnsealed(ctx statemachine.Context, sector SectorInfo) er
return ctx.Send(SectorSealFailed{xerrors.Errorf("getting ticket failed: %w", err)}) return ctx.Send(SectorSealFailed{xerrors.Errorf("getting ticket failed: %w", err)})
} }
rspco, err := m.sb.SealPreCommit(ctx.Context(), sector.SectorID, *ticket, sector.pieceInfos()) sealed, unsealed, err := m.sb.SealPreCommit(ctx.Context(), sector.SectorID, ticket.Value, sector.pieceInfos())
if err != nil { if err != nil {
return ctx.Send(SectorSealFailed{xerrors.Errorf("seal pre commit failed: %w", err)}) return ctx.Send(SectorSealFailed{xerrors.Errorf("seal pre commit failed: %w", err)})
} }
return ctx.Send(SectorSealed{ return ctx.Send(SectorSealed{
commD: rspco.CommD[:], commD: unsealed,
commR: rspco.CommR[:], commR: sealed,
ticket: SealTicket{ ticket: *ticket,
BlockHeight: abi.ChainEpoch(ticket.BlockHeight),
TicketBytes: ticket.TicketBytes[:],
},
}) })
} }
@ -102,10 +100,10 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
params := &miner.SectorPreCommitInfo{ params := &miner.SectorPreCommitInfo{
Expiration: 10000000, // TODO: implement Expiration: 10000000, // TODO: implement
SectorNumber: sector.SectorID, SectorNumber: sector.SectorID,
RegisteredProof: abi.RegisteredProof_StackedDRG32GiBSeal, RegisteredProof: sector.SectorType,
SealedCID: commcid.ReplicaCommitmentV1ToCID(sector.CommR), SealedCID: *sector.CommR,
SealRandEpoch: sector.Ticket.BlockHeight, SealRandEpoch: sector.Ticket.Epoch,
DealIDs: sector.deals(), DealIDs: sector.deals(),
} }
enc, aerr := actors.SerializeParams(params) enc, aerr := actors.SerializeParams(params)
@ -159,9 +157,9 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er
return err return err
} }
ctx.Send(SectorSeedReady{seed: SealSeed{ ctx.Send(SectorSeedReady{seed: api.SealSeed{
BlockHeight: randHeight, Epoch: randHeight,
TicketBytes: rand, Value: abi.InteractiveSealRandomness(rand),
}}) }})
return nil return nil
@ -180,9 +178,9 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er
func (m *Sealing) handleCommitting(ctx statemachine.Context, sector SectorInfo) error { func (m *Sealing) handleCommitting(ctx statemachine.Context, sector SectorInfo) error {
log.Info("scheduling seal proof computation...") log.Info("scheduling seal proof computation...")
log.Infof("KOMIT %d %x(%d); %x(%d); %v; r:%x; d:%x", sector.SectorID, sector.Ticket.TicketBytes, sector.Ticket.BlockHeight, sector.Seed.TicketBytes, sector.Seed.BlockHeight, sector.pieceInfos(), sector.CommR, sector.CommD) log.Infof("KOMIT %d %x(%d); %x(%d); %v; r:%x; d:%x", sector.SectorID, sector.Ticket.Value, sector.Ticket.Epoch, sector.Seed.Value, sector.Seed.Epoch, sector.pieceInfos(), sector.CommR, sector.CommD)
proof, err := m.sb.SealCommit(ctx.Context(), sector.SectorID, sector.Ticket.SB(), sector.Seed.SB(), sector.pieceInfos(), sector.rspco()) proof, err := m.sb.SealCommit(ctx.Context(), sector.SectorID, sector.Ticket.Value, sector.Seed.Value, sector.pieceInfos(), *sector.CommR, *sector.CommD)
if err != nil { if err != nil {
return ctx.Send(SectorComputeProofFailed{xerrors.Errorf("computing seal proof failed: %w", err)}) return ctx.Send(SectorComputeProofFailed{xerrors.Errorf("computing seal proof failed: %w", err)})
} }
@ -234,7 +232,7 @@ func (m *Sealing) handleCommitWait(ctx statemachine.Context, sector SectorInfo)
} }
if mw.Receipt.ExitCode != 0 { if mw.Receipt.ExitCode != 0 {
return ctx.Send(SectorCommitFailed{xerrors.Errorf("submitting sector proof failed (exit=%d, msg=%s) (t:%x; s:%x(%d); p:%x)", mw.Receipt.ExitCode, sector.CommitMessage, sector.Ticket.TicketBytes, sector.Seed.TicketBytes, sector.Seed.BlockHeight, sector.Proof)}) return ctx.Send(SectorCommitFailed{xerrors.Errorf("submitting sector proof failed (exit=%d, msg=%s) (t:%x; s:%x(%d); p:%x)", mw.Receipt.ExitCode, sector.CommitMessage, sector.Ticket.Value, sector.Seed.Value, sector.Seed.Epoch, sector.Proof)})
} }
return ctx.Send(SectorProving{}) return ctx.Send(SectorProving{})

View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"time" "time"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/specs-actors/actors/util/adt"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -96,13 +95,8 @@ func (m *Sealing) handlePreCommitFailed(ctx statemachine.Context, sector SectorI
return nil // TODO: SeedWait needs this currently return nil // TODO: SeedWait needs this currently
} }
pciR, err := commcid.CIDToReplicaCommitmentV1(pci.Info.SealedCID) if pci.Info.SealedCID != *sector.CommR {
if err != nil { log.Warn("sector %d is precommitted on chain, with different CommR: %x != %x", sector.SectorID, pci.Info.SealedCID, sector.CommR)
return err
}
if string(pciR) != string(sector.CommR) {
log.Warn("sector %d is precommitted on chain, with different CommR: %x != %x", sector.SectorID, pciR, sector.CommR)
return nil // TODO: remove when the actor allows re-precommit return nil // TODO: remove when the actor allows re-precommit
} }

View File

@ -1,49 +1,16 @@
package sealing package sealing
import ( import (
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
) )
type SealTicket struct {
BlockHeight abi.ChainEpoch
TicketBytes []byte
}
func (t *SealTicket) SB() sectorbuilder.SealTicket {
out := sectorbuilder.SealTicket{BlockHeight: uint64(t.BlockHeight)}
copy(out.TicketBytes[:], t.TicketBytes)
return out
}
type SealSeed struct {
BlockHeight abi.ChainEpoch
TicketBytes []byte
}
func (t *SealSeed) SB() sectorbuilder.SealSeed {
out := sectorbuilder.SealSeed{BlockHeight: uint64(t.BlockHeight)}
copy(out.TicketBytes[:], t.TicketBytes)
return out
}
func (t *SealSeed) Equals(o *SealSeed) bool {
return string(t.TicketBytes) == string(o.TicketBytes) && t.BlockHeight == o.BlockHeight
}
type Piece struct { type Piece struct {
DealID *abi.DealID DealID *abi.DealID
Size abi.UnpaddedPieceSize Size abi.UnpaddedPieceSize
CommP []byte CommP cid.Cid
}
func (p *Piece) ppi() (out sectorbuilder.PublicPieceInfo) {
out.Size = p.Size
copy(out.CommP[:], p.CommP)
return out
} }
type Log struct { type Log struct {
@ -61,20 +28,22 @@ type SectorInfo struct {
SectorID abi.SectorNumber SectorID abi.SectorNumber
Nonce uint64 // TODO: remove Nonce uint64 // TODO: remove
SectorType abi.RegisteredProof
// Packing // Packing
Pieces []Piece Pieces []Piece
// PreCommit // PreCommit
CommD []byte CommD *cid.Cid
CommR []byte CommR *cid.Cid
Proof []byte Proof []byte
Ticket SealTicket Ticket api.SealTicket
PreCommitMessage *cid.Cid PreCommitMessage *cid.Cid
// WaitSeed // WaitSeed
Seed SealSeed Seed api.SealSeed
// Committing // Committing
CommitMessage *cid.Cid CommitMessage *cid.Cid
@ -88,10 +57,13 @@ type SectorInfo struct {
Log []Log Log []Log
} }
func (t *SectorInfo) pieceInfos() []sectorbuilder.PublicPieceInfo { func (t *SectorInfo) pieceInfos() []abi.PieceInfo {
out := make([]sectorbuilder.PublicPieceInfo, len(t.Pieces)) out := make([]abi.PieceInfo, len(t.Pieces))
for i, piece := range t.Pieces { for i, piece := range t.Pieces {
out[i] = piece.ppi() out[i] = abi.PieceInfo{
Size: piece.Size.Padded(),
PieceCID: piece.CommP,
}
} }
return out return out
} }
@ -114,12 +86,3 @@ func (t *SectorInfo) existingPieces() []abi.UnpaddedPieceSize {
} }
return out return out
} }
func (t *SectorInfo) rspco() sectorbuilder.RawSealPreCommitOutput {
var out sectorbuilder.RawSealPreCommitOutput
copy(out.CommD[:], t.CommD)
copy(out.CommR[:], t.CommR)
return out
}

View File

@ -4,15 +4,19 @@ import (
"bytes" "bytes"
"testing" "testing"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
"gotest.tools/assert" "gotest.tools/assert"
"github.com/filecoin-project/go-cbor-util" cborutil "github.com/filecoin-project/go-cbor-util"
) )
func TestSectorInfoSelialization(t *testing.T) { func TestSectorInfoSelialization(t *testing.T) {
d := abi.DealID(1234) d := abi.DealID(1234)
dummyCid := builtin.AccountActorCodeID
si := &SectorInfo{ si := &SectorInfo{
State: 123, State: 123,
SectorID: 234, SectorID: 234,
@ -20,17 +24,17 @@ func TestSectorInfoSelialization(t *testing.T) {
Pieces: []Piece{{ Pieces: []Piece{{
DealID: &d, DealID: &d,
Size: 5, Size: 5,
CommP: []byte{3}, CommP: dummyCid,
}}, }},
CommD: []byte{32, 4}, CommD: &dummyCid,
CommR: nil, CommR: nil,
Proof: nil, Proof: nil,
Ticket: SealTicket{ Ticket: api.SealTicket{
BlockHeight: 345, Epoch: 345,
TicketBytes: []byte{87, 78, 7, 87}, Value: []byte{87, 78, 7, 87},
}, },
PreCommitMessage: nil, PreCommitMessage: nil,
Seed: SealSeed{}, Seed: api.SealSeed{},
CommitMessage: nil, CommitMessage: nil,
FaultReportMsg: nil, FaultReportMsg: nil,
LastErr: "hi", LastErr: "hi",

View File

@ -5,8 +5,6 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/lotus/storage/sbmock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -45,19 +43,3 @@ func TestFillersFromRem(t *testing.T) {
testFill(t, ub, []abi.UnpaddedPieceSize{ub1, ub4}) testFill(t, ub, []abi.UnpaddedPieceSize{ub1, ub4})
} }
} }
func TestFastPledge(t *testing.T) {
sz := abi.PaddedPieceSize(16 << 20)
s := Sealing{sb: sbmock.NewMockSectorBuilder(0, abi.SectorSize(sz))}
if _, err := s.fastPledgeCommitment(sz.Unpadded(), 5); err != nil {
t.Fatalf("%+v", err)
}
sz = abi.PaddedPieceSize(1024)
s = Sealing{sb: sbmock.NewMockSectorBuilder(0, abi.SectorSize(sz))}
if _, err := s.fastPledgeCommitment(sz.Unpadded(), 64); err != nil {
t.Fatalf("%+v", err)
}
}