Deal flow fixes

This commit is contained in:
Łukasz Magiera 2020-02-23 16:50:36 +01:00
parent 97425ea1c9
commit a82d156ccb
15 changed files with 125 additions and 62 deletions

View File

@ -74,9 +74,9 @@ func TestDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration) {
if err != nil {
t.Fatal(err)
}
deal, err := client.ClientStartDeal(ctx, fcid, addr, maddr, types.NewInt(40000000), 100)
deal, err := client.ClientStartDeal(ctx, fcid, addr, maddr, types.NewInt(1000000), 100)
if err != nil {
t.Fatal(err)
t.Fatalf("%+v", err)
}
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this

View File

@ -57,7 +57,7 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr address.Address, am
fm.lk.Unlock()
var err error
params, err := actors.SerializeParams(&toAdd)
params, err := actors.SerializeParams(&addr)
if err != nil {
return err
}

View File

@ -14,6 +14,7 @@ import (
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/runtime"
"github.com/filecoin-project/specs-actors/actors/util/adt"
@ -399,6 +400,15 @@ func (sm *StateManager) GetBlsPublicKey(ctx context.Context, addr address.Addres
return pubk, nil
}
func (sm *StateManager) LookupID(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
cst := cbor.NewCborStore(sm.cs.Blockstore())
state, err := state.LoadStateTree(cst, sm.parentState(ts))
if err != nil {
return address.Undef, xerrors.Errorf("load state tree: %w", err)
}
return state.LookupID(addr)
}
func (sm *StateManager) GetReceipt(ctx context.Context, msg cid.Cid, ts *types.TipSet) (*types.MessageReceipt, error) {
m, err := sm.cs.GetCMessage(msg)
if err != nil {
@ -623,15 +633,39 @@ func (sm *StateManager) MarketBalance(ctx context.Context, addr address.Address,
return api.MarketBalance{}, err
}
var out api.MarketBalance
out.Escrow, err = adt.AsBalanceTable(sm.cs.Store(ctx), state.EscrowTable).Get(addr)
addr, err = sm.LookupID(ctx, addr, ts)
if err != nil {
return api.MarketBalance{}, xerrors.Errorf("getting escrow balance: %w", err)
return api.MarketBalance{}, err
}
out.Locked, err = adt.AsBalanceTable(sm.cs.Store(ctx), state.LockedTable).Get(addr)
var out api.MarketBalance
et := adt.AsBalanceTable(sm.cs.Store(ctx), state.EscrowTable)
ehas, err := et.Has(addr)
if err != nil {
return api.MarketBalance{}, xerrors.Errorf("getting locked balance: %w", err)
return api.MarketBalance{}, err
}
if ehas {
out.Escrow, err = et.Get(addr)
if err != nil {
return api.MarketBalance{}, xerrors.Errorf("getting escrow balance: %w", err)
}
} else {
out.Escrow = big.Zero()
}
lt := adt.AsBalanceTable(sm.cs.Store(ctx), state.LockedTable)
lhas, err := lt.Has(addr)
if err != nil {
return api.MarketBalance{}, err
}
if lhas {
out.Locked, err = lt.Get(addr)
if err != nil {
return api.MarketBalance{}, xerrors.Errorf("getting locked balance: %w", err)
}
} else {
out.Locked = big.Zero()
}
return out, nil

View File

@ -221,7 +221,7 @@ func GetMinerFaults(ctx context.Context, sm *StateManager, ts *types.TipSet, mad
}
func GetStorageDeal(ctx context.Context, sm *StateManager, dealId abi.DealID, ts *types.TipSet) (*api.MarketDeal, error) {
var state actors.StorageMarketState
var state market.State
if _, err := sm.LoadActorState(ctx, actors.StorageMarketAddress, &state, ts); err != nil {
return nil, err
}
@ -236,19 +236,15 @@ func GetStorageDeal(ctx context.Context, sm *StateManager, dealId abi.DealID, ts
return nil, err
}
sa, err := amt.LoadAMT(ctx, cbor.NewCborStore(sm.ChainStore().Blockstore()), state.States)
sa := market.AsDealStateArray(sm.ChainStore().Store(ctx), state.States)
st, err := sa.Get(dealId)
if err != nil {
return nil, err
}
var st market.DealState
if err := sa.Get(ctx, uint64(dealId), &st); err != nil {
return nil, err
}
return &api.MarketDeal{
Proposal: dp,
State: st,
State: *st,
}, nil
}

View File

@ -647,7 +647,7 @@ func copyRec(from, to blockstore.Blockstore, root cid.Cid, cp func(block.Block)
}
for _, link := range links {
if link.Prefix().MhType == mh.IDENTITY || link.Prefix().MhType == uint64(commcid.FC_SEALED_V1) {
if link.Prefix().MhType == mh.IDENTITY || link.Prefix().MhType == uint64(commcid.FC_SEALED_V1) || link.Prefix().MhType == uint64(commcid.FC_UNSEALED_V1) {
continue
}

2
go.mod
View File

@ -18,7 +18,7 @@ require (
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-fil-commcid v0.0.0-20200208005934-2b8bd03caca5
github.com/filecoin-project/go-fil-markets v0.0.0-20200220181918-bfd030852a59
github.com/filecoin-project/go-fil-markets v0.0.0-20200223154807-f7afd8e927f9
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-sectorbuilder v0.0.2-0.20200210220012-eb75ec747d6b

2
go.sum
View File

@ -115,6 +115,8 @@ github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5 h1
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-20200220181918-bfd030852a59 h1:AULXvl86fSjh1gS3V/xo2YEWntAOSe3HGAHO0+S2h8k=
github.com/filecoin-project/go-fil-markets v0.0.0-20200220181918-bfd030852a59/go.mod h1:ftsiBbjLjNLAZ52FVDigkdCp73ltdcvAzAXav6drSLA=
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-20200223154807-f7afd8e927f9/go.mod h1:ftsiBbjLjNLAZ52FVDigkdCp73ltdcvAzAXav6drSLA=
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-paramfetch v0.0.0-20200102181131-b20d579f2878/go.mod h1:40kI2Gv16mwcRsHptI3OAV4nlOEU7wVDc4RgMylNFjU=

View File

@ -93,7 +93,8 @@ func (n *ClientNodeAdapter) ListStorageProviders(ctx context.Context) ([]*storag
}
func (n *ClientNodeAdapter) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) bool {
panic("TODO")
log.Warn("stub VerifySignature")
return true
}
func (n *ClientNodeAdapter) ListClientDeals(ctx context.Context, addr address.Address) ([]storagemarket.StorageDeal, error) {
@ -194,7 +195,7 @@ func (c *ClientNodeAdapter) ValidatePublishedDeal(ctx context.Context, deal stor
for i, storageDeal := range params.Deals {
// TODO: make it less hacky
sd := storageDeal
eq, err := cborutil.Equals(&deal.Proposal, &sd)
eq, err := cborutil.Equals(&deal.ClientDealProposal, &sd)
if err != nil {
return 0, err
}
@ -302,7 +303,7 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider
}
if err := c.ev.Called(checkFunc, called, revert, 3, build.SealRandomnessLookbackLimit, matchEvent); err != nil {
return xerrors.Errorf("failed to set up called handler")
return xerrors.Errorf("failed to set up called handler: %w", err)
}
return nil
@ -310,8 +311,14 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider
func (n *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal samarket.DealProposal) (*samarket.ClientDealProposal, error) {
// TODO: output spec signed proposal
panic("nyi")
return nil, nil
log.Warn("TODO: stub SignProposal")
return &samarket.ClientDealProposal{
Proposal: proposal,
ClientSignature: crypto.Signature{
Type: crypto.SigTypeBLS,
Data: []byte{},
},
}, nil
}
func (n *ClientNodeAdapter) GetDefaultWalletAddress(ctx context.Context) (address.Address, error) {

View File

@ -109,7 +109,8 @@ func (n *ProviderNodeAdapter) OnDealComplete(ctx context.Context, deal storagema
}
func (n *ProviderNodeAdapter) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) bool {
panic("nyi")
log.Warn("stub VerifySignature")
return true
}
func (n *ProviderNodeAdapter) ListProviderDeals(ctx context.Context, addr address.Address) ([]storagemarket.StorageDeal, error) {
@ -294,7 +295,7 @@ func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provide
}
if err := n.ev.Called(checkFunc, called, revert, 3, build.SealRandomnessLookbackLimit, matchEvent); err != nil {
return xerrors.Errorf("failed to set up called handler")
return xerrors.Errorf("failed to set up called handler: %w", err)
}
return nil

View File

@ -3,6 +3,7 @@ package utils
import (
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
peer "github.com/libp2p/go-libp2p-peer"
@ -29,6 +30,6 @@ func FromOnChainDeal(prop market.DealProposal, state market.DealState) storagema
func ToSharedBalance(bal api.MarketBalance) storagemarket.Balance {
return storagemarket.Balance{
Locked: bal.Locked,
Available: bal.Escrow,
Available: big.Sub(bal.Escrow, bal.Locked),
}
}

View File

@ -10,15 +10,6 @@ import (
"testing"
"time"
"github.com/filecoin-project/go-address"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/lotus/build"
genesis "github.com/filecoin-project/lotus/genesis"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
saminer "github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
badger "github.com/ipfs/go-ds-badger2"
@ -28,12 +19,23 @@ import (
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
"github.com/stretchr/testify/require"
"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/big"
"github.com/filecoin-project/specs-actors/actors/builtin"
saminer "github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/client"
"github.com/filecoin-project/lotus/api/test"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors"
genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
genesis "github.com/filecoin-project/lotus/genesis"
"github.com/filecoin-project/lotus/lib/jsonrpc"
"github.com/filecoin-project/lotus/miner"
"github.com/filecoin-project/lotus/node"
@ -164,7 +166,7 @@ func builder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []test.Te
var presealDirs []string
for i := 0; i < len(storage); i++ {
maddr, err := address.NewIDAddress(300 + uint64(i))
maddr, err := address.NewIDAddress(genesis2.MinerStart + uint64(i))
if err != nil {
t.Fatal(err)
}
@ -172,7 +174,7 @@ func builder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []test.Te
if err != nil {
t.Fatal(err)
}
genm, _, err := seed.PreSeal(maddr, 1024, 0, 1, tdir, []byte("make genesis mem random"), nil)
genm, _, err := seed.PreSeal(maddr, 1024, 0, 2, tdir, []byte("make genesis mem random"), nil)
if err != nil {
t.Fatal(err)
}
@ -273,8 +275,6 @@ func mockSbBuilder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []t
minerPid, err := peer.IDFromPrivateKey(pk)
require.NoError(t, err)
_ = minerPid // TODO
var genbuf bytes.Buffer
if len(storage) > 1 {
@ -284,10 +284,12 @@ func mockSbBuilder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []t
// TODO: would be great if there was a better way to fake the preseals
var genms []genesis.Miner
var genaccs []genesis.Actor
var maddrs []address.Address
var presealDirs []string
var keys []*wallet.Key
for i := 0; i < len(storage); i++ {
maddr, err := address.NewIDAddress(300 + uint64(i))
maddr, err := address.NewIDAddress(genesis2.MinerStart + uint64(i))
if err != nil {
t.Fatal(err)
}
@ -295,17 +297,31 @@ func mockSbBuilder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []t
if err != nil {
t.Fatal(err)
}
genm, err := sbmock.PreSeal(1024, maddr, 1)
genm, k, err := sbmock.PreSeal(1024, maddr, 2)
if err != nil {
t.Fatal(err)
}
genm.PeerId = minerPid
wk, err := wallet.NewKey(*k)
if err != nil {
return nil, nil
}
genaccs = append(genaccs, genesis.Actor{
Type: genesis.TAccount,
Balance: big.NewInt(40000000000),
Meta: (&genesis.AccountMeta{Owner: wk.Address}).ActorMeta(),
})
keys = append(keys, wk)
presealDirs = append(presealDirs, tdir)
maddrs = append(maddrs, maddr)
genms = append(genms, *genm)
}
templ := &genesis.Template{
Miners: genms,
Accounts: genaccs,
Miners: genms,
}
// END PRESEAL SECTION
@ -332,9 +348,8 @@ func mockSbBuilder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []t
genesis,
)
if err != nil {
t.Fatal(err)
t.Fatalf("%+v", err)
}
}
for i, full := range storage {
@ -347,6 +362,12 @@ func mockSbBuilder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []t
}
f := fulls[full]
if _, err := f.FullNode.WalletImport(ctx, &keys[i].KeyInfo); err != nil {
return nil, nil
}
if err := f.FullNode.WalletSetDefault(ctx, keys[i].Address); err != nil {
return nil, nil
}
genMiner := maddrs[i]
wa := genms[i].Worker

View File

@ -1,11 +1,10 @@
package sbmock
import (
"math"
"github.com/filecoin-project/go-address"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/filecoin-project/lotus/chain/actors"
@ -14,18 +13,19 @@ import (
"github.com/filecoin-project/lotus/genesis"
)
func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis.Miner, error) {
func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis.Miner, *types.KeyInfo, error) {
k, err := wallet.GenerateKey(crypto.SigTypeBLS)
if err != nil {
return nil, err
return nil, nil, err
}
genm := &genesis.Miner{
Owner: k.Address,
Worker: k.Address,
SectorSize: ssize,
Sectors: make([]*genesis.PreSeal, sectors),
//Key: k.KeyInfo,
Owner: k.Address,
Worker: k.Address,
MarketBalance: big.NewInt(0),
PowerBalance: big.NewInt(0),
SectorSize: ssize,
Sectors: make([]*genesis.PreSeal, sectors),
}
for i := range genm.Sectors {
@ -41,13 +41,14 @@ func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis
Client: maddr,
Provider: maddr,
StartEpoch: 1,
EndEpoch: math.MaxInt64,
StoragePricePerEpoch: types.NewInt(0),
ProviderCollateral: types.NewInt(0),
EndEpoch: 10000,
StoragePricePerEpoch: big.Zero(),
ProviderCollateral: big.Zero(),
ClientCollateral: big.Zero(),
}
genm.Sectors[i] = preseal
}
return genm, nil
return genm, &k.KeyInfo, nil
}

View File

@ -9,7 +9,7 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi"
)
type nullReader struct {}
type nullReader struct{}
func (nullReader) Read(out []byte) (int, error) {
for i := range out {

View File

@ -127,13 +127,13 @@ func (m *Sealing) SealPiece(ctx context.Context, size abi.UnpaddedPieceSize, r i
Size: ppi.Size,
CommP: ppi.CommP[:],
},
},)
})
}
func (m *Sealing) newSector(sid abi.SectorNumber, pieces []Piece) error {
log.Infof("Start sealing %d", sid)
return m.sectors.Send(uint64(sid), SectorStart{
id: sid,
id: sid,
pieces: pieces,
})
}

View File

@ -99,8 +99,8 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
}
params := &miner.SectorPreCommitInfo{
Expiration: 10000000, // TODO: implement
SectorNumber: sector.SectorID,
Expiration: 10000000, // TODO: implement
SectorNumber: sector.SectorID,
RegisteredProof: abi.RegisteredProof_StackedDRG32GiBSeal,
SealedCID: commcid.ReplicaCommitmentV1ToCID(sector.CommR),