1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Initial commit of block generator for fisherman testing

This commit is contained in:
trinitil 2025-01-28 13:35:02 +04:00
parent ea0dc16163
commit 383a0c574a
14 changed files with 523 additions and 2 deletions

View file

@ -890,7 +890,7 @@ void ArchiveManager::start_up() {
td::WalkPath::run(db_root_ + "/archive/states/", [&](td::CSlice fname, td::WalkPath::Type t) -> void {
if (t == td::WalkPath::Type::NotDir) {
LOG(ERROR) << "checking file " << fname;
LOG(DEBUG) << "checking file " << fname;
auto pos = fname.rfind(TD_DIR_SLASH);
if (pos != td::Slice::npos) {
fname.remove_prefix(pos + 1);

View file

@ -265,6 +265,48 @@ void CellDbIn::get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>>
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();
} else {
LOG(INFO) << "Found key with \"desc\" prefix but not 48 bytes: key.size()=" << raw_key.size();
}
}
return td::Status::OK();
});
if (status.is_error()) {
LOG(ERROR) << "Iteration error: " << status.error().message();
} else {
LOG(INFO) << "Done enumerating CellDb keys.";
}
}
std::vector<std::pair<std::string, std::string>> CellDbIn::prepare_stats() {
TD_PERF_COUNTER(celldb_prepare_stats);
auto r_boc_stats = boc_->get_stats();
@ -528,6 +570,15 @@ td::Result<CellDbIn::DbEntry> CellDbIn::get_block(KeyHash key_hash) {
return DbEntry{obj.move_as_ok()};
}
void CellDbIn::get_block_id_async(KeyHash key_hash, td::Promise<BlockIdExt> promise) {
auto result = get_block(key_hash);
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(result.move_as_ok().block_id);
}
}
void CellDbIn::set_block(KeyHash key_hash, DbEntry e) {
const auto key = get_key(key_hash);
cell_db_->set(td::as_slice(key), e.release()).ensure();
@ -649,6 +700,15 @@ void CellDb::get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>> p
td::actor::send_closure(cell_db_, &CellDbIn::get_cell_db_reader, std::move(promise));
}
void CellDb::get_block_id(CellDbIn::KeyHash key_hash, td::Promise<BlockIdExt> promise) {
td::actor::send_closure(cell_db_, &CellDbIn::get_block_id_async, key_hash, std::move(promise));
}
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);
}
void CellDb::start_up() {
CellDbBase::start_up();
boc_ = vm::DynamicBagOfCellsDb::create();

View file

@ -66,6 +66,8 @@ class CellDbIn : public CellDbBase {
void load_cell(RootHash hash, td::Promise<td::Ref<vm::DataCell>> promise);
void store_cell(BlockIdExt block_id, td::Ref<vm::Cell> cell, td::Promise<td::Ref<vm::DataCell>> promise);
void get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>> promise);
void get_block_id_async(KeyHash key_hash, td::Promise<BlockIdExt> promise);
void print_all_hashes();
void migrate_cell(td::Bits256 hash);
@ -204,6 +206,8 @@ class CellDb : public CellDbBase {
in_memory_boc_ = std::move(in_memory_boc);
}
void get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>> promise);
void get_block_id(CellDbIn::KeyHash key_hash, td::Promise<BlockIdExt> promise);
void print_all_hashes();
CellDb(td::actor::ActorId<RootDb> root_db, std::string path, td::Ref<ValidatorManagerOptions> opts)
: root_db_(root_db), path_(path), opts_(opts) {