Skip to content

Commit f1c2c44

Browse files
Ferature/snap fsm (#655)
Signed-off-by: Alexey Chernyshov <[email protected]> Co-authored-by: Artem Iurin <[email protected]>
1 parent 88e0b31 commit f1c2c44

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2122
-667
lines changed

core/api/rpc/json.hpp

-16
Original file line numberDiff line numberDiff line change
@@ -2114,20 +2114,4 @@ namespace fc::api {
21142114
Get(j, "MinerPeer", v.peer);
21152115
}
21162116

2117-
JSON_ENCODE(std::set<TaskType>) {
2118-
Value j{rapidjson::kObjectType};
2119-
j.MemberReserve(v.size(), allocator);
2120-
for (auto &pair : v) {
2121-
std::map<std::string, std::string> value;
2122-
Set(j, pair, value, allocator);
2123-
}
2124-
return j;
2125-
}
2126-
2127-
JSON_DECODE(std::set<TaskType>) {
2128-
for (auto it = j.MemberBegin(); it != j.MemberEnd(); ++it) {
2129-
v.emplace(TaskType(AsString(it->name)));
2130-
}
2131-
}
2132-
21332117
} // namespace fc::api

core/api/storage_miner/return_api.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,11 @@ namespace fc::api {
8989
const boost::optional<CallError> &call_error) {
9090
return scheduler->returnResult(call_id, {proof, call_error});
9191
};
92+
93+
api->ReturnFinalizeReplicaUpdate =
94+
[=](const CallId &call_id,
95+
const boost::optional<CallError> &call_error) {
96+
return scheduler->returnResult(call_id, {{}, call_error});
97+
};
9298
}
9399
} // namespace fc::api

core/api/storage_miner/storage_api.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace fc::api {
114114
sector_info->precommit_message,
115115
sector_info->message,
116116
sector_info->invalid_proofs,
117-
miner->getSealing()->isMarkedForUpgrade(id),
117+
sector_info->update,
118118
};
119119
if (not show_onchain_info) {
120120
return api_sector_info;
@@ -199,6 +199,16 @@ namespace fc::api {
199199
});
200200
};
201201

202+
api->SectorMarkForUpgrade = [=](SectorNumber sector,
203+
bool snap_deal) -> outcome::result<void> {
204+
if (snap_deal) {
205+
return miner->getSealing()->markForSnapUpgrade(sector);
206+
}
207+
return ERROR_TEXT(
208+
"Old capacity sector upgrade deprecated, use snap deals capacity "
209+
"sector upgrade");
210+
};
211+
202212
api->Version = [] {
203213
return api::VersionResult{kMinerVersion, kMinerApiVersion, 0};
204214
};

core/api/storage_miner/storage_api.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ namespace fc::api {
220220
void,
221221
const CallId &,
222222
const boost::optional<CallError> &)
223+
API_METHOD(ReturnFinalizeReplicaUpdate,
224+
jwt::kAdminPermission,
225+
void,
226+
const CallId &,
227+
const boost::optional<CallError> &)
223228
API_METHOD(ReturnMoveStorage,
224229
jwt::kAdminPermission,
225230
void,
@@ -259,6 +264,11 @@ namespace fc::api {
259264
const CallId &,
260265
Proof,
261266
const boost::optional<CallError> &)
267+
API_METHOD(SectorMarkForUpgrade,
268+
jwt::kAdminPermission,
269+
void,
270+
SectorNumber,
271+
bool /* snap_deal */)
262272

263273
API_METHOD(WorkerConnect, jwt::kAdminPermission, void, const std::string &);
264274
};
@@ -307,13 +317,15 @@ namespace fc::api {
307317
f(a.ReturnSealCommit1);
308318
f(a.ReturnSealCommit2);
309319
f(a.ReturnFinalizeSector);
320+
f(a.ReturnFinalizeReplicaUpdate);
310321
f(a.ReturnMoveStorage);
311322
f(a.ReturnUnsealPiece);
312323
f(a.ReturnReadPiece);
313324
f(a.ReturnFetch);
314325
f(a.ReturnReplicaUpdate);
315326
f(a.ReturnProveReplicaUpdate1);
316327
f(a.ReturnProveReplicaUpdate2);
328+
f(a.SectorMarkForUpgrade);
317329
f(a.WorkerConnect);
318330
}
319331
} // namespace fc::api

core/api/worker_api.hpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
#include "api/utils.hpp"
99
#include "api/version.hpp"
10+
#include "codec/json/basic_coding.hpp"
1011
#include "common/outcome.hpp"
1112
#include "primitives/jwt/jwt.hpp"
1213
#include "sector_storage/worker.hpp"
1314

1415
namespace fc::api {
16+
using codec::json::CodecSetAsMap;
1517
using primitives::jwt::kAdminPermission;
1618
using primitives::piece::MetaPieceData;
1719
using primitives::piece::PieceInfo;
@@ -74,6 +76,11 @@ namespace fc::api {
7476
const CID &,
7577
const CID &,
7678
const Update1Output &)
79+
API_METHOD(FinalizeReplicaUpdate,
80+
kAdminPermission,
81+
CallId,
82+
const SectorRef &,
83+
const std::vector<Range> &)
7784

7885
API_METHOD(Info, kAdminPermission, primitives::WorkerInfo)
7986

@@ -115,7 +122,7 @@ namespace fc::api {
115122

116123
API_METHOD(StorageAddLocal, kAdminPermission, void, const std::string &)
117124

118-
API_METHOD(TaskTypes, kAdminPermission, std::set<primitives::TaskType>)
125+
API_METHOD(TaskTypes, kAdminPermission, CodecSetAsMap<primitives::TaskType>)
119126

120127
API_METHOD(UnsealPiece,
121128
kAdminPermission,
@@ -137,6 +144,7 @@ namespace fc::api {
137144
f(a.ReplicaUpdate);
138145
f(a.ProveReplicaUpdate1);
139146
f(a.ProveReplicaUpdate2);
147+
f(a.FinalizeReplicaUpdate);
140148
f(a.Info);
141149
f(a.MoveStorage);
142150
f(a.Paths);

core/codec/json/basic_coding.hpp

+26
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ namespace fc::codec::json {
3636
using rapidjson::Value;
3737
using base64 = cppcodec::base64_rfc4648;
3838

39+
/**
40+
* Set is encoded as an array: "[a, b, c]", but this class allows to encode
41+
* set as map: "{a:{}, b:{}, c:{}}. Used for lotus compatibility.
42+
*/
43+
template <typename T>
44+
class CodecSetAsMap : public std::set<T> {};
45+
46+
3947
template <typename T>
4048
T innerDecode(const Value &j);
4149

@@ -279,4 +287,22 @@ namespace fc::codec::json {
279287
v.emplace(innerDecode<T>(it));
280288
}
281289
}
290+
291+
template <typename T>
292+
JSON_ENCODE(CodecSetAsMap<T>) {
293+
Value j{rapidjson::kObjectType};
294+
j.MemberReserve(v.size(), allocator);
295+
for (auto &pair : v) {
296+
std::map<T, std::string> value;
297+
Set(j, pair, value, allocator);
298+
}
299+
return j;
300+
}
301+
302+
template <typename T>
303+
JSON_DECODE(CodecSetAsMap<T>) {
304+
for (auto it = j.MemberBegin(); it != j.MemberEnd(); ++it) {
305+
v.emplace(T(AsString(it->name)));
306+
}
307+
}
282308
} // namespace fc::codec::json

core/common/map_utils.hpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#pragma once
7+
8+
#include <map>
9+
10+
namespace fc::common {
11+
12+
/**
13+
* @returns map value if present, otherwise default_value
14+
*/
15+
template <template <class, class, class...> class C,
16+
typename K,
17+
typename V,
18+
typename... Args>
19+
const V &getOrDefault(const C<K, V, Args...> &map,
20+
const K &key,
21+
const V &default_value) {
22+
const auto &found = map.find(key);
23+
if (found == map.end()) return default_value;
24+
return found->second;
25+
}
26+
} // namespace fc::common

core/const.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ namespace fc {
5757

5858
namespace fc::vm::actor::builtin::types::market {
5959
DEFINE(kDealUpdatesInterval) = static_cast<EpochDuration>(kEpochsInDay);
60-
}
60+
DEFINE(kDealMinDuration) = static_cast<EpochDuration>(kEpochsInDay) * 180;
61+
} // namespace fc::vm::actor::builtin::types::market
6162

6263
namespace fc::vm::actor::builtin::types::miner {
6364
DEFINE(kWPoStProvingPeriod) = kEpochsInDay;

core/markets/storage/deal_protocol.hpp

Whitespace-only changes.

core/miner/impl/miner_impl.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ namespace fc::miner {
9494
fee_config->max_precommit_batch_gas_fee.per_sector =
9595
TokenAmount{"2000000000000000"};
9696
fee_config->max_precommit_gas_fee = TokenAmount{"25000000000000000"};
97+
fee_config->max_commit_gas_fee = TokenAmount{"50000000000000000"};
9798

9899
std::shared_ptr<PreCommitBatcher> precommit_batcher =
99100
std::make_shared<PreCommitBatcherImpl>(std::chrono::seconds(60),

core/miner/storage_fsm/impl/checks.cpp

+17-8
Original file line numberDiff line numberDiff line change
@@ -299,29 +299,34 @@ namespace fc::mining::checks {
299299
if (deal_count == 0) {
300300
return ERROR_TEXT("checkUpdate: no deals");
301301
}
302+
303+
if (!sector_info->update_unsealed) {
304+
return ChecksError::kBadUpdateReplica;
305+
}
306+
302307
OUTCOME_TRY(comm_d,
303308
getDataCommitment(miner_address, sector_info, tipset_key, api));
304-
if (sector_info->update_comm_d != comm_d) {
305-
return ERROR_TEXT("checkUpdate: wrong update_comm_d");
309+
if (sector_info->update_unsealed != comm_d) {
310+
return ChecksError::kBadUpdateReplica;
306311
}
307-
if (!sector_info->update_comm_r) {
308-
return ERROR_TEXT("checkUpdate: no update_comm_r");
312+
if (!sector_info->update_sealed) {
313+
return ChecksError::kBadUpdateReplica;
309314
}
310315
if (!sector_info->update_proof) {
311-
return ERROR_TEXT("checkUpdate: no update_proof");
316+
return ChecksError::kBadUpdateProof;
312317
}
313318
OUTCOME_TRY(update_type,
314319
getRegisteredUpdateProof(sector_info->sector_type));
315320
OUTCOME_TRY(verified,
316321
proofs->verifyUpdateProof({
317322
update_type,
318323
*sector_info->comm_r,
319-
*sector_info->update_comm_r,
320-
*sector_info->update_comm_d,
324+
*sector_info->update_sealed,
325+
*sector_info->update_unsealed,
321326
*sector_info->update_proof,
322327
}));
323328
if (!verified) {
324-
return ERROR_TEXT("checkUpdate: wrong proof");
329+
return ChecksError::kBadUpdateProof;
325330
}
326331
return outcome::success();
327332
}
@@ -358,6 +363,10 @@ OUTCOME_CPP_DEFINE_CATEGORY(fc::mining::checks, ChecksError, e) {
358363
return "ChecksError: need to wait commit";
359364
case E::kMinerVersion:
360365
return "ChecksError::kMinerVersion";
366+
case E::kBadUpdateReplica:
367+
return "ChecksError: bad update replica";
368+
case E::kBadUpdateProof:
369+
return "ChecksError: bad update proof";
361370
default:
362371
return "ChecksError: unknown error";
363372
}

core/miner/storage_fsm/impl/checks.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ namespace fc::mining::checks {
7474
kInvalidProof,
7575
kCommitWaitFail,
7676
kMinerVersion,
77+
kBadUpdateReplica,
78+
kBadUpdateProof,
7779
};
7880

7981
} // namespace fc::mining::checks

0 commit comments

Comments
 (0)