diff --git a/test/print-all-shard-states.cpp b/test/print-all-shard-states.cpp index d0a4784d..fe599f05 100644 --- a/test/print-all-shard-states.cpp +++ b/test/print-all-shard-states.cpp @@ -4,15 +4,11 @@ #include "td/actor/actor.h" #include "td/utils/logging.h" -// TON / CellDb includes (проверьте свои пути) #include "validator/db/celldb.hpp" -// ====================== GLOBAL STORAGE FOR ACTORS ===================== -// Чтобы актор LoadCellActor не уничтожился, когда локальная переменная исчезнет. static td::actor::ActorOwn g_cell_db_actor; static td::actor::ActorOwn g_loader_actor; // LoadCellActor хранить здесь -// ============ 1) Актор, печатающий все ключи (если нужно) ============ class PrintHashesActor : public td::actor::Actor { public: explicit PrintHashesActor(td::actor::ActorId cell_db) @@ -21,14 +17,13 @@ class PrintHashesActor : public td::actor::Actor { void start_up() override { LOG(INFO) << "PrintHashesActor: calling CellDb::print_all_hashes()"; td::actor::send_closure(cell_db_, &ton::validator::CellDb::print_all_hashes); - stop(); // завершить работу + stop(); } private: td::actor::ActorId cell_db_; }; -// ============ Helper: Парсим 64-hex-символов в ton::RootHash ============ ton::RootHash parse_hex_hash(const std::string &hex_str) { if (hex_str.size() != 64) { throw std::runtime_error("Root hash must be 64 hex chars"); @@ -46,18 +41,12 @@ ton::RootHash parse_hex_hash(const std::string &hex_str) { return root; } -// ============ MAIN ============ - int main(int argc, char* argv[]) { - // Аргументы: path/to/celldb [64-hex-hash] if (argc < 2) { std::cerr << "Usage: " << argv[0] << " /path/to/celldb [64-hex-hash]\n"; return 1; } - // Если нужно, включите логи - // td::Logger::instance().set_verbosity_level(3); - std::string celldb_path = argv[1]; bool load_hash = (argc > 2); ton::RootHash cell_hash; @@ -66,19 +55,14 @@ int main(int argc, char* argv[]) { LOG(INFO) << "We will load hash = " << cell_hash.to_hex(); } - // Создаём Scheduler td::actor::Scheduler scheduler({1}); // 1-thread - // Запускаем инициализацию в run_in_context, чтобы всё делалось внутри Actor среды scheduler.run_in_context([&] { - // 1) Строим opts (ValidatorManagerOptions) auto opts = ton::validator::ValidatorManagerOptions::create( - // 2 аргумента, если у вас 2-param create ton::BlockIdExt{ton::masterchainId, ton::shardIdAll, 0, ton::RootHash::zero(), ton::FileHash::zero()}, ton::BlockIdExt{ton::masterchainId, ton::shardIdAll, 0, ton::RootHash::zero(), ton::FileHash::zero()} ); - // 2) Создаём CellDb g_cell_db_actor = td::actor::create_actor( "celldb_actor", td::actor::ActorId(), // пустой @@ -86,16 +70,12 @@ int main(int argc, char* argv[]) { opts ); - // Если захотите печатать все ключи: auto printer_actor = td::actor::create_actor("printer", g_cell_db_actor.get()); }); - // Главный цикл - while (scheduler.run(0.1)) { - // do nothing + while (scheduler.run(1)) { } - // Останавливаем планировщик scheduler.stop(); LOG(INFO) << "Done. Exiting."; diff --git a/validator/db/celldb.cpp b/validator/db/celldb.cpp index 22a84305..57924d17 100644 --- a/validator/db/celldb.cpp +++ b/validator/db/celldb.cpp @@ -265,31 +265,24 @@ void CellDbIn::get_cell_db_reader(td::Promise> promise.set_result(boc_->get_cell_db_reader()); } -// In celldb.cpp (somewhere after CellDbIn is declared and defined) void CellDbIn::print_all_hashes() { LOG(INFO) << "Enumerating keys in CellDb..."; - // Create a snapshot of RocksDB so we can iterate it auto snapshot = cell_db_->snapshot(); - // snapshot->for_each(...) calls our lambda for each (key, value) pair in the DB auto status = snapshot->for_each([&](td::Slice raw_key, td::Slice raw_value) -> td::Status { - // Special check: in official CellDb code, the "empty" key is "desczero" if (raw_key == "desczero") { LOG(INFO) << "Found empty key: desczero"; return td::Status::OK(); } - // Check if the key starts with "desc" if (raw_key.size() >= 4 && std::memcmp(raw_key.data(), "desc", 4) == 0) { if (raw_key.size() == 4 + 44) { - // Slice out the 32-byte hash KeyHash khash; LOG(INFO) << "raw_key: " << raw_key.substr(4, 44); auto hash_part = td::base64_decode(raw_key.substr(4, 44)).move_as_ok(); std::memcpy(khash.as_slice().begin(), hash_part.data(), 32); auto block = get_block(khash).move_as_ok(); - // LOG(INFO) << raw_key.str(); LOG(INFO) << "Found key: hash=" << block.root_hash << " d: " << block.root_hash.to_hex(); LOG(INFO) << "Block_id = " << block.block_id.to_str(); @@ -705,7 +698,6 @@ void CellDb::get_block_id(CellDbIn::KeyHash key_hash, td::Promise pr } void CellDb::print_all_hashes() { - // The underlying RocksDB tasks happen in the CellDbIn actor, so we forward: td::actor::send_closure(cell_db_, &CellDbIn::print_all_hashes); }