Skip to content

Commit 365a7c3

Browse files
authored
Feature/sector info (#504)
* sevtorInfo structure Signed-off-by: elestrias <[email protected]> * ApiSectorInfo with onchain Signed-off-by: elestrias <[email protected]> * Storage miner fixes Signed-off-by: elestrias <[email protected]> * Miner fixes, Json fixes Signed-off-by: elestrias <[email protected]> * pr fixes Signed-off-by: elestrias <[email protected]> * json encoder fix, pieces added Signed-off-by: elestrias <[email protected]> * pr fix std::move(pieces) Signed-off-by: elestrias <[email protected]> * pr fixes 2 Signed-off-by: elestrias <[email protected]> * json encoding interface changes Signed-off-by: elestrias <[email protected]> * FormatFixes Signed-off-by: elestrias <[email protected]>
1 parent a9634fe commit 365a7c3

File tree

3 files changed

+158
-5
lines changed

3 files changed

+158
-5
lines changed

core/api/rpc/json.hpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,48 @@ namespace fc::api {
930930
decode(v.size, Get(j, "Size"));
931931
}
932932

933+
ENCODE(DealSchedule) {
934+
Value j{rapidjson::kObjectType};
935+
Set(j, "StartEpoch", v.start_epoch);
936+
Set(j, "EndEpoch", v.end_epoch);
937+
return j;
938+
}
939+
940+
DECODE(DealSchedule) {
941+
Get(j, "StartEpoch", v.end_epoch);
942+
Get(j, "EndEpoch", v.end_epoch);
943+
}
944+
945+
ENCODE(DealInfo) {
946+
Value j{rapidjson::kObjectType};
947+
Set(j, "PublishCid", v.publish_cid);
948+
Set(j, "DealID", v.deal_id);
949+
Set(j, "DealProposal", v.deal_proposal);
950+
Set(j, "DealSchedule", v.deal_schedule);
951+
Set(j, "KeepUnsealed", v.is_keep_unsealed);
952+
return j;
953+
}
954+
955+
DECODE(DealInfo) {
956+
Get(j, "PublishCid", v.publish_cid);
957+
Get(j, "DealID", v.deal_id);
958+
Get(j, "DealProposal", v.deal_proposal);
959+
Get(j, "DealSchedule", v.deal_schedule);
960+
Get(j, "KeepUnsealed", v.is_keep_unsealed);
961+
}
962+
963+
ENCODE(Piece) {
964+
Value j{rapidjson::kObjectType};
965+
Set(j, "Piece", v.piece);
966+
Set(j, "DealInfo", v.deal_info);
967+
return j;
968+
}
969+
970+
DECODE(Piece) {
971+
Get(j, "Piece", v.piece);
972+
Get(j, "DealInfo", v.deal_info);
973+
}
974+
933975
ENCODE(SealedAndUnsealedCID) {
934976
Value j{rapidjson::kObjectType};
935977
Set(j, "Sealed", v.sealed_cid);
@@ -1055,12 +1097,52 @@ namespace fc::api {
10551097

10561098
ENCODE(ApiSectorInfo) {
10571099
Value j{rapidjson::kObjectType};
1100+
Set(j, "SectorID", v.sector_id);
10581101
Set(j, "State", v.state);
1102+
Set(j, "CommD", v.comm_d);
1103+
Set(j, "CommR", v.comm_r);
1104+
Set(j, "Proof", v.proof);
1105+
Set(j, "Deals", v.deals);
1106+
Set(j, "Pieces", v.pieces);
1107+
Set(j, "Ticket", v.ticket);
1108+
Set(j, "Seed", v.seed);
1109+
Set(j, "PreCommitMsg", v.precommit_message);
1110+
Set(j, "CommitMsg", v.commit_message);
1111+
Set(j, "Retries", v.retries);
1112+
Set(j, "ToUpgrade", v.to_upgrade);
1113+
Set(j, "SealProof", v.seal_proof);
1114+
Set(j, "Activation", v.activation);
1115+
Set(j, "Expiration", v.expiration);
1116+
Set(j, "DealWeight", v.deal_weight);
1117+
Set(j, "VerifiedDealWeight", v.verified_deal_weight);
1118+
Set(j, "InitialPledge", v.initial_pledge);
1119+
Set(j, "OnTime", v.on_time);
1120+
Set(j, "Early", v.early);
10591121
return j;
10601122
}
10611123

10621124
DECODE(ApiSectorInfo) {
1125+
Get(j, "SectorID", v.sector_id);
10631126
Get(j, "State", v.state);
1127+
Get(j, "CommD", v.comm_d);
1128+
Get(j, "CommR", v.comm_r);
1129+
Get(j, "Proof", v.proof);
1130+
Get(j, "Deals", v.deals);
1131+
Get(j, "Ticket", v.ticket);
1132+
Get(j, "Pieces", v.pieces);
1133+
Get(j, "Seed", v.seed);
1134+
Get(j, "PreCommitMsg", v.precommit_message);
1135+
Get(j, "CommitMsg", v.commit_message);
1136+
Get(j, "Retries", v.retries);
1137+
Get(j, "ToUpgrade", v.to_upgrade);
1138+
Get(j, "SealProof", v.seal_proof);
1139+
Get(j, "Activation", v.activation);
1140+
Get(j, "Expiration", v.expiration);
1141+
Get(j, "DealWeight", v.deal_weight);
1142+
Get(j, "VerifiedDealWeight", v.verified_deal_weight);
1143+
Get(j, "InitialPledge", v.initial_pledge);
1144+
Get(j, "OnTime", v.on_time);
1145+
Get(j, "Early", v.early);
10641146
}
10651147

10661148
ENCODE(PowerPair) {

core/api/storage_miner/storage_api.cpp

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,56 @@ namespace fc::api {
8686
return result;
8787
};
8888

89-
api->SectorsStatus = [=](SectorNumber id,
90-
bool) -> outcome::result<ApiSectorInfo> {
91-
// TODO(ortyomka): [FIL-421] implement it
89+
api->SectorsStatus =
90+
[=](SectorNumber id,
91+
bool show_onchain_info) -> outcome::result<ApiSectorInfo> {
9292
OUTCOME_TRY(sector_info, miner->getSealing()->getSectorInfo(id));
93-
return ApiSectorInfo{.state = sector_info->state};
93+
94+
const auto &pieces{sector_info->pieces};
95+
std::vector<DealId> deals;
96+
deals.reserve(sector_info->pieces.size());
97+
98+
for (const auto &piece : pieces) {
99+
deals.push_back(piece.deal_info ? piece.deal_info->deal_id : 0);
100+
}
101+
ApiSectorInfo api_sector_info{
102+
sector_info->state,
103+
id,
104+
sector_info->sector_type,
105+
sector_info->comm_d,
106+
sector_info->comm_r,
107+
sector_info->proof,
108+
std::move(deals),
109+
pieces,
110+
sector_info->ticket,
111+
sector_info->seed,
112+
sector_info->precommit_message,
113+
sector_info->message,
114+
sector_info->invalid_proofs,
115+
miner->getSealing()->isMarkedForUpgrade(id),
116+
};
117+
if (not show_onchain_info) {
118+
return api_sector_info;
119+
}
120+
OUTCOME_TRY(chain_info,
121+
full_node_api->StateSectorGetInfo(
122+
miner->getAddress(), id, TipsetKey{}));
123+
if (!chain_info.has_value()) {
124+
return api_sector_info;
125+
}
126+
api_sector_info.seal_proof = chain_info->seal_proof;
127+
api_sector_info.activation = chain_info->activation_epoch;
128+
api_sector_info.expiration = chain_info->expiration;
129+
api_sector_info.deal_weight = chain_info->deal_weight;
130+
api_sector_info.verified_deal_weight = chain_info->verified_deal_weight;
131+
api_sector_info.initial_pledge = chain_info->init_pledge;
132+
auto maybe_expiration_info = full_node_api->StateSectorExpiration(
133+
miner->getAddress(), id, TipsetKey{});
134+
if (maybe_expiration_info.has_value()) {
135+
api_sector_info.on_time = maybe_expiration_info.value().on_time;
136+
api_sector_info.early = maybe_expiration_info.value().early;
137+
}
138+
return api_sector_info;
94139
};
95140

96141
api->StorageAttach = [=](const StorageInfo_ &storage_info,

core/api/storage_miner/storage_api.hpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ namespace fc::api {
3232
using miner::Miner;
3333
using mining::types::DealInfo;
3434
using mining::types::DealSchedule;
35+
using mining::types::Piece;
3536
using mining::types::PieceLocation;
3637
using primitives::ChainEpoch;
3738
using primitives::DealId;
39+
using primitives::DealWeight;
3840
using primitives::SectorNumber;
3941
using primitives::SectorSize;
4042
using primitives::StorageID;
@@ -60,9 +62,33 @@ namespace fc::api {
6062
const static common::Logger kStorageApiLogger =
6163
common::createLogger("Storage API");
6264

63-
// TODO(ortyomka): [FIL-421] implement it
6465
struct ApiSectorInfo {
6566
mining::SealingState state = mining::SealingState::kStateUnknown;
67+
SectorNumber sector_id;
68+
RegisteredSealProof sector_type;
69+
boost::optional<CID> comm_d;
70+
boost::optional<CID> comm_r;
71+
proofs::Proof proof;
72+
std::vector<DealId> deals;
73+
std::vector<Piece> pieces;
74+
proofs::SealRandomness ticket;
75+
sector_storage::InteractiveRandomness seed;
76+
boost::optional<CID> precommit_message;
77+
boost::optional<CID> commit_message;
78+
uint64_t retries;
79+
bool to_upgrade;
80+
81+
// On chain info
82+
83+
RegisteredSealProof seal_proof{};
84+
ChainEpoch activation{};
85+
ChainEpoch expiration{};
86+
DealWeight deal_weight{};
87+
DealWeight verified_deal_weight{};
88+
TokenAmount initial_pledge{};
89+
90+
ChainEpoch on_time = {};
91+
ChainEpoch early = {};
6692
};
6793

6894
constexpr ApiVersion kMinerApiVersion = makeApiVersion(1, 0, 0);

0 commit comments

Comments
 (0)