From cf2eefdfbefd3570744bb9f2fe6e93b2ec8e2f4f Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Fri, 28 Feb 2020 16:05:56 -0800 Subject: [PATCH] Fix up client storage deal matcher --- chain/events/events_called.go | 2 +- chain/store/store.go | 13 ++++--- go.mod | 2 ++ markets/storageadapter/client.go | 54 +++++++++++++++++++--------- markets/storageadapter/provider.go | 56 ++++++++++++++++++++++-------- storage/sbmock/preseal.go | 7 ++++ 6 files changed, 97 insertions(+), 37 deletions(-) diff --git a/chain/events/events_called.go b/chain/events/events_called.go index 3b1d86123..cbdae4483 100644 --- a/chain/events/events_called.go +++ b/chain/events/events_called.go @@ -130,7 +130,7 @@ func (e *calledEvents) checkNewCalls(ts *types.TipSet) { for _, matchFn := range matchFns { ok, err := matchFn(msg) if err != nil { - log.Warnf("event matcher failed: %s", err) + log.Errorf("event matcher failed: %s", err) continue } matched = ok diff --git a/chain/store/store.go b/chain/store/store.go index 130d9c7c3..ed86b1727 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -5,11 +5,12 @@ import ( "context" "encoding/binary" "encoding/json" - "github.com/filecoin-project/specs-actors/actors/crypto" - "github.com/minio/blake2b-simd" "io" "sync" + "github.com/filecoin-project/specs-actors/actors/crypto" + "github.com/minio/blake2b-simd" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/specs-actors/actors/abi" "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() 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 { nts, err := cs.LoadTipSet(types.NewTipSetKey(blks...)) diff --git a/go.mod b/go.mod index 98729ecc6..e0acf3672 100644 --- a/go.mod +++ b/go.mod @@ -116,3 +116,5 @@ replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi replace github.com/filecoin-project/specs-actors => ../specs-actors + +replace github.com/filecoin-project/go-fil-markets => ../go-fil-markets diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index c872782ff..438265d70 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -276,29 +276,51 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider return nil } + var sectorNumber abi.SectorNumber + var sectorFound bool matchEvent := func(msg *types.Message) (bool, error) { if msg.To != provider { 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) { + log.Error("FOUND OUR SECTOR!", params.SectorNumber) + sectorNumber = params.SectorNumber + sectorFound = true + return false, nil + } + } + + return false, nil + case builtin.MethodsMiner.ProveCommitSector: + log.Errorf("Look! a prove commit!") + 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) + } + log.Warn("prove commit: ", params.SectorNumber, sectorFound, sectorNumber) + + if !sectorFound { + return false, nil + } + + if params.SectorNumber != sectorNumber { + return false, nil + } + + log.Warn("getting out of here") + return true, nil + default: 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 { diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index d437bf269..95900dcc0 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -219,6 +219,7 @@ func (n *ProviderNodeAdapter) LocatePieceForDealWithinSector(ctx context.Context } func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealID uint64, cb storagemarket.DealSectorCommittedCallback) error { + log.Errorf("ON DEAL SECTOR COMMITTED", provider, dealID) checkFunc := func(ts *types.TipSet) (done bool, more bool, err error) { sd, err := n.StateMarketStorageDeal(ctx, abi.DealID(dealID), ts.Key()) @@ -236,6 +237,7 @@ func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provide } called := func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (more bool, err error) { + log.Errorf("CAllled callllllback") defer func() { if err != nil { cb(xerrors.Errorf("handling applied event: %w", err)) @@ -269,29 +271,53 @@ func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provide return nil } + var sectorNumber abi.SectorNumber + var sectorFound bool + matchEvent := func(msg *types.Message) (bool, error) { if msg.To != provider { 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) { + log.Error("FOUND OUR SECTOR!", params.SectorNumber) + sectorNumber = params.SectorNumber + sectorFound = true + return false, nil + } + } + + return false, nil + case builtin.MethodsMiner.ProveCommitSector: + log.Errorf("Look! a prove commit!") + 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) + } + log.Warn("prove commit: ", params.SectorNumber, sectorFound, sectorNumber) + + if !sectorFound { + return false, nil + } + + if params.SectorNumber != sectorNumber { + return false, nil + } + + log.Warn("getting out of here") + return true, nil + default: 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 { diff --git a/storage/sbmock/preseal.go b/storage/sbmock/preseal.go index 66b9b72b0..7d7e1d741 100644 --- a/storage/sbmock/preseal.go +++ b/storage/sbmock/preseal.go @@ -8,6 +8,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/market" "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/wallet" "github.com/filecoin-project/lotus/genesis" @@ -29,9 +30,15 @@ func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis Sectors: make([]*genesis.PreSeal, sectors), } + _, st, err := api.ProofTypeFromSectorSize(ssize) + if err != nil { + return nil, nil, err + } + for i := range genm.Sectors { preseal := &genesis.PreSeal{} + preseal.ProofType = st preseal.CommD = zerocomm.ForSize(abi.PaddedPieceSize(ssize).Unpadded()) d, _ := commcid.CIDToPieceCommitmentV1(preseal.CommD) r := commDR(d)