Skip to content

Commit c8c9dfb

Browse files
authored
Feature/verfy seal (#100)
* Added Seal functions Signed-off-by: artyom-yurin <[email protected]> * Disabled proofs tests Signed-off-by: artyom-yurin <[email protected]>
1 parent 82466fd commit c8c9dfb

File tree

9 files changed

+538
-50
lines changed

9 files changed

+538
-50
lines changed

core/crypto/blake2/blake2b160.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace fc::crypto::blake2b {
3737

3838
blake2b_ctx ctx;
3939

40-
if (blake2b_init(&ctx, BLAKE2B512_HASH_LENGTH, nullptr, 0)) {
40+
if (blake2b_init(&ctx, BLAKE2B512_HASH_LENGTH, nullptr, 0) != 0) {
4141
return {};
4242
}
4343

core/proofs/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ target_link_libraries(proofs
3535
filecoin_ffi
3636
outcome
3737
blob
38-
proof_param_provider
3938
logger
4039
)

core/proofs/proof_param_provider.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
namespace fc::proofs {
2626

27-
boost::mutex ProofParamProvider::fetch_mutex_ = boost::mutex();
2827
common::Logger ProofParamProvider::logger_ =
2928
common::createLogger("proofs params");
3029

@@ -39,17 +38,15 @@ namespace fc::proofs {
3938
ending.length(),
4039
ending)
4140
== 0);
42-
} else {
43-
return false;
4441
}
42+
return false;
4543
}
4644

4745
outcome::result<ResponseParseUrl> parseUrl(const std::string &url_str) {
4846
ResponseParseUrl response{};
4947

5048
std::smatch match;
51-
std::regex reg(
52-
"(https|http):\\/\\/([A-Za-z0-9\\-.]+)(\\/[\\/A-Za-z0-9\\-.]+)");
49+
std::regex reg(R"((https|http)://([A-Za-z0-9-.]+)(/[/A-Za-z0-9-.]+))");
5350

5451
if (std::regex_match(url_str, match, reg)) {
5552
response.host = match[2];
@@ -71,7 +68,7 @@ namespace fc::proofs {
7168
using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp>
7269

7370
outcome::result<void> ProofParamProvider::doFetch(const std::string &out,
74-
ParamFile info) {
71+
const ParamFile &info) {
7572
try {
7673
std::string gateway = default_gateway;
7774
if (char *custom_gateway = std::getenv("IPFS_GATEWAY")) {
@@ -178,7 +175,7 @@ namespace fc::proofs {
178175
outcome::result<void> checkFile(const std::string &path,
179176
const ParamFile &info) {
180177
char *res = std::getenv("TRUST_PARAMS");
181-
if (res && std::strcmp(res, "1") == 0) {
178+
if (res != nullptr && std::strcmp(res, "1") == 0) {
182179
// Assuming parameter files are ok. DO NOT USE IN PRODUCTION
183180
return outcome::success();
184181
}
@@ -206,17 +203,18 @@ namespace fc::proofs {
206203
if (!res.has_error()) {
207204
logger_->info(info.name + " already uploaded");
208205
return;
209-
} else if (boost::filesystem::exists(path)) {
206+
}
207+
if (boost::filesystem::exists(path)) {
210208
logger_->warn(res.error().message());
211209
}
212210

213-
fetch_mutex_.lock();
211+
static std::mutex mutex;
212+
std::lock_guard<std::mutex> lock(mutex);
214213

215214
auto fetch_res = doFetch(path.string(), info);
216215

217216
if (fetch_res.has_error()) {
218217
logger_->error(res.error().message());
219-
fetch_mutex_.unlock();
220218
return;
221219
}
222220

@@ -225,12 +223,10 @@ namespace fc::proofs {
225223
if (res.has_error()) {
226224
logger_->error(res.error().message());
227225
boost::filesystem::remove(path);
228-
fetch_mutex_.unlock();
229226
return;
230227
}
231228

232229
logger_->info(info.name + " uploaded successfully");
233-
fetch_mutex_.unlock();
234230
}
235231

236232
namespace pt = boost::property_tree;

core/proofs/proof_param_provider.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#ifndef CPP_FILECOIN_PROOF_PARAM_PROVIDER_HPP
77
#define CPP_FILECOIN_PROOF_PARAM_PROVIDER_HPP
88

9-
#include "boost/thread/mutex.hpp"
109
#include "common/logger.hpp"
1110
#include "common/outcome.hpp"
1211
#include "gsl/span"
@@ -17,7 +16,7 @@ namespace fc::proofs {
1716
std::string name;
1817
std::string cid;
1918
std::string digest;
20-
uint64_t sector_size;
19+
uint64_t sector_size = 0;
2120
};
2221

2322
class ProofParamProvider {
@@ -31,9 +30,8 @@ namespace fc::proofs {
3130
private:
3231
static void fetch(const ParamFile &info);
3332
static outcome::result<void> doFetch(const std::string &out,
34-
ParamFile info);
33+
const ParamFile &info);
3534

36-
static boost::mutex fetch_mutex_;
3735
static common::Logger logger_;
3836
};
3937

0 commit comments

Comments
 (0)