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

Lines changed: 0 additions & 16 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 11 additions & 1 deletion
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 9 additions & 1 deletion
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

Lines changed: 26 additions & 0 deletions
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

Lines changed: 26 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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),

0 commit comments

Comments
 (0)