generated from Warchant/cmake-hunter-seed
-
Notifications
You must be signed in to change notification settings - Fork 36
Storage market protocols versions 1.1.0 #505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Alexey-N-Chernyshov
merged 16 commits into
master
from
feature/check-signature-on-storage-deal-status
Dec 4, 2021
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d604f2c
deal protocols versions 1.1.1 added
Alexey-N-Chernyshov dd89f21
Merge branch 'master' into feature/check-signature-on-storage-deal-st…
Alexey-N-Chernyshov 8a288f5
named ask protocol
Alexey-N-Chernyshov 6dd3c31
deal status protocol with OOP
Alexey-N-Chernyshov 43ef36d
deal protocols versions 1.1.0 - WiP
Alexey-N-Chernyshov 936285b
deal status protocol
Alexey-N-Chernyshov 1af24ca
fix stored_ask
Alexey-N-Chernyshov 1bc4381
Merge branch 'master' into feature/check-signature-on-storage-deal-st…
Alexey-N-Chernyshov 5a3de1f
add version display based on `git describe` command to command line, …
Alexey-N-Chernyshov 9f6e387
remove map reencoding
Alexey-N-Chernyshov 4bb8a68
Merge branch 'master' into feature/check-signature-on-storage-deal-st…
Alexey-N-Chernyshov 0519b3d
respect cbor map order
Alexey-N-Chernyshov e42c8d0
fixed old protocol and tests added
Alexey-N-Chernyshov 2a15302
pr fixes
Alexey-N-Chernyshov cec0f8f
Merge branch 'master' into feature/check-signature-on-storage-deal-st…
Alexey-N-Chernyshov b964107
Merge branch 'master' into feature/check-signature-on-storage-deal-st…
Alexey-N-Chernyshov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,6 +6,7 @@ | |||||||||||
#pragma once | ||||||||||||
|
||||||||||||
#include <libp2p/peer/protocol.hpp> | ||||||||||||
#include "codec/cbor/cbor_codec.hpp" | ||||||||||||
#include "codec/cbor/streams_annotation.hpp" | ||||||||||||
#include "crypto/signature/signature.hpp" | ||||||||||||
#include "primitives/address/address.hpp" | ||||||||||||
|
@@ -15,29 +16,39 @@ | |||||||||||
#include "primitives/types.hpp" | ||||||||||||
|
||||||||||||
namespace fc::markets::storage { | ||||||||||||
|
||||||||||||
using codec::cbor::CborDecodeStream; | ||||||||||||
using codec::cbor::CborEncodeStream; | ||||||||||||
using crypto::signature::Signature; | ||||||||||||
using primitives::ChainEpoch; | ||||||||||||
using primitives::TokenAmount; | ||||||||||||
using primitives::address::Address; | ||||||||||||
using primitives::piece::PaddedPieceSize; | ||||||||||||
|
||||||||||||
const libp2p::peer::Protocol kAskProtocolId0 = "/fil/storage/ask/1.0.1"; | ||||||||||||
const libp2p::peer::Protocol kAskProtocolId = "/fil/storage/ask/1.1.1"; | ||||||||||||
const libp2p::peer::Protocol kAskProtocolId_v1_0_1 = "/fil/storage/ask/1.0.1"; | ||||||||||||
|
||||||||||||
/** Protocol 1.1.1 uses named cbor */ | ||||||||||||
const libp2p::peer::Protocol kAskProtocolId_v1_1_0 = "/fil/storage/ask/1.1.0"; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* StorageAsk defines the parameters by which a miner will choose to accept or | ||||||||||||
* reject a deal. | ||||||||||||
*/ | ||||||||||||
struct StorageAsk { | ||||||||||||
// Price per GiB / Epoch | ||||||||||||
TokenAmount price; | ||||||||||||
TokenAmount verified_price; | ||||||||||||
PaddedPieceSize min_piece_size; | ||||||||||||
PaddedPieceSize max_piece_size; | ||||||||||||
Address miner; | ||||||||||||
ChainEpoch timestamp; | ||||||||||||
ChainEpoch expiry; | ||||||||||||
uint64_t seq_no; | ||||||||||||
ChainEpoch timestamp{}; | ||||||||||||
ChainEpoch expiry{}; | ||||||||||||
uint64_t seq_no{}; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
CBOR_TUPLE(StorageAsk, | ||||||||||||
/** StorageAsk used in V1.0.1 */ | ||||||||||||
struct StorageAskV1_0_1 : public StorageAsk {}; | ||||||||||||
|
||||||||||||
CBOR_TUPLE(StorageAskV1_0_1, | ||||||||||||
price, | ||||||||||||
verified_price, | ||||||||||||
min_piece_size, | ||||||||||||
|
@@ -47,12 +58,101 @@ namespace fc::markets::storage { | |||||||||||
expiry, | ||||||||||||
seq_no) | ||||||||||||
|
||||||||||||
/** StorageAsk used in V1.1.0. Cbores with field names. */ | ||||||||||||
struct StorageAskV1_1_0 : public StorageAsk {}; | ||||||||||||
|
||||||||||||
inline CBOR2_ENCODE(StorageAskV1_1_0) { | ||||||||||||
auto m{CborEncodeStream::orderedMap()}; | ||||||||||||
m["Price"] << v.price; | ||||||||||||
m["VerifiedPrice"] << v.verified_price; | ||||||||||||
m["MinPieceSize"] << v.min_piece_size; | ||||||||||||
m["MaxPieceSize"] << v.max_piece_size; | ||||||||||||
m["Miner"] << v.miner; | ||||||||||||
m["Timestamp"] << v.timestamp; | ||||||||||||
m["Expiry"] << v.expiry; | ||||||||||||
m["SeqNo"] << v.seq_no; | ||||||||||||
return s << m; | ||||||||||||
} | ||||||||||||
|
||||||||||||
inline CBOR2_DECODE(StorageAskV1_1_0) { | ||||||||||||
auto m{s.map()}; | ||||||||||||
CborDecodeStream::named(m, "Price") >> v.price; | ||||||||||||
CborDecodeStream::named(m, "VerifiedPrice") >> v.verified_price; | ||||||||||||
CborDecodeStream::named(m, "MinPieceSize") >> v.min_piece_size; | ||||||||||||
CborDecodeStream::named(m, "MaxPieceSize") >> v.max_piece_size; | ||||||||||||
CborDecodeStream::named(m, "Miner") >> v.miner; | ||||||||||||
CborDecodeStream::named(m, "Timestamp") >> v.timestamp; | ||||||||||||
CborDecodeStream::named(m, "Expiry") >> v.expiry; | ||||||||||||
CborDecodeStream::named(m, "SeqNo") >> v.seq_no; | ||||||||||||
return s; | ||||||||||||
} | ||||||||||||
|
||||||||||||
struct SignedStorageAsk { | ||||||||||||
virtual ~SignedStorageAsk() = default; | ||||||||||||
|
||||||||||||
StorageAsk ask; | ||||||||||||
Signature signature; | ||||||||||||
|
||||||||||||
/** Returns response digset */ | ||||||||||||
virtual outcome::result<Bytes> getDigest() const = 0; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
CBOR_TUPLE(SignedStorageAsk, ask, signature) | ||||||||||||
/** SignedStorageAsk used in V1.0.1 */ | ||||||||||||
struct SignedStorageAskV1_0_1 : public SignedStorageAsk { | ||||||||||||
SignedStorageAskV1_0_1() = default; | ||||||||||||
explicit SignedStorageAskV1_0_1(StorageAsk ask) { | ||||||||||||
this->ask = std::move(ask); | ||||||||||||
} | ||||||||||||
SignedStorageAskV1_0_1(StorageAsk ask, Signature signature) { | ||||||||||||
this->ask = std::move(ask); | ||||||||||||
this->signature = std::move(signature); | ||||||||||||
} | ||||||||||||
|
||||||||||||
outcome::result<Bytes> getDigest() const override { | ||||||||||||
return codec::cbor::encode(StorageAskV1_0_1{this->ask}); | ||||||||||||
}; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
inline CBOR2_ENCODE(SignedStorageAskV1_0_1) { | ||||||||||||
return s << (CborEncodeStream::list() | ||||||||||||
<< StorageAskV1_0_1{v.ask} << v.signature); | ||||||||||||
} | ||||||||||||
inline CBOR2_DECODE(SignedStorageAskV1_0_1) { | ||||||||||||
auto cbor_list{s.list()}; | ||||||||||||
v.ask = cbor_list.get<StorageAskV1_0_1>(); | ||||||||||||
cbor_list >> v.signature; | ||||||||||||
return s; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** SignedStorageAsk used in V1.1.0 with named fields. */ | ||||||||||||
struct SignedStorageAskV1_1_0 : public SignedStorageAsk { | ||||||||||||
SignedStorageAskV1_1_0() = default; | ||||||||||||
explicit SignedStorageAskV1_1_0(StorageAsk ask) { | ||||||||||||
this->ask = std::move(ask); | ||||||||||||
} | ||||||||||||
SignedStorageAskV1_1_0(StorageAsk ask, Signature signature) { | ||||||||||||
this->ask = std::move(ask); | ||||||||||||
this->signature = std::move(signature); | ||||||||||||
} | ||||||||||||
|
||||||||||||
outcome::result<Bytes> getDigest() const override { | ||||||||||||
return codec::cbor::encode(StorageAskV1_1_0{this->ask}); | ||||||||||||
turuslan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
}; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
inline CBOR2_ENCODE(SignedStorageAskV1_1_0) { | ||||||||||||
auto m{CborEncodeStream::orderedMap()}; | ||||||||||||
m["Ask"] << StorageAskV1_1_0{v.ask}; | ||||||||||||
turuslan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
m["Signature"] << v.signature; | ||||||||||||
return s << m; | ||||||||||||
} | ||||||||||||
|
||||||||||||
inline CBOR2_DECODE(SignedStorageAskV1_1_0) { | ||||||||||||
auto m{s.map()}; | ||||||||||||
v.ask = CborDecodeStream::named(m, "Ask").get<StorageAskV1_1_0>(); | ||||||||||||
CborDecodeStream::named(m, "Signature") >> v.signature; | ||||||||||||
return s; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* AskRequest is a request for current ask parameters for a given miner | ||||||||||||
|
@@ -61,16 +161,95 @@ namespace fc::markets::storage { | |||||||||||
Address miner; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
CBOR_TUPLE(AskRequest, miner) | ||||||||||||
/** AskRequest used in V1.0.1 */ | ||||||||||||
struct AskRequestV1_0_1 : public AskRequest {}; | ||||||||||||
|
||||||||||||
CBOR_TUPLE(AskRequestV1_0_1, miner) | ||||||||||||
|
||||||||||||
/** AskRequest used in V1.1.0. Cbores with field names. */ | ||||||||||||
struct AskRequestV1_1_0 : public AskRequest {}; | ||||||||||||
|
||||||||||||
inline CBOR2_ENCODE(AskRequestV1_1_0) { | ||||||||||||
auto m{CborEncodeStream::orderedMap()}; | ||||||||||||
m["Miner"] << v.miner; | ||||||||||||
return s << m; | ||||||||||||
} | ||||||||||||
|
||||||||||||
inline CBOR2_DECODE(AskRequestV1_1_0) { | ||||||||||||
auto m{s.map()}; | ||||||||||||
CborDecodeStream::named(m, "Miner") >> v.miner; | ||||||||||||
return s; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* AskResponse is the response sent over the network in response to an ask | ||||||||||||
* request | ||||||||||||
*/ | ||||||||||||
struct AskResponse { | ||||||||||||
SignedStorageAsk ask; | ||||||||||||
virtual ~AskResponse() = default; | ||||||||||||
|
||||||||||||
virtual const SignedStorageAsk &ask() const = 0; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
struct AskResponseV1_0_1 : public AskResponse { | ||||||||||||
AskResponseV1_0_1() = default; | ||||||||||||
|
||||||||||||
explicit AskResponseV1_0_1(SignedStorageAskV1_0_1 ask) | ||||||||||||
: ask_(std::move(ask)) {} | ||||||||||||
|
||||||||||||
const SignedStorageAsk &ask() const override { | ||||||||||||
return ask_; | ||||||||||||
} | ||||||||||||
|
||||||||||||
private: | ||||||||||||
friend CborEncodeStream &operator<<(CborEncodeStream &, | ||||||||||||
const AskResponseV1_0_1 &); | ||||||||||||
friend CborDecodeStream &operator>>(CborDecodeStream &, | ||||||||||||
AskResponseV1_0_1 &); | ||||||||||||
Comment on lines
+204
to
+208
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
SignedStorageAskV1_0_1 ask_; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
CBOR_TUPLE(AskResponse, ask) | ||||||||||||
inline CBOR2_ENCODE(AskResponseV1_0_1) { | ||||||||||||
auto cbor_list = CborEncodeStream::list(); | ||||||||||||
cbor_list << v.ask_; | ||||||||||||
return s << cbor_list; | ||||||||||||
} | ||||||||||||
inline CBOR2_DECODE(AskResponseV1_0_1) { | ||||||||||||
auto cbor_list{s.list()}; | ||||||||||||
cbor_list >> v.ask_; | ||||||||||||
return s; | ||||||||||||
} | ||||||||||||
|
||||||||||||
struct AskResponseV1_1_0 : public AskResponse { | ||||||||||||
AskResponseV1_1_0() = default; | ||||||||||||
|
||||||||||||
explicit AskResponseV1_1_0(SignedStorageAskV1_1_0 ask) | ||||||||||||
: ask_(std::move(ask)) {} | ||||||||||||
|
||||||||||||
const SignedStorageAsk &ask() const override { | ||||||||||||
return ask_; | ||||||||||||
} | ||||||||||||
|
||||||||||||
private: | ||||||||||||
friend CborEncodeStream &operator<<(CborEncodeStream &, | ||||||||||||
const AskResponseV1_1_0 &); | ||||||||||||
friend CborDecodeStream &operator>>(CborDecodeStream &, | ||||||||||||
AskResponseV1_1_0 &); | ||||||||||||
Comment on lines
+234
to
+238
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
SignedStorageAskV1_1_0 ask_; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
inline CBOR2_ENCODE(AskResponseV1_1_0) { | ||||||||||||
auto m{CborEncodeStream::orderedMap()}; | ||||||||||||
m["Ask"] << v.ask_; | ||||||||||||
return s << m; | ||||||||||||
} | ||||||||||||
|
||||||||||||
inline CBOR2_DECODE(AskResponseV1_1_0) { | ||||||||||||
auto m{s.map()}; | ||||||||||||
CborDecodeStream::named(m, "Ask") >> v.ask_; | ||||||||||||
return s; | ||||||||||||
} | ||||||||||||
|
||||||||||||
} // namespace fc::markets::storage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "vm/actor/builtin/types/market/deal.hpp" | ||
|
||
namespace fc::markets::storage::client { | ||
using vm::actor::builtin::types::market::ClientDealProposal; | ||
|
||
/** Internal state of a deal on the client side. */ | ||
struct ClientDeal { | ||
ClientDealProposal client_deal_proposal; | ||
CID proposal_cid; | ||
boost::optional<CID> add_funds_cid; | ||
StorageDealStatus state; | ||
PeerInfo miner; | ||
Address miner_worker; | ||
DealId deal_id; | ||
DataRef data_ref; | ||
bool is_fast_retrieval; | ||
std::string message; | ||
CID publish_message; | ||
}; | ||
|
||
} // namespace fc::markets::storage::client |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.