deals: Ask prices per GiB

This commit is contained in:
Łukasz Magiera 2019-10-29 11:19:39 +01:00
parent 72af55d067
commit 738e8c5a3c
6 changed files with 11 additions and 8 deletions

View File

@ -109,7 +109,7 @@ func NewProvider(ds dtypes.MetadataDS, secst *sectorblocks.SectorBlocks, commt *
if h.ask == nil { if h.ask == nil {
// TODO: we should be fine with this state, and just say it means 'not actively accepting deals' // TODO: we should be fine with this state, and just say it means 'not actively accepting deals'
// for now... lets just set a price // for now... lets just set a price
if err := h.SetPrice(types.NewInt(3), 1000000); err != nil { if err := h.SetPrice(types.NewInt(500_000_000), 1000000); err != nil {
return nil, xerrors.Errorf("failed setting a default price: %w", err) return nil, xerrors.Errorf("failed setting a default price: %w", err)
} }
} }

View File

@ -88,7 +88,7 @@ func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal)
// TODO: check StorageCollateral // TODO: check StorageCollateral
// TODO: // TODO:
minPrice := types.BigMul(p.ask.Ask.Price, types.NewInt(deal.Proposal.PieceSize)) minPrice := types.BigDiv(types.BigMul(p.ask.Ask.Price, types.NewInt(deal.Proposal.PieceSize)), types.NewInt(1 << 30))
if deal.Proposal.StoragePricePerEpoch.LessThan(minPrice) { if deal.Proposal.StoragePricePerEpoch.LessThan(minPrice) {
return nil, xerrors.Errorf("storage price per epoch less than asking price: %s < %s", deal.Proposal.StoragePricePerEpoch, minPrice) return nil, xerrors.Errorf("storage price per epoch less than asking price: %s < %s", deal.Proposal.StoragePricePerEpoch, minPrice)
} }

View File

@ -16,7 +16,9 @@ type SignedStorageAsk struct {
} }
type StorageAsk struct { type StorageAsk struct {
// Price per GiB / Epoch
Price BigInt Price BigInt
MinPieceSize uint64 MinPieceSize uint64
Miner address.Address Miner address.Address
Timestamp uint64 Timestamp uint64

View File

@ -314,13 +314,14 @@ var clientQueryAskCmd = &cli.Command{
if size == 0 { if size == 0 {
return nil return nil
} }
fmt.Printf("Price per Block: %s\n", types.BigMul(ask.Ask.Price, types.NewInt(uint64(size)))) perEpoch := types.BigDiv(types.BigMul(ask.Ask.Price, types.NewInt(uint64(size))), types.NewInt(1<<30))
fmt.Printf("Price per Block: %s\n", perEpoch)
duration := cctx.Int64("duration") duration := cctx.Int64("duration")
if duration == 0 { if duration == 0 {
return nil return nil
} }
fmt.Printf("Total Price: %s\n", types.BigMul(types.BigMul(ask.Ask.Price, types.NewInt(uint64(size))), types.NewInt(uint64(duration)))) fmt.Printf("Total Price: %s\n", types.BigMul(perEpoch, types.NewInt(uint64(duration))))
return nil return nil
}, },

View File

@ -21,7 +21,7 @@ class Client extends React.Component {
this.state = { this.state = {
miners: ["t0101"], miners: ["t0101"],
ask: {Price: "3"}, ask: {Price: "500000000"},
kbs: 1, kbs: 1,
blocks: 12, blocks: 12,
@ -52,7 +52,7 @@ class Client extends React.Component {
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 let perBlk = this.state.ask.Price * this.state.kbs * 1000 / (1 << 30)
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])

View File

@ -123,10 +123,10 @@ class MarketState extends React.Component {
{Object.keys(this.state.deals).map(d => <tr> {Object.keys(this.state.deals).map(d => <tr>
<td>{d}</td> <td>{d}</td>
<td>{this.state.deals[d].ActivationEpoch || "No"}</td> <td>{this.state.deals[d].ActivationEpoch || "No"}</td>
<td><Address short={true} addr={this.state.deals[d].Deal.Proposal.Provider} client={this.props.client} mountWindow={this.props.mountWindow}/></td>
<td><Address short={true} addr={this.state.deals[d].Deal.Proposal.Client} client={this.props.client} mountWindow={this.props.mountWindow}/></td> <td><Address short={true} addr={this.state.deals[d].Deal.Proposal.Client} client={this.props.client} mountWindow={this.props.mountWindow}/></td>
<td><Address short={true} addr={this.state.deals[d].Deal.Proposal.Provider} client={this.props.client} mountWindow={this.props.mountWindow}/></td>
<td>{this.state.deals[d].Deal.Proposal.PieceSize}B</td> <td>{this.state.deals[d].Deal.Proposal.PieceSize}B</td>
<td>{this.state.deals[d].Deal.Proposal.StoragePrice}</td> <td>{this.state.deals[d].Deal.Proposal.StoragePricePerEpoch*this.state.deals[d].Deal.Proposal.Duration}</td>
<td>{this.state.deals[d].Deal.Proposal.Duration}</td> <td>{this.state.deals[d].Deal.Proposal.Duration}</td>
</tr>)} </tr>)}
</table> </table>