fix(dealstate): update deal states to match current

This commit is contained in:
hannahhoward 2020-01-24 13:44:28 -08:00
parent 17a4a99f9c
commit b8077fadaa
6 changed files with 168 additions and 100 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/libp2p/go-libp2p-core/peer"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
@ -153,7 +154,7 @@ type Import struct {
type DealInfo struct {
ProposalCid cid.Cid
State DealState
State storagemarket.StorageDealStatus
Provider address.Address
PieceRef []byte // cid bytes

View File

@ -13,7 +13,7 @@ import (
logging "github.com/ipfs/go-log/v2"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/impl"
@ -88,17 +88,17 @@ loop:
t.Fatal(err)
}
switch di.State {
case api.DealRejected:
case storagemarket.StorageDealProposalRejected:
t.Fatal("deal rejected")
case api.DealFailed:
case storagemarket.StorageDealFailing:
t.Fatal("deal failed")
case api.DealError:
case storagemarket.StorageDealError:
t.Fatal("deal errored")
case api.DealComplete:
case storagemarket.StorageDealActive:
fmt.Println("COMPLETE", di)
break loop
}
fmt.Println("Deal state: ", api.DealStates[di.State])
fmt.Println("Deal state: ", storagemarket.DealStates[di.State])
time.Sleep(time.Second / 2)
}

View File

@ -6,36 +6,6 @@ import (
ma "github.com/multiformats/go-multiaddr"
)
type DealState = uint64
const (
DealUnknown = DealState(iota)
DealRejected // Provider didn't like the proposal
DealAccepted // Proposal accepted, data moved
DealStaged // Data put into the sector
DealSealing // Data in process of being sealed
DealFailed
DealComplete
// Internal
DealError // deal failed with an unexpected error
DealNoUpdate = DealUnknown
)
var DealStates = []string{
"DealUnknown",
"DealRejected",
"DealAccepted",
"DealStaged",
"DealSealing",
"DealFailed",
"DealComplete",
"DealError",
}
// TODO: check if this exists anywhere else
type MultiaddrSlice []ma.Multiaddr

View File

@ -13,7 +13,7 @@ import (
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-address"
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/go-fil-markets/storagemarket"
actors "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
)
@ -359,7 +359,7 @@ var clientListDeals = &cli.Command{
w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
fmt.Fprintf(w, "DealCid\tProvider\tState\tPieceRef\tSize\tPrice\tDuration\n")
for _, d := range deals {
fmt.Fprintf(w, "%s\t%s\t%s\t%x\t%d\t%s\t%d\n", d.ProposalCid, d.Provider, lapi.DealStates[d.State], d.PieceRef, d.Size, d.PricePerEpoch, d.Duration)
fmt.Fprintf(w, "%s\t%s\t%s\t%x\t%d\t%s\t%d\n", d.ProposalCid, d.Provider, storagemarket.DealStates[d.State], d.PieceRef, d.Size, d.PricePerEpoch, d.Duration)
}
return w.Flush()
},

View File

@ -293,7 +293,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
MinerDeal: storagemarket.MinerDeal{
Proposal: *proposal,
ProposalCid: proposalCid,
State: lapi.DealComplete,
State: storagemarket.StorageDealActive,
Ref: proposalCid, // TODO: This is super wrong, but there
// are no params for CommP CIDs, we can't recover unixfs cid easily,
// and this isn't even used after the deal enters Complete state

View File

@ -1,68 +1,92 @@
import React from 'react';
import Address from "./Address";
import Window from "./Window";
import Fil from "./Fil";
import React from 'react'
import Address from './Address'
import Window from './Window'
import Fil from './Fil'
const dealStates = [
"Unknown",
"Rejected",
"Accepted",
"Staged",
"Sealing",
"Failed",
"Complete",
"Error",
]
'Unknown',
'ProposalNotFound',
'ProposalRejected',
'ProposalAccepted',
'Staged',
'Sealing',
'ProposalSigned',
'Published',
'Committed',
'Active',
'Failing',
'Recovering',
'Expired',
'NotFound',
'Validating',
'Transferring',
'VerifyData',
'Publishing',
'Error'
]
class Client extends React.Component {
constructor(props) {
super(props)
this.state = {
miners: ["t0101"],
ask: {Price: "1000000000"}, // 2x min default ask to account for bin packing (could also do the math correctly below, but..)
miners: ['t0101'],
ask: { Price: '1000000000' }, // 2x min default ask to account for bin packing (could also do the math correctly below, but..)
kbs: 1,
blocks: 12,
total: 36000,
miner: "t0101",
miner: 't0101',
deals: [],
blockDelay: 10,
blockDelay: 10
}
}
async componentDidMount() {
let ver = await this.props.client.call('Filecoin.Version', [])
this.setState({blockDelay: ver.BlockDelay})
this.setState({ blockDelay: ver.BlockDelay })
this.getDeals()
setInterval(this.getDeals, 1325)
}
getDeals = async () => {
let miners = await this.props.client.call('Filecoin.StateListMiners', [null])
let miners = await this.props.client.call('Filecoin.StateListMiners', [
null
])
let deals = await this.props.client.call('Filecoin.ClientListDeals', [])
miners.sort()
this.setState({deals, miners})
this.setState({ deals, miners })
}
update = (name) => (e) => this.setState({ [name]: e.target.value });
update = name => e => this.setState({ [name]: e.target.value })
makeDeal = async () => {
let perBlk = this.state.ask.Price * this.state.kbs * 1000 / (1 << 30) * 2
let perBlk =
((this.state.ask.Price * this.state.kbs * 1000) / (1 << 30)) * 2
let file = await this.props.pondClient.call('Pond.CreateRandomFile', [this.state.kbs * 1000]) // 1024 won't fit in 1k blocks :(
let file = await this.props.pondClient.call('Pond.CreateRandomFile', [
this.state.kbs * 1000
]) // 1024 won't fit in 1k blocks :(
let cid = await this.props.client.call('Filecoin.ClientImport', [file])
let dealcid = await this.props.client.call('Filecoin.ClientStartDeal', [cid, this.state.miner, `${Math.round(perBlk)}`, Number(this.state.blocks)])
console.log("deal cid: ", dealcid)
let dealcid = await this.props.client.call('Filecoin.ClientStartDeal', [
cid,
this.state.miner,
`${Math.round(perBlk)}`,
Number(this.state.blocks)
])
console.log('deal cid: ', dealcid)
}
retrieve = (deal) => async () => {
retrieve = deal => async () => {
console.log(deal)
let client = await this.props.client.call('Filecoin.WalletDefaultAddress', [])
let client = await this.props.client.call(
'Filecoin.WalletDefaultAddress',
[]
)
let order = {
Root: deal.PieceRef,
@ -74,7 +98,10 @@ class Client extends React.Component {
Miner: deal.Miner
}
await this.props.client.call('Filecoin.ClientRetrieve', [order, '/dev/null'])
await this.props.client.call('Filecoin.ClientRetrieve', [
order,
'/dev/null'
])
}
render() {
@ -82,41 +109,111 @@ class Client extends React.Component {
let total = perBlk * this.state.blocks
let days = (this.state.blocks * this.state.blockDelay) / 60 / 60 / 24
let dealMaker = <div hidden={!this.props.pondClient}>
<div>
<span>Make Deal: </span>
<select>{this.state.miners.map(m => <option key={m} value={m}>{m}</option>)}</select>
<span> Ask: <b><Fil>{this.state.ask.Price}</Fil></b> Fil/Byte/Block</span>
let dealMaker = (
<div hidden={!this.props.pondClient}>
<div>
<span>Make Deal: </span>
<select>
{this.state.miners.map(m => (
<option key={m} value={m}>
{m}
</option>
))}
</select>
<span>
{' '}
Ask:{' '}
<b>
<Fil>{this.state.ask.Price}</Fil>
</b>{' '}
Fil/Byte/Block
</span>
</div>
<div>
Data Size:{' '}
<input
type="text"
placeholder="KBs"
defaultValue={1}
onChange={this.update('kbs')}
style={{ width: '5em' }}
/>
KB; Duration:
<input
type="text"
placeholder="blocks"
defaultValue={12}
onChange={this.update('blocks')}
style={{ width: '5em' }}
/>
Blocks
</div>
<div>
Total: <Fil>{total}</Fil>; {days} Days
</div>
<button onClick={this.makeDeal}>Deal!</button>
</div>
<div>
Data Size: <input type="text" placeholder="KBs" defaultValue={1} onChange={this.update("kbs")} style={{width: "5em"}}/>KB;
Duration:<input type="text" placeholder="blocks" defaultValue={12} onChange={this.update("blocks")} style={{width: "5em"}}/>Blocks
</div>
<div>
Total: <Fil>{total}</Fil>; {days} Days
</div>
<button onClick={this.makeDeal}>Deal!</button>
</div>
)
let deals = this.state.deals.map((deal, i) => <div key={i}>
<ul>
<li>{i}. Proposal: {deal.ProposalCid['/'].substr(0, 18)}... <Address nobalance={true} client={this.props.client} addr={deal.Provider} mountWindow={this.props.mountWindow}/>: <b>{dealStates[deal.State]}</b>
{dealStates[deal.State] === 'Complete' ? <span>&nbsp;<a href="#" onClick={this.retrieve(deal)}>[Retrieve]</a></span> : <span/> }
<ul>
<li>Data: {deal.PieceRef['/']}, <b>{deal.Size}</b>B; Duration: <b>{deal.Duration}</b>Blocks</li>
<li>Total: <b>{deal.TotalPrice}</b>FIL; Per Block: <b>{Math.round(deal.TotalPrice / deal.Duration * 100) / 100}</b>FIL; PerMbyteByteBlock: <b>{Math.round(deal.TotalPrice / deal.Duration / (deal.Size / 1000000) * 100) / 100}</b>FIL</li>
</ul>
</li>
</ul>
</div>)
return <Window title={"Client - Node " + this.props.node.ID} onClose={this.props.onClose} initialSize={{width: 600, height: 400}}>
<div className="Client">
<div>{dealMaker}</div>
<div>{deals}</div>
let deals = this.state.deals.map((deal, i) => (
<div key={i}>
<ul>
<li>
{i}. Proposal: {deal.ProposalCid['/'].substr(0, 18)}...{' '}
<Address
nobalance={true}
client={this.props.client}
addr={deal.Provider}
mountWindow={this.props.mountWindow}
/>
: <b>{dealStates[deal.State]}</b>
{dealStates[deal.State] === 'Complete' ? (
<span>
&nbsp;
<a href="#" onClick={this.retrieve(deal)}>
[Retrieve]
</a>
</span>
) : (
<span />
)}
<ul>
<li>
Data: {deal.PieceRef['/']}, <b>{deal.Size}</b>B; Duration:{' '}
<b>{deal.Duration}</b>Blocks
</li>
<li>
Total: <b>{deal.TotalPrice}</b>FIL; Per Block:{' '}
<b>
{Math.round((deal.TotalPrice / deal.Duration) * 100) / 100}
</b>
FIL; PerMbyteByteBlock:{' '}
<b>
{Math.round(
(deal.TotalPrice / deal.Duration / (deal.Size / 1000000)) *
100
) / 100}
</b>
FIL
</li>
</ul>
</li>
</ul>
</div>
</Window>
))
return (
<Window
title={'Client - Node ' + this.props.node.ID}
onClose={this.props.onClose}
initialSize={{ width: 600, height: 400 }}
>
<div className="Client">
<div>{dealMaker}</div>
<div>{deals}</div>
</div>
</Window>
)
}
}