Skip to content

Commit 6135f02

Browse files
ElestriasMarkuu-s
authored andcommitted
ClientUpdates, DealStatus enum conversion
Signed-off-by: elestrias <[email protected]>
1 parent ed259f5 commit 6135f02

File tree

2 files changed

+116
-39
lines changed

2 files changed

+116
-39
lines changed

core/cli/node/client.hpp

Lines changed: 84 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#pragma once
55
#include <inttypes.h>
6+
#include "api/full_node/node_api.hpp"
67
#include "cli/node/node.hpp"
78
#include "markets/storage/mk_protocol.hpp"
89
#include "primitives/chain_epoch/chain_epoch.hpp"
@@ -14,12 +15,14 @@
1415
#include "vm/actor/actor.hpp"
1516
#include "vm/actor/builtin/states/verified_registry/verified_registry_actor_state.hpp"
1617
#include "vm/actor/builtin/v0/verified_registry/verified_registry_actor.hpp"
18+
#include "common/enum.hpp"
1719

1820
namespace fc::cli::_node {
1921
using api::FileRef;
2022
using api::FullNodeApi;
2123
using api::ImportRes;
2224
using api::RetrievalOrder;
25+
using api::StartDealParams;
2326
using boost::lexical_cast;
2427
using ::fc::storage::car::makeCar;
2528
using ::fc::storage::unixfs::wrapFile;
@@ -31,12 +34,13 @@ namespace fc::cli::_node {
3134
using primitives::piece::UnpaddedPieceSize;
3235
using proofs::padPiece;
3336
using storage::ipfs::ApiIpfsDatastore;
37+
using vm::VMExitCode;
3438
using vm::actor::kVerifiedRegistryAddress;
3539
using vm::actor::builtin::states::VerifiedRegistryActorStatePtr;
36-
using vm::VMExitCode;
37-
38-
const ChainEpoch kLoopback = 100; // TODO: lookback
40+
using markets::storage::StorageDealStatus;
41+
using common::toString;
3942

43+
const ChainEpoch kLoopback = 100; // TODO: lookback
4044

4145
StoragePower checkNotary(std::shared_ptr<FullNodeApi> api,
4246
const Address &vaddr) {
@@ -223,16 +227,42 @@ namespace fc::cli::_node {
223227
auto duration{cliArgv<ChainEpoch>(
224228
argv, 3, "is a period of storing the data for, in blocks")};
225229
Node::Api api{argm};
226-
if (duration < kMinDealDuration) throw CliError("Minimal deal duration is {}", kMinDealDuration);
227-
if (duration < kMaxDealDuration) throw CliError("Max deal duration is {}", kMaxDealDuration);
228-
230+
if (duration < kMinDealDuration)
231+
throw CliError("Minimal deal duration is {}", kMinDealDuration);
232+
if (duration < kMaxDealDuration)
233+
throw CliError("Max deal duration is {}", kMaxDealDuration);
234+
DataRef data_ref;
229235
Address address_from =
230236
args.from ? *args.from : cliTry(api._->WalletDefaultAddress());
231-
UnpaddedPieceSize piece_size{*args.man_piece_size};
232-
DataRef data_ref = {.transfer_type = "graphsync",
233-
.root = data_cid,
234-
.piece_cid = *args.man_piece_cid,
235-
.piece_size = piece_size};
237+
if (args.man_piece_cid) {
238+
UnpaddedPieceSize piece_size{*args.man_piece_size};
239+
data_ref = {.transfer_type = "manual",
240+
.root = data_cid,
241+
.piece_cid = *args.man_piece_cid,
242+
.piece_size = piece_size};
243+
} else {
244+
data_ref = {.transfer_type = "graphsync", .root = data_cid};
245+
}
246+
auto dcap =
247+
cliTry(api._->StateVerifiedClientStatus(address_from, TipsetKey()),
248+
"Failed to get status of {}",
249+
address_from);
250+
bool isVerified = dcap.has_value();
251+
if (args.verified_deal && !isVerified)
252+
throw CliError(
253+
"Cannot perform verified deal using unverified address {}",
254+
address_from);
255+
StartDealParams deal_params = {.data = data_ref,
256+
.wallet = address_from,
257+
.miner = miner,
258+
.epoch_price = price,
259+
.min_blocks_duration = duration,
260+
.deal_start_epoch = *args.start_epoch,
261+
.fast_retrieval = args.fast_ret,
262+
.verified_deal = isVerified,
263+
.provider_collateral = *args.collateral};
264+
auto proposal_cid = cliTry(api._->ClientStartDeal(deal_params));
265+
fmt::print("Deal proposal CID: {}\n", cliTry(proposal_cid.toString(), "Cannot extract CID"));
236266
}
237267
};
238268

@@ -363,6 +393,7 @@ namespace fc::cli::_node {
363393

364394
<<<<<<< HEAD
365395
<<<<<<< HEAD
396+
<<<<<<< HEAD
366397

367398

368399
<<<<<<< HEAD
@@ -377,6 +408,9 @@ namespace fc::cli::_node {
377408
=======
378409
struct Node_client_inspectDeal { //TODO: continue
379410
>>>>>>> 3d9435d6 (FFi+ and client updates)
411+
=======
412+
struct Node_client_inspectDeal { // TODO: continue
413+
>>>>>>> ad42f96d (ClientUpdates, DealStatus enum conversion)
380414
struct Args {
381415
CLI_OPTIONAL("proposal-cid", "proposal cid of deal to be inspected", CID)
382416
proposal_cid;
@@ -393,25 +427,33 @@ namespace fc::cli::_node {
393427
}
394428
};
395429

396-
struct Node_client_dealStats{
430+
struct Node_client_dealStats {
397431
struct Args {
398432
CLI_DEFAULT("newer-than",
399433
"list all deals stas that was made after given period",
400434
ChainEpoch,
401-
{0})newer;
402-
CLI_OPTS(){
435+
{0})
436+
newer;
437+
CLI_OPTS() {
403438
Opts opts;
404439
newer(opts);
405440
return opts;
406441
}
407442
};
408-
CLI_RUN(){
443+
CLI_RUN() {
409444
Node::Api api{argm};
410445
auto deals = cliTry(api._->ClientListDeals());
411-
for(const auto deal: deals){
412-
413-
}//TODO: Continue
414-
446+
uint64_t total_size{0};
447+
std::map<StorageDealStatus, uint64_t> by_state;
448+
for (const auto &deal : deals) {
449+
//TODO(@Elestrias): [FIL-615] Check Creation time and since-epoch flag
450+
total_size += deal.size;
451+
by_state[deal.state] += deal.size;
452+
}
453+
fmt::print("Total: {} deals, {}", deals.size(), total_size);
454+
for(const auto &[state, size]: by_state){
455+
fmt::print("Deal with status {} allocates {} bytes", toString(state), size);
456+
}
415457
}
416458
};
417459

@@ -545,10 +587,13 @@ namespace fc::cli::_node {
545587
encoded_params},
546588
api::kPushNoSpec));
547589

548-
fmt::print("message sent, now waiting on cid: {}", signed_message.getCid());
549-
auto mwait = cliTry(api._->StateWaitMsg(signed_message.getCid(), kMessageConfidence, kLoopback, false));
550-
if (mwait.receipt.exit_code != VMExitCode::kOk) throw CliError("failed to add verified client");
551-
fmt::print("Client {} was added successfully!", target);
590+
fmt::print("message sent, now waiting on cid: {}",
591+
signed_message.getCid());
592+
auto mwait = cliTry(api._->StateWaitMsg(
593+
signed_message.getCid(), kMessageConfidence, kLoopback, false));
594+
if (mwait.receipt.exit_code != VMExitCode::kOk)
595+
throw CliError("failed to add verified client");
596+
fmt::print("Client {} was added successfully!", target);
552597
}
553598
};
554599

@@ -562,8 +607,8 @@ namespace fc::cli::_node {
562607
}
563608
};
564609

565-
struct Node_client_listNotaries: Empty{
566-
CLI_RUN(){
610+
struct Node_client_listNotaries : Empty {
611+
CLI_RUN() {
567612
Node::Api api{argm};
568613
auto actor =
569614
cliTry(api._->StateGetActor(kVerifiedRegistryAddress, TipsetKey()),
@@ -574,16 +619,16 @@ namespace fc::cli::_node {
574619
auto state =
575620
cliTry(getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head));
576621

577-
cliTry(state->verifiers.visit([=](auto &key, auto &value)->outcome::result<void>{
578-
fmt::print("{}: {}", key, value);
579-
return outcome::success();
580-
}));
622+
cliTry(state->verifiers.visit(
623+
[=](auto &key, auto &value) -> outcome::result<void> {
624+
fmt::print("{}: {}", key, value);
625+
return outcome::success();
626+
}));
581627
}
582628
};
583629

584-
585-
struct Node_client_listClients: Empty{
586-
CLI_RUN(){
630+
struct Node_client_listClients : Empty {
631+
CLI_RUN() {
587632
Node::Api api{argm};
588633
auto actor =
589634
cliTry(api._->StateGetActor(kVerifiedRegistryAddress, TipsetKey()),
@@ -594,16 +639,16 @@ namespace fc::cli::_node {
594639
auto state =
595640
cliTry(getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head));
596641

597-
cliTry(state->verified_clients.visit([=](auto &key, auto &value)->outcome::result<void>{
598-
fmt::print("{}: {}", key, value);
599-
return outcome::success();
600-
}));
642+
cliTry(state->verified_clients.visit(
643+
[=](auto &key, auto &value) -> outcome::result<void> {
644+
fmt::print("{}: {}", key, value);
645+
return outcome::success();
646+
}));
601647
}
602648
};
603649

604-
605-
struct Node_client_checkNotaryDataCap: Empty{
606-
CLI_RUN(){
650+
struct Node_client_checkNotaryDataCap : Empty {
651+
CLI_RUN() {
607652
auto address{cliArgv<Address>(argv, 0, "address")};
608653
Node::Api api{argm};
609654
auto dcap = checkNotary(api._, address);

core/markets/storage/mk_protocol.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,38 @@ namespace fc::markets::storage {
135135
/** deal failed with an unexpected error */
136136
STORAGE_DEAL_ERROR,
137137
};
138+
inline auto &classConversionMap(StorageDealStatus &&) {
139+
using E = StorageDealStatus;
140+
static fc::common::ConversionTable<E, 26> table{{
141+
{E::STORAGE_DEAL_UNKNOWN, "Unknown"},
142+
{E::STORAGE_DEAL_PROPOSAL_NOT_FOUND, "NotFound"},
143+
{E::STORAGE_DEAL_PROPOSAL_REJECTED, "ProposalRejected"},
144+
{E::STORAGE_DEAL_PROPOSAL_ACCEPTED, "ProposalAccepted"},
145+
{E::STORAGE_DEAL_STAGED, "Staged"},
146+
{E::STORAGE_DEAL_SEALING, "Sealing"},
147+
{E::STORAGE_DEAL_FINALIZING, "Finalizing"},
148+
{E::STORAGE_DEAL_ACTIVE, "Active"},
149+
{E::STORAGE_DEAL_EXPIRED, "Expired"},
150+
{E::STORAGE_DEAL_SLASHED, "Slashed"},
151+
{E::STORAGE_DEAL_REJECTING, "Rejecting"},
152+
{E::STORAGE_DEAL_FAILING, "Falling"},
153+
{E::STORAGE_DEAL_FUNDS_ENSURED, "FundsEnsured"},
154+
{E::STORAGE_DEAL_CHECK_FOR_ACCEPTANCE, "CheckForAcceptance"},
155+
{E::STORAGE_DEAL_VALIDATING, "DealValidating"},
156+
{E::STORAGE_DEAL_ACCEPT_WAIT, "AcceptWait"},
157+
{E::STORAGE_DEAL_START_DATA_TRANSFER, "StartDataTransfer"},
158+
{E::STORAGE_DEAL_TRANSFERRING, "DealTransfering"},
159+
{E::STORAGE_DEAL_WAITING_FOR_DATA, "WaitingForData"},
160+
{E::STORAGE_DEAL_VERIFY_DATA, "VerifyData"},
161+
{E::STORAGE_DEAL_ENSURE_PROVIDER_FUNDS, "EnsureProvidedFunds"},
162+
{E::STORAGE_DEAL_PROVIDER_FUNDING, "ProviderFunding"},
163+
{E::STORAGE_DEAL_CLIENT_FUNDING, "ClientFunding"},
164+
{E::STORAGE_DEAL_PUBLISH, "DealPublish"},
165+
{E::STORAGE_DEAL_PUBLISHING, "DealPublishing"},
166+
{E::STORAGE_DEAL_ERROR, "Error"},
167+
}};
168+
return table;
169+
}
138170

139171
/**
140172
* StorageDeal is a local combination of a proposal and a current deal state

0 commit comments

Comments
 (0)