Skip to content

Commit 399ec86

Browse files
authored
fix deals (#471)
Signed-off-by: turuslan <[email protected]>
1 parent df0aba8 commit 399ec86

File tree

20 files changed

+123
-100
lines changed

20 files changed

+123
-100
lines changed

core/api/full_node/make.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "primitives/tipset/chain.hpp"
2323
#include "proofs/impl/proof_engine_impl.hpp"
2424
#include "storage/car/car.hpp"
25+
#include "storage/unixfs/unixfs.hpp"
2526
#include "vm/actor/builtin/states/account/account_actor_state.hpp"
2627
#include "vm/actor/builtin/states/init/init_actor_state.hpp"
2728
#include "vm/actor/builtin/states/market/market_actor_state.hpp"
@@ -458,9 +459,6 @@ namespace fc::api {
458459
* Initiates the retrieval deal of a file in retrieval market.
459460
*/
460461
api->ClientRetrieve = [=](auto &&cb, auto order, auto &&file_ref) {
461-
if (!file_ref.is_car) {
462-
return cb(ERROR_TEXT("ClientRetrieve unixfs not implemented"));
463-
}
464462
if (order.size == 0) {
465463
return cb(ERROR_TEXT("Cannot make retrieval deal for zero bytes"));
466464
}
@@ -491,8 +489,14 @@ namespace fc::api {
491489
return cb(res.error());
492490
}
493491
logger->info("retrieval deal done");
494-
OUTCOME_CB1(storage::car::makeSelectiveCar(
495-
*markets_ipld, {{order.root, {}}}, file_ref.path));
492+
if (file_ref.is_car) {
493+
OUTCOME_CB1(storage::car::makeSelectiveCar(
494+
*markets_ipld, {{order.root, {}}}, file_ref.path));
495+
} else {
496+
std::ofstream file{file_ref.path};
497+
OUTCOME_CB1(
498+
storage::unixfs::unwrapFile(file, *markets_ipld, order.root));
499+
}
496500
cb(outcome::success());
497501
}));
498502
};

core/data_transfer/dt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace fc::data_transfer {
8181
push.on_begin = {};
8282
if (res.is_accepted) {
8383
storage::ipld::traverser::Traverser t{
84-
*push.ipld, req.root_cid, CborRaw{req.selector}};
84+
*push.ipld, req.root_cid, CborRaw{req.selector}, true};
8585
gsns::Response res{
8686
gsns::ResponseStatusCode::RS_FULL_CONTENT, {}, {}};
8787
if (auto _cids{t.traverseAll()}) {

core/markets/retrieval/client/impl/retrieval_client_impl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@
99
#include "common/libp2p/peer/peer_info_helper.hpp"
1010

1111
namespace fc::markets::retrieval::client {
12+
DealState::DealState(const DealProposal &proposal,
13+
const IpldPtr &ipld,
14+
const RetrieveResponseHandler &handler,
15+
const Address &client_wallet,
16+
const Address &miner_wallet,
17+
const TokenAmount &total_funds)
18+
: proposal{proposal},
19+
state{proposal.params},
20+
handler{handler},
21+
client_wallet{client_wallet},
22+
miner_wallet{miner_wallet},
23+
total_funds(total_funds),
24+
traverser{
25+
*ipld, proposal.payload_cid, proposal.params.selector, false} {}
1226

1327
RetrievalClientImpl::RetrievalClientImpl(
1428
std::shared_ptr<Host> host,

core/markets/retrieval/client/impl/retrieval_client_impl.hpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ namespace fc::markets::retrieval::client {
3838
const RetrieveResponseHandler &handler,
3939
const Address &client_wallet,
4040
const Address &miner_wallet,
41-
const TokenAmount &total_funds)
42-
: proposal{proposal},
43-
state{proposal.params},
44-
handler{handler},
45-
client_wallet{client_wallet},
46-
miner_wallet{miner_wallet},
47-
total_funds(total_funds),
48-
traverser{*ipld, proposal.payload_cid, proposal.params.selector} {}
41+
const TokenAmount &total_funds);
4942

5043
DealProposal proposal;
5144
State state;

core/markets/retrieval/provider/impl/retrieval_provider_impl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ namespace fc::markets::retrieval::provider {
191191
*deal->ipld,
192192
deal->proposal.payload_cid,
193193
deal->proposal.params.selector,
194+
false,
194195
});
195196
deal->unsealed = true;
196197
doBlocks(deal);

core/markets/storage/client/impl/storage_market_client_impl.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -336,39 +336,6 @@ namespace fc::markets::storage::client {
336336
return client_deal->proposal_cid;
337337
}
338338

339-
outcome::result<StorageParticipantBalance>
340-
StorageMarketClientImpl::getPaymentEscrow(const Address &address) const {
341-
OUTCOME_TRY(chain_head, api_->ChainHead());
342-
OUTCOME_TRY(balance, api_->StateMarketBalance(address, chain_head->key));
343-
return StorageParticipantBalance{balance.locked,
344-
balance.escrow - balance.locked};
345-
}
346-
347-
outcome::result<void> StorageMarketClientImpl::addPaymentEscrow(
348-
const Address &address, const TokenAmount &amount) {
349-
UnsignedMessage unsigned_message{
350-
kStorageMarketAddress,
351-
address,
352-
{},
353-
amount,
354-
kDefaultGasPrice,
355-
kDefaultGasLimit,
356-
vm::actor::builtin::v0::market::AddBalance::Number,
357-
{}};
358-
OUTCOME_TRY(signed_message,
359-
api_->MpoolPushMessage(unsigned_message, api::kPushNoSpec));
360-
// TODO: maybe async call, it's long
361-
OUTCOME_TRY(msg_state,
362-
api_->StateWaitMsg(signed_message.getCid(),
363-
kMessageConfidence,
364-
api::kLookbackNoLimit,
365-
true));
366-
if (msg_state.receipt.exit_code != VMExitCode::kOk) {
367-
return StorageMarketClientError::kAddFundsCallError;
368-
}
369-
return outcome::success();
370-
}
371-
372339
outcome::result<SignedStorageAsk>
373340
StorageMarketClientImpl::validateAskResponse(
374341
const outcome::result<AskResponse> &response,

core/markets/storage/client/impl/storage_market_client_impl.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ namespace fc::markets::storage::client {
8484
bool verified_deal,
8585
bool is_fast_retrieval) override;
8686

87-
outcome::result<StorageParticipantBalance> getPaymentEscrow(
88-
const Address &address) const override;
89-
90-
outcome::result<void> addPaymentEscrow(const Address &address,
91-
const TokenAmount &amount) override;
92-
9387
private:
9488
void askDealStatus(std::shared_ptr<ClientDeal> deal);
9589

core/markets/storage/client/import_manager/import_manager.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,30 @@ namespace fc::markets::storage::client::import_manager {
3030
outcome::result<CID> ImportManager::import(
3131
const boost::filesystem::path &path, bool is_car) {
3232
CID root;
33+
std::shared_ptr<MemoryIndexedCar> ipld;
34+
std::string tmp_path;
3335
if (is_car) {
34-
// validate CAR
35-
OUTCOME_TRY(ipld, MemoryIndexedCar::make(path.string(), false));
36+
OUTCOME_TRYA(ipld, MemoryIndexedCar::make(path.string(), false));
3637
if (ipld->roots.size() != 1) {
3738
return ERROR_TEXT(
3839
"StorageMarketImportManager: cannot import car with more that one "
3940
"root");
4041
}
4142
root = ipld->roots.front();
42-
OUTCOME_TRY(car_path, makeFilename(root));
43-
boost::filesystem::copy_file(
44-
path, car_path, boost::filesystem::copy_option::overwrite_if_exists);
45-
padPiece(car_path);
4643
} else {
47-
const auto tmp_path{path.string() + ".unixfs-tmp.car"};
48-
OUTCOME_TRY(ipld, MemoryIndexedCar::make(tmp_path, true));
44+
tmp_path = path.string() + ".unixfs-tmp.car";
45+
OUTCOME_TRYA(ipld, MemoryIndexedCar::make(tmp_path, true));
4946
std::ifstream file{path.string()};
5047
OUTCOME_TRYA(root, wrapFile(*ipld, file));
51-
OUTCOME_TRY(car_path, makeFilename(root));
52-
// add header with root and reorder objects
53-
OUTCOME_TRY(::fc::storage::car::makeSelectiveCar(
54-
*ipld, {{root, {}}}, car_path.string()));
48+
}
49+
OUTCOME_TRY(car_path, makeFilename(root));
50+
// add header with root and reorder objects
51+
OUTCOME_TRY(::fc::storage::car::makeSelectiveCar(
52+
*ipld, {{root, {}}}, car_path.string()));
53+
if (!tmp_path.empty()) {
5554
boost::filesystem::remove(tmp_path);
56-
padPiece(car_path);
5755
}
56+
padPiece(car_path);
5857
OUTCOME_TRY(addImported(root, path));
5958
return root;
6059
}

core/markets/storage/client/storage_market_client.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ namespace fc::markets::storage::client {
9696
const RegisteredSealProof &registered_proof,
9797
bool verified_deal,
9898
bool is_fast_retrieval) = 0;
99-
100-
virtual outcome::result<StorageParticipantBalance> getPaymentEscrow(
101-
const Address &address) const = 0;
102-
103-
virtual outcome::result<void> addPaymentEscrow(
104-
const Address &address, const TokenAmount &amount) = 0;
10599
};
106100

107101
} // namespace fc::markets::storage::client

core/node/graphsync_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace fc::sync {
2727
common::hex_lower(request.selector));
2828

2929
storage::ipld::traverser::Traverser traverser{
30-
ipld, request.root_cid, {request.selector}};
30+
ipld, request.root_cid, {request.selector}, true};
3131
auto ok{true};
3232
if (auto _cids{traverser.traverseAll()}) {
3333
for (auto &cid : _cids.value()) {

0 commit comments

Comments
 (0)