generated from Warchant/cmake-hunter-seed
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathworker.hpp
194 lines (161 loc) · 5.95 KB
/
worker.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "common/outcome.hpp"
#include "common/vector_cow.hpp"
#include "primitives/piece/piece.hpp"
#include "primitives/piece/piece_data.hpp"
#include "primitives/seal_tasks/task.hpp"
#include "primitives/sector/sector.hpp"
#include "primitives/sector_file/sector_file.hpp"
#include "proofs/proof_engine.hpp"
#include "sector_storage/stores/store.hpp"
#include "sector_storage/stores/store_error.hpp"
namespace fc::api {
struct StorageMinerApi;
} // namespace fc::api
namespace fc::sector_storage {
using primitives::piece::PieceData;
using primitives::piece::PieceInfo;
using primitives::piece::UnpaddedByteIndex;
using primitives::piece::UnpaddedPieceSize;
using primitives::sector::InteractiveRandomness;
using primitives::sector::Proof;
using primitives::sector::SealRandomness;
using primitives::sector::SectorId;
using primitives::sector::SectorRef;
using primitives::sector_file::SectorFileType;
using stores::AcquireMode;
using stores::PathType;
using stores::StoreError;
using PreCommit1Output = proofs::Phase1Output;
using Commit1Output = proofs::Phase1Output;
using Update1Output = proofs::UpdateProofs1;
using SectorCids = proofs::SealedAndUnsealedCID;
using ReplicaUpdateOut = proofs::SealedAndUnsealedCID;
struct Range {
UnpaddedPieceSize offset;
UnpaddedPieceSize size;
};
inline bool operator==(const Range &lhs, const Range &rhs) {
return lhs.offset == rhs.offset && lhs.size == rhs.size;
}
struct CallId {
SectorId sector{};
std::string id; // uuid
};
CBOR_TUPLE(CallId, sector, id);
inline bool operator<(const CallId &lhs, const CallId &rhs) {
return less(lhs.sector, rhs.sector, lhs.id, rhs.id);
}
inline bool operator==(const CallId &lhs, const CallId &rhs) {
return lhs.sector == rhs.sector && lhs.id == rhs.id;
}
class WorkerCalls {
public:
virtual ~WorkerCalls() = default;
virtual outcome::result<CallId> addPiece(
const SectorRef §or,
VectorCoW<UnpaddedPieceSize> piece_sizes,
const UnpaddedPieceSize &new_piece_size,
PieceData piece_data) = 0;
virtual outcome::result<CallId> sealPreCommit1(
const SectorRef §or,
const SealRandomness &ticket,
const std::vector<PieceInfo> &pieces) = 0;
virtual outcome::result<CallId> sealPreCommit2(
const SectorRef §or,
const PreCommit1Output &pre_commit_1_output) = 0;
virtual outcome::result<CallId> sealCommit1(
const SectorRef §or,
const SealRandomness &ticket,
const InteractiveRandomness &seed,
const std::vector<PieceInfo> &pieces,
const SectorCids &cids) = 0;
virtual outcome::result<CallId> sealCommit2(
const SectorRef §or, const Commit1Output &commit_1_output) = 0;
virtual outcome::result<CallId> finalizeSector(
const SectorRef §or, std::vector<Range> keep_unsealed) = 0;
virtual outcome::result<CallId> replicaUpdate(
const SectorRef §or, const std::vector<PieceInfo> &pieces) = 0;
virtual outcome::result<CallId> proveReplicaUpdate1(
const SectorRef §or,
const CID §or_key,
const CID &new_sealed,
const CID &new_unsealed) = 0;
virtual outcome::result<CallId> proveReplicaUpdate2(
const SectorRef §or,
const CID §or_key,
const CID &new_sealed,
const CID &new_unsealed,
const Update1Output &update_1_output) = 0;
virtual outcome::result<CallId> moveStorage(const SectorRef §or,
SectorFileType types) = 0;
virtual outcome::result<CallId> unsealPiece(
const SectorRef §or,
UnpaddedByteIndex offset,
const UnpaddedPieceSize &size,
const SealRandomness &randomness,
const CID &unsealed_cid) = 0;
virtual outcome::result<CallId> readPiece(
PieceData output,
const SectorRef §or,
UnpaddedByteIndex offset,
const UnpaddedPieceSize &size) = 0;
virtual outcome::result<CallId> fetch(const SectorRef §or,
const SectorFileType &file_type,
PathType path_type,
AcquireMode mode) = 0;
};
class Worker : public WorkerCalls {
public:
virtual outcome::result<primitives::WorkerInfo> getInfo() = 0;
virtual outcome::result<std::set<primitives::TaskType>>
getSupportedTask() = 0;
virtual outcome::result<std::vector<primitives::StoragePath>>
getAccessiblePaths() = 0;
virtual void ping(std::function<void(const bool resp)> cb) = 0;
};
enum class CallErrorCode : uint64_t {
kUnknown = 0,
kWorkerRestart = 101, // from lotus
kAllocateSpace // same as StoreError::kCannotReserve
};
struct CallError {
CallErrorCode code;
std::string message;
};
struct CallResult {
// `Bytes` = (`Proof` | `PreCommit1Output` | `Commit1Output`)
// 'SealedAndUnsealedCID' = ('SectorCids' | 'ReplicaUpdateOut)
std::variant<std::monostate,
PieceInfo,
Bytes,
bool,
Update1Output,
proofs::SealedAndUnsealedCID>
value;
boost::optional<CallError> maybe_error;
};
using ReturnCb = std::function<void(outcome::result<CallResult>)>;
using WorkerReturn = api::StorageMinerApi;
enum class WorkerErrors {
kCannotCreateSealedFile = 1,
kCannotCreateCacheDir,
kCannotRemoveCacheDir,
kPiecesDoNotMatchSectorSize,
kCannotCreateTempFile,
kCannotGetNumberOfCPUs,
kCannotGetVMStat,
kCannotGetPageSize,
kCannotOpenMemInfoFile,
kCannotRemoveSector,
kUnsupportedPlatform,
kOutOfBound,
kCannotOpenFile,
kUnsupportedCall,
};
} // namespace fc::sector_storage
OUTCOME_HPP_DECLARE_ERROR(fc::sector_storage, WorkerErrors);