Skip to content

Commit c42535e

Browse files
committed
Final touches
1 parent 8546dc4 commit c42535e

File tree

8 files changed

+86
-82
lines changed

8 files changed

+86
-82
lines changed

crypto/vm/cells/CellUsageContainer.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,40 @@
55
#include <vector>
66
#include <mutex>
77

8+
/**
9+
* Thread-safe container for storing cell usage tree nodes.
10+
* @tparam T node type
11+
*/
812
template <typename T>
9-
class DynamicArray {
10-
static constexpr size_t kBlockSize = std::max(1ul, 4096 / sizeof(T));
11-
static constexpr size_t kDefaultSize = 512;
13+
class CellUsageContainer {
14+
static constexpr size_t BLOCK_SIZE = std::max(1ul, 4096 / sizeof(T));
15+
static constexpr size_t DEFAULT_CAP = 512;
1216

1317
public:
14-
explicit DynamicArray(size_t initial_size) : size_(0), cap_(0) {
18+
explicit CellUsageContainer(size_t initial_size) : size_(0), cap_(0) {
1519
static_assert(std::atomic<T**>::is_always_lock_free);
16-
resize(0, (std::max(kDefaultSize, initial_size) + kBlockSize - 1) / kBlockSize);
20+
ensure_capacity(0, (std::max(DEFAULT_CAP, initial_size) + BLOCK_SIZE - 1) / BLOCK_SIZE);
1721
size_ = initial_size;
1822
}
1923

2024
const T& operator[](size_t i) const {
21-
return pointer_[i / kBlockSize][i % kBlockSize];
25+
return pointer_[i / BLOCK_SIZE][i % BLOCK_SIZE];
2226
}
2327

2428
T& operator[](size_t i) {
25-
return pointer_[i / kBlockSize][i % kBlockSize];
29+
return pointer_[i / BLOCK_SIZE][i % BLOCK_SIZE];
2630
}
2731

2832
size_t emplace_back() {
2933
size_t pos = size_.fetch_add(1);
3034
size_t current_cap;
31-
while (pos / kBlockSize >= (current_cap = cap_.load())) {
32-
resize(current_cap, 2 * current_cap);
35+
while (pos / BLOCK_SIZE >= (current_cap = cap_.load())) {
36+
ensure_capacity(current_cap, 2 * current_cap);
3337
}
3438
return pos;
3539
}
3640

37-
~DynamicArray() {
41+
~CellUsageContainer() {
3842
for (size_t i = 0; i < cap_; ++i) {
3943
delete[] pointer_[i];
4044
}
@@ -53,7 +57,7 @@ class DynamicArray {
5357

5458
std::vector<T**> storage_;
5559

56-
void resize(size_t current_cap, size_t target_cap) {
60+
void ensure_capacity(size_t current_cap, size_t target_cap) {
5761
std::lock_guard lock(resize_lock_);
5862
if (current_cap != cap_) {
5963
return;
@@ -64,7 +68,7 @@ class DynamicArray {
6468
new_data[i] = pointer_[i];
6569
}
6670
for (size_t i = cap_; i < target_cap; ++i) {
67-
new_data[i] = new T[kBlockSize];
71+
new_data[i] = new T[BLOCK_SIZE];
6872
}
6973
storage_.emplace_back(new_data);
7074
pointer_.store(new_data);

crypto/vm/cells/CellUsageTree.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include "vm/cells/CellUsageTree.h"
2020
#include "DataCell.h"
2121

22-
#include <mutex>
23-
2422
namespace vm {
2523
//
2624
// CellUsageTree::NodePtr

crypto/vm/cells/CellUsageTree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class CellUsageTree : public std::enable_shared_from_this<CellUsageTree> {
8787
std::array<td::uint32, CellTraits::max_refs> children{};
8888
};
8989
bool use_mark_{false};
90-
DynamicArray<Node> nodes_{2};
90+
CellUsageContainer<Node> nodes_{2};
9191
std::function<void(const LoadedCell&)> cell_load_callback_;
9292

9393
void on_load(NodeId node_id, const LoadedCell& loaded_cell);

crypto/vm/dict.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ bool DictionaryBase::append_dict_to_bool(CellBuilder& cb) && {
180180
return cb.store_maybe_ref(std::move(root_cell));
181181
}
182182

183-
bool DictionaryBase::append_dict_to_bool(CellBuilder& cb) const& {
183+
bool DictionaryBase::append_dict_to_bool(CellBuilder& cb) const & {
184184
return is_valid() && cb.store_maybe_ref(root_cell);
185185
}
186186

@@ -1102,8 +1102,8 @@ Ref<CellSlice> Dictionary::lookup_set_gen(td::ConstBitPtr key, int key_len, cons
11021102
}
11031103

11041104
Ref<CellSlice> Dictionary::lookup_set(td::ConstBitPtr key, int key_len, Ref<CellSlice> value, SetMode mode) {
1105-
return lookup_set_gen(
1106-
key, key_len, [value](CellBuilder& cb) { return cell_builder_add_slice_bool(cb, *value); }, mode);
1105+
return lookup_set_gen(key, key_len, [value](CellBuilder& cb) { return cell_builder_add_slice_bool(cb, *value); },
1106+
mode);
11071107
}
11081108

11091109
Ref<Cell> Dictionary::lookup_set_ref(td::ConstBitPtr key, int key_len, Ref<Cell> val_ref, SetMode mode) {
@@ -2282,7 +2282,7 @@ bool DictionaryFixed::dict_check_for_each(Ref<Cell> dict, td::BitPtr key_buffer,
22822282
if (l) {
22832283
invert_first = false;
22842284
}
2285-
bool invert = shuffle ? td::Random::fast(0, 1) == 1 : invert_first;
2285+
bool invert = shuffle ? td::Random::fast(0, 1) == 1: invert_first;
22862286
if (invert) {
22872287
std::swap(c1, c2);
22882288
}
@@ -2804,7 +2804,7 @@ Ref<CellSlice> AugmentedDictionary::extract_root() && {
28042804
return std::move(root);
28052805
}
28062806

2807-
bool AugmentedDictionary::append_dict_to_bool(CellBuilder& cb) const& {
2807+
bool AugmentedDictionary::append_dict_to_bool(CellBuilder& cb) const & {
28082808
if (!is_valid()) {
28092809
return false;
28102810
}

crypto/vm/dict.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class DictionaryBase {
138138
return std::move(root_cell);
139139
}
140140
bool append_dict_to_bool(CellBuilder& cb) &&;
141-
bool append_dict_to_bool(CellBuilder& cb) const&;
141+
bool append_dict_to_bool(CellBuilder& cb) const &;
142142
int get_key_bits() const {
143143
return key_bits;
144144
}
@@ -575,7 +575,7 @@ class AugmentedDictionary final : public DictionaryFixed {
575575
Ref<Cell> get_wrapped_dict_root() const;
576576
Ref<CellSlice> extract_root() &&;
577577
bool append_dict_to_bool(CellBuilder& cb) &&;
578-
bool append_dict_to_bool(CellBuilder& cb) const&;
578+
bool append_dict_to_bool(CellBuilder& cb) const &;
579579
Ref<CellSlice> get_root_extra() const;
580580
Ref<CellSlice> lookup(td::ConstBitPtr key, int key_len);
581581
Ref<Cell> lookup_ref(td::ConstBitPtr key, int key_len);

validator-engine/validator-engine.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5483,7 +5483,7 @@ int main(int argc, char *argv[]) {
54835483
});
54845484
p.add_option(
54855485
'\0', "celldb-disable-bloom-filter",
5486-
"disable using bloom filter in CellDb. Enabled bloom filter reduces read latency, but increases memory usage",
5486+
"disable using bloom filter in CellDb. Enabled bloom filter reduces read latency, but increases memory usage",
54875487
[&]() {
54885488
acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_celldb_disable_bloom_filter, true); });
54895489
});
@@ -5598,13 +5598,9 @@ int main(int argc, char *argv[]) {
55985598
}
55995599
return td::Status::OK();
56005600
});
5601-
p.add_option(
5602-
'\0', "parallel-accounts-validation",
5603-
"parallel validation over different accounts",
5604-
[&]() {
5605-
acts.push_back(
5606-
[&x]() { td::actor::send_closure(x, &ValidatorEngine::set_parallel_accounts_validation, true); });
5607-
});
5601+
p.add_option('\0', "parallel-accounts-validation", "parallel validation over different accounts", [&]() {
5602+
acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_parallel_accounts_validation, true); });
5603+
});
56085604
auto S = p.run(argc, argv);
56095605
if (S.is_error()) {
56105606
LOG(ERROR) << "failed to parse options: " << S.move_as_error();

0 commit comments

Comments
 (0)