Skip to content

Commit

Permalink
Test that exposes problem with deals awaiting seal
Browse files Browse the repository at this point in the history
  • Loading branch information
rkowalick committed Jan 2, 2019
1 parent 81d3361 commit b5c0deb
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 34 deletions.
35 changes: 26 additions & 9 deletions commands/client_daemon_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package commands

import (
"fmt"
"github.com/filecoin-project/go-filecoin/fixtures"
th "github.com/filecoin-project/go-filecoin/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"strings"
"testing"

"github.com/stretchr/testify/assert"

"github.com/filecoin-project/go-filecoin/fixtures"
th "github.com/filecoin-project/go-filecoin/testhelpers"
"time"
)

func TestListAsks(t *testing.T) {
Expand Down Expand Up @@ -53,20 +53,37 @@ func TestQueryStorageDeal(t *testing.T) {
minerDaemon.ConnectSuccess(clientDaemon)

minerDaemon.CreateAsk(minerDaemon, fixtures.TestMiners[0], fixtures.TestAddresses[0], "20", "10")
dataCid := clientDaemon.RunWithStdin(strings.NewReader("HODLHODLHODL"), "client", "import").ReadStdoutTrimNewlines()
dataCid := clientDaemon.RunWithStdin(strings.NewReader("HODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODLHODL"), "client", "import").ReadStdoutTrimNewlines()

proposeDealOutput := clientDaemon.RunSuccess("client", "propose-storage-deal", fixtures.TestMiners[0], dataCid, "0", "5").ReadStdoutTrimNewlines()

splitOnSpace := strings.Split(proposeDealOutput, " ")

dealCid := splitOnSpace[len(splitOnSpace)-1]

minerDaemon.Restart()
minerDaemon.RunSuccess("mining", "start")
// TODO: Get me to pass without commenting these lines out!
//minerDaemon.Restart()
//minerDaemon.RunSuccess("mining", "start")

clientDaemon.Restart()

minerDaemon.ConnectSuccess(clientDaemon)

clientDaemon.RunSuccess("client", "query-storage-deal", dealCid).ReadStdout()
var queryDealOutput string
for i := 1; true; i++ {
fmt.Printf("ON THE %d-th Attempt\n", i)
queryDealOutput = clientDaemon.RunSuccess("client", "query-storage-deal", dealCid).ReadStdout()
if strings.Contains(queryDealOutput, "posted") {
t.Log("Passed!")
break
}

if i >= 20 {
t.Logf("Failed waiting for Deal to reach 'POSTED' state. Deal status is %s", queryDealOutput)
t.Fail()
}

time.Sleep(10 * time.Second)
}

}
12 changes: 1 addition & 11 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import (

"github.com/filecoin-project/go-filecoin/abi"
"github.com/filecoin-project/go-filecoin/address"
api2impl "github.com/filecoin-project/go-filecoin/api2/impl"
"github.com/filecoin-project/go-filecoin/api2/impl/msgapi"
"github.com/filecoin-project/go-filecoin/api2/impl/mthdsigapi"
"github.com/filecoin-project/go-filecoin/chain"
"github.com/filecoin-project/go-filecoin/consensus"
"github.com/filecoin-project/go-filecoin/core"
Expand Down Expand Up @@ -149,16 +146,9 @@ func TestNodeStartMining(t *testing.T) {
seed := MakeChainSeed(t, TestGenCfg)
minerNode := NodeWithChainSeed(t, seed, PeerKeyOpt(PeerKeys[0]), AutoSealIntervalSecondsOpt(1))

// TODO we need a principled way to construct an API that can be used both by node and by
// tests. It should enable selective replacement of dependencies.
sigGetter := mthdsigapi.NewGetter(minerNode.ChainReader)
msgSender := msgapi.NewSender(minerNode.Repo, minerNode.Wallet, minerNode.ChainReader, minerNode.MsgPool, minerNode.PubSub.Publish)
msgWaiter := msgapi.NewWaiter(minerNode.ChainReader, minerNode.Blockstore, minerNode.CborStore())
plumbingAPI := api2impl.New(sigGetter, msgSender, msgWaiter)

seed.GiveKey(t, minerNode, 0)
mineraddr, minerOwnerAddr := seed.GiveMiner(t, minerNode, 0)
_, err := storage.NewMiner(ctx, mineraddr, minerOwnerAddr, minerNode, minerNode.Repo.MinerDealsDatastore(), plumbingAPI)
_, err := storage.NewMiner(ctx, mineraddr, minerOwnerAddr, minerNode, minerNode.Repo.MinerDealsDatastore(), minerNode.PlumbingAPI)
assert.NoError(err)

assert.NoError(minerNode.Start(ctx))
Expand Down
4 changes: 0 additions & 4 deletions protocol/storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ func init() {

// NewClient creates a new storage client.
func NewClient(nd clientNode, dealsDs repo.Datastore) (*Client, error) {
if dealsDs == nil {
fmt.Println("dub tee eff")
}
smc := &Client{
deals: make(map[cid.Cid]*clientDealState),
node: nd,
Expand Down Expand Up @@ -173,7 +170,6 @@ func (smc *Client) checkDealResponse(ctx context.Context, resp *DealResponse) er
func (smc *Client) minerForProposal(c cid.Cid) (address.Address, error) {
smc.dealsLk.Lock()
defer smc.dealsLk.Unlock()
fmt.Println(smc.deals)
st, ok := smc.deals[c]
if !ok {
return address.Address{}, fmt.Errorf("no such Proposal by cid: %s", c)
Expand Down
18 changes: 13 additions & 5 deletions protocol/storage/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,24 @@ func (sm *Miner) getStorageDeal(c cid.Cid) *storageDealState {
return sm.deals[c]
}

func (sm *Miner) updateDealState(c cid.Cid, f func(*DealResponse)) {
func (sm *Miner) updateDealState(proposalCid cid.Cid, f func(*DealResponse)) {
sm.dealsLk.Lock()
defer sm.dealsLk.Unlock()
fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
fmt.Printf("PREVIOUS STATE: %v\n", sm.deals[c].State)
f(sm.deals[c].State)
fmt.Printf("NEW STATE: %v\n", sm.deals[c].State)
fmt.Printf("PREVIOUS STATE: %v\n", sm.deals[proposalCid].State)
f(sm.deals[proposalCid].State)
fmt.Printf("NEW STATE: %v\n", sm.deals[proposalCid].State)
fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
datum, err := cbor.DumpObject(sm.deals[proposalCid])
if err != nil {
log.Errorf("failed to marshal CBOR data: %s", err)
}
err = sm.DealsDs.Put(datastore.NewKey(proposalCid.String()), datum)
if err != nil {
log.Errorf("failed to store deal in datastore: %s", err)
}

log.Debugf("Miner.updateDealState(%s) - %d", c.String(), sm.deals[c].State)
log.Debugf("Miner.updateDealState(%s) - %d", proposalCid.String(), sm.deals[proposalCid].State)
}

func (sm *Miner) processStorageDeal(c cid.Cid) {
Expand Down
2 changes: 1 addition & 1 deletion protocol/storage/storage_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestStorageProtocolBasic(t *testing.T) {
return [][]byte{enc}, 0, nil
},
)
c, _ := NewClient(cni, client.Repo.ClientDealsDatastore())
c, _ := NewClient(cni, client.Repo.ClientDealsDatastore())
m, err := NewMiner(ctx, mineraddr, minerOwnerAddr, miner, miner.Repo.MinerDealsDatastore(), plumbingAPI)
assert.NoError(err)
_ = m
Expand Down
2 changes: 1 addition & 1 deletion repo/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewInMemoryRepoWithSectorDirectories(staging, sealedDir string) *MemRepo {
MinerDealsDs: dss.MutexWrap(datastore.NewMapDatastore()),
ClientDealsDs: dss.MutexWrap(datastore.NewMapDatastore()),
version: Version,
stagingDir: staging,
stagingDir: staging,
sealedDir: sealedDir,
}
}
Expand Down
5 changes: 2 additions & 3 deletions testhelpers/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,7 @@ func (td *TestDaemon) Stop() *TestDaemon {

// Restart restarts the daemon
func (td *TestDaemon) Restart() *TestDaemon {
td.Stop()
td.Start()
return td
return td.Stop().Start()
}

// Shutdown stops the daemon and deletes the repository.
Expand Down Expand Up @@ -783,6 +781,7 @@ func NewDaemon(t *testing.T, options ...func(*TestDaemon)) *TestDaemon {
// build command options
initopts := []string{
repoDirFlag,
"--auto-seal-interval-seconds=1",
}

if td.genesisFile != "" {
Expand Down

0 comments on commit b5c0deb

Please sign in to comment.