mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Remove rocksdb usage from fift (#1064)
* add github action for macOS 14 (arm64, M1) * add github action (portable) for macOS 14 (arm64, M1) * rename macOS arm64 output artifact * Update libsodium on windows * Compile libsodium * Update build-windows.bat * use upgraded libsodium 1.0.20; use compiled static libsodium for Windows instead of precompiled; * revert libsodium 1.0.20; use compiled static libsodium for Windows instead of precompiled; * use upgraded libsodium 1.0.20; use compiled static libsodium for Windows instead of precompiled; * fix libsodium version 1.0.19; use compiled static libsodium for Windows instead of precompiled; * try 1.0.20 libsodium precompiled on github * try 1.0.18 libsodium precompiled on github * try windows build on win server 2019 * and use PlatformToolset=v142 * use cmake -G "Visual Studio 16 2019" * fix path to msvc 2019 on github * separate github windows build on win server 2019 and build on win server 2022 * Update assembly/native/build-windows-2019.bat add retry mechanism Co-authored-by: Dr. Awesome Doge <doge@ton.org> * add test-emulator; disable test groovy pipeline * trigger all gh actions * fix win build * call test-emulator * remove usage of rocksdb in fift-lib * put back some code for test-db * fix test-emulator * remove usage of db-path parameter in fift * some func adjustments * fix checkout of openssl in fift-func-wasm-build-ubuntu.sh * typo * improve wasm build script for quicker turn around * remove sENVIRONMENT=web,worker for funcfiftlib. will be added later. * remove sENVIRONMENT=web,worker for funcfiftlib. will be added later. * remove sENVIRONMENT=web,worker for funcfiftlib. will be added later. * minor adjustments * remove -d option in fift; optimize fift-lib usage * reduce tondb usage --------- Co-authored-by: neodiX <neodix42@ton.org> Co-authored-by: Dr. Awesome Doge <doge@ton.org> Co-authored-by: ms <dungeon666master@protonmail.com>
This commit is contained in:
parent
28f9a9b159
commit
679e6be294
12 changed files with 122 additions and 328 deletions
|
@ -49,7 +49,6 @@ td::Result<int> Fift::interpret_istream(std::istream& stream, std::string curren
|
|||
}
|
||||
|
||||
td::Result<int> Fift::do_interpret(IntCtx& ctx, bool is_interactive) {
|
||||
ctx.ton_db = &config_.ton_db;
|
||||
ctx.source_lookup = &config_.source_lookup;
|
||||
ctx.dictionary = ctx.main_dictionary = ctx.context = config_.dictionary;
|
||||
ctx.output_stream = config_.output_stream;
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "SourceLookup.h"
|
||||
#include "vm/db/TonDb.h"
|
||||
#include "Dictionary.h"
|
||||
|
||||
#include "td/utils/Status.h"
|
||||
|
@ -31,13 +30,11 @@ struct Fift {
|
|||
public:
|
||||
struct Config {
|
||||
fift::SourceLookup source_lookup;
|
||||
vm::TonDb ton_db;
|
||||
fift::Dictionary dictionary;
|
||||
std::ostream* output_stream{&std::cout};
|
||||
std::ostream* error_stream{&std::cerr};
|
||||
bool show_backtrace{true};
|
||||
};
|
||||
// Fift must own ton_db and dictionary, no concurrent access is allowed
|
||||
explicit Fift(Config config);
|
||||
|
||||
td::Result<int> interpret_file(std::string fname, std::string current_dir, bool interactive = false);
|
||||
|
|
|
@ -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"
|
||||
|
@ -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";
|
||||
|
@ -94,13 +91,12 @@ 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;
|
||||
|
||||
int i;
|
||||
int new_verbosity_level = VERBOSITY_NAME(INFO);
|
||||
while (!script_mode && (i = getopt(argc, argv, "hinI:L:d:sv:V")) != -1) {
|
||||
while (!script_mode && (i = getopt(argc, argv, "hinI:L:sv:V")) != -1) {
|
||||
switch (i) {
|
||||
case 'i':
|
||||
interactive = true;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "td/utils/filesystem.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/port/path.h"
|
||||
#include "vm/boc.h"
|
||||
#include <map>
|
||||
|
||||
namespace fift {
|
||||
namespace {
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue