2020-07-01 16:29:09 +00:00
|
|
|
package testkit
|
2020-06-30 22:02:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
|
2020-06-30 22:02:01 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
2020-09-16 10:51:23 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-06-14 15:00:51 +00:00
|
|
|
|
2020-06-30 22:02:01 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2021-04-06 10:36:32 +00:00
|
|
|
"github.com/filecoin-project/lotus/api/v0api"
|
2020-06-30 22:02:01 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2021-09-01 23:47:32 +00:00
|
|
|
tsync "github.com/filecoin-project/lotus/tools/stats/sync"
|
2020-06-30 22:02:01 +00:00
|
|
|
)
|
|
|
|
|
2020-07-27 11:57:01 +00:00
|
|
|
func StartDeal(ctx context.Context, minerActorAddr address.Address, client api.FullNode, fcid cid.Cid, fastRetrieval bool) *cid.Cid {
|
2020-06-30 22:02:01 +00:00
|
|
|
addr, err := client.WalletDefaultAddress(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
deal, err := client.ClientStartDeal(ctx, &api.StartDealParams{
|
2020-07-30 14:22:43 +00:00
|
|
|
Data: &storagemarket.DataRef{
|
|
|
|
TransferType: storagemarket.TTGraphsync,
|
|
|
|
Root: fcid,
|
|
|
|
},
|
2020-06-30 22:02:01 +00:00
|
|
|
Wallet: addr,
|
|
|
|
Miner: minerActorAddr,
|
2020-11-27 18:36:02 +00:00
|
|
|
EpochPrice: types.NewInt(4000000),
|
2020-07-30 14:22:43 +00:00
|
|
|
MinBlocksDuration: 640000,
|
2020-10-06 14:40:23 +00:00
|
|
|
DealStartEpoch: 200,
|
2020-07-27 11:57:01 +00:00
|
|
|
FastRetrieval: fastRetrieval,
|
2020-06-30 22:02:01 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return deal
|
|
|
|
}
|
|
|
|
|
2020-07-01 16:29:09 +00:00
|
|
|
func WaitDealSealed(t *TestEnvironment, ctx context.Context, client api.FullNode, deal *cid.Cid) {
|
2020-07-27 11:57:01 +00:00
|
|
|
height := 0
|
|
|
|
headlag := 3
|
|
|
|
|
|
|
|
cctx, cancel := context.WithCancel(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
2021-09-01 23:47:32 +00:00
|
|
|
tipsetsCh, err := tsync.BufferedTipsetChannel(cctx, &v0api.WrapperV1Full{FullNode: client}, abi.ChainEpoch(height), headlag)
|
2020-07-27 11:57:01 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for tipset := range tipsetsCh {
|
|
|
|
t.RecordMessage("got tipset: height %d", tipset.Height())
|
|
|
|
|
2020-06-30 22:02:01 +00:00
|
|
|
di, err := client.ClientGetDealInfo(ctx, *deal)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
switch di.State {
|
|
|
|
case storagemarket.StorageDealProposalRejected:
|
|
|
|
panic("deal rejected")
|
|
|
|
case storagemarket.StorageDealFailing:
|
|
|
|
panic("deal failed")
|
|
|
|
case storagemarket.StorageDealError:
|
|
|
|
panic(fmt.Sprintf("deal errored %s", di.Message))
|
|
|
|
case storagemarket.StorageDealActive:
|
|
|
|
t.RecordMessage("completed deal: %s", di)
|
2020-07-27 11:57:01 +00:00
|
|
|
return
|
2020-06-30 22:02:01 +00:00
|
|
|
}
|
2020-07-27 11:57:01 +00:00
|
|
|
|
2020-06-30 22:02:01 +00:00
|
|
|
t.RecordMessage("deal state: %s", storagemarket.DealStates[di.State])
|
|
|
|
}
|
|
|
|
}
|