Skip to content

Commit ad026fd

Browse files
authoredFeb 16, 2022
lookback sectors deadlines (#598)
Signed-off-by: turuslan <[email protected]>
1 parent 24d8b4d commit ad026fd

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
 

‎core/codec/cbor/light_reader/amt_walk.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@ namespace fc::codec::cbor::light_reader {
1212
struct AmtWalk : Walk {
1313
using Walk::Walk;
1414

15+
bool visit() {
16+
if (!load()) {
17+
return false;
18+
}
19+
BytesIn value;
20+
while (next(value)) {
21+
// note: ignoring value
22+
}
23+
return empty();
24+
}
25+
1526
inline bool load() {
27+
if (next_cid != 0) {
28+
return true;
29+
}
1630
cbor::CborToken token;
1731
if (!Walk::next()) {
1832
return false;

‎core/codec/cbor/light_reader/miner_actor_reader.hpp

+40
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,44 @@ namespace fc::codec::cbor::light_reader {
9595
}
9696
return std::make_tuple(*miner_info, *sectors, *deadlines);
9797
}
98+
99+
template <typename F>
100+
inline bool minerDeadlines(const CbIpldPtr &ipld,
101+
const CbCid &_deadlines,
102+
const F &f) {
103+
Bytes deadlines_cbor;
104+
if (!ipld->get(_deadlines, deadlines_cbor)) {
105+
return false;
106+
}
107+
BytesIn deadlines_input{deadlines_cbor};
108+
cbor::CborToken token;
109+
if (!read(token, deadlines_input).listCount()) {
110+
return false;
111+
}
112+
if (!read(token, deadlines_input).listCount()) {
113+
return false;
114+
}
115+
Bytes deadline_cbor;
116+
for (size_t n{*token.listCount()}; n != 0; --n) {
117+
const CbCid *_deadline = nullptr;
118+
if (!cbor::readCborBlake(_deadline, deadlines_input)) {
119+
return false;
120+
}
121+
if (!ipld->get(*_deadline, deadline_cbor)) {
122+
return false;
123+
}
124+
BytesIn deadline_input{deadline_cbor};
125+
if (!read(token, deadline_input).listCount()) {
126+
return false;
127+
}
128+
const CbCid *_partitions = nullptr;
129+
if (!cbor::readCborBlake(_partitions, deadline_input)) {
130+
return false;
131+
}
132+
if (!f(*_deadline, *_partitions)) {
133+
return false;
134+
}
135+
}
136+
return true;
137+
}
98138
} // namespace fc::codec::cbor::light_reader

‎core/storage/compacter/lookback.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
#include "codec/cbor/light_reader/actor.hpp"
99
#include "codec/cbor/light_reader/address.hpp"
10+
#include "codec/cbor/light_reader/amt_walk.hpp"
1011
#include "codec/cbor/light_reader/hamt_walk.hpp"
1112
#include "codec/cbor/light_reader/miner_actor_reader.hpp"
1213
#include "codec/cbor/light_reader/state_tree.hpp"
1314
#include "codec/cbor/light_reader/storage_power_actor_reader.hpp"
15+
#include "common/append.hpp"
1416
#include "storage/compacter/queue.hpp"
1517
#include "vm/actor/codes.hpp"
1618

@@ -46,6 +48,18 @@ namespace fc::storage::compacter {
4648
const auto &[info, sectors, deadlines]{_r.value()};
4749
copy.push_back(head);
4850
copy.push_back(info);
51+
recurse.push_back(sectors);
52+
copy.push_back(deadlines);
53+
codec::cbor::light_reader::minerDeadlines(
54+
ipld, deadlines, [&](const CbCid &deadline, const CbCid &partitions) {
55+
copy.push_back(deadline);
56+
codec::cbor::light_reader::AmtWalk walk{ipld, partitions};
57+
if (!walk.visit()) {
58+
return false;
59+
}
60+
append(copy, walk.cids);
61+
return true;
62+
});
4963
return;
5064
}
5165
if (ACTOR_CODE_IS(kStoragePowerCodeId)) {

0 commit comments

Comments
 (0)