fixing some tests

This commit is contained in:
whyrusleeping 2019-11-28 21:38:18 -06:00
parent cb7d15e67e
commit ce89ddbd6a
8 changed files with 135 additions and 33 deletions

View File

@ -818,11 +818,27 @@ func (t *SubmitFallbackPoStParams) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{129}); err != nil {
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Proof (types.EPostProof) (struct)
// t.t.Proof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil {
return err
}
if _, err := w.Write(t.Proof); err != nil {
return err
}
// t.t.Candidates ([]types.EPostTicket) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Candidates)))); err != nil {
return err
}
for _, v := range t.Candidates {
if err := v.MarshalCBOR(w); err != nil {
return err
}
}
return nil
}
@ -837,15 +853,53 @@ func (t *SubmitFallbackPoStParams) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 1 {
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Proof (types.EPostProof) (struct)
{
// t.t.Proof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Proof: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Proof = make([]byte, extra)
if _, err := io.ReadFull(br, t.Proof); err != nil {
return err
}
// t.t.Candidates ([]types.EPostTicket) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Candidates: array too large (%d)", extra)
}
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Candidates = make([]types.EPostTicket, extra)
}
for i := 0; i < int(extra); i++ {
var v types.EPostTicket
if err := v.UnmarshalCBOR(br); err != nil {
return err
}
t.Candidates[i] = v
}
return nil
}

View File

@ -10,7 +10,7 @@ import (
"testing"
"time"
"github.com/filecoin-project/filecoin-ffi"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-leb128"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -285,7 +285,7 @@ func TestVectorActorAddress(t *testing.T) {
func TestRandomBLSAddress(t *testing.T) {
assert := assert.New(t)
pk := bls.PrivateKeyPublicKey(bls.PrivateKeyGenerate())
pk := ffi.PrivateKeyPublicKey(ffi.PrivateKeyGenerate())
addr, err := NewBLSAddress(pk[:])
assert.NoError(err)
@ -410,8 +410,8 @@ func TestInvalidByteAddresses(t *testing.T) {
{append([]byte{2}, make([]byte, PayloadHashLength+1)...), ErrInvalidPayload},
// BLS Protocol
{append([]byte{3}, make([]byte, bls.PublicKeyBytes-1)...), ErrInvalidPayload},
{append([]byte{3}, make([]byte, bls.PrivateKeyBytes+1)...), ErrInvalidPayload},
{append([]byte{3}, make([]byte, ffi.PublicKeyBytes-1)...), ErrInvalidPayload},
{append([]byte{3}, make([]byte, ffi.PrivateKeyBytes+1)...), ErrInvalidPayload},
}
for _, tc := range testCases {

View File

@ -6,9 +6,11 @@ import (
"crypto/sha256"
"encoding/binary"
"fmt"
ffi "github.com/filecoin-project/filecoin-ffi"
"io/ioutil"
"sync/atomic"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/ipfs/go-blockservice"
"github.com/ipfs/go-car"
offline "github.com/ipfs/go-ipfs-exchange-offline"
@ -24,6 +26,8 @@ import (
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
"github.com/filecoin-project/lotus/genesis"
"github.com/filecoin-project/lotus/lib/sectorbuilder"
"github.com/filecoin-project/lotus/node/repo"
@ -131,9 +135,28 @@ func NewGenerator() (*ChainGen, error) {
}
}
// TODO: this is really weird, we have to guess the miner addresses that
// will be created in order to preseal data for them
maddr1, err := address.NewFromString("t0101")
if err != nil {
return nil, err
}
m1temp, err := ioutil.TempDir("", "preseal")
if err != nil {
return nil, err
}
genm1, err := seed.PreSeal(maddr1, 1024, 1, m1temp, []byte("some randomness"))
if err != nil {
return nil, err
}
minercfg := &GenMinerCfg{
PeerIDs: []peer.ID{"peerID1", "peerID2"},
// Call PreSeal(and give worker addrs to it somehow)
PreSeals: map[string]genesis.GenesisMiner{
maddr1.String(): *genm1,
},
}
genb, err := MakeGenesisBlock(bs, map[address.Address]types.BigInt{

View File

@ -2,6 +2,7 @@ package types
import (
"bytes"
"fmt"
"reflect"
"testing"
@ -25,7 +26,8 @@ func testBlockHeader(t testing.TB) *BlockHeader {
return &BlockHeader{
Miner: addr,
EPostProof: EPostProof{
Proof: []byte("pruuf"),
Proof: []byte("pruuf"),
PostRand: []byte("random"),
},
Ticket: &Ticket{
VRFProof: []byte("vrf proof0000000vrf proof0000000"),
@ -55,6 +57,8 @@ func TestBlockHeaderSerialization(t *testing.T) {
}
if !reflect.DeepEqual(&out, bh) {
fmt.Printf("%#v\n", &out)
fmt.Printf("%#v\n", bh)
t.Fatal("not equal")
}
}

View File

@ -135,12 +135,19 @@ func (s *StateWrapper) SetSingletonActor(addr vstate.SingletonActorID, balance v
return &actorWrapper{*initact}, s.storage, s.flush(tree)
case actors.StorageMarketAddress:
smact, err := gen.SetupStorageMarketActor(s.bs)
nsroot, err := gen.SetupStorageMarketActor(s.bs, s.stateRoot, nil)
if err != nil {
return nil, nil, err
}
if err := tree.SetActor(actors.StorageMarketAddress, smact); err != nil {
return nil, nil, xerrors.Errorf("set network storage market actor: %w", err)
s.stateRoot = nsroot
tree, err = state.LoadStateTree(s.cst, s.stateRoot)
if err != nil {
return nil, nil, err
}
smact, err := tree.GetActor(actors.StorageMarketAddress)
if err != nil {
return nil, nil, err
}
return &actorWrapper{*smact}, s.storage, s.flush(tree)
case actors.StoragePowerAddress:

View File

@ -79,6 +79,11 @@ var preSealCmd = &cli.Command{
return err
}
return seed.PreSeal(maddr, c.Uint64("sector-size"), c.Uint64("num-sectors"), sbroot, []byte(c.String("ticket-preimage")))
gm, err := seed.PreSeal(maddr, c.Uint64("sector-size"), c.Uint64("num-sectors"), sbroot, []byte(c.String("ticket-preimage")))
if err != nil {
return err
}
return seed.WriteGenesisMiner(maddr, sbroot, gm)
},
}

View File

@ -23,7 +23,7 @@ import (
"github.com/filecoin-project/lotus/lib/sectorbuilder"
)
func PreSeal(maddr address.Address, ssize uint64, sectors uint64, sbroot string, preimage []byte) error {
func PreSeal(maddr address.Address, ssize uint64, sectors uint64, sbroot string, preimage []byte) (*genesis.GenesisMiner, error) {
cfg := &sectorbuilder.Config{
Miner: maddr,
SectorSize: ssize,
@ -36,22 +36,22 @@ func PreSeal(maddr address.Address, ssize uint64, sectors uint64, sbroot string,
for _, d := range []string{cfg.CacheDir, cfg.SealedDir, cfg.StagedDir, cfg.MetadataDir} {
if err := os.MkdirAll(d, 0775); err != nil {
return err
return nil, err
}
}
mds, err := badger.NewDatastore(filepath.Join(sbroot, "badger"), nil)
if err != nil {
return err
return nil, err
}
if err := build.GetParams(true, false); err != nil {
return xerrors.Errorf("getting params: %w", err)
return nil, xerrors.Errorf("getting params: %w", err)
}
sb, err := sectorbuilder.New(cfg, mds)
if err != nil {
return err
return nil, err
}
r := rand.New(rand.NewSource(101))
@ -61,12 +61,12 @@ func PreSeal(maddr address.Address, ssize uint64, sectors uint64, sbroot string,
for i := uint64(1); i <= sectors; i++ {
sid, err := sb.AcquireSectorId()
if err != nil {
return err
return nil, err
}
pi, err := sb.AddPiece(size, sid, r, nil)
if err != nil {
return err
return nil, err
}
trand := sha256.Sum256(preimage)
@ -78,7 +78,7 @@ func PreSeal(maddr address.Address, ssize uint64, sectors uint64, sbroot string,
pco, err := sb.SealPreCommit(sid, ticket, []sectorbuilder.PublicPieceInfo{pi})
if err != nil {
return xerrors.Errorf("commit: %w", err)
return nil, xerrors.Errorf("commit: %w", err)
}
sealedSectors = append(sealedSectors, &genesis.PreSeal{
@ -90,7 +90,7 @@ func PreSeal(maddr address.Address, ssize uint64, sectors uint64, sbroot string,
minerAddr, err := wallet.GenerateKey(types.KTBLS)
if err != nil {
return err
return nil, err
}
miner := &genesis.GenesisMiner{
@ -105,11 +105,19 @@ func PreSeal(maddr address.Address, ssize uint64, sectors uint64, sbroot string,
}
if err := createDeals(miner, minerAddr, ssize); err != nil {
return xerrors.Errorf("creating deals: %w", err)
return nil, xerrors.Errorf("creating deals: %w", err)
}
if err := mds.Close(); err != nil {
return nil, xerrors.Errorf("closing datastore: %w", err)
}
return miner, nil
}
func WriteGenesisMiner(maddr address.Address, sbroot string, gm *genesis.GenesisMiner) error {
output := map[string]genesis.GenesisMiner{
maddr.String(): *miner,
maddr.String(): *gm,
}
out, err := json.MarshalIndent(output, "", " ")
@ -121,10 +129,6 @@ func PreSeal(maddr address.Address, ssize uint64, sectors uint64, sbroot string,
return err
}
if err := mds.Close(); err != nil {
return xerrors.Errorf("closing datastore: %w", err)
}
return nil
}

View File

@ -35,10 +35,15 @@ func (api *api) Spawn() (nodeInfo, error) {
return nodeInfo{}, err
}
err = seed.PreSeal(genMiner, build.SectorSizes[0], 1, filepath.Join(dir, "preseal"), []byte("8"))
sbroot := filepath.Join(dir, "preseal")
genm, err := seed.PreSeal(genMiner, build.SectorSizes[0], 1, sbroot, []byte("8"))
if err != nil {
return nodeInfo{}, xerrors.Errorf("preseal failed: %w", err)
}
if err := seed.WriteGenesisMiner(genMiner, sbroot, genm); err != nil {
return nodeInfo{}, xerrors.Errorf("failed to write genminer info: %w", err)
}
params = append(params, "--genesis-presealed-sectors="+filepath.Join(dir, "preseal", "pre-seal-t0101.json"))
// make genesis