Skip to content

Commit

Permalink
remove usage of rocksdb in fift-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
neodiX committed Jul 4, 2024
1 parent 0523892 commit e8eb0de
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 248 deletions.
18 changes: 1 addition & 17 deletions crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,6 @@ set(TON_CRYPTO_SOURCE
vm/vm.h
vm/bls.h)

set(TON_DB_SOURCE
vm/db/DynamicBagOfCellsDb.cpp
vm/db/CellStorage.cpp
vm/db/TonDb.cpp

vm/db/DynamicBagOfCellsDb.h
vm/db/CellHashTable.h
vm/db/CellStorage.h
vm/db/TonDb.h
)

set(FIFT_SOURCE
fift/Dictionary.cpp
fift/Fift.cpp
Expand Down Expand Up @@ -347,18 +336,13 @@ endif()
target_include_directories(ton_crypto_core PUBLIC $<BUILD_INTERFACE:${SODIUM_INCLUDE_DIR}>)
target_link_libraries(ton_crypto PUBLIC ${SODIUM_LIBRARY_RELEASE})

add_library(ton_db STATIC ${TON_DB_SOURCE})
target_include_directories(ton_db PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
target_link_libraries(ton_db PUBLIC tdutils tddb ton_crypto)

add_executable(test-ed25519-crypto test/test-ed25519-crypto.cpp)
target_include_directories(test-ed25519-crypto PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(test-ed25519-crypto PUBLIC ton_crypto)

add_library(fift-lib STATIC ${FIFT_SOURCE})
target_include_directories(fift-lib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(fift-lib PUBLIC ton_crypto ton_db tdutils ton_block)
target_link_libraries(fift-lib PUBLIC ton_crypto tdutils ton_block)
if (USE_EMSCRIPTEN)
target_link_options(fift-lib PRIVATE -fexceptions)
target_compile_options(fift-lib PRIVATE -fexceptions)
Expand Down
17 changes: 0 additions & 17 deletions crypto/fift/fift-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
#include "SourceLookup.h"
#include "words.h"

#include "vm/db/TonDb.h"

#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/Parser.h"
Expand All @@ -65,7 +63,6 @@ void usage(const char* progname) {
"\t-I<source-search-path>\tSets colon-separated (unix) or at-separated (windows) library source include path. If not indicated, "
"$FIFTPATH is used instead.\n"
"\t-L<library-fif-file>\tPre-loads a library source file\n"
"\t-d<ton-db-path>\tUse a ton database\n"
"\t-s\tScript mode: use first argument as a fift source file and import remaining arguments as $n)\n"
"\t-v<verbosity-level>\tSet verbosity level\n"
"\t-V<version>\tShow fift build information\n";
Expand Down Expand Up @@ -94,7 +91,6 @@ int main(int argc, char* const argv[]) {
bool script_mode = false;
std::vector<std::string> library_source_files, source_list;
std::vector<std::string> source_include_path;
std::string ton_db_path;

fift::Fift::Config config;

Expand All @@ -115,9 +111,6 @@ int main(int argc, char* const argv[]) {
case 'L':
library_source_files.emplace_back(optarg);
break;
case 'd':
ton_db_path = optarg;
break;
case 's':
script_mode = true;
break;
Expand Down Expand Up @@ -158,16 +151,6 @@ int main(int argc, char* const argv[]) {
config.source_lookup.add_include_path(path);
}

if (!ton_db_path.empty()) {
auto r_ton_db = vm::TonDbImpl::open(ton_db_path);
if (r_ton_db.is_error()) {
LOG(ERROR) << "Error opening ton database: " << r_ton_db.error().to_string();
std::exit(2);
}
config.ton_db = r_ton_db.move_as_ok();
// FIXME //std::atexit([&] { config.ton_db.reset(); });
}

fift::init_words_common(config.dictionary);
fift::init_words_vm(config.dictionary, true); // enable vm debug
fift::init_words_ton(config.dictionary);
Expand Down
112 changes: 0 additions & 112 deletions crypto/fift/words.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
#include "vm/box.hpp"
#include "vm/atom.h"

#include "vm/db/TonDb.h" // only for interpret_db_run_vm{,_parallel}

#include "block/block.h"
#include "common/global-version.h"

Expand Down Expand Up @@ -2721,114 +2719,6 @@ void interpret_vmop_dump(vm::Stack& stack) {
stack.push_string(std::move(dump));
}

void do_interpret_db_run_vm_parallel(std::ostream* stream, vm::Stack& stack, vm::TonDb* ton_db_ptr, int threads_n,
int tasks_n) {
if (!ton_db_ptr || !*ton_db_ptr) {
throw vm::VmError{vm::Excno::fatal, "Ton database is not available"};
}
auto& ton_db = *ton_db_ptr;
auto txn = ton_db->begin_transaction();
auto txn_abort = td::ScopeExit() + [&] { ton_db->abort_transaction(std::move(txn)); };

struct Task {
vm::Ref<vm::CellSlice> code;
vm::SmartContractDb smart;
td::optional<vm::SmartContractDiff> diff;
td::unique_ptr<td::Guard> guard;
Ref<vm::Stack> stack;
int res{0};
Ref<vm::Cell> data;
std::string log;
};
std::vector<Task> tasks(tasks_n);
std::vector<td::thread> threads(threads_n);

for (auto& task : tasks) {
task.code = stack.pop_cellslice();
auto smart_hash = td::serialize(stack.pop_smallint_range(1000000000));
task.smart = txn->begin_smartcontract(smart_hash);
task.guard = td::create_lambda_guard([&] { txn->abort_smartcontract(std::move(task.smart)); });
auto argsn = stack.pop_smallint_range(100);
task.stack = stack.split_top(argsn);
}

std::atomic<int> next_task_i{0};
auto run_tasks = [&] {
while (true) {
auto task_i = next_task_i++;
if (task_i >= tasks_n) {
break;
}
auto& task = tasks[task_i];
auto data = task.smart->get_root();

StringLogger logger;
vm::VmLog log = create_vm_log(stream ? &logger : nullptr);

task.res = vm::run_vm_code(task.code, task.stack, 3, &data, std::move(log));
task.smart->set_root(data);
task.diff = vm::SmartContractDiff(std::move(task.smart));
task.data = std::move(data);
task.log = std::move(logger.res);
}
};

td::Timer timer;
for (auto& thread : threads) {
thread = td::thread(run_tasks);
}
run_tasks();
for (auto& thread : threads) {
thread.join();
}

if (stream) {
int id = 0;
for (auto& task : tasks) {
id++;
*stream << "Task #" << id << " vm_log begin" << std::endl;
*stream << task.log;
*stream << "Task #" << id << " vm_log end" << std::endl;
}
}

LOG(ERROR) << timer;
timer = {};

for (auto& task : tasks) {
auto retn = task.stack.write().pop_smallint_range(100, -1);
if (retn == -1) {
retn = task.stack->depth();
}
stack.push_from_stack(std::move(*task.stack), retn);
stack.push_smallint(task.res);
stack.push_cell(std::move(task.data));
task.guard->dismiss();
if (task.diff) {
txn->commit_smartcontract(std::move(task.diff.value()));
} else {
txn->commit_smartcontract(std::move(task.smart));
}
}
LOG(ERROR) << timer;
timer = {};

txn_abort.dismiss();
ton_db->commit_transaction(std::move(txn));
timer = {};
LOG(INFO) << "TonDB stats: \n" << ton_db->stats();
}

void interpret_db_run_vm(IntCtx& ctx) {
do_interpret_db_run_vm_parallel(ctx.error_stream, ctx.stack, ctx.ton_db, 0, 1);
}

void interpret_db_run_vm_parallel(IntCtx& ctx) {
auto threads_n = ctx.stack.pop_smallint_range(32, 0);
auto tasks_n = ctx.stack.pop_smallint_range(1000000000);
do_interpret_db_run_vm_parallel(ctx.error_stream, ctx.stack, ctx.ton_db, threads_n, tasks_n);
}

void interpret_store_vm_cont(vm::Stack& stack) {
auto vmcont = stack.pop_cont();
auto cb = stack.pop_builder();
Expand Down Expand Up @@ -3518,8 +3408,6 @@ void init_words_vm(Dictionary& d, bool enable_debug) {
// d.def_ctx_word("runvmcode ", std::bind(interpret_run_vm, _1, 0x40));
// d.def_ctx_word("runvm ", std::bind(interpret_run_vm, _1, 0x45));
d.def_ctx_word("runvmx ", std::bind(interpret_run_vm, _1, -1));
d.def_ctx_word("dbrunvm ", interpret_db_run_vm);
d.def_ctx_word("dbrunvm-parallel ", interpret_db_run_vm_parallel);
d.def_stack_word("vmcont, ", interpret_store_vm_cont);
d.def_stack_word("vmcont@ ", interpret_fetch_vm_cont);
d.def_stack_word("(vmoplen) ", interpret_vmop_len);
Expand Down
102 changes: 0 additions & 102 deletions crypto/test/fift/testdb.fif

This file was deleted.

0 comments on commit e8eb0de

Please sign in to comment.