Skip to content
This repository was archived by the owner on Aug 23, 2021. It is now read-only.

Adds endpoint for proposing a storage deal #68

Merged

Conversation

hazmatzo
Copy link
Contributor

@hazmatzo hazmatzo commented Aug 7, 2019

Adds the ability to propose a storage deal

Issue #15

Endpoint
/api/client/propose-storage-deal

Description
Propose a storage deal with a storage miner

Arguments

  • arg [string]: Address of miner to send storage proposal Required: yes.
  • arg [string]: CID of the data to be stored Required: yes.
  • arg [string]: ID of ask for which to propose a deal Required: yes.
  • arg [string]: Time in blocks (about 30 seconds per block) to store data Required: yes.
  • allow-duplicates [bool]: Allows duplicate proposals to be created. Unless this flag is set, you will not be able to make more than one deal per piece per miner. This protection exists to prevent erroneous duplicate deals. Required: no.

Response
On success, the call to this endpoint will return with 200 and the following body:

{
  "State":7,
  "Message":"",
  "ProposalCid":
    {
      "/":"zDPWYqFD8CNXu7Mo9qPSUANbTK2vi9vJBnvavF9S1pVGPHafVHpT"
    },
  "ProofInfo":
    {
      "SectorID":1,
      "CommitmentMessage":
        {
          "/":"zDPWYqFCtHkWNkE2p6t6TeV1sPP5kbnKc5ajUhMVV8xvrw1u5F1R"
        },
      "PieceInclusionProof":"EiAbbOy4pChsCYqFYA6qJaUJYStlnwYMdQPHZX7YBkVXDD6vgmGTPnWrcdA9M0oAXQCzOq735YKySLUoTI6pAw=="
    },
  "Signature":"c2lnbmF0dXJycmVlZQ=="
}

resolves #15

@hazmatzo hazmatzo force-pushed the api/client/propose-storage-deal branch 2 times, most recently from 8ea3833 to 365df8b Compare August 7, 2019 21:18
"Signature":"c2lnbmF0dXJycmVlZQ=="
}
*/
```
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I got back locally when I ran it. This somewhat differs from what I expected, honestly, but I represented what is currently returning from go-filecoin.

API.md Outdated
const storageDealProposal = await fc.client.proposeStorageDeal(miner, cid, askId, time, { allowDuplicates: true })

// with allow duplicates flag and options, order important
const storageDealProposal = await fc.client.proposeStorageDeal(miner, cid, askId, time, { allowDuplicates: true }, { signal: "some signal to abort" })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my proposal for how to handle all the arguments and also options on our end. If you use the go-filecoin command line, it ends up being and optional flag like so: --allow-duplicates. If you'd like a different interface, let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In existing endpoints both options are bundled together e.g. { allowDuplicates, signal }. I think this is best for simplicity (and consistency) and we'll deal with a collision if/when it happens.

@hazmatzo
Copy link
Contributor Author

hazmatzo commented Aug 7, 2019

@alanshaw This is the propose storage deal one, let me know if you have questions.

@mishmosh mishmosh requested a review from alanshaw August 7, 2019 21:27
API.md Outdated
| cid | `String` | CID of the data to be stored |
| id | `String` | ID of ask for which to propose a deal |
| time | `String` | Time in blocks (about 30 seconds per block) to store data. For example, storing for 1 day (2 blocks/min * 60 min/hr * 24 hr/day) = 2880 blocks. |
| allowDuplicates | `Boolean` | Allows duplicate proposals to be created. Unless this flag is set, you will not be able to make more than one deal per piece per miner. This protection exists to prevent erroneous duplicate deals. This parameter is not required. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be options.allowDuplicates

Copy link
Contributor Author

@hazmatzo hazmatzo Aug 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for the clarifying.

API.md Outdated
const storageDealProposal = await fc.client.proposeStorageDeal(miner, cid, askId, time, { allowDuplicates: true })

// with allow duplicates flag and options, order important
const storageDealProposal = await fc.client.proposeStorageDeal(miner, cid, askId, time, { allowDuplicates: true }, { signal: "some signal to abort" })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In existing endpoints both options are bundled together e.g. { allowDuplicates, signal }. I think this is best for simplicity (and consistency) and we'll deal with a collision if/when it happens.

},
"ProofInfo":null,
"Signature":"c2lnbmF0dXJycmVlZQ=="
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use toCamel utility on this response to be more idiomatic for JS users.


const duplicatesParam = allowDuplicates ? `&allow-duplicates=${encodeURIComponent(allowDuplicates)}` : ""

const url = `${toUri(config.apiAddr)}/api/client/proposeStorageDeal?arg=${miner}&arg=${cid}&arg${askId}&arg${time}${duplicatesParam}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the querystring module to stringify an object when multiple params. Please check other endpoints for examples.

* /api/client/propose-storage-deal

Propose a storage deal with a storage miner

Arguments
* arg [string]: Address of miner to send storage proposal Required: yes.
* arg [string]: CID of the data to be stored Required: yes.
* arg [string]: ID of ask for which to propose a deal Required: yes.
* arg [string]: Time in blocks (about 30 seconds per block) to store data Required: yes.
* allow-duplicates [bool]: Allows duplicate proposals to be created. Unless this flag is set, you will not be able to make more than one deal per piece per miner. This protection exists to prevent erroneous duplicate deals. Required: no.

Response
On success, the call to this endpoint will return with 200 and the following body:

{
  "State":7,
  "Message":"",
  "ProposalCid":
    {
      "/":"zDPWYqFD8CNXu7Mo9qPSUANbTK2vi9vJBnvavF9S1pVGPHafVHpT"
    },
  "ProofInfo":
    {
      "SectorID":1,
      "CommitmentMessage":
        {
          "/":"zDPWYqFCtHkWNkE2p6t6TeV1sPP5kbnKc5ajUhMVV8xvrw1u5F1R"
        },
      "PieceInclusionProof":"EiAbbOy4pChsCYqFYA6qJaUJYStlnwYMdQPHZX7YBkVXDD6vgmGTPnWrcdA9M0oAXQCzOq735YKySLUoTI6pAw=="
    },
  "Signature":"c2lnbmF0dXJycmVlZQ=="
}
@hazmatzo hazmatzo force-pushed the api/client/propose-storage-deal branch 2 times, most recently from b60479e to e69f5d8 Compare August 9, 2019 21:35
* The thought here being this is more idiomatic for JS users
* Updates params with querystring
@hazmatzo hazmatzo force-pushed the api/client/propose-storage-deal branch from bb3fd7b to 6628693 Compare August 9, 2019 22:37
@hazmatzo
Copy link
Contributor Author

hazmatzo commented Aug 9, 2019

@alanshaw

Updated! Let me know if there's anything else.

@alanshaw alanshaw merged commit 3826029 into filecoin-shipyard:master Aug 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add command client.proposeStorageDeal
2 participants