mirror of
https://github.com/ton-blockchain/ton
synced 2025-02-15 04:32:21 +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
|
@ -19,7 +19,7 @@ jobs:
|
||||||
|
|
||||||
- name: Build TON WASM artifacts
|
- name: Build TON WASM artifacts
|
||||||
run: |
|
run: |
|
||||||
cd assembly/wasm
|
cp assembly/wasm/fift-func-wasm-build-ubuntu.sh .
|
||||||
chmod +x fift-func-wasm-build-ubuntu.sh
|
chmod +x fift-func-wasm-build-ubuntu.sh
|
||||||
./fift-func-wasm-build-ubuntu.sh -a
|
./fift-func-wasm-build-ubuntu.sh -a
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ pipeline {
|
||||||
steps {
|
steps {
|
||||||
timeout(time: 180, unit: 'MINUTES') {
|
timeout(time: 180, unit: 'MINUTES') {
|
||||||
sh '''
|
sh '''
|
||||||
cd assembly/wasm
|
cp assembly/wasm/fift-func-wasm-build-ubuntu.sh .
|
||||||
chmod +x fift-func-wasm-build-ubuntu.sh
|
chmod +x fift-func-wasm-build-ubuntu.sh
|
||||||
./fift-func-wasm-build-ubuntu.sh -a
|
./fift-func-wasm-build-ubuntu.sh -a
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
# The script builds funcfift compiler to WASM
|
|
||||||
|
|
||||||
# Execute these prerequisites first
|
# Execute these prerequisites first
|
||||||
# sudo apt update
|
# sudo apt update
|
||||||
# sudo apt install -y build-essential git make cmake ninja-build clang libgflags-dev zlib1g-dev libssl-dev \
|
# sudo apt install -y build-essential git make cmake ninja-build clang libgflags-dev zlib1g-dev libssl-dev \
|
||||||
|
@ -11,10 +9,12 @@
|
||||||
# sudo ./llvm.sh 16 all
|
# sudo ./llvm.sh 16 all
|
||||||
|
|
||||||
with_artifacts=false
|
with_artifacts=false
|
||||||
|
scratch_new=false
|
||||||
|
|
||||||
while getopts 'a' flag; do
|
while getopts 'af' flag; do
|
||||||
case "${flag}" in
|
case "${flag}" in
|
||||||
a) with_artifacts=true ;;
|
a) with_artifacts=true ;;
|
||||||
|
f) scratch_new=true ;;
|
||||||
*) break
|
*) break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -24,78 +24,66 @@ export CC=$(which clang-16)
|
||||||
export CXX=$(which clang++-16)
|
export CXX=$(which clang++-16)
|
||||||
export CCACHE_DISABLE=1
|
export CCACHE_DISABLE=1
|
||||||
|
|
||||||
cd ../..
|
|
||||||
rm -rf openssl zlib emsdk secp256k1 libsodium build
|
|
||||||
echo `pwd`
|
echo `pwd`
|
||||||
|
if [ "$scratch_new" = true ]; then
|
||||||
|
echo Compiling openssl zlib lz4 emsdk secp256k1 libsodium emsdk ton
|
||||||
|
rm -rf openssl zlib lz4 emsdk secp256k1 libsodium build
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [ ! -d "openssl" ]; then
|
||||||
git clone https://github.com/openssl/openssl.git
|
git clone https://github.com/openssl/openssl.git
|
||||||
cd openssl
|
cd openssl
|
||||||
git checkout checkout openssl-3.1.4
|
git checkout openssl-3.1.4
|
||||||
./config
|
./config
|
||||||
make -j16
|
make -j16
|
||||||
OPENSSL_DIR=`pwd`
|
OPENSSL_DIR=`pwd`
|
||||||
cd ..
|
cd ..
|
||||||
|
else
|
||||||
|
OPENSSL_DIR=`pwd`/openssl
|
||||||
|
echo Using compiled openssl at $OPENSSL_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
git clone https://github.com/madler/zlib.git
|
if [ ! -d "build" ]; then
|
||||||
cd zlib
|
|
||||||
git checkout v1.3.1
|
|
||||||
ZLIB_DIR=`pwd`
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
git clone https://github.com/lz4/lz4.git
|
|
||||||
cd lz4
|
|
||||||
git checkout v1.9.4
|
|
||||||
LZ4_DIR=`pwd`
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
git clone https://github.com/bitcoin-core/secp256k1.git
|
|
||||||
cd secp256k1
|
|
||||||
git checkout v0.3.2
|
|
||||||
./autogen.sh
|
|
||||||
SECP256K1_DIR=`pwd`
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
git clone https://github.com/jedisct1/libsodium
|
|
||||||
cd libsodium
|
|
||||||
git checkout 1.0.18-RELEASE
|
|
||||||
SODIUM_DIR=`pwd`
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake -GNinja -DCMAKE_BUILD_TYPE=Release \
|
cmake -GNinja -DCMAKE_BUILD_TYPE=Release \
|
||||||
-DCMAKE_CXX_STANDARD=17 \
|
-DCMAKE_CXX_STANDARD=17 \
|
||||||
-DOPENSSL_FOUND=1 \
|
-DOPENSSL_FOUND=1 \
|
||||||
-DOPENSSL_ROOT_DIR=$OPENSSL_DIR \
|
|
||||||
-DOPENSSL_INCLUDE_DIR=$OPENSSL_DIR/include \
|
-DOPENSSL_INCLUDE_DIR=$OPENSSL_DIR/include \
|
||||||
-DOPENSSL_CRYPTO_LIBRARY=$OPENSSL_DIR/libcrypto.so \
|
-DOPENSSL_CRYPTO_LIBRARY=$OPENSSL_DIR/libcrypto.so \
|
||||||
-DOPENSSL_SSL_LIBRARY=$OPENSSL_DIR/libssl.so \
|
|
||||||
-DTON_USE_ABSEIL=OFF ..
|
-DTON_USE_ABSEIL=OFF ..
|
||||||
|
|
||||||
test $? -eq 0 || { echo "Can't configure TON build"; exit 1; }
|
test $? -eq 0 || { echo "Can't configure TON build"; exit 1; }
|
||||||
|
|
||||||
ninja fift smc-envelope
|
ninja fift smc-envelope
|
||||||
|
|
||||||
test $? -eq 0 || { echo "Can't compile fift "; exit 1; }
|
test $? -eq 0 || { echo "Can't compile fift "; exit 1; }
|
||||||
|
|
||||||
rm -rf *
|
rm -rf *
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
|
else
|
||||||
|
echo cleaning build...
|
||||||
|
rm -rf build/*
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "emsdk" ]; then
|
||||||
git clone https://github.com/emscripten-core/emsdk.git
|
git clone https://github.com/emscripten-core/emsdk.git
|
||||||
|
echo
|
||||||
|
echo Using cloned emsdk
|
||||||
|
fi
|
||||||
|
|
||||||
cd emsdk
|
cd emsdk
|
||||||
./emsdk install 3.1.19
|
./emsdk install 3.1.19
|
||||||
./emsdk activate 3.1.19
|
./emsdk activate 3.1.19
|
||||||
EMSDK_DIR=`pwd`
|
EMSDK_DIR=`pwd`
|
||||||
ls $EMSDK_DIR
|
|
||||||
|
|
||||||
. $EMSDK_DIR/emsdk_env.sh
|
. $EMSDK_DIR/emsdk_env.sh
|
||||||
export CC=$(which emcc)
|
export CC=$(which emcc)
|
||||||
export CXX=$(which em++)
|
export CXX=$(which em++)
|
||||||
export CCACHE_DISABLE=1
|
export CCACHE_DISABLE=1
|
||||||
|
|
||||||
cd ../openssl
|
cd ..
|
||||||
|
|
||||||
|
if [ ! -f "openssl/openssl_em" ]; then
|
||||||
|
cd openssl
|
||||||
make clean
|
make clean
|
||||||
emconfigure ./Configure linux-generic32 no-shared no-dso no-engine no-unit-test
|
emconfigure ./Configure linux-generic32 no-shared no-dso no-engine no-unit-test
|
||||||
sed -i 's/CROSS_COMPILE=.*/CROSS_COMPILE=/g' Makefile
|
sed -i 's/CROSS_COMPILE=.*/CROSS_COMPILE=/g' Makefile
|
||||||
|
@ -104,32 +92,71 @@ sed -i 's/-O3/-Os/g' Makefile
|
||||||
emmake make depend
|
emmake make depend
|
||||||
emmake make -j16
|
emmake make -j16
|
||||||
test $? -eq 0 || { echo "Can't compile OpenSSL with emmake "; exit 1; }
|
test $? -eq 0 || { echo "Can't compile OpenSSL with emmake "; exit 1; }
|
||||||
|
touch openssl_em
|
||||||
|
cd ..
|
||||||
|
else
|
||||||
|
echo Using compiled openssl with emscripten
|
||||||
|
fi
|
||||||
|
|
||||||
cd ../zlib
|
if [ ! -d "zlib" ]; then
|
||||||
|
git clone https://github.com/madler/zlib.git
|
||||||
|
cd zlib
|
||||||
|
git checkout v1.3.1
|
||||||
|
ZLIB_DIR=`pwd`
|
||||||
emconfigure ./configure --static
|
emconfigure ./configure --static
|
||||||
emmake make -j16
|
emmake make -j16
|
||||||
test $? -eq 0 || { echo "Can't compile zlib with emmake "; exit 1; }
|
test $? -eq 0 || { echo "Can't compile zlib with emmake "; exit 1; }
|
||||||
|
cd ..
|
||||||
|
else
|
||||||
|
ZLIB_DIR=`pwd`/zlib
|
||||||
|
echo Using compiled zlib with emscripten at $ZLIB_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
cd ../lz4
|
if [ ! -d "lz4" ]; then
|
||||||
|
git clone https://github.com/lz4/lz4.git
|
||||||
|
cd lz4
|
||||||
|
git checkout v1.9.4
|
||||||
|
LZ4_DIR=`pwd`
|
||||||
emmake make -j16
|
emmake make -j16
|
||||||
test $? -eq 0 || { echo "Can't compile lz4 with emmake "; exit 1; }
|
test $? -eq 0 || { echo "Can't compile lz4 with emmake "; exit 1; }
|
||||||
|
cd ..
|
||||||
|
else
|
||||||
|
LZ4_DIR=`pwd`/lz4
|
||||||
|
echo Using compiled lz4 with emscripten at $LZ4_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
cd ../secp256k1
|
if [ ! -d "secp256k1" ]; then
|
||||||
|
git clone https://github.com/bitcoin-core/secp256k1.git
|
||||||
|
cd secp256k1
|
||||||
|
git checkout v0.3.2
|
||||||
|
./autogen.sh
|
||||||
|
SECP256K1_DIR=`pwd`
|
||||||
emconfigure ./configure --enable-module-recovery
|
emconfigure ./configure --enable-module-recovery
|
||||||
emmake make -j16
|
emmake make -j16
|
||||||
test $? -eq 0 || { echo "Can't compile secp256k1 with emmake "; exit 1; }
|
test $? -eq 0 || { echo "Can't compile secp256k1 with emmake "; exit 1; }
|
||||||
|
cd ..
|
||||||
|
else
|
||||||
|
SECP256K1_DIR=`pwd`/secp256k1
|
||||||
|
echo Using compiled secp256k1 with emscripten at $SECP256K1_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
cd ../libsodium
|
if [ ! -d "libsodium" ]; then
|
||||||
|
git clone https://github.com/jedisct1/libsodium
|
||||||
|
cd libsodium
|
||||||
|
git checkout 1.0.18-RELEASE
|
||||||
|
SODIUM_DIR=`pwd`
|
||||||
emconfigure ./configure --disable-ssp
|
emconfigure ./configure --disable-ssp
|
||||||
emmake make -j16
|
emmake make -j16
|
||||||
test $? -eq 0 || { echo "Can't compile libsodium with emmake "; exit 1; }
|
test $? -eq 0 || { echo "Can't compile libsodium with emmake "; exit 1; }
|
||||||
|
cd ..
|
||||||
|
else
|
||||||
|
SODIUM_DIR=`pwd`/libsodium
|
||||||
|
echo Using compiled libsodium with emscripten at $SODIUM_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
cd ../build
|
cd build
|
||||||
|
|
||||||
emcmake cmake -DUSE_EMSCRIPTEN=ON -DCMAKE_BUILD_TYPE=Release \
|
emcmake cmake -DUSE_EMSCRIPTEN=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
|
||||||
-DZLIB_FOUND=1 \
|
-DZLIB_FOUND=1 \
|
||||||
-DZLIB_LIBRARIES=$ZLIB_DIR/libz.a \
|
-DZLIB_LIBRARIES=$ZLIB_DIR/libz.a \
|
||||||
-DZLIB_INCLUDE_DIR=$ZLIB_DIR \
|
-DZLIB_INCLUDE_DIR=$ZLIB_DIR \
|
||||||
|
@ -137,18 +164,15 @@ emcmake cmake -DUSE_EMSCRIPTEN=ON -DCMAKE_BUILD_TYPE=Release \
|
||||||
-DLZ4_LIBRARIES=$LZ4_DIR/lib/liblz4.a \
|
-DLZ4_LIBRARIES=$LZ4_DIR/lib/liblz4.a \
|
||||||
-DLZ4_INCLUDE_DIRS=$LZ4_DIR/lib \
|
-DLZ4_INCLUDE_DIRS=$LZ4_DIR/lib \
|
||||||
-DOPENSSL_FOUND=1 \
|
-DOPENSSL_FOUND=1 \
|
||||||
-DOPENSSL_ROOT_DIR=$OPENSSL_DIR \
|
|
||||||
-DOPENSSL_INCLUDE_DIR=$OPENSSL_DIR/include \
|
-DOPENSSL_INCLUDE_DIR=$OPENSSL_DIR/include \
|
||||||
-DOPENSSL_CRYPTO_LIBRARY=$OPENSSL_DIR/libcrypto.a \
|
-DOPENSSL_CRYPTO_LIBRARY=$OPENSSL_DIR/libcrypto.a \
|
||||||
-DOPENSSL_SSL_LIBRARY=$OPENSSL_DIR/libssl.a \
|
|
||||||
-DCMAKE_TOOLCHAIN_FILE=$EMSDK_DIR/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \
|
-DCMAKE_TOOLCHAIN_FILE=$EMSDK_DIR/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \
|
||||||
-DCMAKE_CXX_FLAGS="-sUSE_ZLIB=1" \
|
-DCMAKE_CXX_FLAGS="-sUSE_ZLIB=1" \
|
||||||
-DSECP256K1_FOUND=1 \
|
|
||||||
-DSECP256K1_INCLUDE_DIR=$SECP256K1_DIR/include \
|
-DSECP256K1_INCLUDE_DIR=$SECP256K1_DIR/include \
|
||||||
-DSECP256K1_LIBRARY=$SECP256K1_DIR/.libs/libsecp256k1.a \
|
-DSECP256K1_LIBRARY=$SECP256K1_DIR/.libs/libsecp256k1.a \
|
||||||
-DSODIUM_INCLUDE_DIR=$SODIUM_DIR/src/libsodium/include \
|
-DSODIUM_INCLUDE_DIR=$SODIUM_DIR/src/libsodium/include \
|
||||||
-DSODIUM_LIBRARY_RELEASE=$SODIUM_DIR/src/libsodium/.libs/libsodium.a \
|
-DSODIUM_LIBRARY_RELEASE=$SODIUM_DIR/src/libsodium/.libs/libsodium.a \
|
||||||
-DSODIUM_USE_STATIC_LIBS=ON ..
|
..
|
||||||
|
|
||||||
test $? -eq 0 || { echo "Can't configure TON with emmake "; exit 1; }
|
test $? -eq 0 || { echo "Can't configure TON with emmake "; exit 1; }
|
||||||
cp -R ../crypto/smartcont ../crypto/fift/lib crypto
|
cp -R ../crypto/smartcont ../crypto/fift/lib crypto
|
||||||
|
|
|
@ -358,7 +358,8 @@ target_link_libraries(test-ed25519-crypto PUBLIC ton_crypto)
|
||||||
|
|
||||||
add_library(fift-lib STATIC ${FIFT_SOURCE})
|
add_library(fift-lib STATIC ${FIFT_SOURCE})
|
||||||
target_include_directories(fift-lib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
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)
|
if (USE_EMSCRIPTEN)
|
||||||
target_link_options(fift-lib PRIVATE -fexceptions)
|
target_link_options(fift-lib PRIVATE -fexceptions)
|
||||||
target_compile_options(fift-lib PRIVATE -fexceptions)
|
target_compile_options(fift-lib PRIVATE -fexceptions)
|
||||||
|
|
|
@ -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) {
|
td::Result<int> Fift::do_interpret(IntCtx& ctx, bool is_interactive) {
|
||||||
ctx.ton_db = &config_.ton_db;
|
|
||||||
ctx.source_lookup = &config_.source_lookup;
|
ctx.source_lookup = &config_.source_lookup;
|
||||||
ctx.dictionary = ctx.main_dictionary = ctx.context = config_.dictionary;
|
ctx.dictionary = ctx.main_dictionary = ctx.context = config_.dictionary;
|
||||||
ctx.output_stream = config_.output_stream;
|
ctx.output_stream = config_.output_stream;
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SourceLookup.h"
|
#include "SourceLookup.h"
|
||||||
#include "vm/db/TonDb.h"
|
|
||||||
#include "Dictionary.h"
|
#include "Dictionary.h"
|
||||||
|
|
||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
|
@ -31,13 +30,11 @@ struct Fift {
|
||||||
public:
|
public:
|
||||||
struct Config {
|
struct Config {
|
||||||
fift::SourceLookup source_lookup;
|
fift::SourceLookup source_lookup;
|
||||||
vm::TonDb ton_db;
|
|
||||||
fift::Dictionary dictionary;
|
fift::Dictionary dictionary;
|
||||||
std::ostream* output_stream{&std::cout};
|
std::ostream* output_stream{&std::cout};
|
||||||
std::ostream* error_stream{&std::cerr};
|
std::ostream* error_stream{&std::cerr};
|
||||||
bool show_backtrace{true};
|
bool show_backtrace{true};
|
||||||
};
|
};
|
||||||
// Fift must own ton_db and dictionary, no concurrent access is allowed
|
|
||||||
explicit Fift(Config config);
|
explicit Fift(Config config);
|
||||||
|
|
||||||
td::Result<int> interpret_file(std::string fname, std::string current_dir, bool interactive = false);
|
td::Result<int> interpret_file(std::string fname, std::string current_dir, bool interactive = false);
|
||||||
|
|
|
@ -46,8 +46,6 @@
|
||||||
#include "SourceLookup.h"
|
#include "SourceLookup.h"
|
||||||
#include "words.h"
|
#include "words.h"
|
||||||
|
|
||||||
#include "vm/db/TonDb.h"
|
|
||||||
|
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/misc.h"
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/Parser.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, "
|
"\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"
|
"$FIFTPATH is used instead.\n"
|
||||||
"\t-L<library-fif-file>\tPre-loads a library source file\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-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<verbosity-level>\tSet verbosity level\n"
|
||||||
"\t-V<version>\tShow fift build information\n";
|
"\t-V<version>\tShow fift build information\n";
|
||||||
|
@ -94,13 +91,12 @@ int main(int argc, char* const argv[]) {
|
||||||
bool script_mode = false;
|
bool script_mode = false;
|
||||||
std::vector<std::string> library_source_files, source_list;
|
std::vector<std::string> library_source_files, source_list;
|
||||||
std::vector<std::string> source_include_path;
|
std::vector<std::string> source_include_path;
|
||||||
std::string ton_db_path;
|
|
||||||
|
|
||||||
fift::Fift::Config config;
|
fift::Fift::Config config;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int new_verbosity_level = VERBOSITY_NAME(INFO);
|
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) {
|
switch (i) {
|
||||||
case 'i':
|
case 'i':
|
||||||
interactive = true;
|
interactive = true;
|
||||||
|
@ -115,9 +111,6 @@ int main(int argc, char* const argv[]) {
|
||||||
case 'L':
|
case 'L':
|
||||||
library_source_files.emplace_back(optarg);
|
library_source_files.emplace_back(optarg);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
|
||||||
ton_db_path = optarg;
|
|
||||||
break;
|
|
||||||
case 's':
|
case 's':
|
||||||
script_mode = true;
|
script_mode = true;
|
||||||
break;
|
break;
|
||||||
|
@ -158,16 +151,6 @@ int main(int argc, char* const argv[]) {
|
||||||
config.source_lookup.add_include_path(path);
|
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_common(config.dictionary);
|
||||||
fift::init_words_vm(config.dictionary, true); // enable vm debug
|
fift::init_words_vm(config.dictionary, true); // enable vm debug
|
||||||
fift::init_words_ton(config.dictionary);
|
fift::init_words_ton(config.dictionary);
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include "td/utils/filesystem.h"
|
#include "td/utils/filesystem.h"
|
||||||
#include "td/utils/misc.h"
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/port/path.h"
|
#include "td/utils/port/path.h"
|
||||||
|
#include "vm/boc.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace fift {
|
namespace fift {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -43,8 +43,6 @@
|
||||||
#include "vm/box.hpp"
|
#include "vm/box.hpp"
|
||||||
#include "vm/atom.h"
|
#include "vm/atom.h"
|
||||||
|
|
||||||
#include "vm/db/TonDb.h" // only for interpret_db_run_vm{,_parallel}
|
|
||||||
|
|
||||||
#include "block/block.h"
|
#include "block/block.h"
|
||||||
#include "common/global-version.h"
|
#include "common/global-version.h"
|
||||||
|
|
||||||
|
@ -2721,114 +2719,6 @@ void interpret_vmop_dump(vm::Stack& stack) {
|
||||||
stack.push_string(std::move(dump));
|
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) {
|
void interpret_store_vm_cont(vm::Stack& stack) {
|
||||||
auto vmcont = stack.pop_cont();
|
auto vmcont = stack.pop_cont();
|
||||||
auto cb = stack.pop_builder();
|
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("runvmcode ", std::bind(interpret_run_vm, _1, 0x40));
|
||||||
// d.def_ctx_word("runvm ", std::bind(interpret_run_vm, _1, 0x45));
|
// 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("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_store_vm_cont);
|
||||||
d.def_stack_word("vmcont@ ", interpret_fetch_vm_cont);
|
d.def_stack_word("vmcont@ ", interpret_fetch_vm_cont);
|
||||||
d.def_stack_word("(vmoplen) ", interpret_vmop_len);
|
d.def_stack_word("(vmoplen) ", interpret_vmop_len);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
Copyright 2017-2020 Telegram Systems LLP
|
Copyright 2017-2020 Telegram Systems LLP
|
||||||
*/
|
*/
|
||||||
#include "func.h"
|
#include "func.h"
|
||||||
|
#include "vm/boc.h"
|
||||||
|
|
||||||
namespace funC {
|
namespace funC {
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include "vm/boc.h"
|
||||||
|
|
||||||
td::Result<std::string> compile_internal(char *config_json) {
|
td::Result<std::string> compile_internal(char *config_json) {
|
||||||
TRY_RESULT(input_json, td::json_decode(td::MutableSlice(config_json)))
|
TRY_RESULT(input_json, td::json_decode(td::MutableSlice(config_json)))
|
||||||
|
|
|
@ -1,102 +0,0 @@
|
||||||
"Asm.fif" include
|
|
||||||
|
|
||||||
PROGRAM{
|
|
||||||
|
|
||||||
NEWPROC load_dict
|
|
||||||
NEWPROC generate_dict
|
|
||||||
NEWPROC save_dict
|
|
||||||
|
|
||||||
NEWPROC do_get
|
|
||||||
NEWPROC do_set
|
|
||||||
NEWPROC do_erase
|
|
||||||
|
|
||||||
main PROC:<{
|
|
||||||
DUP 1 INT EQUAL IF:<{
|
|
||||||
DROP
|
|
||||||
do_get CALL
|
|
||||||
}>ELSE<{
|
|
||||||
DUP 2 INT EQUAL IF:<{
|
|
||||||
DROP
|
|
||||||
do_set CALL
|
|
||||||
}>ELSE<{
|
|
||||||
DUP 3 INT EQUAL IF:<{
|
|
||||||
DROP
|
|
||||||
do_erase CALL
|
|
||||||
}> }> }>
|
|
||||||
-1 INT
|
|
||||||
}>
|
|
||||||
|
|
||||||
do_get PROC:<{
|
|
||||||
load_dict CALL
|
|
||||||
32 INT
|
|
||||||
DICTIGET
|
|
||||||
}>
|
|
||||||
|
|
||||||
do_set PROC:<{
|
|
||||||
load_dict CALL
|
|
||||||
32 INT
|
|
||||||
DICTISET
|
|
||||||
save_dict CALL
|
|
||||||
}>
|
|
||||||
|
|
||||||
do_erase PROC:<{
|
|
||||||
load_dict CALL
|
|
||||||
32 INT
|
|
||||||
DICTIDEL
|
|
||||||
DROP
|
|
||||||
save_dict CALL
|
|
||||||
}>
|
|
||||||
|
|
||||||
generate_dict PROC:<{
|
|
||||||
4 INT 100 INT REPEAT:<{
|
|
||||||
DUP 2DUP MUL ROT 617 INT ADD 1000 INT MOD
|
|
||||||
}>
|
|
||||||
DROP 100 INT
|
|
||||||
NEWDICT
|
|
||||||
SWAP REPEAT:<{
|
|
||||||
s0 s2 XCHG
|
|
||||||
NEWC
|
|
||||||
16 STU
|
|
||||||
s0 s2 XCHG
|
|
||||||
32 INT
|
|
||||||
DICTISETB
|
|
||||||
}>
|
|
||||||
}>
|
|
||||||
|
|
||||||
load_dict PROC:<{
|
|
||||||
PUSHROOT
|
|
||||||
CTOS DUP SEMPTY IF:<{
|
|
||||||
DROP
|
|
||||||
generate_dict CALL
|
|
||||||
}>
|
|
||||||
}>
|
|
||||||
|
|
||||||
save_dict PROC:<{
|
|
||||||
NEWC
|
|
||||||
STSLICE
|
|
||||||
ENDC
|
|
||||||
POPROOT
|
|
||||||
}>
|
|
||||||
|
|
||||||
}END>s constant pmc_prog
|
|
||||||
|
|
||||||
{ 1 2 rot pmc_prog } : task_pmc_get
|
|
||||||
{ 2 3 rot pmc_prog } : task_pmc_set
|
|
||||||
{ 3 2 rot pmc_prog } : task_pmc_erase
|
|
||||||
|
|
||||||
{ task_pmc_get dbrunvm 2drop } : pmc_get
|
|
||||||
{ task_pmc_set dbrunvm 2drop } : pmc_set
|
|
||||||
{ task_pmc_erase dbrunvm 2drop } : pmc_erase
|
|
||||||
|
|
||||||
<b x{abacaba} s, <b x{dead} s, x{1dead} sr, b> <s sr, b> <s constant test_value
|
|
||||||
|
|
||||||
// 123 "a" pmc_get
|
|
||||||
// { csr. } if
|
|
||||||
// 123 "a" pmc_set
|
|
||||||
|
|
||||||
// test_value 123 x{a} task_pmc_set test_value 123 x{b} task_pmc_set test_value 123 x{c} task_pmc_set 3 3 dbrunvm-parallel
|
|
||||||
|
|
||||||
{ test_value 150 rot task_pmc_set } 0 { 1 + 2dup swap execute 7 roll 7 roll } 10000 times 2drop 10000 4 dbrunvm-parallel
|
|
||||||
|
|
||||||
// 123 "a" task_pmc_get 123 "b" task_pmc_get 123 "c" task_pmc_get 3 dbrunvm-parallel
|
|
||||||
|
|
Loading…
Reference in a new issue