fix(dealstate): update deal states to match current
This commit is contained in:
parent
17a4a99f9c
commit
b8077fadaa
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"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/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
@ -153,7 +154,7 @@ type Import struct {
|
|||||||
|
|
||||||
type DealInfo struct {
|
type DealInfo struct {
|
||||||
ProposalCid cid.Cid
|
ProposalCid cid.Cid
|
||||||
State DealState
|
State storagemarket.StorageDealStatus
|
||||||
Provider address.Address
|
Provider address.Address
|
||||||
|
|
||||||
PieceRef []byte // cid bytes
|
PieceRef []byte // cid bytes
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
logging "github.com/ipfs/go-log/v2"
|
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/build"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/node/impl"
|
"github.com/filecoin-project/lotus/node/impl"
|
||||||
@ -88,17 +88,17 @@ loop:
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
switch di.State {
|
switch di.State {
|
||||||
case api.DealRejected:
|
case storagemarket.StorageDealProposalRejected:
|
||||||
t.Fatal("deal rejected")
|
t.Fatal("deal rejected")
|
||||||
case api.DealFailed:
|
case storagemarket.StorageDealFailing:
|
||||||
t.Fatal("deal failed")
|
t.Fatal("deal failed")
|
||||||
case api.DealError:
|
case storagemarket.StorageDealError:
|
||||||
t.Fatal("deal errored")
|
t.Fatal("deal errored")
|
||||||
case api.DealComplete:
|
case storagemarket.StorageDealActive:
|
||||||
fmt.Println("COMPLETE", di)
|
fmt.Println("COMPLETE", di)
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
fmt.Println("Deal state: ", api.DealStates[di.State])
|
fmt.Println("Deal state: ", storagemarket.DealStates[di.State])
|
||||||
time.Sleep(time.Second / 2)
|
time.Sleep(time.Second / 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
api/types.go
30
api/types.go
@ -6,36 +6,6 @@ import (
|
|||||||
ma "github.com/multiformats/go-multiaddr"
|
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
|
// TODO: check if this exists anywhere else
|
||||||
type MultiaddrSlice []ma.Multiaddr
|
type MultiaddrSlice []ma.Multiaddr
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"gopkg.in/urfave/cli.v2"
|
"gopkg.in/urfave/cli.v2"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"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"
|
actors "github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
@ -359,7 +359,7 @@ var clientListDeals = &cli.Command{
|
|||||||
w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
||||||
fmt.Fprintf(w, "DealCid\tProvider\tState\tPieceRef\tSize\tPrice\tDuration\n")
|
fmt.Fprintf(w, "DealCid\tProvider\tState\tPieceRef\tSize\tPrice\tDuration\n")
|
||||||
for _, d := range deals {
|
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()
|
return w.Flush()
|
||||||
},
|
},
|
||||||
|
@ -293,7 +293,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
|
|||||||
MinerDeal: storagemarket.MinerDeal{
|
MinerDeal: storagemarket.MinerDeal{
|
||||||
Proposal: *proposal,
|
Proposal: *proposal,
|
||||||
ProposalCid: proposalCid,
|
ProposalCid: proposalCid,
|
||||||
State: lapi.DealComplete,
|
State: storagemarket.StorageDealActive,
|
||||||
Ref: proposalCid, // TODO: This is super wrong, but there
|
Ref: proposalCid, // TODO: This is super wrong, but there
|
||||||
// are no params for CommP CIDs, we can't recover unixfs cid easily,
|
// 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
|
// and this isn't even used after the deal enters Complete state
|
||||||
|
@ -1,68 +1,92 @@
|
|||||||
import React from 'react';
|
import React from 'react'
|
||||||
import Address from "./Address";
|
import Address from './Address'
|
||||||
import Window from "./Window";
|
import Window from './Window'
|
||||||
import Fil from "./Fil";
|
import Fil from './Fil'
|
||||||
|
|
||||||
const dealStates = [
|
const dealStates = [
|
||||||
"Unknown",
|
'Unknown',
|
||||||
"Rejected",
|
'ProposalNotFound',
|
||||||
"Accepted",
|
'ProposalRejected',
|
||||||
"Staged",
|
'ProposalAccepted',
|
||||||
"Sealing",
|
'Staged',
|
||||||
"Failed",
|
'Sealing',
|
||||||
"Complete",
|
'ProposalSigned',
|
||||||
"Error",
|
'Published',
|
||||||
]
|
'Committed',
|
||||||
|
'Active',
|
||||||
|
'Failing',
|
||||||
|
'Recovering',
|
||||||
|
'Expired',
|
||||||
|
'NotFound',
|
||||||
|
|
||||||
|
'Validating',
|
||||||
|
'Transferring',
|
||||||
|
'VerifyData',
|
||||||
|
'Publishing',
|
||||||
|
'Error'
|
||||||
|
]
|
||||||
|
|
||||||
class Client extends React.Component {
|
class Client extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
miners: ["t0101"],
|
miners: ['t0101'],
|
||||||
ask: {Price: "1000000000"}, // 2x min default ask to account for bin packing (could also do the math correctly below, but..)
|
ask: { Price: '1000000000' }, // 2x min default ask to account for bin packing (could also do the math correctly below, but..)
|
||||||
|
|
||||||
kbs: 1,
|
kbs: 1,
|
||||||
blocks: 12,
|
blocks: 12,
|
||||||
total: 36000,
|
total: 36000,
|
||||||
miner: "t0101",
|
miner: 't0101',
|
||||||
|
|
||||||
deals: [],
|
deals: [],
|
||||||
|
|
||||||
blockDelay: 10,
|
blockDelay: 10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
let ver = await this.props.client.call('Filecoin.Version', [])
|
let ver = await this.props.client.call('Filecoin.Version', [])
|
||||||
this.setState({blockDelay: ver.BlockDelay})
|
this.setState({ blockDelay: ver.BlockDelay })
|
||||||
|
|
||||||
this.getDeals()
|
this.getDeals()
|
||||||
setInterval(this.getDeals, 1325)
|
setInterval(this.getDeals, 1325)
|
||||||
}
|
}
|
||||||
|
|
||||||
getDeals = async () => {
|
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', [])
|
let deals = await this.props.client.call('Filecoin.ClientListDeals', [])
|
||||||
miners.sort()
|
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 () => {
|
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 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)])
|
let dealcid = await this.props.client.call('Filecoin.ClientStartDeal', [
|
||||||
console.log("deal cid: ", dealcid)
|
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)
|
console.log(deal)
|
||||||
let client = await this.props.client.call('Filecoin.WalletDefaultAddress', [])
|
let client = await this.props.client.call(
|
||||||
|
'Filecoin.WalletDefaultAddress',
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
let order = {
|
let order = {
|
||||||
Root: deal.PieceRef,
|
Root: deal.PieceRef,
|
||||||
@ -74,7 +98,10 @@ class Client extends React.Component {
|
|||||||
Miner: deal.Miner
|
Miner: deal.Miner
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.props.client.call('Filecoin.ClientRetrieve', [order, '/dev/null'])
|
await this.props.client.call('Filecoin.ClientRetrieve', [
|
||||||
|
order,
|
||||||
|
'/dev/null'
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -82,41 +109,111 @@ class Client extends React.Component {
|
|||||||
let total = perBlk * this.state.blocks
|
let total = perBlk * this.state.blocks
|
||||||
let days = (this.state.blocks * this.state.blockDelay) / 60 / 60 / 24
|
let days = (this.state.blocks * this.state.blockDelay) / 60 / 60 / 24
|
||||||
|
|
||||||
let dealMaker = <div hidden={!this.props.pondClient}>
|
let dealMaker = (
|
||||||
<div>
|
<div hidden={!this.props.pondClient}>
|
||||||
<span>Make Deal: </span>
|
<div>
|
||||||
<select>{this.state.miners.map(m => <option key={m} value={m}>{m}</option>)}</select>
|
<span>Make Deal: </span>
|
||||||
<span> Ask: <b><Fil>{this.state.ask.Price}</Fil></b> Fil/Byte/Block</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>
|
||||||
<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}>
|
let deals = this.state.deals.map((deal, i) => (
|
||||||
<ul>
|
<div key={i}>
|
||||||
<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>
|
<ul>
|
||||||
{dealStates[deal.State] === 'Complete' ? <span> <a href="#" onClick={this.retrieve(deal)}>[Retrieve]</a></span> : <span/> }
|
<li>
|
||||||
<ul>
|
{i}. Proposal: {deal.ProposalCid['/'].substr(0, 18)}...{' '}
|
||||||
<li>Data: {deal.PieceRef['/']}, <b>{deal.Size}</b>B; Duration: <b>{deal.Duration}</b>Blocks</li>
|
<Address
|
||||||
<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>
|
nobalance={true}
|
||||||
</ul>
|
client={this.props.client}
|
||||||
</li>
|
addr={deal.Provider}
|
||||||
</ul>
|
mountWindow={this.props.mountWindow}
|
||||||
|
/>
|
||||||
</div>)
|
: <b>{dealStates[deal.State]}</b>
|
||||||
|
{dealStates[deal.State] === 'Complete' ? (
|
||||||
return <Window title={"Client - Node " + this.props.node.ID} onClose={this.props.onClose} initialSize={{width: 600, height: 400}}>
|
<span>
|
||||||
<div className="Client">
|
|
||||||
<div>{dealMaker}</div>
|
<a href="#" onClick={this.retrieve(deal)}>
|
||||||
<div>{deals}</div>
|
[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>
|
</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>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user