2
2
// Created by Ruslan Gilvanov on 12.02.2022.
3
3
4
4
#pragma once
5
+ #include < inttypes.h>
5
6
#include " cli/node/node.hpp"
7
+ #include " markets/storage/mk_protocol.hpp"
8
+ #include " primitives/chain_epoch/chain_epoch.hpp"
9
+ #include " primitives/piece/piece.hpp"
6
10
#include " storage/car/car.hpp"
11
+ #include " storage/ipfs/api_ipfs_datastore/api_ipfs_datastore.hpp"
7
12
#include " storage/ipld/memory_indexed_car.hpp"
8
13
#include " storage/unixfs/unixfs.hpp"
14
+ #include " vm/actor/actor.hpp"
15
+ #include " vm/actor/builtin/states/verified_registry/verified_registry_actor_state.hpp"
16
+ #include " vm/actor/builtin/v0/verified_registry/verified_registry_actor.hpp"
9
17
10
18
namespace fc ::cli::_node {
11
19
using api::FileRef;
20
+ using api::FullNodeApi;
12
21
using api::ImportRes;
13
22
using api::RetrievalOrder;
23
+ using boost::lexical_cast;
14
24
using ::fc::storage::car::makeCar;
15
25
using ::fc::storage::unixfs::wrapFile;
26
+ using markets::storage::DataRef;
27
+ using primitives::ChainEpoch;
28
+ using primitives::StoragePower;
16
29
using primitives::address::Address;
30
+ using primitives::address::encodeToString;
31
+ using primitives::piece::UnpaddedPieceSize;
17
32
using proofs::padPiece;
33
+ using storage::ipfs::ApiIpfsDatastore;
34
+ using vm::actor::kVerifiedRegistryAddress ;
35
+ using vm::actor::builtin::states::VerifiedRegistryActorStatePtr;
36
+ using vm::VMExitCode;
37
+
38
+ const ChainEpoch kLoopback = 100 ; // TODO: lookback
39
+
40
+
41
+ StoragePower checkNotary (std::shared_ptr<FullNodeApi> api,
42
+ const Address &vaddr) {
43
+ auto vid =
44
+ cliTry (api->StateLookupID (vaddr, TipsetKey ()),
45
+ " Getting IPLD id of data associated with provided address..." );
46
+ auto actor =
47
+ cliTry (api->StateGetActor (kVerifiedRegistryAddress , TipsetKey ()),
48
+ " Getting VerifierActor" );
49
+ auto ipfs = std::make_shared<ApiIpfsDatastore>(api);
50
+ auto version = cliTry (api->StateNetworkVersion (TipsetKey ()),
51
+ " Getting Chain Version..." );
52
+ auto state =
53
+ cliTry (getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head ));
54
+ auto res = cliTry (cliTry (state->getVerifiedClientDataCap (vid)),
55
+ " Client {} isn't in notary tables" ,
56
+ vaddr);
57
+ return res;
58
+ }
18
59
19
60
struct clientRetrieve {
20
61
struct Args {
@@ -96,6 +137,7 @@ namespace fc::cli::_node {
96
137
};
97
138
98
139
<<<<<<< HEAD
140
+ <<<<<<< HEAD
99
141
100
142
<<<<<<< HEAD
101
143
struct clientGenerateCar {
@@ -111,6 +153,90 @@ namespace fc::cli::_node {
111
153
=======
112
154
struct Node_client_generateCar : Empty{
113
155
=======
156
+ =======
157
+ struct Node_client_deal {
158
+ struct Args {
159
+ CLI_OPTIONAL (" manual-piece-cid" ,
160
+ " manually specify piece commitment for data (dataCid must "
161
+ " be to a car file)" ,
162
+ CID)
163
+ man_piece_cid;
164
+ CLI_DEFAULT (" manual-piece-size" ,
165
+ " if manually specifying piece cid, used to specify size "
166
+ " (dataCid must be to a car file)" ,
167
+ uint64_t ,
168
+ {0 })
169
+ man_piece_size;
170
+ CLI_BOOL (" manual-stateless-deal" ,
171
+ " instructs the node to send an offline deal without registering "
172
+ " it with the deallist/fsm" )
173
+ man_stateless;
174
+ CLI_OPTIONAL (" from" , " specify address to fund the deal with" , Address)
175
+ from;
176
+ CLI_DEFAULT (" start-epoch" ,
177
+ " specify the epoch that the deal should start at" ,
178
+ ChainEpoch,
179
+ {-1 })
180
+ start_epoch;
181
+ CLI_DEFAULT (" cid-base" ,
182
+ " Multibase encoding used for version 1 CIDs in output." ,
183
+ std::string,
184
+ {" base-32" })
185
+ cid_base;
186
+ CLI_BOOL (" fast-retrieval" ,
187
+ " indicates that data should be available for fast retrieval" )
188
+ fast_ret;
189
+ CLI_BOOL (" verified-deal" ,
190
+ " indicate that the deal counts towards verified client tota" )
191
+ verified_deal;
192
+ CLI_DEFAULT (
193
+ " provider-collateral" ,
194
+ " specify the requested provider collateral the miner should put up" ,
195
+ TokenAmount,
196
+ {0 })
197
+ collateral;
198
+
199
+ CLI_OPTS () {
200
+ Opts opts;
201
+ man_piece_cid (opts);
202
+ man_piece_size (opts);
203
+ man_stateless (opts);
204
+ from (opts);
205
+ start_epoch (opts);
206
+ cid_base (opts);
207
+ fast_ret (opts);
208
+ verified_deal (opts);
209
+ collateral (opts);
210
+ return opts;
211
+ }
212
+ };
213
+
214
+ CLI_RUN () {
215
+ ChainEpoch kMinDealDuration {60 }; // TODO: read from config;
216
+ ChainEpoch kMaxDealDuration {160 };
217
+ auto data_cid{cliArgv<CID>(
218
+ argv, 0 , " dataCid comes from running 'lotus client import" )};
219
+ auto miner{cliArgv<Address>(
220
+ argv, 1 , " address of the miner you wish to make a deal with" )};
221
+ auto price{
222
+ cliArgv<TokenAmount>(argv, 2 , " price calculated in FIL/Epoch" )};
223
+ auto duration{cliArgv<ChainEpoch>(
224
+ argv, 3 , " is a period of storing the data for, in blocks" )};
225
+ 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
+
229
+ Address address_from =
230
+ 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};
236
+ }
237
+ };
238
+
239
+ >>>>>>> 3d9435d6 (FFi+ and client updates)
114
240
struct Node_client_generateCar : Empty {
115
241
>>>>>>> f1466404 (client updates)
116
242
CLI_RUN() {
@@ -151,6 +277,7 @@ namespace fc::cli::_node {
151
277
}
152
278
};
153
279
280
+ <<<<<<< HEAD
154
281
<<<<<<< HEAD
155
282
<<<<<<< HEAD
156
283
struct clientFind {
@@ -160,8 +287,42 @@ namespace fc::cli::_node {
160
287
=======
161
288
struct Node_client_find {};
162
289
>>>>>>> f1466404 (client updates)
290
+ =======
291
+ struct Node_client_find {
292
+ struct Args {
293
+ CLI_OPTIONAL (" piece-cid" ,
294
+ " require data to be retrieved from a specific Piece CID" ,
295
+ CID)
296
+ piece_cid;
297
+ CLI_OPTS () {
298
+ Opts opts;
299
+ piece_cid (opts);
300
+ }
301
+ };
302
+ CLI_RUN () {
303
+ auto data_cid{cliArgv<CID>(argv, 0 , " data-cid" )};
304
+ Node::Api api{argm};
305
+ auto querry_offers =
306
+ cliTry (api._ ->ClientFindData (data_cid, *args.piece_cid ));
307
+ for (const auto &offer : querry_offers) {
308
+ if (offer.error == " " ) {
309
+ fmt::print (" ERROR: {}@{}: {}\n " ,
310
+ encodeToString (offer.miner ),
311
+ offer.peer .peer_id .toHex (),
312
+ offer.error );
313
+ } else {
314
+ fmt::print (" RETRIEVAL: {}@{}-{}-{}\n " ,
315
+ encodeToString (offer.miner ),
316
+ offer.peer .peer_id .toHex (),
317
+ offer.min_price ,
318
+ offer.size );
319
+ }
320
+ }
321
+ }
322
+ };
323
+ >>>>>>> 3d9435d6 (FFi+ and client updates)
163
324
164
- struct Node_client_listRetrieval {
325
+ struct Node_client_listRetrievals { // TODO: Done
165
326
struct Args {
166
327
<<<<<<< HEAD
167
328
CLI_BOOL (" verbose" , " print verbose deal details" )verbose;
@@ -201,6 +362,7 @@ namespace fc::cli::_node {
201
362
};
202
363
203
364
<<<<<<< HEAD
365
+ <<<<<<< HEAD
204
366
205
367
206
368
<<<<<<< HEAD
@@ -212,6 +374,9 @@ namespace fc::cli::_node {
212
374
=======
213
375
struct Node_client_inspectDeal {
214
376
>>>>>>> f1466404 (client updates)
377
+ =======
378
+ struct Node_client_inspectDeal { // TODO: continue
379
+ >>>>>>> 3d9435d6 (FFi+ and client updates)
215
380
struct Args {
216
381
CLI_OPTIONAL (" proposal-cid" , " proposal cid of deal to be inspected" , CID)
217
382
proposal_cid;
@@ -227,6 +392,29 @@ namespace fc::cli::_node {
227
392
Node::Api api{argm};
228
393
}
229
394
};
395
+
396
+ struct Node_client_dealStats {
397
+ struct Args {
398
+ CLI_DEFAULT (" newer-than" ,
399
+ " list all deals stas that was made after given period" ,
400
+ ChainEpoch,
401
+ {0 })newer;
402
+ CLI_OPTS (){
403
+ Opts opts;
404
+ newer (opts);
405
+ return opts;
406
+ }
407
+ };
408
+ CLI_RUN (){
409
+ Node::Api api{argm};
410
+ auto deals = cliTry (api._ ->ClientListDeals ());
411
+ for (const auto deal: deals){
412
+
413
+ }// TODO: Continue
414
+
415
+ }
416
+ };
417
+
230
418
struct Node_client_list_deals {
231
419
struct Args {
232
420
CLI_BOOL (" show-failed" , " show failed/failing deals" ) failed_show;
@@ -264,9 +452,12 @@ namespace fc::cli::_node {
264
452
" Getting address of default wallet..." ));
265
453
auto balance = cliTry (api._ ->StateMarketBalance (addr, TipsetKey ()));
266
454
267
- fmt::print (" Escrowed Funds: {}\n " , AttoFil{balance.escrow });
268
- fmt::print (" Locked Funds: {}\n " , AttoFil{balance.locked });
269
- // TODO: Reserved and Avaliable
455
+ fmt::print (" Escrowed Funds: {}\n " ,
456
+ lexical_cast<std::string>(balance.escrow ));
457
+ fmt::print (" Locked Funds: {}\n " ,
458
+ lexical_cast<std::string>(balance.locked ));
459
+ fmt::print (" Avaliable: {}\n " ,
460
+ lexical_cast<std::string>(balance.escrow - balance.locked ));
270
461
}
271
462
};
272
463
<<<<<<< HEAD
@@ -332,7 +523,91 @@ namespace fc::cli::_node {
332
523
333
524
CLI_RUN () {
334
525
auto target{cliArgv<Address>(argv, 0 , " target address" )};
335
- auto allowness{cliArgv<AttoFil>(argv, 1 , " amount" )};
526
+ auto allowness{cliArgv<TokenAmount>(argv, 1 , " amount" )};
527
+ Node::Api api{argm};
528
+ auto dcap = checkNotary (api._ , *args.from );
529
+ if (dcap < allowness)
530
+ throw CliError (
531
+ " cannot allot more allowance than notary data cap: {} < {}" ,
532
+ dcap,
533
+ allowness);
534
+ auto encoded_params = cliTry (codec::cbor::encode (
535
+ vm::actor::builtin::v0::verified_registry::AddVerifiedClient::Params{
536
+ target, allowness}));
537
+ auto signed_message = cliTry (api._ ->MpoolPushMessage (
538
+ {kVerifiedRegistryAddress ,
539
+ *args.from ,
540
+ {},
541
+ 0 ,
542
+ 0 ,
543
+ 0 ,
544
+ vm::actor::builtin::v0::verified_registry::AddVerifiedClient::Number,
545
+ encoded_params},
546
+ api::kPushNoSpec ));
547
+
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);
552
+ }
553
+ };
554
+
555
+ struct Node_client_checkClientDataCap : Empty {
556
+ CLI_RUN () {
557
+ auto address{cliArgv<Address>(argv, 0 , " address of client" )};
558
+ Node::Api api{argm};
559
+ auto res = cliTry (api._ ->StateVerifiedClientStatus (address, TipsetKey ()),
560
+ " Getting Verified Client info..." );
561
+ fmt::print (" Client {} info: {}" , encodeToString (address), res);
562
+ }
563
+ };
564
+
565
+ struct Node_client_listNotaries : Empty{
566
+ CLI_RUN (){
567
+ Node::Api api{argm};
568
+ auto actor =
569
+ cliTry (api._ ->StateGetActor (kVerifiedRegistryAddress , TipsetKey ()),
570
+ " Getting VerifierActor" );
571
+ auto ipfs = std::make_shared<ApiIpfsDatastore>(api._ );
572
+ auto version = cliTry (api._ ->StateNetworkVersion (TipsetKey ()),
573
+ " Getting Chain Version..." );
574
+ auto state =
575
+ cliTry (getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head ));
576
+
577
+ cliTry (state->verifiers .visit ([=](auto &key, auto &value)->outcome ::result<void >{
578
+ fmt::print (" {}: {}" , key, value);
579
+ return outcome::success ();
580
+ }));
581
+ }
582
+ };
583
+
584
+
585
+ struct Node_client_listClients : Empty{
586
+ CLI_RUN (){
587
+ Node::Api api{argm};
588
+ auto actor =
589
+ cliTry (api._ ->StateGetActor (kVerifiedRegistryAddress , TipsetKey ()),
590
+ " Getting VerifierActor" );
591
+ auto ipfs = std::make_shared<ApiIpfsDatastore>(api._ );
592
+ auto version = cliTry (api._ ->StateNetworkVersion (TipsetKey ()),
593
+ " Getting Chain Version..." );
594
+ auto state =
595
+ cliTry (getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head ));
596
+
597
+ cliTry (state->verified_clients .visit ([=](auto &key, auto &value)->outcome ::result<void >{
598
+ fmt::print (" {}: {}" , key, value);
599
+ return outcome::success ();
600
+ }));
601
+ }
602
+ };
603
+
604
+
605
+ struct Node_client_checkNotaryDataCap : Empty{
606
+ CLI_RUN (){
607
+ auto address{cliArgv<Address>(argv, 0 , " address" )};
608
+ Node::Api api{argm};
609
+ auto dcap = checkNotary (api._ , address);
610
+ fmt::print (" DataCap amount: {}" , dcap);
336
611
}
337
612
};
338
613
0 commit comments