Skip to content

Commit ec9b516

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

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
@@ -4,6 +4,7 @@
44

55
#pragma once
66
#include <inttypes.h>
7+
#include "api/full_node/node_api.hpp"
78
#include "cli/node/node.hpp"
89
#include "markets/storage/mk_protocol.hpp"
910
#include "primitives/chain_epoch/chain_epoch.hpp"
@@ -15,12 +16,14 @@
1516
#include "vm/actor/actor.hpp"
1617
#include "vm/actor/builtin/states/verified_registry/verified_registry_actor_state.hpp"
1718
#include "vm/actor/builtin/v0/verified_registry/verified_registry_actor.hpp"
19+
#include "common/enum.hpp"
1820

1921
namespace fc::cli::_node {
2022
using api::FileRef;
2123
using api::FullNodeApi;
2224
using api::ImportRes;
2325
using api::RetrievalOrder;
26+
using api::StartDealParams;
2427
using boost::lexical_cast;
2528
using ::fc::storage::car::makeCar;
2629
using ::fc::storage::unixfs::wrapFile;
@@ -32,12 +35,13 @@ namespace fc::cli::_node {
3235
using primitives::piece::UnpaddedPieceSize;
3336
using proofs::padPiece;
3437
using storage::ipfs::ApiIpfsDatastore;
38+
using vm::VMExitCode;
3539
using vm::actor::kVerifiedRegistryAddress;
3640
using vm::actor::builtin::states::VerifiedRegistryActorStatePtr;
37-
using vm::VMExitCode;
38-
39-
const ChainEpoch kLoopback = 100; // TODO: lookback
41+
using markets::storage::StorageDealStatus;
42+
using common::toString;
4043

44+
const ChainEpoch kLoopback = 100; // TODO: lookback
4145

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

@@ -364,6 +394,7 @@ namespace fc::cli::_node {
364394

365395
<<<<<<< HEAD
366396
<<<<<<< HEAD
397+
<<<<<<< HEAD
367398

368399

369400
<<<<<<< HEAD
@@ -461,6 +492,9 @@ namespace fc::cli::_node {
461492
=======
462493
struct Node_client_inspectDeal { //TODO: continue
463494
>>>>>>> 3d9435d6 (FFi+ and client updates)
495+
=======
496+
struct Node_client_inspectDeal { // TODO: continue
497+
>>>>>>> ad42f96d (ClientUpdates, DealStatus enum conversion)
464498
struct Args {
465499
CLI_OPTIONAL("proposal-cid", "proposal cid of deal to be inspected", CID)
466500
proposal_cid;
@@ -477,25 +511,33 @@ namespace fc::cli::_node {
477511
}
478512
};
479513

480-
struct Node_client_dealStats{
514+
struct Node_client_dealStats {
481515
struct Args {
482516
CLI_DEFAULT("newer-than",
483517
"list all deals stas that was made after given period",
484518
ChainEpoch,
485-
{0})newer;
486-
CLI_OPTS(){
519+
{0})
520+
newer;
521+
CLI_OPTS() {
487522
Opts opts;
488523
newer(opts);
489524
return opts;
490525
}
491526
};
492-
CLI_RUN(){
527+
CLI_RUN() {
493528
Node::Api api{argm};
494529
auto deals = cliTry(api._->ClientListDeals());
495-
for(const auto deal: deals){
496-
497-
}//TODO: Continue
498-
530+
uint64_t total_size{0};
531+
std::map<StorageDealStatus, uint64_t> by_state;
532+
for (const auto &deal : deals) {
533+
//TODO(@Elestrias): [FIL-615] Check Creation time and since-epoch flag
534+
total_size += deal.size;
535+
by_state[deal.state] += deal.size;
536+
}
537+
fmt::print("Total: {} deals, {}", deals.size(), total_size);
538+
for(const auto &[state, size]: by_state){
539+
fmt::print("Deal with status {} allocates {} bytes", toString(state), size);
540+
}
499541
}
500542
};
501543

@@ -631,10 +673,13 @@ namespace fc::cli::_node {
631673
encoded_params},
632674
api::kPushNoSpec));
633675

634-
fmt::print("message sent, now waiting on cid: {}", signed_message.getCid());
635-
auto mwait = cliTry(api._->StateWaitMsg(signed_message.getCid(), kMessageConfidence, kLoopback, false));
636-
if (mwait.receipt.exit_code != VMExitCode::kOk) throw CliError("failed to add verified client");
637-
fmt::print("Client {} was added successfully!", target);
676+
fmt::print("message sent, now waiting on cid: {}",
677+
signed_message.getCid());
678+
auto mwait = cliTry(api._->StateWaitMsg(
679+
signed_message.getCid(), kMessageConfidence, kLoopback, false));
680+
if (mwait.receipt.exit_code != VMExitCode::kOk)
681+
throw CliError("failed to add verified client");
682+
fmt::print("Client {} was added successfully!", target);
638683
}
639684
};
640685

@@ -648,8 +693,8 @@ namespace fc::cli::_node {
648693
}
649694
};
650695

651-
struct Node_client_listNotaries: Empty{
652-
CLI_RUN(){
696+
struct Node_client_listNotaries : Empty {
697+
CLI_RUN() {
653698
Node::Api api{argm};
654699
auto actor =
655700
cliTry(api._->StateGetActor(kVerifiedRegistryAddress, TipsetKey()),
@@ -660,16 +705,16 @@ namespace fc::cli::_node {
660705
auto state =
661706
cliTry(getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head));
662707

663-
cliTry(state->verifiers.visit([=](auto &key, auto &value)->outcome::result<void>{
664-
fmt::print("{}: {}", key, value);
665-
return outcome::success();
666-
}));
708+
cliTry(state->verifiers.visit(
709+
[=](auto &key, auto &value) -> outcome::result<void> {
710+
fmt::print("{}: {}", key, value);
711+
return outcome::success();
712+
}));
667713
}
668714
};
669715

670-
671-
struct Node_client_listClients: Empty{
672-
CLI_RUN(){
716+
struct Node_client_listClients : Empty {
717+
CLI_RUN() {
673718
Node::Api api{argm};
674719
auto actor =
675720
cliTry(api._->StateGetActor(kVerifiedRegistryAddress, TipsetKey()),
@@ -680,16 +725,16 @@ namespace fc::cli::_node {
680725
auto state =
681726
cliTry(getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head));
682727

683-
cliTry(state->verified_clients.visit([=](auto &key, auto &value)->outcome::result<void>{
684-
fmt::print("{}: {}", key, value);
685-
return outcome::success();
686-
}));
728+
cliTry(state->verified_clients.visit(
729+
[=](auto &key, auto &value) -> outcome::result<void> {
730+
fmt::print("{}: {}", key, value);
731+
return outcome::success();
732+
}));
687733
}
688734
};
689735

690-
691-
struct Node_client_checkNotaryDataCap: Empty{
692-
CLI_RUN(){
736+
struct Node_client_checkNotaryDataCap : Empty {
737+
CLI_RUN() {
693738
auto address{cliArgv<Address>(argv, 0, "address")};
694739
Node::Api api{argm};
695740
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)