Skip to content

Commit 90d3186

Browse files
Feature/filecoin ffi update (#554)
* update filecoin-ffi to 52d80081bfdd8a30bc44bcfe44cb0f299615b9f3 * proof engine update - add UpdateProof Signed-off-by: Alexey Chernyshov <[email protected]>
1 parent 65190ea commit 90d3186

File tree

9 files changed

+219
-54
lines changed

9 files changed

+219
-54
lines changed

core/primitives/sector/sector.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ namespace fc::primitives::sector {
6767
SnarkPackV1,
6868
};
6969

70+
/**
71+
* Empty sector update.
72+
*/
73+
enum class RegisteredUpdateProof : int64_t {
74+
kUndefined = -1,
75+
76+
kStackedDrg2KiBV1,
77+
kStackedDrg8MiBV1,
78+
kStackedDrg512MiBV1,
79+
kStackedDrg32GiBV1,
80+
kStackedDrg64GiBV1,
81+
};
82+
7083
/**
7184
* Produces the PoSt-specific RegisteredProof corresponding to the receiving
7285
* RegisteredSealProof.
@@ -230,6 +243,20 @@ namespace fc::primitives::sector {
230243
aggregate_proof,
231244
proof,
232245
infos)
246+
247+
struct ReplicaUpdateInfo {
248+
RegisteredUpdateProof update_proof_type{};
249+
CID old_sealed_sector_cid;
250+
CID new_sealed_sector_cid;
251+
CID new_unsealed_sector_cid;
252+
Bytes proof;
253+
};
254+
CBOR_TUPLE(ReplicaUpdateInfo,
255+
update_proof_type,
256+
old_sealed_sector_cid,
257+
new_sealed_sector_cid,
258+
new_unsealed_sector_cid,
259+
proof);
233260
} // namespace fc::primitives::sector
234261

235262
OUTCOME_HPP_DECLARE_ERROR(fc::primitives::sector, Errors);

core/primitives/sector_file/sector_file.cpp

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ namespace fc::primitives::sector_file {
9999
}
100100

101101
outcome::result<SectorId> parseSectorName(const std::string &sector_str) {
102-
SectorNumber sector_id;
103-
ActorId miner_id;
102+
SectorNumber sector_id{};
103+
ActorId miner_id{};
104104

105105
auto count =
106-
std::sscanf(sector_str.c_str(), "s-t0%lld-%lld", &miner_id, &sector_id);
106+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
107+
std::sscanf(sector_str.c_str(), "s-t0%ld-%ld", &miner_id, &sector_id);
107108

108109
if (count != 2) {
109110
return SectorFileTypeErrors::kInvalidSectorName;
@@ -137,11 +138,11 @@ namespace fc::primitives::sector_file {
137138
trailer.put(0, 1);
138139
}
139140
is_first = false;
140-
} else if (not(i % 2) == is_previous_value) {
141+
} else if (((i % 2) == 0) == is_previous_value) {
141142
return SectorFileError::kInvalidRuns;
142143
}
143144

144-
is_previous_value = not(i % 2);
145+
is_previous_value = ((i % 2) == 0);
145146

146147
if (runs[i] == 1) {
147148
trailer.put(1, 1);
@@ -182,23 +183,24 @@ namespace fc::primitives::sector_file {
182183
return SectorFileError::kCannotMoveCursor;
183184
}
184185

185-
file.write((char *)trailer.data(), trailer.size());
186+
file.write(common::span::bytestr(trailer.data()),
187+
gsl::narrow<int64_t>(trailer.size()));
186188

187189
if (!file.good()) {
188190
return SectorFileError::kCannotWrite;
189191
}
190192

191193
boost::endian::little_uint32_buf_t trailer_size(trailer.size());
192194

193-
file.write((char *)trailer_size.data(), sizeof(uint32_t));
195+
file.write(common::span::bytestr(trailer_size.data()), sizeof(uint32_t));
194196

195197
if (!file.good()) {
196198
return SectorFileError::kCannotWrite;
197199
}
198200

199201
file.close();
200202

201-
boost::system::error_code ec;
203+
boost::system::error_code ec{};
202204
fs::resize_file(
203205
path, max_piece_size + sizeof(uint32_t) + trailer.size(), ec);
204206
if (ec.failed()) {
@@ -211,13 +213,14 @@ namespace fc::primitives::sector_file {
211213
outcome::result<std::shared_ptr<SectorFile>> SectorFile::createFile(
212214
const std::string &path, PaddedPieceSize max_piece_size) {
213215
{
216+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
214217
int fd = open(path.c_str(), O_RDWR | O_CREAT, 0644);
215218
if (fd == -1) {
216219
return SectorFileError::kCannotCreateFile;
217220
}
218221
close(fd);
219222
}
220-
boost::system::error_code ec;
223+
boost::system::error_code ec{};
221224
fs::resize_file(path, max_piece_size, ec);
222225
if (ec.failed()) {
223226
return SectorFileError::kCannotResizeFile;
@@ -233,7 +236,7 @@ namespace fc::primitives::sector_file {
233236
if (!fs::exists(path)) {
234237
return SectorFileError::kFileNotExist;
235238
}
236-
239+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
237240
int fd = open(path.c_str(), O_RDWR, 0644);
238241
if (fd == -1) {
239242
return SectorFileError::kCannotOpenFile;
@@ -250,7 +253,7 @@ namespace fc::primitives::sector_file {
250253
pread(fd,
251254
trailer_size_buf.data(),
252255
trailer_size_bytes,
253-
file_size - trailer_size_bytes);
256+
gsl::narrow<int64_t>(file_size - trailer_size_bytes));
254257

255258
uint64_t trailer_size = trailer_size_buf.value();
256259

@@ -261,7 +264,8 @@ namespace fc::primitives::sector_file {
261264
uint64_t trailer_offset = file_size - trailer_size_bytes - trailer_size;
262265

263266
std::vector<uint8_t> trailer(trailer_size);
264-
pread(fd, trailer.data(), trailer_size, trailer_offset);
267+
pread(
268+
fd, trailer.data(), trailer_size, gsl::narrow<int64_t>(trailer_offset));
265269

266270
OUTCOME_TRY(runs, runsFromBuffer(trailer));
267271

@@ -304,7 +308,7 @@ namespace fc::primitives::sector_file {
304308

305309
outcome::result<void> SectorFile::free(PaddedByteIndex offset,
306310
PaddedPieceSize size) {
307-
// TODO: deallocate
311+
// TODO(ortyomka): deallocate
308312

309313
auto new_runs =
310314
primitives::runsAnd(runs_, std::vector<uint64_t>{offset, size}, true);
@@ -340,6 +344,7 @@ namespace fc::primitives::sector_file {
340344
logger_ = common::createLogger("sector file");
341345
}
342346

347+
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
343348
outcome::result<boost::optional<PieceInfo>> SectorFile::write(
344349
const PieceData &data,
345350
PaddedByteIndex offset,
@@ -365,7 +370,7 @@ namespace fc::primitives::sector_file {
365370
}
366371
}
367372

368-
file_.seekp(offset, std::ios_base::beg);
373+
file_.seekp(gsl::narrow<int64_t>(offset), std::ios_base::beg);
369374

370375
if (not file_.good()) {
371376
return SectorFileError::kCannotMoveCursor;
@@ -398,7 +403,7 @@ namespace fc::primitives::sector_file {
398403
(char *)(buffer.data() + read),
399404
chunk_size.unpadded() - read);
400405
if (current_read == -1) {
401-
// TODO: check errno
406+
// TODO(ortyomka): check errno
402407
return SectorFileError::kCannotRead;
403408
}
404409

@@ -472,7 +477,7 @@ namespace fc::primitives::sector_file {
472477
}
473478
}
474479

475-
file_.seekg(offset, std::ios_base::beg);
480+
file_.seekg(gsl::narrow<int64_t>(offset), std::ios_base::beg);
476481

477482
if (!file_.good()) {
478483
return SectorFileError::kCannotMoveCursor;
@@ -482,15 +487,15 @@ namespace fc::primitives::sector_file {
482487
constexpr auto kDefaultBufferSize = uint64_t(32 * 1024);
483488
PaddedPieceSize output_size =
484489
primitives::piece::paddedSize(kDefaultBufferSize).padded();
485-
std::vector<uint8_t> read(output_size);
490+
std::vector<char> read(output_size);
486491
std::vector<uint8_t> buffer(output_size.unpadded());
487492

488493
while (left > 0) {
489494
if (left < output_size.unpadded()) {
490495
output_size = primitives::piece::paddedSize(left).padded();
491496
}
492497

493-
file_.read((char *)read.data(), output_size);
498+
file_.read(read.data(), gsl::narrow<int64_t>(output_size));
494499

495500
if (!file_.good()) {
496501
return SectorFileError::kCannotRead;
@@ -500,17 +505,18 @@ namespace fc::primitives::sector_file {
500505
return SectorFileError::kNotReadEnough;
501506
}
502507

508+
// TODO(ortyomka): maybe boost map file
503509
primitives::piece::unpad(
504-
gsl::make_span(read.data(), output_size),
505-
gsl::make_span(
506-
buffer.data(),
507-
output_size.unpadded())); // TODO: maybe boost map file
510+
common::span::cbytes(
511+
gsl::make_span(read.data(), gsl::narrow<int64_t>(output_size))),
512+
gsl::make_span(buffer.data(),
513+
gsl::narrow<int64_t>(output_size.unpadded())));
508514

509515
auto write_size =
510516
::write(output.getFd(), buffer.data(), output_size.unpadded());
511517

512518
if (write_size == -1) {
513-
// TODO: check errno
519+
// TODO(ortyomka): check errno
514520
return SectorFileError::kCannotWrite;
515521
}
516522

@@ -568,16 +574,19 @@ namespace fc::primitives::sector_file {
568574
}
569575

570576
primitives::piece::pad(
571-
gsl::make_span<const uint8_t>(input.data(), biggest),
572-
gsl::make_span<uint8_t>(work_.data(), biggest.padded()));
577+
gsl::make_span<const uint8_t>(input.data(),
578+
gsl::narrow<int64_t>(biggest)),
579+
gsl::make_span<uint8_t>(work_.data(),
580+
gsl::narrow<int64_t>(biggest.padded())));
573581

574-
output_.write((char *)work_.data(), biggest.padded());
582+
output_.write(common::span::bytestr(work_.data()),
583+
gsl::narrow<int64_t>(biggest.padded()));
575584

576585
if (not output_.good()) {
577586
return SectorFileError::kCannotWrite;
578587
}
579588

580-
input.erase(input.begin(), input.begin() + biggest);
589+
input.erase(input.begin(), input.begin() + gsl::narrow<int64_t>(biggest));
581590

582591
if (input.size() < 127) {
583592
stash_ = std::move(input);

0 commit comments

Comments
 (0)