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

Various changes in TVM, github builds and tests (#793)

* Bugfixes in TVM and node

* Upgrade to C++17

* Improve GitHub builds

* Fix existing tests and partially integrate them into builds

---------

Co-authored-by: neodiX42 <namlem@gmail.com>
Co-authored-by: EmelyanenkoK <emelyanenko.kirill@gmail.com>
This commit is contained in:
SpyCheese 2023-11-03 14:43:34 +03:00 committed by GitHub
parent 89700cb2aa
commit 5847897b37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
122 changed files with 2889 additions and 4100 deletions

View file

@ -1,5 +1,5 @@
-xc++
-std=c++14
-std=c++17
-iquote .
-iquote tdtl/
-iquote tl/

View file

@ -13,7 +13,7 @@ echo `pwd`
git clone https://github.com/openssl/openssl.git
cd openssl
git checkout OpenSSL_1_1_1j
git checkout checkout openssl-3.1.4
./config
make -j16
OPENSSL_DIR=`pwd`

View file

@ -12,24 +12,33 @@ jobs:
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Compile OpenSSL
- name: Compile Secp256k1
run: |
export NONINTERACTIVE=1
brew install ninja secp256k1 libsodium libmicrohttpd pkg-config automake libtool
git clone https://github.com/openssl/openssl openssl_1_1_1
cd openssl_1_1_1
git checkout OpenSSL_1_1_1-stable
./Configure darwin64-x86_64-cc -static -mmacosx-version-min=11.7
make build_libs -j4
git clone https://github.com/libbitcoin/secp256k1.git
cd secp256k1
./autogen.sh
./configure --enable-module-recovery
make
make install
- name: Build all
run: |
brew unlink openssl@3
brew unlink openssl@1.1
brew install openssl@3
brew unlink openssl@3 && brew link --overwrite openssl@3
rootPath=`pwd`
mkdir build
cd build
cmake -GNinja -DOPENSSL_FOUND=1 -DOPENSSL_INCLUDE_DIR=$rootPath/openssl_1_1_1/include -DOPENSSL_CRYPTO_LIBRARY=$rootPath/openssl_1_1_1/libcrypto.a -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=11.7 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release ..
ninja storage-daemon storage-daemon-cli blockchain-explorer fift func tonlib tonlibjson tonlib-cli validator-engine lite-client pow-miner validator-engine-console generate-random-id json2tlo dht-server http-proxy rldp-http-proxy adnl-proxy create-state create-hardfork tlbc emulator
cmake -GNinja -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=11.7 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release ..
ninja storage-daemon storage-daemon-cli blockchain-explorer fift func tonlib tonlibjson tonlib-cli validator-engine \
lite-client pow-miner validator-engine-console generate-random-id json2tlo dht-server \
http-proxy rldp-http-proxy adnl-proxy create-state create-hardfork tlbc emulator \
test-ed25519 test-ed25519-crypto test-bigint test-vm test-fift test-cells test-smartcont test-net test-tdactor \
test-tdutils test-tonlib-offline test-adnl test-dht test-rldp test-rldp2 test-catchain test-fec test-tddb test-db test-validator-session-state
- name: Strip binaries
run: |
@ -51,6 +60,11 @@ jobs:
strip build/utils/json2tlo
strip build/adnl/adnl-proxy
- name: Run tests
run: |
cd build
ctest --output-on-failure -E "test-catchain|test-actors"
- name: Find & copy binaries
run: |
mkdir artifacts

View file

@ -12,18 +12,11 @@ jobs:
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Compile OpenSSL
run: |
export NONINTERACTIVE=1
brew install ninja secp256k1 libsodium libmicrohttpd pkg-config automake libtool
git clone https://github.com/openssl/openssl openssl_1_1_1
cd openssl_1_1_1
git checkout OpenSSL_1_1_1-stable
./Configure darwin64-x86_64-cc -static -mmacosx-version-min=12.6
make build_libs -j4
- name: Compile Secp256k1
run: |
export NONINTERACTIVE=1
brew install ninja secp256k1 libsodium libmicrohttpd pkg-config automake libtool
git clone https://github.com/libbitcoin/secp256k1.git
cd secp256k1
./autogen.sh
@ -33,12 +26,19 @@ jobs:
- name: Build all
run: |
brew unlink openssl@3
brew unlink openssl@1.1
brew install openssl@3
brew unlink openssl@3 && brew link --overwrite openssl@3
rootPath=`pwd`
mkdir build
cd build
cmake -GNinja -DOPENSSL_FOUND=1 -DOPENSSL_INCLUDE_DIR=$rootPath/openssl_1_1_1/include -DOPENSSL_CRYPTO_LIBRARY=$rootPath/openssl_1_1_1/libcrypto.a -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=12.6 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release ..
ninja storage-daemon storage-daemon-cli blockchain-explorer fift func tonlib tonlibjson tonlib-cli validator-engine lite-client pow-miner validator-engine-console generate-random-id json2tlo dht-server http-proxy rldp-http-proxy adnl-proxy create-state create-hardfork tlbc emulator
cmake -GNinja -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=12.6 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release ..
ninja storage-daemon storage-daemon-cli blockchain-explorer fift func tonlib tonlibjson tonlib-cli \
validator-engine lite-client pow-miner validator-engine-console generate-random-id json2tlo dht-server \
http-proxy rldp-http-proxy adnl-proxy create-state create-hardfork tlbc emulator \
test-ed25519 test-ed25519-crypto test-bigint test-vm test-fift test-cells test-smartcont test-net test-tdactor \
test-tdutils test-tonlib-offline test-adnl test-dht test-rldp test-rldp2 test-catchain test-fec test-tddb test-db test-validator-session-state
- name: Strip binaries
run: |
@ -60,6 +60,11 @@ jobs:
strip build/utils/json2tlo
strip build/adnl/adnl-proxy
- name: Run tests
run: |
cd build
ctest --output-on-failure -E "test-catchain|test-actors"
- name: Find & copy binaries
run: |
mkdir artifacts

View file

@ -15,7 +15,7 @@ jobs:
with:
submodules: 'recursive'
- uses: cachix/install-nix-action@v18
- uses: cachix/install-nix-action@v23
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}

View file

@ -11,7 +11,7 @@ jobs:
with:
submodules: 'recursive'
- uses: cachix/install-nix-action@v22
- uses: cachix/install-nix-action@v23
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}

View file

@ -28,9 +28,9 @@ jobs:
export CXX=$(which clang++)
export CCACHE_DISABLE=1
git clone https://github.com/openssl/openssl openssl_1_1_1
cd openssl_1_1_1
git checkout OpenSSL_1_1_1-stable
git clone https://github.com/openssl/openssl openssl_3
cd openssl_3
git checkout openssl-3.1.4
./config
make build_libs -j4
@ -39,13 +39,23 @@ jobs:
mkdir build
cd build
cmake -GNinja -DOPENSSL_FOUND=1 -DOPENSSL_INCLUDE_DIR=$rootPath/openssl_1_1_1/include -DOPENSSL_CRYPTO_LIBRARY=$rootPath/openssl_1_1_1/libcrypto.a -DCMAKE_BUILD_TYPE=Release -DPORTABLE=1 -DTON_ARCH= ..
ninja storage-daemon storage-daemon-cli fift func tonlib tonlibjson tonlib-cli validator-engine lite-client pow-miner validator-engine-console generate-random-id json2tlo dht-server http-proxy rldp-http-proxy adnl-proxy create-state emulator
cmake -GNinja -DOPENSSL_FOUND=1 -DOPENSSL_INCLUDE_DIR=$rootPath/openssl_3/include -DOPENSSL_CRYPTO_LIBRARY=$rootPath/openssl_3/libcrypto.a -DCMAKE_BUILD_TYPE=Release -DPORTABLE=1 -DTON_ARCH= ..
ninja storage-daemon storage-daemon-cli fift func tonlib tonlibjson tonlib-cli validator-engine lite-client \
pow-miner validator-engine-console generate-random-id json2tlo dht-server http-proxy rldp-http-proxy \
adnl-proxy create-state emulator \
test-ed25519 test-ed25519-crypto test-bigint test-vm test-fift test-cells test-smartcont test-net test-tdactor \
test-tdutils test-tonlib-offline test-adnl test-dht test-rldp test-rldp2 test-catchain test-fec test-tddb test-db test-validator-session-state
- name: Strip binaries
run: |
strip -g build/storage/storage-daemon/storage-daemon build/storage/storage-daemon/storage-daemon-cli build/crypto/fift build/crypto/tlbc build/crypto/func build/crypto/create-state build/validator-engine-console/validator-engine-console build/tonlib/tonlib-cli build/tonlib/libtonlibjson.so.0.5 build/http/http-proxy build/rldp-http-proxy/rldp-http-proxy build/dht-server/dht-server build/lite-client/lite-client build/validator-engine/validator-engine build/utils/generate-random-id build/utils/json2tlo build/adnl/adnl-proxy build/emulator/libemulator.*
- name: Run tests
run: |
cd build
ctest --output-on-failure -E "test-catchain|test-actors"
- name: Find & copy binaries
run: |
mkdir artifacts

View file

@ -34,22 +34,31 @@ jobs:
mkdir build-${{ matrix.os }}
cd build-${{ matrix.os }}
git clone https://github.com/openssl/openssl openssl_1_1_1
cd openssl_1_1_1
git checkout OpenSSL_1_1_1-stable
git clone https://github.com/openssl/openssl openssl_3
cd openssl_3
git checkout openssl-3.1.4
./config
make build_libs -j4
cd ..
buildPath=`pwd`
rootPath=`pwd`
cmake -GNinja -DOPENSSL_FOUND=1 -DOPENSSL_INCLUDE_DIR=$buildPath/openssl_1_1_1/include -DOPENSSL_CRYPTO_LIBRARY=$buildPath/openssl_1_1_1/libcrypto.a -DCMAKE_BUILD_TYPE=Release -DPORTABLE=1 -DTON_ARCH= ..
ninja storage-daemon storage-daemon-cli fift func tonlib tonlibjson tonlib-cli validator-engine lite-client pow-miner validator-engine-console generate-random-id json2tlo dht-server http-proxy rldp-http-proxy adnl-proxy create-state create-hardfork emulator
cmake -GNinja -DOPENSSL_FOUND=1 -DOPENSSL_INCLUDE_DIR=$rootPath/openssl_3/include -DOPENSSL_CRYPTO_LIBRARY=$rootPath/openssl_3/libcrypto.a -DCMAKE_BUILD_TYPE=Release -DPORTABLE=1 -DTON_ARCH= ..
ninja storage-daemon storage-daemon-cli fift func tonlib tonlibjson tonlib-cli validator-engine lite-client \
pow-miner validator-engine-console generate-random-id json2tlo dht-server http-proxy rldp-http-proxy adnl-proxy \
create-state create-hardfork emulator \
test-ed25519 test-ed25519-crypto test-bigint test-vm test-fift test-cells test-smartcont test-net test-tdactor \
test-tdutils test-tonlib-offline test-adnl test-dht test-rldp test-rldp2 test-catchain test-fec test-tddb test-db test-validator-session-state
- name: Strip binaries
run: |
strip -g build-${{ matrix.os }}/storage/storage-daemon/storage-daemon build-${{ matrix.os }}/storage/storage-daemon/storage-daemon-cli build-${{ matrix.os }}/crypto/fift build-${{ matrix.os }}/crypto/tlbc build-${{ matrix.os }}/crypto/func build-${{ matrix.os }}/crypto/create-state build-${{ matrix.os }}/validator-engine-console/validator-engine-console build-${{ matrix.os }}/tonlib/tonlib-cli build-${{ matrix.os }}/tonlib/libtonlibjson.so.0.5 build-${{ matrix.os }}/http/http-proxy build-${{ matrix.os }}/rldp-http-proxy/rldp-http-proxy build-${{ matrix.os }}/dht-server/dht-server build-${{ matrix.os }}/lite-client/lite-client build-${{ matrix.os }}/validator-engine/validator-engine build-${{ matrix.os }}/utils/generate-random-id build-${{ matrix.os }}/utils/json2tlo build-${{ matrix.os }}/adnl/adnl-proxy build-${{ matrix.os }}/emulator/libemulator.*
- name: Run tests
run: |
cd build-${{ matrix.os }}
ctest --output-on-failure -E "test-catchain|test-actors"
- name: Find & copy binaries
run: |
mkdir artifacts-${{ matrix.os }}

View file

@ -49,10 +49,10 @@ jobs:
curl -Lo libsodium-1.0.18-stable-msvc.zip https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable-msvc.zip
unzip libsodium-1.0.18-stable-msvc.zip
- name: Install pre-compiled OpenSSL Win64
- name: Install pre-compiled OpenSSL 3 Win64
run: |
curl -Lo openssl-1.1.1j.zip https://github.com/neodiX42/precompiled-openssl-win64/raw/main/openssl-1.1.1j.zip
jar xf openssl-1.1.1j.zip
curl -Lo openssl-3.1.4.zip https://github.com/neodiX42/precompiled-openssl-win64/raw/main/openssl-3.1.4.zip
unzip openssl-3.1.4.zip
- name: Install pre-compiled libmicrohttpd Win64
run: |
@ -72,8 +72,13 @@ jobs:
echo %SODIUM_DIR%
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DSODIUM_USE_STATIC_LIBS=1 -DSECP256K1_INCLUDE_DIR=%root%\secp256k1\include -DSECP256K1_LIBRARY=%root%\secp256k1\bin\x64\Release\v142\static\secp256k1.lib -DREADLINE_INCLUDE_DIR=%root%\readline-5.0-1-lib\include\readline -DREADLINE_LIBRARY=%root%\readline-5.0-1-lib\lib\readline.lib -DPORTABLE=1 -DZLIB_FOUND=1 -DMHD_FOUND=1 -DMHD_LIBRARY=%root%\libmicrohttpd-0.9.77-w32-bin\x86_64\VS2019\Release-static\libmicrohttpd.lib -DMHD_INCLUDE_DIR=%root%\libmicrohttpd-0.9.77-w32-bin\x86_64\VS2019\Release-static -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DOPENSSL_FOUND=1 -DOPENSSL_INCLUDE_DIR=%root%/openssl-1.1.1j/include -DOPENSSL_CRYPTO_LIBRARY=%root%/openssl-1.1.1j/lib/libcrypto_static.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" ..
cmake --build . --target storage-daemon storage-daemon-cli blockchain-explorer fift func tonlib tonlibjson tonlib-cli validator-engine lite-client pow-miner validator-engine-console generate-random-id json2tlo dht-server http-proxy rldp-http-proxy adnl-proxy create-state create-hardfork emulator --config Release
cmake -DSODIUM_USE_STATIC_LIBS=1 -DSECP256K1_INCLUDE_DIR=%root%\secp256k1\include -DSECP256K1_LIBRARY=%root%\secp256k1\bin\x64\Release\v142\static\secp256k1.lib -DREADLINE_INCLUDE_DIR=%root%\readline-5.0-1-lib\include\readline -DREADLINE_LIBRARY=%root%\readline-5.0-1-lib\lib\readline.lib -DPORTABLE=1 -DZLIB_FOUND=1 -DMHD_FOUND=1 -DMHD_LIBRARY=%root%\libmicrohttpd-0.9.77-w32-bin\x86_64\VS2019\Release-static\libmicrohttpd.lib -DMHD_INCLUDE_DIR=%root%\libmicrohttpd-0.9.77-w32-bin\x86_64\VS2019\Release-static -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DOPENSSL_FOUND=1 -DOPENSSL_INCLUDE_DIR=%root%/openssl-3.1.4/x64/include -DOPENSSL_CRYPTO_LIBRARY=%root%/openssl-3.1.4/x64/lib/libcrypto_static.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" ..
cmake --build . --config Release --target storage-daemon storage-daemon-cli blockchain-explorer fift func tonlib tonlibjson tonlib-cli validator-engine lite-client pow-miner validator-engine-console generate-random-id json2tlo dht-server http-proxy rldp-http-proxy adnl-proxy create-state create-hardfork emulator test-ed25519 test-ed25519-crypto test-bigint test-vm test-fift test-cells test-smartcont test-net test-tdactor test-tdutils test-tonlib-offline test-adnl test-dht test-rldp test-rldp2 test-catchain test-fec test-tddb test-db test-validator-session-state
- name: Run tests
run: |
cd build
ctest -C Release --output-on-failure -E "test-catchain|test-actors|test-validator-session-state"
- name: Show executables
run: |

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(TON VERSION 0.5 LANGUAGES C CXX)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@ -79,7 +79,7 @@ else()
set(HAVE_SSE42 FALSE)
endif()
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS FALSE)
@ -255,6 +255,9 @@ if (MSVC)
add_definitions(-D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /W4 /wd4100 /wd4127 /wd4324 /wd4456 /wd4457 /wd4458 /wd4505 /wd4702")
elseif (CLANG OR GCC)
if (GCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstrong-eval-order=some")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
if (APPLE)
#use "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/export_list" for exported symbols
@ -447,6 +450,10 @@ target_link_libraries(test-smartcont PRIVATE smc-envelope fift-lib ton_db)
add_executable(test-bigint ${BIGINT_TEST_SOURCE})
target_link_libraries(test-bigint PRIVATE ton_crypto)
if (WINGETOPT_FOUND)
target_link_libraries_system(test-bigint wingetopt)
endif()
add_executable(test-cells test/test-td-main.cpp ${CELLS_TEST_SOURCE})
target_link_libraries(test-cells PRIVATE ton_crypto)
@ -513,26 +520,12 @@ target_link_libraries(test-rldp2 adnl adnltest dht rldp2 tl_api)
add_executable(test-validator-session-state test/test-validator-session-state.cpp)
target_link_libraries(test-validator-session-state adnl dht rldp validatorsession tl_api)
#add_executable(test-node test/test-node.cpp)
#target_link_libraries(test-node overlay tdutils tdactor adnl tl_api dht
# catchain validatorsession)
add_executable(test-catchain test/test-catchain.cpp)
target_link_libraries(test-catchain overlay tdutils tdactor adnl adnltest rldp tl_api dht
catchain )
#add_executable(test-validator-session test/test-validator-session.cpp)
#target_link_libraries(test-validator-session overlay tdutils tdactor adnl tl_api dht
# catchain validatorsession)
add_executable(test-ton-collator test/test-ton-collator.cpp)
target_link_libraries(test-ton-collator overlay tdutils tdactor adnl tl_api dht
catchain validatorsession validator-disk ton_validator validator-disk )
#add_executable(test-validator test/test-validator.cpp)
#target_link_libraries(test-validator overlay tdutils tdactor adnl tl_api dht
# rldp catchain validatorsession ton-node validator ton_validator validator memprof ${JEMALLOC_LIBRARIES})
#add_executable(test-ext-server test/test-ext-server.cpp)
#target_link_libraries(test-ext-server tdutils tdactor adnl tl_api dht )
#add_executable(test-ext-client test/test-ext-client.cpp)
#target_link_libraries(test-ext-client tdutils tdactor adnl tl_api tl-lite-utils)
add_executable(test-http test/test-http.cpp)
target_link_libraries(test-http PRIVATE tonhttp)
@ -574,13 +567,53 @@ add_test(test-tdutils test-tdutils)
add_test(test-tonlib-offline test-tonlib-offline)
#END tonlib
# FunC tests
if (NOT NIX)
if (MSVC)
set(PYTHON_VER "python")
else()
set(PYTHON_VER "python3")
endif()
add_test(
NAME test-func
COMMAND ${PYTHON_VER} run_tests.py tests/
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/crypto/func/auto-tests)
if (WIN32)
set_property(TEST test-func PROPERTY ENVIRONMENT
"FUNC_EXECUTABLE=${CMAKE_CURRENT_BINARY_DIR}/crypto/Release/func.exe"
"FIFT_EXECUTABLE=${CMAKE_CURRENT_BINARY_DIR}/crypto/Release/fift.exe"
"FIFTPATH=${CMAKE_CURRENT_SOURCE_DIR}/crypto/fift/lib/")
else()
set_property(TEST test-func PROPERTY ENVIRONMENT
"FUNC_EXECUTABLE=${CMAKE_CURRENT_BINARY_DIR}/crypto/func"
"FIFT_EXECUTABLE=${CMAKE_CURRENT_BINARY_DIR}/crypto/fift"
"FIFTPATH=${CMAKE_CURRENT_SOURCE_DIR}/crypto/fift/lib/")
endif()
add_test(
NAME test-func-legacy
COMMAND ${PYTHON_VER} legacy_tester.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/crypto/func/auto-tests)
if (WIN32)
set_property(TEST test-func-legacy PROPERTY ENVIRONMENT
"FUNC_EXECUTABLE=${CMAKE_CURRENT_BINARY_DIR}/crypto/Release/func.exe"
"FIFT_EXECUTABLE=${CMAKE_CURRENT_BINARY_DIR}/crypto/Release/fift.exe"
"FIFTPATH=${CMAKE_CURRENT_SOURCE_DIR}/crypto/fift/lib/")
else()
set_property(TEST test-func-legacy PROPERTY ENVIRONMENT
"FUNC_EXECUTABLE=${CMAKE_CURRENT_BINARY_DIR}/crypto/func"
"FIFT_EXECUTABLE=${CMAKE_CURRENT_BINARY_DIR}/crypto/fift"
"FIFTPATH=${CMAKE_CURRENT_SOURCE_DIR}/crypto/fift/lib/")
endif()
endif()
#BEGIN internal
if (NOT TON_ONLY_TONLIB)
add_test(test-adnl test-adnl)
add_test(test-dht test-dht)
add_test(test-rldp test-rldp)
add_test(test-rldp2 test-rldp2)
#add_test(test-validator-session-state test-validator-session-state)
add_test(test-validator-session-state test-validator-session-state)
add_test(test-catchain test-catchain)
add_test(test-fec test-fec)

View file

@ -66,3 +66,8 @@ If a CI workflow fails not because of your changes but workflow issues, try to f
* **C/C++ CI (ccpp-linux.yml)**: TBD
* **C/C++ CI Win64 Compile (ccpp-win64.yml)**: TBD
## Running tests
Tests are executed by running `ctest` in the build directory.

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
#BEGIN internal
if (NOT TON_ONLY_TONLIB)

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
option(NIX "Use \"ON\" for a static build." OFF)

View file

@ -52,7 +52,7 @@
#include "vm/boc.h"
#include "vm/cellops.h"
#include "vm/cells/MerkleProof.h"
#include "vm/cp0.h"
#include "vm/vm.h"
#include "auto/tl/lite_api.h"
#include "ton/lite-tl.hpp"
@ -654,7 +654,7 @@ int main(int argc, char* argv[]) {
});
#endif
vm::init_op_cp0();
vm::init_vm().ensure();
td::actor::Scheduler scheduler({2});
scheduler_ptr = &scheduler;

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(COMMON_SOURCE
checksum.h

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)

View file

@ -49,7 +49,7 @@
#include "validator/fabric.h"
#include "validator/impl/collator.h"
#include "crypto/vm/cp0.h"
#include "crypto/vm/vm.h"
#include "crypto/block/block-db.h"
#include "common/errorlog.h"
@ -307,7 +307,7 @@ int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_INFO);
td::set_default_failure_signal_handler().ensure();
CHECK(vm::init_op_cp0());
vm::init_vm().ensure();
td::actor::ActorOwn<HardforkCreator> x;

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)

File diff suppressed because it is too large Load diff

View file

@ -270,7 +270,7 @@ struct Account {
return balance;
}
bool set_address(ton::WorkchainId wc, td::ConstBitPtr new_addr);
bool unpack(Ref<vm::CellSlice> account, Ref<vm::CellSlice> extra, ton::UnixTime now, bool special = false);
bool unpack(Ref<vm::CellSlice> account, ton::UnixTime now, bool special);
bool init_new(ton::UnixTime now);
bool deactivate();
bool recompute_tmp_addr(Ref<vm::CellSlice>& tmp_addr, int split_depth, td::ConstBitPtr orig_addr_rewrite) const;
@ -382,8 +382,6 @@ struct Transaction {
td::Result<vm::NewCellStorageStat::Stat> estimate_block_storage_profile_incr(
const vm::NewCellStorageStat& store_stat, const vm::CellUsageTree* usage_tree) const;
bool update_block_storage_profile(vm::NewCellStorageStat& store_stat, const vm::CellUsageTree* usage_tree) const;
bool would_fit(unsigned cls, const block::BlockLimitStatus& blk_lim_st) const;
bool update_limits(block::BlockLimitStatus& blk_lim_st, bool with_size = true) const;
Ref<vm::Cell> commit(Account& _account); // _account should point to the same account

View file

@ -130,7 +130,7 @@ void bits_memcpy(unsigned char* to, int to_offs, const unsigned char* from, int
from_offs &= 7;
to_offs &= 7;
//fprintf(stderr, "bits_memcpy: from=%p (%02x) to=%p (%02x) from_offs=%d to_offs=%d count=%lu\n", from, *from, to, *to, from_offs, to_offs, bit_count);
int sz = (int)bit_count;
int sz = static_cast<int>(bit_count);
bit_count += from_offs;
if (from_offs == to_offs) {
if (bit_count < 8) {
@ -206,7 +206,7 @@ void bits_memset(unsigned char* to, int to_offs, bool val, std::size_t bit_count
}
to += (to_offs >> 3);
to_offs &= 7;
int sz = (int)bit_count;
int sz = static_cast<int>(bit_count);
bit_count += to_offs;
int c = *to;
if (bit_count <= 8) {

View file

@ -461,19 +461,109 @@ x{B7A3} @Defop QNEGATE
x{B7A4} @Defop QINC
x{B7A5} @Defop QDEC
x{B7A8} @Defop QMUL
x{B7A904} @Defop QDIV
x{B7A905} @Defop QDIVR
x{B7A906} @Defop QDIVC
x{B7A908} @Defop QMOD
x{B7A909} @Defop QMODR
x{B7A90A} @Defop QMODC
x{B7A90C} @Defop QDIVMOD
x{B7A90D} @Defop QDIVMODR
x{B7A90E} @Defop QDIVMODC
x{B7A900} @Defop QADDDIVMOD
x{B7A901} @Defop QADDDIVMODR
x{B7A902} @Defop QADDDIVMODC
x{B7A925} @Defop QRSHIFTR
x{B7A926} @Defop QRSHIFTC
x{B7A928} @Defop QMODPOW2
x{B7A929} @Defop QMODPOW2R
x{B7A92A} @Defop QMODPOW2C
x{B7A92C} @Defop QRSHIFTMOD
x{B7A92D} @Defop QRSHIFTMODR
x{B7A92E} @Defop QRSHIFTMODC
x{B7A920} @Defop QADDRSHIFTMOD
x{B7A921} @Defop QADDRSHIFTMODR
x{B7A922} @Defop QADDRSHIFTMODC
x{B7A935} @Defop(8u+1) QRSHIFTR#
x{B7A936} @Defop(8u+1) QRSHIFTC#
x{B7A938} @Defop(8u+1) QMODPOW2#
x{B7A939} @Defop(8u+1) QMODPOW2R#
x{B7A93A} @Defop(8u+1) QMODPOW2C#
x{B7A93C} @Defop(8u+1) QRSHIFT#MOD
x{B7A93D} @Defop(8u+1) QRSHIFTR#MOD
x{B7A93E} @Defop(8u+1) QRSHIFTC#MOD
x{B7A930} @Defop(8u+1) QADDRSHIFT#MOD
x{B7A931} @Defop(8u+1) QADDRSHIFTR#MOD
x{B7A932} @Defop(8u+1) QADDRSHIFTC#MOD
x{B7A984} @Defop QMULDIV
x{B7A985} @Defop QMULDIVR
x{B7A986} @Defop QMULDIVC
x{B7A988} @Defop QMULMOD
x{B7A989} @Defop QMULMODR
x{B7A98A} @Defop QMULMODC
x{B7A98C} @Defop QMULDIVMOD
x{B7A980} @Defop QADDMULDIVMOD
x{B7A98D} @Defop QMULDIVMODR
x{B7A98E} @Defop QMULDIVMODC
x{B7A980} @Defop QMULADDDIVMOD
x{B7A981} @Defop QMULADDDIVMODR
x{B7A982} @Defop QMULADDDIVMODC
x{B7A9A4} @Defop QMULRSHIFT
x{B7A9A5} @Defop QMULRSHIFTR
x{B7A9A6} @Defop QMULRSHIFTC
x{B7A9A8} @Defop QMULMODPOW2
x{B7A9A9} @Defop QMULMODPOW2R
x{B7A9AA} @Defop QMULMODPOW2C
x{B7A9AC} @Defop QMULRSHIFTMOD
x{B7A9AD} @Defop QMULRSHIFTRMOD
x{B7A9AE} @Defop QMULRSHIFTCMOD
x{B7A9A0} @Defop QMULADDRSHIFTMOD
x{B7A9A1} @Defop QMULADDRSHIFTRMOD
x{B7A9A2} @Defop QMULADDRSHIFTCMOD
x{B7A9B4} @Defop(8u+1) QMULRSHIFT#
x{B7A9B5} @Defop(8u+1) QMULRSHIFTR#
x{B7A9B6} @Defop(8u+1) QMULRSHIFTC#
x{B7A9B8} @Defop(8u+1) QMULMODPOW2#
x{B7A9B9} @Defop(8u+1) QMULMODPOW2R#
x{B7A9BA} @Defop(8u+1) QMULMODPOW2C#
x{B7A9BC} @Defop(8u+1) QMULRSHIFT#MOD
x{B7A9BD} @Defop(8u+1) QMULRSHIFTR#MOD
x{B7A9BE} @Defop(8u+1) QMULRSHIFTC#MOD
x{B7A9B0} @Defop(8u+1) QMULADDRSHIFT#MOD
x{B7A9B1} @Defop(8u+1) QMULADDRSHIFTR#MOD
x{B7A9B2} @Defop(8u+1) QMULADDRSHIFTC#MOD
x{B7A9C4} @Defop QLSHIFTDIV
x{B7A9C5} @Defop QLSHIFTDIVR
x{B7A9C6} @Defop QLSHIFTDIVC
x{B7A9C8} @Defop QLSHIFTMOD
x{B7A9C9} @Defop QLSHIFTMODR
x{B7A9CA} @Defop QLSHIFTMODC
x{B7A9CC} @Defop QLSHIFTDIVMOD
x{B7A9CD} @Defop QLSHIFTDIVMODR
x{B7A9CE} @Defop QLSHIFTDIVMODC
x{B7A9C0} @Defop QLSHIFTADDDIVMOD
x{B7A9C1} @Defop QLSHIFTADDDIVMODR
x{B7A9C2} @Defop QLSHIFTADDDIVMODC
x{B7A9D4} @Defop(8u+1) QLSHIFT#DIV
x{B7A9D5} @Defop(8u+1) QLSHIFT#DIVR
x{B7A9D6} @Defop(8u+1) QLSHIFT#DIVC
x{B7A9D8} @Defop(8u+1) QLSHIFT#MOD
x{B7A9D9} @Defop(8u+1) QLSHIFT#MODR
x{B7A9DA} @Defop(8u+1) QLSHIFT#MODC
x{B7A9DC} @Defop(8u+1) QLSHIFT#DIVMOD
x{B7A9DD} @Defop(8u+1) QLSHIFT#DIVMODR
x{B7A9DE} @Defop(8u+1) QLSHIFT#DIVMODC
x{B7A9D0} @Defop(8u+1) QLSHIFT#ADDDIVMOD
x{B7A9D1} @Defop(8u+1) QLSHIFT#ADDDIVMODR
x{B7A9D2} @Defop(8u+1) QLSHIFT#ADDDIVMODC
x{B7AC} @Defop QLSHIFT
x{B7AD} @Defop QRSHIFT
x{B7AE} @Defop QPOW2
@ -1185,7 +1275,7 @@ x{F4BF} @Defop DICTUGETEXECZ
x{F800} @Defop ACCEPT
x{F801} @Defop SETGASLIMIT
x{F802} @Defop GASCONSUMED
x{F806} @Defop GASCONSUMED
x{F80F} @Defop COMMIT
x{F810} @Defop RANDU256

View file

@ -3512,7 +3512,7 @@ void init_words_ton(Dictionary& d) {
void init_words_vm(Dictionary& d, bool enable_debug) {
using namespace std::placeholders;
vm::init_op_cp0(enable_debug);
vm::init_vm(enable_debug).ensure();
// vm run
d.def_word("vmlibs ", LitCont::literal(vm_libraries));
// d.def_ctx_word("runvmcode ", std::bind(interpret_run_vm, _1, 0x40));

View file

@ -8,37 +8,37 @@ import shutil
add_pragmas = [] #["allow-post-modification", "compute-asm-ltr"];
tests = [
# note, that deployed version of elector,config and multisig differ since it is compilled with func-0.1.0.
# Newer compillators optimize arithmetic and logic expression that can be calculated at the compile time
["elector/elector-code.fc", 115226404411715505328583639896096915745686314074575650766750648324043316883483],
["config/config-code.fc", 10913070768607625342121305745084703121685937915388357634624451844356456145601],
["eth-bridge-multisig/multisig-code.fc", 101509909129354488841890823627011033360100627957439967918234053299675481277954],
# note, that deployed version of elector,config and multisig differ since it is compilled with func-0.1.0.
# Newer compillators optimize arithmetic and logic expression that can be calculated at the compile time
["elector/elector-code.fc", 115226404411715505328583639896096915745686314074575650766750648324043316883483],
["config/config-code.fc", 10913070768607625342121305745084703121685937915388357634624451844356456145601],
["eth-bridge-multisig/multisig-code.fc", 101509909129354488841890823627011033360100627957439967918234053299675481277954],
["bsc-bridge-collector/votes-collector.fc", 62190447221288642706570413295807615918589884489514159926097051017036969900417],
["uni-lock-wallet/uni-lockup-wallet.fc", 61959738324779104851267145467044677651344601417998258530238254441977103654381],
["nft-collection/nft-collection-editable.fc", 45561997735512210616567774035540357815786262097548276229169737015839077731274],
["dns-collection/nft-collection.fc", 107999822699841936063083742021519765435859194241091312445235370766165379261859],
["bsc-bridge-collector/votes-collector.fc", 62190447221288642706570413295807615918589884489514159926097051017036969900417],
["uni-lock-wallet/uni-lockup-wallet.fc", 61959738324779104851267145467044677651344601417998258530238254441977103654381],
["nft-collection/nft-collection-editable.fc", 45561997735512210616567774035540357815786262097548276229169737015839077731274],
["dns-collection/nft-collection.fc", 107999822699841936063083742021519765435859194241091312445235370766165379261859],
# note, that deployed version of tele-nft-item differs since it is compilled with func-0.3.0.
# After introducing of try/catch construction, c2 register is not always the default one.
# Thus it is necessary to save it upon jumps, differences of deployed and below compilled is that
# "c2 SAVE" is added to the beginning of recv_internal. It does not change behavior.
["tele-nft-item/nft-item.fc", 69777543125381987786450436977742010705076866061362104025338034583422166453344],
# note, that deployed version of tele-nft-item differs since it is compilled with func-0.3.0.
# After introducing of try/catch construction, c2 register is not always the default one.
# Thus it is necessary to save it upon jumps, differences of deployed and below compilled is that
# "c2 SAVE" is added to the beginning of recv_internal. It does not change behavior.
["tele-nft-item/nft-item.fc", 69777543125381987786450436977742010705076866061362104025338034583422166453344],
["storage/storage-contract.fc", 91377830060355733016937375216020277778264560226873154627574229667513068328151],
["storage/storage-provider.fc", 13618336676213331164384407184540461509022654507176709588621016553953760588122],
["nominator-pool/pool.fc", 69767057279163099864792356875696330339149706521019810113334238732928422055375],
["jetton-minter/jetton-minter.fc", 9028309926287301331466371999814928201427184114165428257502393474125007156494],
["gg-marketplace/nft-marketplace-v2.fc", 92199806964112524639740773542356508485601908152150843819273107618799016205930],
["jetton-wallet/jetton-wallet.fc", 86251125787443633057458168028617933212663498001665054651523310772884328206542],
["whales-nominators/nominators.fc", 8941364499854379927692172316865293429893094891593442801401542636695127885153],
["storage/storage-contract.fc", 91377830060355733016937375216020277778264560226873154627574229667513068328151],
["storage/storage-provider.fc", 13618336676213331164384407184540461509022654507176709588621016553953760588122],
["nominator-pool/pool.fc", 69767057279163099864792356875696330339149706521019810113334238732928422055375],
["jetton-minter/jetton-minter.fc", 9028309926287301331466371999814928201427184114165428257502393474125007156494],
["gg-marketplace/nft-marketplace-v2.fc", 92199806964112524639740773542356508485601908152150843819273107618799016205930],
["jetton-wallet/jetton-wallet.fc", 86251125787443633057458168028617933212663498001665054651523310772884328206542],
["whales-nominators/nominators.fc", 8941364499854379927692172316865293429893094891593442801401542636695127885153],
["tact-examples/treasure_Treasure.code.fc", 13962538639825790677138656603323869918938565499584297120566680287245364723897],
["tact-examples/jetton_SampleJetton.code.fc", 94076762218493729104783735200107713211245710256802265203823917715299139499110],
["tact-examples/jetton_JettonDefaultWallet.code.fc", 29421313492520031238091587108198906058157443241743283101866538036369069620563],
["tact-examples/maps_MapTestContract.code.fc", 22556550222249123835909180266811414538971143565993192846012583552876721649744],
["tact-examples/treasure_Treasure.code.fc", 13962538639825790677138656603323869918938565499584297120566680287245364723897],
["tact-examples/jetton_SampleJetton.code.fc", 94076762218493729104783735200107713211245710256802265203823917715299139499110],
["tact-examples/jetton_JettonDefaultWallet.code.fc", 29421313492520031238091587108198906058157443241743283101866538036369069620563],
["tact-examples/maps_MapTestContract.code.fc", 22556550222249123835909180266811414538971143565993192846012583552876721649744],
]
def getenv(name, default=None):
@ -51,7 +51,6 @@ def getenv(name, default=None):
FUNC_EXECUTABLE = getenv("FUNC_EXECUTABLE", "func")
FIFT_EXECUTABLE = getenv("FIFT_EXECUTABLE", "fift")
FIFT_LIBS = getenv("FIFTPATH")
TMP_DIR = tempfile.mkdtemp()
COMPILED_FIF = os.path.join(TMP_DIR, "compiled.fif")
@ -63,49 +62,49 @@ class ExecutionError(Exception):
pass
def pre_process_func(f):
shutil.copyfile(f, f+"_backup")
with open(f, "r") as src:
sources = src.read()
with open(f, "w") as src:
for pragma in add_pragmas:
src.write("#pragma %s;\n"%pragma)
src.write(sources)
shutil.copyfile(f, f+"_backup")
with open(f, "r") as src:
sources = src.read()
with open(f, "w") as src:
for pragma in add_pragmas:
src.write("#pragma %s;\n"%pragma)
src.write(sources)
def post_process_func(f):
shutil.move(f+"_backup", f)
shutil.move(f+"_backup", f)
def compile_func(f):
res = None
try:
pre_process_func(f)
if "storage-provider.fc" in f :
# This contract requires building of storage-contract to include it as ref
with open(f, "r") as src:
sources = src.read()
# This contract requires building of storage-contract to include it as ref
with open(f, "r") as src:
sources = src.read()
COMPILED_ST_BOC = os.path.join(TMP_DIR, "storage-contract-code.boc")
sources = sources.replace("storage-contract-code.boc", COMPILED_ST_BOC)
with open(f, "w") as src:
src.write(sources)
COMPILED_ST_FIF = os.path.join(TMP_DIR, "storage-contract.fif")
COMPILED_ST_BOC = os.path.join(TMP_DIR, "storage-contract-code.boc")
sources = sources.replace("storage-contract-code.boc", COMPILED_ST_BOC)
with open(f, "w") as src:
src.write(sources)
COMPILED_ST_FIF = os.path.join(TMP_DIR, "storage-contract.fif")
COMPILED_ST_BOC = os.path.join(TMP_DIR, "storage-contract-code.boc")
COMPILED_BUILD_BOC = os.path.join(TMP_DIR, "build-boc.fif")
res = subprocess.run([FUNC_EXECUTABLE, "-o", COMPILED_ST_FIF, "-SPA", f.replace("storage-provider.fc","storage-contract.fc")], capture_output=False, timeout=10)
with open(COMPILED_BUILD_BOC, "w") as scr:
scr.write("\"%s\" include boc>B \"%s\" B>file "%(COMPILED_ST_FIF, COMPILED_ST_BOC))
res = subprocess.run([FIFT_EXECUTABLE, COMPILED_BUILD_BOC ], capture_output=True, timeout=10)
COMPILED_BUILD_BOC = os.path.join(TMP_DIR, "build-boc.fif")
res = subprocess.run([FUNC_EXECUTABLE, "-o", COMPILED_ST_FIF, "-SPA", f.replace("storage-provider.fc","storage-contract.fc")], capture_output=False, timeout=10)
with open(COMPILED_BUILD_BOC, "w") as scr:
scr.write("\"%s\" include boc>B \"%s\" B>file "%(COMPILED_ST_FIF, COMPILED_ST_BOC))
res = subprocess.run([FIFT_EXECUTABLE, COMPILED_BUILD_BOC ], capture_output=True, timeout=10)
res = subprocess.run([FUNC_EXECUTABLE, "-o", COMPILED_FIF, "-SPA", f], capture_output=True, timeout=10)
except Exception as e:
post_process_func(f)
raise e
post_process_func(f)
raise e
else:
post_process_func(f)
post_process_func(f)
if res.returncode != 0:
raise ExecutionError(str(res.stderr, "utf-8"))
def run_runner():
res = subprocess.run([FIFT_EXECUTABLE, "-I", FIFT_LIBS, RUNNER_FIF], capture_output=True, timeout=10)
res = subprocess.run([FIFT_EXECUTABLE, RUNNER_FIF], capture_output=True, timeout=10)
if res.returncode != 0:
raise ExecutionError(str(res.stderr, "utf-8"))
s = str(res.stdout, "utf-8")
@ -138,16 +137,15 @@ for ti, t in enumerate(tests):
try:
func_out = run_runner()
if func_out != th:
raise ExecutionError("Error : expected '%d', found '%d'" % (th, func_out))
raise ExecutionError("Error : expected '%d', found '%d'" % (th, func_out))
success += 1
except ExecutionError as e:
print(e, file=sys.stderr)
#print("Compiled:", file=sys.stderr)
#with open(COMPILED_FIF, "r") as f:
# print(f.read(), file=sys.stderr)
#exit(2)
print("Compiled:", file=sys.stderr)
with open(COMPILED_FIF, "r") as f:
print(f.read(), file=sys.stderr)
exit(2)
print(" OK ", file=sys.stderr)
print(get_version())
print("Done: Success %d, Error: %d"%(success, len(tests)-success), file=sys.stderr)
print("Done: Success %d, Error: %d"%(success, len(tests)-success), file=sys.stderr)

View file

@ -4,6 +4,7 @@ import subprocess
import sys
import tempfile
def getenv(name, default=None):
if name in os.environ:
return os.environ[name]
@ -12,10 +13,9 @@ def getenv(name, default=None):
exit(1)
return default
FUNC_EXECUTABLE = getenv("FUNC_EXECUTABLE", "func")
FIFT_EXECUTABLE = getenv("FIFT_EXECUTABLE", "fift")
#FUNC_STDLIB = getenv("FUNC_STDLIB")
FIFT_LIBS = getenv("FIFT_LIBS")
TMP_DIR = tempfile.mkdtemp()
COMPILED_FIF = os.path.join(TMP_DIR, "compiled.fif")
RUNNER_FIF = os.path.join(TMP_DIR, "runner.fif")
@ -25,22 +25,26 @@ if len(sys.argv) != 2:
exit(1)
TESTS_DIR = sys.argv[1]
class ExecutionError(Exception):
pass
def compile_func(f):
res = subprocess.run([FUNC_EXECUTABLE, "-o", COMPILED_FIF, "-SPA", f], capture_output=True, timeout=10)
if res.returncode != 0:
raise ExecutionError(str(res.stderr, "utf-8"))
def run_runner():
res = subprocess.run([FIFT_EXECUTABLE, "-I", FIFT_LIBS, RUNNER_FIF], capture_output=True, timeout=10)
res = subprocess.run([FIFT_EXECUTABLE, RUNNER_FIF], capture_output=True, timeout=10)
if res.returncode != 0:
raise ExecutionError(str(res.stderr, "utf-8"))
s = str(res.stdout, "utf-8")
s = [x.strip() for x in s.split("\n")]
return [x for x in s if x != ""]
tests = [s for s in os.listdir(TESTS_DIR) if s.endswith(".fc")]
tests.sort()
print("Found", len(tests), "tests", file=sys.stderr)
@ -68,18 +72,18 @@ for ti, tf in enumerate(tests):
# preprocess arithmetics in input
for i in range(len(cases)):
inputs = cases[i][1].split(" ")
processed_inputs = ""
for in_arg in inputs:
if "x{" in in_arg:
processed_inputs += in_arg
continue
# filter and execute
# is it safe enough?
filtered_in = "".join(filter(lambda x: x in "0x123456789()+-*/<>", in_arg))
if(filtered_in):
processed_inputs += str(eval(filtered_in)) + " ";
cases[i][1] = processed_inputs.strip()
inputs = cases[i][1].split(" ")
processed_inputs = ""
for in_arg in inputs:
if "x{" in in_arg:
processed_inputs += in_arg
continue
# filter and execute
# is it safe enough?
filtered_in = "".join(filter(lambda x: x in "0x123456789()+-*/<>", in_arg))
if filtered_in:
processed_inputs += str(eval(filtered_in)) + " "
cases[i][1] = processed_inputs.strip()
with open(RUNNER_FIF, "w") as f:
print("\"%s\" include <s constant code" % COMPILED_FIF, file=f)
@ -103,4 +107,4 @@ for ti, tf in enumerate(tests):
exit(2)
print(" OK, %d cases" % len(cases), file=sys.stderr)
print("Done", file=sys.stderr)
print("Done", file=sys.stderr)

View file

@ -232,6 +232,7 @@ Bignum& Bignum::import_lsb(const unsigned char* buffer, std::size_t size) {
std::string Bignum::to_str() const {
char* ptr = BN_bn2dec(val);
CHECK(ptr);
std::string z(ptr);
OPENSSL_free(ptr);
return z;
@ -239,6 +240,7 @@ std::string Bignum::to_str() const {
std::string Bignum::to_hex() const {
char* ptr = BN_bn2hex(val);
CHECK(ptr);
std::string z(ptr);
OPENSSL_free(ptr);
return z;
@ -255,7 +257,13 @@ std::istream& operator>>(std::istream& is, Bignum& x) {
return is;
}
bool is_prime(const Bignum& p, int nchecks, bool trial_div) {
return BN_is_prime_fasttest_ex(p.bn_ptr(), BN_prime_checks, get_ctx(), trial_div, 0);
bool is_prime(const Bignum& p) {
#if OPENSSL_VERSION_MAJOR >= 3
int result = BN_check_prime(p.bn_ptr(), get_ctx(), nullptr);
LOG_IF(FATAL, result == -1);
return result;
#else
return BN_is_prime_fasttest_ex(p.bn_ptr(), BN_prime_checks, get_ctx(), true, 0);
#endif
}
} // namespace arith

View file

@ -335,7 +335,7 @@ const Bignum sqr(const Bignum& x);
std::ostream& operator<<(std::ostream& os, const Bignum& x);
std::istream& operator>>(std::istream& is, Bignum& x);
bool is_prime(const Bignum& p, int nchecks = 64, bool trial_div = true);
bool is_prime(const Bignum& p);
inline int cmp(const Bignum& x, const Bignum& y) {
return BN_cmp(x.bn_ptr(), y.bn_ptr());

View file

@ -250,7 +250,6 @@ const Lexem& Lexer::next() {
}
if (is_multiline_quote(src.get_ptr(), src.get_end_ptr())) {
src.advance(multiline_quote.size());
const char* begin = src.get_ptr();
const char* end = nullptr;
SrcLocation here = src.here();
std::string body;

View file

@ -305,7 +305,7 @@ class ManualDns : public ton::SmartContract, public DnsInterface {
if (!info.known_category.insert(action.category).second) {
continue;
}
if (action.category == 0) {
if (action.category.is_zero()) {
info.closed = true;
auto old_actions = std::move(info.actions);
bool is_empty = true;
@ -327,7 +327,7 @@ class ManualDns : public ton::SmartContract, public DnsInterface {
if (info.closed) {
CombinedActions<ActionT> ca;
ca.name = it.first;
ca.category = 0;
ca.category = td::Bits256::zero();
if (!info.actions.empty() || info.non_empty) {
ca.actions = std::move(info.actions);
}

View file

@ -181,7 +181,7 @@ SmartContract::Answer run_smartcont(SmartContract::State state, td::Ref<vm::Stac
int vm_log_verbosity, bool debug_enabled,
std::shared_ptr<const block::Config> config) {
auto gas_credit = gas.gas_credit;
vm::init_op_cp0(debug_enabled);
vm::init_vm(debug_enabled).ensure();
vm::DictionaryBase::get_empty_dictionary();
class Logger : public td::LogInterface {

View file

@ -33,7 +33,7 @@ std::string load_test(std::string name) {
return td::read_file_str(current_dir() + "fift/" + name).move_as_ok();
}
td::Status run_fift(std::string name, bool expect_error = false, bool preload_fift = true) {
td::Status run_fift(std::string name, bool expect_error = false) {
auto res = fift::mem_run_fift(load_test(name));
if (expect_error) {
res.ensure_error();

View file

@ -9,6 +9,9 @@
[[ <{ RIST255_MULBASE DUP RIST255_VALIDATE }>s ]] 0 runvmx abort"Exitcode != 0"
@' n . dup (x.) type cr
@' ans <> abort"Invalid result"
@' n
[[ <{ 1 INT RIST255_MULBASE SWAP RIST255_MUL DUP RIST255_VALIDATE }>s ]] 0 runvmx abort"Exitcode != 0"
@' ans <> abort"Invalid result"
} : test-basepoint
0 0x0000000000000000000000000000000000000000000000000000000000000000 test-basepoint

View file

@ -180,7 +180,7 @@ struct MixedRadix {
template <int M>
const MixedRadix<M>& as_shorter() const {
static_assert(M <= N);
static_assert(M <= N,"error");
return *reinterpret_cast<const MixedRadix<M>*>(this);
}
@ -458,7 +458,7 @@ struct ModArray {
}
template <int M>
ModArray(const ModArray<M>& other) {
static_assert(M >= N);
static_assert(M >= N,"error");
std::copy(other.a, other.a + N, a);
}
ModArray(const int* p) : a(p) {
@ -819,7 +819,7 @@ struct ModArray {
template <int M>
const ModArray<M>& as_shorter() const {
static_assert(M <= N);
static_assert(M <= N,"error");
return *reinterpret_cast<const ModArray<M>*>(this);
}

View file

@ -16,12 +16,12 @@
*/
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <array>
#include <string>
#include <iostream>
#include <sstream>
#include <random>
#include <getopt.h>
#include "common/refcnt.hpp"
#include "common/bigint.hpp"
#include "common/refint.h"
@ -211,7 +211,7 @@ bool coin() {
// returns 0 with probability 1/2, 1 with prob. 1/4, ..., k with prob. 1/2^(k+1)
int randexp(int max = 63, int min = 0) {
return min + __builtin_clzll(Random() | (1ULL << (63 - max + min)));
return min + td::count_leading_zeroes64(Random() | (1ULL << (63 - max + min)));
}
void bin_add_small(unsigned char bin[64], long long val, int shift = 0) {
@ -363,7 +363,7 @@ void check_one_int_repr(td::RefInt256 x, int mode, int in_range, const BInt* val
if (is_small) {
// special check for small (64-bit) values
CHECK(x->to_long() == xval);
CHECK((long long)__builtin_bswap64(*(long long*)(bytes + 64 - 8)) == xval);
CHECK((long long)td::bswap64(*(long long*)(bytes + 64 - 8)) == xval);
CHECK(in_range);
// check sign
CHECK(x->sgn() == (xval > 0 ? 1 : (xval < 0 ? -1 : 0)));

View file

@ -127,12 +127,12 @@ class BenchSha256Low : public td::Benchmark {
void run(int n) override {
int res = 0;
SHA256_CTX ctx;
td::Sha256State ctx;
for (int i = 0; i < n; i++) {
SHA256_Init(&ctx);
SHA256_Update(&ctx, "abcd", 4);
ctx.init();
ctx.feed("abcd");
unsigned char buf[32];
SHA256_Final(buf, &ctx);
ctx.extract(td::MutableSlice{buf, 32});
res += buf[0];
}
td::do_not_optimize_away(res);

View file

@ -958,7 +958,7 @@ class MapDns {
}
return;
}
if (!actions.category.is_zero()) {
if (actions.category.is_zero()) {
entries_.erase(actions.name);
LOG(ERROR) << "CLEAR " << actions.name;
if (!actions.actions) {
@ -1003,7 +1003,7 @@ class CheckedDns {
explicit CheckedDns(bool check_smc = true, bool check_combine = true) {
if (check_smc) {
key_ = td::Ed25519::generate_private_key().move_as_ok();
dns_ = ManualDns::create(ManualDns::create_init_data_fast(key_.value().get_public_key().move_as_ok(), 123));
dns_ = ManualDns::create(ManualDns::create_init_data_fast(key_.value().get_public_key().move_as_ok(), 123), -1);
}
if (check_combine) {
combined_map_dns_ = MapDns();
@ -1094,9 +1094,10 @@ class CheckedDns {
}
};
static td::Bits256 intToCat(int x) {
td::Bits256 cat = td::Bits256::zero();
cat.as_slice().copy_from(td::Slice((char*)&x, sizeof(x)));
static td::Bits256 intToCat(td::uint32 x) {
auto y = td::make_refint(x);
td::Bits256 cat;
y->export_bytes(cat.data(), 32, false);
return cat;
}
@ -1182,7 +1183,7 @@ TEST(Smartcont, DnsManual) {
auto key = td::Ed25519::generate_private_key().move_as_ok();
auto manual = ManualDns::create(ManualDns::create_init_data_fast(key.get_public_key().move_as_ok(), 123));
auto manual = ManualDns::create(ManualDns::create_init_data_fast(key.get_public_key().move_as_ok(), 123), -1);
CHECK(manual->get_wallet_id().move_as_ok() == 123);
auto init_query = manual->create_init_query(key).move_as_ok();
LOG(ERROR) << "A";

View file

@ -28,7 +28,7 @@
#include "td/utils/StringBuilder.h"
std::string run_vm(td::Ref<vm::Cell> cell) {
vm::init_op_cp0();
vm::init_vm().ensure();
vm::DictionaryBase::get_empty_dictionary();
class Logger : public td::LogInterface {

View file

@ -159,7 +159,6 @@ std::string CppIdentSet::compute_cpp_ident(std::string orig_ident, int count) {
}
if (!cnt) {
os << '_';
prev_skip = true;
}
if (count) {
os << count;

View file

@ -2252,11 +2252,9 @@ TypeExpr* parse_expr10(Lexer& lex, Constructor& cs, int mode) {
}
if (op == '>') {
std::swap(expr, expr2);
op = '<';
op_name = Less_name;
} else if (op == src::_Geq) {
std::swap(expr, expr2);
op = src::_Leq;
op_name = Leq_name;
}
auto sym_def = sym::lookup_symbol(op_name, 2);

View file

@ -285,8 +285,11 @@ int exec_divmod(VmState* st, unsigned args, int quiet) {
typename td::BigInt256::DoubleInt tmp{*x}, quot;
tmp += *w;
tmp.mod_div(*y, quot, round_mode);
stack.push_int_quiet(td::make_refint(quot), quiet);
stack.push_int_quiet(td::make_refint(tmp), quiet);
auto q = td::make_refint(quot), r = td::make_refint(tmp);
q.write().normalize();
r.write().normalize();
stack.push_int_quiet(std::move(q), quiet);
stack.push_int_quiet(std::move(r), quiet);
} else {
switch (d) {
case 1:
@ -399,6 +402,7 @@ std::string dump_shrmod(CellSlice&, unsigned args, int mode) {
if (mode & 1) {
os << 'Q';
}
std::string end;
switch (args & 12) {
case 4:
os << "RSHIFT";
@ -407,17 +411,22 @@ std::string dump_shrmod(CellSlice&, unsigned args, int mode) {
os << "MODPOW2";
break;
case 12:
os << "RSHIFTMOD";
os << "RSHIFT";
end = "MOD";
break;
case 0:
os << "ADDRSHIFTMOD";
os << "ADDRSHIFT";
end = "MOD";
break;
}
if (!(mode & 2)) {
os << end;
}
if (round_mode) {
os << "FRC"[round_mode];
}
if (mode & 2) {
os << ' ' << y;
os << "#" << end << ' ' << y;
}
return os.str();
}
@ -519,7 +528,7 @@ int exec_mulshrmod(VmState* st, unsigned args, int mode) {
if (add) {
tmp = *w;
}
tmp.add_mul(*x, *y);
tmp.add_mul(*x, *y).normalize();
switch (d) {
case 1:
tmp.rshift(z, round_mode).normalize();
@ -553,6 +562,7 @@ std::string dump_mulshrmod(CellSlice&, unsigned args, int mode) {
if (mode & 1) {
os << 'Q';
}
std::string end;
switch (args & 12) {
case 4:
os << "MULRSHIFT";
@ -561,15 +571,21 @@ std::string dump_mulshrmod(CellSlice&, unsigned args, int mode) {
os << "MULMODPOW2";
break;
case 12:
os << "MULRSHIFTMOD";
os << "MULRSHIFT";
end = "MOD";
break;
case 0:
os << "MULADDRSHIFTMOD";
os << "MULADDRSHIFT";
end = "MOD";
break;
}
if (round_mode) {
os << "FRC"[round_mode];
}
if (mode & 2) {
os << "#";
}
os << end;
if (mode & 2) {
os << ' ' << y;
}
@ -644,18 +660,22 @@ std::string dump_shldivmod(CellSlice&, unsigned args, int mode) {
if (mode & 1) {
os << "Q";
}
os << "LSHIFT";
if (mode & 2) {
os << "#";
}
switch (args & 12) {
case 4:
os << "LSHIFTDIV";
os << "DIV";
break;
case 8:
os << "LSHIFTMOD";
os << "MOD";
break;
case 12:
os << "LSHIFTDIVMOD";
os << "DIVMOD";
break;
case 0:
os << "LSHIFTADDDIVMOD";
os << "ADDDIVMOD";
break;
}
if (round_mode) {

View file

@ -101,7 +101,7 @@ void register_basic_gas_ops(OpcodeTable& cp0) {
using namespace std::placeholders;
cp0.insert(OpcodeInstr::mksimple(0xf800, 16, "ACCEPT", exec_accept))
.insert(OpcodeInstr::mksimple(0xf801, 16, "SETGASLIMIT", exec_set_gas_limit))
.insert(OpcodeInstr::mksimple(0xf802, 16, "GASCONSUMED", exec_gas_consumed)->require_version(4))
.insert(OpcodeInstr::mksimple(0xf806, 16, "GASCONSUMED", exec_gas_consumed)->require_version(4))
.insert(OpcodeInstr::mksimple(0xf80f, 16, "COMMIT", exec_commit));
}
@ -620,7 +620,6 @@ int exec_ristretto255_from_hash(VmState* st) {
if (!x2->export_bytes(xb + 32, 32, false)) {
throw VmError{Excno::range_chk, "x2 must fit in an unsigned 256-bit integer"};
}
CHECK(sodium_init() >= 0);
crypto_core_ristretto255_from_hash(rb, xb);
td::RefInt256 r{true};
CHECK(r.write().import_bytes(rb, 32, false));
@ -633,8 +632,7 @@ int exec_ristretto255_validate(VmState* st, bool quiet) {
Stack& stack = st->get_stack();
auto x = stack.pop_int();
st->consume_gas(VmState::rist255_validate_gas_price);
unsigned char xb[64];
CHECK(sodium_init() >= 0);
unsigned char xb[32];
if (!x->export_bytes(xb, 32, false) || !crypto_core_ristretto255_is_valid_point(xb)) {
if (quiet) {
stack.push_bool(false);
@ -656,7 +654,6 @@ int exec_ristretto255_add(VmState* st, bool quiet) {
auto x = stack.pop_int();
st->consume_gas(VmState::rist255_add_gas_price);
unsigned char xb[32], yb[32], rb[32];
CHECK(sodium_init() >= 0);
if (!x->export_bytes(xb, 32, false) || !y->export_bytes(yb, 32, false) || crypto_core_ristretto255_add(rb, xb, yb)) {
if (quiet) {
stack.push_bool(false);
@ -681,7 +678,6 @@ int exec_ristretto255_sub(VmState* st, bool quiet) {
auto x = stack.pop_int();
st->consume_gas(VmState::rist255_add_gas_price);
unsigned char xb[32], yb[32], rb[32];
CHECK(sodium_init() >= 0);
if (!x->export_bytes(xb, 32, false) || !y->export_bytes(yb, 32, false) || crypto_core_ristretto255_sub(rb, xb, yb)) {
if (quiet) {
stack.push_bool(false);
@ -719,17 +715,20 @@ int exec_ristretto255_mul(VmState* st, bool quiet) {
auto n = stack.pop_int() % get_ristretto256_l();
auto x = stack.pop_int();
st->consume_gas(VmState::rist255_mul_gas_price);
unsigned char xb[32], nb[32], rb[32];
memset(rb, 255, sizeof(rb));
CHECK(sodium_init() >= 0);
if (!x->export_bytes(xb, 32, false) || !export_bytes_little(n, nb) || crypto_scalarmult_ristretto255(rb, nb, xb)) {
if (std::all_of(rb, rb + 32, [](unsigned char c) { return c == 255; })) {
if (quiet) {
stack.push_bool(false);
return 0;
}
throw VmError{Excno::range_chk, "invalid x or n"};
if (n->sgn() == 0) {
stack.push_smallint(0);
if (quiet) {
stack.push_bool(true);
}
return 0;
}
unsigned char xb[32], nb[32], rb[32];
if (!x->export_bytes(xb, 32, false) || !export_bytes_little(n, nb) || crypto_scalarmult_ristretto255(rb, nb, xb)) {
if (quiet) {
stack.push_bool(false);
return 0;
}
throw VmError{Excno::range_chk, "invalid x or n"};
}
td::RefInt256 r{true};
CHECK(r.write().import_bytes(rb, 32, false));
@ -747,7 +746,6 @@ int exec_ristretto255_mul_base(VmState* st, bool quiet) {
st->consume_gas(VmState::rist255_mulbase_gas_price);
unsigned char nb[32], rb[32];
memset(rb, 255, sizeof(rb));
CHECK(sodium_init() >= 0);
if (!export_bytes_little(n, nb) || crypto_scalarmult_ristretto255_base(rb, nb)) {
if (std::all_of(rb, rb + 32, [](unsigned char c) { return c == 255; })) {
if (quiet) {
@ -833,7 +831,7 @@ int exec_bls_verify(VmState* st) {
VM_LOG(st) << "execute BLS_VERIFY";
Stack& stack = st->get_stack();
stack.check_underflow(3);
st->consume_gas(st->bls_verify_gas_price);
st->consume_gas(VmState::bls_verify_gas_price);
bls::P2 sig = slice_to_bls_p2(*stack.pop_cellslice());
td::BufferSlice msg = slice_to_bls_msg(*stack.pop_cellslice());
bls::P1 pub = slice_to_bls_p1(*stack.pop_cellslice());
@ -845,8 +843,7 @@ int exec_bls_aggregate(VmState* st) {
VM_LOG(st) << "execute BLS_AGGREGATE";
Stack& stack = st->get_stack();
int n = stack.pop_smallint_range(stack.depth() - 1, 1);
st->consume_gas(
std::max(0LL, VmState::bls_aggregate_base_gas_price + (long long)n * VmState::bls_aggregate_element_gas_price));
st->consume_gas(VmState::bls_aggregate_base_gas_price + (long long)n * VmState::bls_aggregate_element_gas_price);
std::vector<bls::P2> sigs(n);
for (int i = n - 1; i >= 0; --i) {
sigs[i] = slice_to_bls_p2(*stack.pop_cellslice());

View file

@ -21,6 +21,8 @@
#include "vm/dict.h"
#include "vm/log.h"
#include "vm/vm.h"
#include "cp0.h"
#include <sodium.h>
namespace vm {
@ -770,4 +772,15 @@ void VmState::restore_parent_vm(int res) {
}
}
td::Status init_vm(bool enable_debug) {
if (!init_op_cp0(enable_debug)) {
return td::Status::Error("Failed to init TVM: failed to init cp0");
}
auto code = sodium_init();
if (code < 0) {
return td::Status::Error(PSTRING() << "Failed to init TVM: sodium_init, code=" << code);
}
return td::Status::OK();
}
} // namespace vm

View file

@ -423,4 +423,6 @@ int run_vm_code(Ref<CellSlice> _code, Stack& _stack, int flags = 0, Ref<Cell>* d
Ref<vm::Cell> lookup_library_in(td::ConstBitPtr key, Ref<vm::Cell> lib_root);
td::Status init_vm(bool enable_debug = false);
} // namespace vm

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
option(BUILD_SHARED_LIBS "Use \"OFF\" for a static build." ON)

View file

@ -139,7 +139,7 @@ const char *transaction_emulator_emulate_transaction(void *transaction_emulator,
now = (unsigned)std::time(nullptr);
}
bool is_special = wc == ton::masterchainId && emulator->get_config().is_special_smartcontract(addr);
if (!account.unpack(vm::load_cell_slice_ref(shard_account_cell.move_as_ok()), td::Ref<vm::CellSlice>(), now, is_special)) {
if (!account.unpack(vm::load_cell_slice_ref(shard_account_cell.move_as_ok()), now, is_special)) {
ERROR_RESPONSE(PSTRING() << "Can't unpack shard account");
}
@ -217,7 +217,7 @@ const char *transaction_emulator_emulate_tick_tock_transaction(void *transaction
now = (unsigned)std::time(nullptr);
}
bool is_special = wc == ton::masterchainId && emulator->get_config().is_special_smartcontract(addr);
if (!account.unpack(vm::load_cell_slice_ref(shard_account_cell.move_as_ok()), td::Ref<vm::CellSlice>(), now, is_special)) {
if (!account.unpack(vm::load_cell_slice_ref(shard_account_cell.move_as_ok()), now, is_special)) {
ERROR_RESPONSE(PSTRING() << "Can't unpack shard account");
}

View file

@ -1,7 +1,7 @@
#include <string>
#include "transaction-emulator.h"
#include "crypto/common/refcnt.hpp"
#include "vm/cp0.h"
#include "vm/vm.h"
#include "tdutils/td/utils/Time.h"
using td::Ref;
@ -34,7 +34,7 @@ td::Result<std::unique_ptr<TransactionEmulator::EmulationResult>> TransactionEmu
return fetch_res.move_as_error_prefix("cannot fetch config params ");
}
vm::init_op_cp0(debug_enabled_);
TRY_STATUS(vm::init_vm(debug_enabled_));
if (!lt) {
lt = lt_;

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)

View file

@ -99,7 +99,7 @@ td::uint32 FecType::symbol_size() const {
}
td::Result<FecType> FecType::create(tl_object_ptr<ton_api::fec_Type> obj) {
td::int32 data_size_int, symbol_size_int, symbols_count_int;
td::int32 data_size_int = 0, symbol_size_int = 0, symbols_count_int = 0;
ton_api::downcast_call(*obj, td::overloaded([&](const auto &obj) {
data_size_int = obj.data_size_;
symbol_size_int = obj.symbol_size_;

6
flake.lock generated
View file

@ -36,8 +36,8 @@
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1682600000,
"narHash": "sha256-ha4BehR1dh8EnXSoE1m/wyyYVvHI9txjW4w5/oxsW5Y=",
"lastModified": 1698846319,
"narHash": "sha256-4jyW/dqFBVpWFnhl0nvP6EN4lP7/ZqPxYRjl6var0Oc=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "50fc86b75d2744e1ab3837ef74b53f103a9b55a0",
@ -45,7 +45,7 @@
},
"original": {
"owner": "nixos",
"ref": "nixos-22.05",
"ref": "nixos-23.05",
"repo": "nixpkgs",
"type": "github"
}

View file

@ -1,6 +1,6 @@
{
inputs = {
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-22.05";
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.05";
nixpkgs-trunk.url = "github:nixos/nixpkgs";
flake-compat = {
url = "github:edolstra/flake-compat";
@ -28,14 +28,14 @@
# then we can skip these manual overrides
# and switch between pkgsStatic and pkgsStatic.pkgsMusl for static glibc and musl builds
if !staticExternalDeps then [
openssl_1_1
openssl
zlib
libmicrohttpd
libsodium
secp256k1
] else
[
(openssl_1_1.override { static = true; }).dev
(openssl.override { static = true; }).dev
(zlib.override { shared = false; }).dev
]
++ optionals (!stdenv.isDarwin) [ pkgsStatic.libmicrohttpd.dev pkgsStatic.libsodium.dev secp256k1 ]
@ -50,6 +50,8 @@
] ++ optionals (staticGlibc || staticMusl) [
"-DCMAKE_LINK_SEARCH_START_STATIC=ON"
"-DCMAKE_LINK_SEARCH_END_STATIC=ON"
] ++ optionals (stdenv.isDarwin) [
"-DCMAKE_CXX_FLAGS=-stdlib=libc++" "-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=11.7"
];
LDFLAGS = optional staticExternalDeps (concatStringsSep " " [

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(HTTP_SOURCE
http.h

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(KEYRING_SOURCE
keyring.h

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(KEYS_SOURCE
keys.cpp

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
add_library(lite-client-common lite-client-common.cpp lite-client-common.h)
target_link_libraries(lite-client-common PUBLIC tdutils tdactor adnllite tl_api tl_lite_api tl-lite-utils ton_crypto ton_block)

View file

@ -4307,7 +4307,7 @@ int main(int argc, char* argv[]) {
});
#endif
vm::init_op_cp0(true); // enable vm debug
vm::init_vm(true).ensure(); // enable vm debug
td::actor::Scheduler scheduler({2});

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(MEMPROF_SOURCE
memprof/memprof.cpp

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
add_executable(rldp-http-proxy rldp-http-proxy.cpp DNSResolver.h DNSResolver.cpp)
target_include_directories(rldp-http-proxy PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
add_executable(embed-provider-code smartcont/embed-provider-code.cpp)

View file

@ -400,7 +400,6 @@ class NetChannel : public td::actor::Actor {
break;
} else if (l > alive_end - eps) {
alive_begin += alive_step + sleep_step;
alive_end = alive_begin + alive_step;
} else {
double new_l = td::min(alive_end, r);
res += (new_l - l) * speed;
@ -516,9 +515,7 @@ class NetChannel : public td::actor::Actor {
queue_ = {};
}
bool ok = false;
while (!queue_.empty() && (double)queue_.front().size < got_) {
ok = true;
auto query = queue_.pop();
got_ -= (double)query.size;
total_size_ -= (double)query.size;

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
#SOURCE SETS
set(TDACTOR_SOURCE

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(BENCHMARK_SOURCE
benchmark.cpp

View file

@ -720,7 +720,7 @@ TEST(Actor2, actor_function_result) {
}
TEST(Actor2, actor_ping_pong) {
Scheduler scheduler{{3}, Scheduler::Paused};
Scheduler scheduler{{3}, false, Scheduler::Paused};
sb.clear();
scheduler.start();
@ -799,7 +799,7 @@ TEST(Actor2, Schedulers) {
for (auto run_count : {0, 1, 2}) {
for (auto stop_count : {0, 1, 2}) {
for (size_t threads : {0, 1}) {
Scheduler scheduler({threads}, mode);
Scheduler scheduler({threads}, false, mode);
for (int i = 0; i < start_count; i++) {
scheduler.start();
}

View file

@ -210,7 +210,7 @@ TEST(Actor, promise_future) {
TEST(Actor2, actor_lost_promise) {
using namespace td::actor;
using namespace td;
Scheduler scheduler({1}, Scheduler::Paused);
Scheduler scheduler({1}, false, Scheduler::Paused);
auto watcher = td::create_shared_destructor([] {
LOG(ERROR) << "STOP";

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
#SOURCE SETS
set(TDDB_UTILS_SOURCE

View file

@ -311,6 +311,7 @@ td::Result<BlobView> FileMemoryMappingBlobView::create(td::CSlice file_path, td:
class CyclicBlobViewImpl : public BlobViewImpl {
public:
CyclicBlobViewImpl(td::BufferSlice data, td::uint64 total_size) : data_(std::move(data)), total_size_(total_size) {
CHECK(!data_.empty());
}
td::Result<td::Slice> view_impl(td::MutableSlice slice, td::uint64 offset) override {
auto res = slice;

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(TDFEC_SOURCE
td/fec/raptorq/Rfc.cpp

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
add_executable(benchmark-fec benchmark.cpp )
target_include_directories(benchmark-fec PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)

View file

@ -61,7 +61,7 @@ class Rfc {
template <class F>
void encoding_row_for_each(EncodingRow t, F &&f) const {
f(t.b);
for (uint16 j = 1; j < t.d; ++j) {
for (uint32 j = 1; j < t.d; ++j) {
t.b = (t.b + t.a) % W;
f(t.b);
}

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(TDNET_SOURCE
td/net/FdListener.cpp

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
#SOURCE SETS
set(TDTL_SOURCE

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
option(TDUTILS_MIME_TYPE "Generate mime types conversion (gperf is required)" ON)
@ -314,7 +314,7 @@ if (WIN32)
# find_library(WS2_32_LIBRARY ws2_32)
# find_library(MSWSOCK_LIBRARY Mswsock)
# target_link_libraries(tdutils PRIVATE ${WS2_32_LIBRARY} ${MSWSOCK_LIBRARY})
target_link_libraries(tdutils PRIVATE ws2_32 Mswsock Normaliz psapi)
target_link_libraries(tdutils PRIVATE ws2_32 Mswsock Normaliz psapi DbgHelp)
endif()
if (NOT CMAKE_CROSSCOMPILING AND TDUTILS_MIME_TYPE)
add_dependencies(tdutils tdmime_auto)

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
# Generates files for MIME type <-> extension conversions
# DEPENDS ON: gperf grep bash/powershell

View file

@ -159,7 +159,11 @@ bool BigNum::is_bit_set(int num) const {
}
bool BigNum::is_prime(BigNumContext &context) const {
#if OPENSSL_VERSION_MAJOR >= 3
int result = BN_check_prime(impl_->big_num, context.impl_->big_num_context, nullptr);
#else
int result = BN_is_prime_ex(impl_->big_num, BN_prime_checks, context.impl_->big_num_context, nullptr);
#endif
LOG_IF(FATAL, result == -1);
return result == 1;
}

View file

@ -106,6 +106,7 @@ class UdpReader {
}
if (status.is_error() && !UdpSocketFd::is_critical_read_error(status)) {
queue.push(UdpMessage{{}, {}, std::move(status)});
return td::Status::OK();
}
return status;
}

View file

@ -25,7 +25,6 @@
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/port/RwMutex.h"
#include "td/utils/port/thread_local.h"
#include "td/utils/Random.h"
#include "td/utils/ScopeGuard.h"
#include "td/utils/SharedSlice.h"
@ -598,16 +597,23 @@ void aes_ige_decrypt(Slice aes_key, MutableSlice aes_iv, Slice from, MutableSlic
static void aes_cbc_xcrypt(Slice aes_key, MutableSlice aes_iv, Slice from, MutableSlice to, bool encrypt_flag) {
CHECK(aes_key.size() == 32);
CHECK(aes_iv.size() == 16);
AES_KEY key;
int err;
if (encrypt_flag) {
err = AES_set_encrypt_key(aes_key.ubegin(), 256, &key);
} else {
err = AES_set_decrypt_key(aes_key.ubegin(), 256, &key);
}
LOG_IF(FATAL, err != 0);
CHECK(from.size() <= to.size());
AES_cbc_encrypt(from.ubegin(), to.ubegin(), from.size(), &key, aes_iv.ubegin(), encrypt_flag);
CHECK(from.size() % 16 == 0);
int out_len = 0;
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
CHECK(ctx);
if (encrypt_flag) {
CHECK(EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, aes_key.ubegin(), aes_iv.ubegin()) == 1);
CHECK(EVP_CIPHER_CTX_set_padding(ctx, 0) == 1);
CHECK(EVP_EncryptUpdate(ctx, to.ubegin(), &out_len, from.ubegin(), td::narrow_cast<int>(from.size())) == 1);
CHECK(EVP_EncryptFinal_ex(ctx, to.ubegin() + out_len, &out_len) == 1);
} else {
CHECK(EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, aes_key.ubegin(), aes_iv.ubegin()) == 1);
CHECK(EVP_CIPHER_CTX_set_padding(ctx, 0) == 1);
CHECK(EVP_DecryptUpdate(ctx, to.ubegin(), &out_len, from.ubegin(), td::narrow_cast<int>(from.size())) == 1);
CHECK(EVP_DecryptFinal_ex(ctx, to.ubegin() + out_len, &out_len) == 1);
}
EVP_CIPHER_CTX_free(ctx);
}
void aes_cbc_encrypt(Slice aes_key, MutableSlice aes_iv, Slice from, MutableSlice to) {
@ -723,7 +729,18 @@ string sha512(Slice data) {
class Sha256State::Impl {
public:
SHA256_CTX ctx_;
EVP_MD_CTX *ctx_ = nullptr;
Impl() {
ctx_ = EVP_MD_CTX_new();
CHECK(ctx_);
}
~Impl() {
if (ctx_) {
EVP_MD_CTX_free(ctx_);
}
}
};
Sha256State::Sha256State() = default;
@ -755,24 +772,23 @@ void Sha256State::init() {
impl_ = make_unique<Sha256State::Impl>();
}
CHECK(!is_inited_);
int err = SHA256_Init(&impl_->ctx_);
LOG_IF(FATAL, err != 1);
CHECK(EVP_DigestInit_ex(impl_->ctx_, EVP_sha256(), nullptr) == 1);
is_inited_ = true;
}
void Sha256State::feed(Slice data) {
CHECK(impl_);
CHECK(is_inited_);
int err = SHA256_Update(&impl_->ctx_, data.ubegin(), data.size());
LOG_IF(FATAL, err != 1);
CHECK(EVP_DigestUpdate(impl_->ctx_, data.ubegin(), data.size()) == 1);
}
void Sha256State::extract(MutableSlice output, bool destroy) {
CHECK(output.size() >= 32);
CHECK(impl_);
CHECK(is_inited_);
int err = SHA256_Final(output.ubegin(), &impl_->ctx_);
LOG_IF(FATAL, err != 1);
unsigned size;
CHECK(EVP_DigestFinal_ex(impl_->ctx_, output.ubegin(), &size) == 1);
CHECK(size == 32);
is_inited_ = false;
if (destroy) {
impl_.reset();

View file

@ -151,7 +151,7 @@ class Sha256State {
bool is_inited_ = false;
};
void md5(Slice input, MutableSlice output);
[[deprecated("MD5 is not cryptographically secure")]] void md5(Slice input, MutableSlice output);
void pbkdf2_sha256(Slice password, Slice salt, int iteration_count, MutableSlice dest);
void pbkdf2_sha512(Slice password, Slice salt, int iteration_count, MutableSlice dest);

View file

@ -20,9 +20,13 @@
#include "td/utils/port/signals.h"
#if __GLIBC__
#if TD_WINDOWS
#include <DbgHelp.h>
#else
#if TD_DARWIN || __GLIBC__
#include <execinfo.h>
#endif
#endif
#if TD_LINUX || TD_FREEBSD
#include <sys/types.h>
@ -39,13 +43,48 @@ namespace td {
namespace {
void print_backtrace(void) {
#if __GLIBC__
#if TD_WINDOWS
void *stack[100];
HANDLE process = GetCurrentProcess();
SymInitialize(process, nullptr, 1);
unsigned frames = CaptureStackBackTrace(0, 100, stack, nullptr);
signal_safe_write("------- Stack Backtrace -------\n", false);
for (unsigned i = 0; i < frames; i++) {
td::uint8 symbol_buf[sizeof(SYMBOL_INFO) + 256];
auto symbol = (SYMBOL_INFO *)symbol_buf;
memset(symbol_buf, 0, sizeof(symbol_buf));
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
SymFromAddr(process, (DWORD64)(stack[i]), nullptr, symbol);
// Don't use sprintf here because it is not signal-safe
char buf[256 + 32];
char* buf_ptr = buf;
if (frames - i - 1 < 10) {
strcpy(buf_ptr, " ");
buf_ptr += strlen(buf_ptr);
}
_itoa(frames - i - 1, buf_ptr, 10);
buf_ptr += strlen(buf_ptr);
strcpy(buf_ptr, ": [");
buf_ptr += strlen(buf_ptr);
_ui64toa(td::uint64(symbol->Address), buf_ptr, 16);
buf_ptr += strlen(buf_ptr);
strcpy(buf_ptr, "] ");
buf_ptr += strlen(buf_ptr);
strcpy(buf_ptr, symbol->Name);
buf_ptr += strlen(buf_ptr);
strcpy(buf_ptr, "\n");
signal_safe_write(td::Slice{buf, strlen(buf)}, false);
}
#else
#if TD_DARWIN || __GLIBC__
void *buffer[128];
int nptrs = backtrace(buffer, 128);
signal_safe_write("------- Stack Backtrace -------\n", false);
backtrace_symbols_fd(buffer, nptrs, 2);
signal_safe_write("-------------------------------\n", false);
#endif
#endif
}
void print_backtrace_gdb(void) {
@ -129,7 +168,7 @@ void Stacktrace::print_to_stderr(const PrintOptions &options) {
}
void Stacktrace::init() {
#if __GLIBC__
#if TD_DARWIN || __GLIBC__
// backtrace needs to be called once to ensure that next calls are async-signal-safe
void *buffer[1];
backtrace(buffer, 1);

View file

@ -75,9 +75,9 @@ void test_waiter_stress_one_one() {
TEST(MpmcEagerWaiter, stress_one_one) {
test_waiter_stress_one_one<td::MpmcEagerWaiter>();
}
TEST(MpmcSleepyWaiter, stress_one_one) {
test_waiter_stress_one_one<td::MpmcSleepyWaiter>();
}
// TEST(MpmcSleepyWaiter, stress_one_one) {
// test_waiter_stress_one_one<td::MpmcSleepyWaiter>();
// }
template <class W>
void test_waiter_stress() {

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)

File diff suppressed because it is too large Load diff

View file

@ -13,7 +13,7 @@ Test_Fift_test_bls_ops_default fb0a81d4f247ab806318b051d12158f7f1aacc5513db5f8cb
Test_Fift_test_deep_stack_ops_default df812efbadfffa8a3f553416f68c8c4435bac07266f84562cf98fe5f0dd62a52
Test_Fift_test_default 4e44b3382963ec89f7b5c8f2ebd85da3bc8aebad5b49f5b11b14075061477b4d
Test_Fift_test_dict_default a9c8cbcfdece5573185022cea07f59f1bc404e5d879e5157a5745757f8ee0525
Test_Fift_test_disasm_default dacaa555f5f217b2373e01e3bcd59634e480f5759dcc43edbdef35273ae38492
Test_Fift_test_disasm_default 412cf37d37c5d9d81f44dbf4e3d3e7cda173c23b890614eb8a3bc5f2b92f13e6
Test_Fift_test_fiftext_default 2b0db5d4d4bfbc705b959cc787540d7b3a21a71469eac54756e76953f0d9afca
Test_Fift_test_fixed_default 278a19d56b773102caf5c1fe2997ea6c8d0d9e720eff8503feede6398a197eec
Test_Fift_test_hash_ext_default 686fc5680feca5b3bb207768215b27f6872a95128762dee0d7f2c88bc492d62d
@ -37,40 +37,40 @@ Test_Fift_testvm8_default 17c9e2205ccecfd8549328b4a501d07dde0336899a7a496e747e10
Test_Fift_testvm_default ee4cbfec76c050b6de7877cfc39817d594cd1e175b6265b76fb642e30b940437
Test_Fift_testvmprog_default e5d0b2c68ee568280877c8495be558bfd0054ca5d99a99eebb525bbeca8a65af
Test_RefInt_main_default 768493e0aef8e09a401a6d369edd1ef503a9215fb09dc460f52b27a8bde767cb
Test_VM_assert_code_not_null_default 05bc07e129181c972b976442f200de9487dee8bfb5ac53dd36ff61c5d4d4291d
Test_VM_assert_extract_minmax_key_default c352309c61bdf62ba7a0ba7280d303c88b0696fe7efa550c05feb2c662275297
Test_VM_assert_lookup_prefix_default c5b45999b46d324e4008c07e5ce671bbcd833f4e15fb21a4a5136f7b980ca6fc
Test_VM_assert_pfx_dict_lookup_default fa6e3f96b31cf2ed9a9dac6b279ec05acfedf13b8ed7b815789f167d1ed7352f
Test_VM_assert_code_not_null_default 09f75cb845e0df27f3ec92405ccb4018484711a79813fd47fe8e158762c1cb93
Test_VM_assert_extract_minmax_key_default 756337c2b2ce489243956a6608d6934ba9f76124a9435f045fc3a3b65c113d41
Test_VM_assert_lookup_prefix_default f7683f9d2010bca53b1ef20c0e82427fb04ed62fa5fea1ee986f005ecfc9a27a
Test_VM_assert_pfx_dict_lookup_default 6d7c80d94dbc6d3ae4bafa216667b95ede4f2cbd44a59384abace84270417ef8
Test_VM_bigint_default feeb473a4ac51133989e1c145d0f49defa77117d2ae8b66bd7d12e3579e91b9f
Test_VM_bug_div_short_any_default f69aca6873f75d53dd37b6952151a2d858407a04589330762827dbc96d8b7c04
Test_VM_bug_exec_dict_getnear_default db314c2e25b49c1f7f044d271e225f36da546c66242a8ab12f6afae37628a81e
Test_VM_bug_stack_overflow_default 7e0e3e96ca438ac96648d569c55213aa82154cf004e80265b1c481b1c4219719
Test_VM_infinity_loop_1_default 670beda76229922806805e558d50d8f320017c642c3e7e34a7e1f2b7edb83cee
Test_VM_infinity_loop_2_default 22d9bd8cb41ff7b6cced5825e4ab73275b2fc07b1e3cd4588de815e2e6df2963
Test_VM_memory_leak_default e10dc118f3538720a16bcbd39be9a68c3ea07f76b3d2ed5719a5e866d91f0ab3
Test_VM_memory_leak_new_default fd2eec0a1d5ae49fb5ff8ba4b938fd9d0fe330be4a07b2b8be12bab249b00d90
Test_VM_memory_leak_old_default f3076ae38d14000c021597b824d2f0e51de4f00601429ec3e23cca1b32dba844
Test_VM_oom_1_default 90862ddf3270840fbc9263c003c628ddd4a8bf6548b9bd3d53eb35a5c34bc325
Test_VM_report3_1_default 7bc6a8e66f9a0e40cd131e9829ff36fed16b464170d27c0b365a3f549df57282
Test_VM_report3_2_default 2231bc352cf431e72a84abad2261969bd5b0ee3d9051bb7a53b69fd8ea05f951
Test_VM_report3_3_default 9416187eb0600ed247795837ca820bccaffb39841bd9d2ff625816bfbba35d6d
Test_VM_report3_4_default 11661eb00ea37c68e3483a8e048f922f73070c6da8219247663e3d6471c5c0cc
Test_VM_report3_6_default 1d7be98a8b07f803e80168247459e620ce4b91df634ad896e878d21a3ed757c0
Test_VM_report3_int_overflow_1_default a0c2414ca2c9672d54409ee375a6aad6e2233306eaa3dfd33a82de3c90bba3ba
Test_VM_report3_int_overflow_2_default 01cd461802e532a6830705ad50eaa1760278737ff7beeb654e3c59ceb4aa8e2e
Test_VM_report3_loop_1_default b28b35d057a1b4fa2282d6f422ecd822b18cc4344733d923ef7b002f64bc4d72
Test_VM_report3_loop_2_default 9f8236535902b04e403d412fcf1f79e64d0f2eb25b3cc014b7d61b2d7a34b9ef
Test_VM_report3_loop_3_default 7ee05ea553c48a2476035817b9d860f614a355927c9e011b2f824dc6e5f7b0cf
Test_VM_report3_loop_4_default 4b6c2f65fda3c9e9c6660b6cbbcb1b2103c5b52870cb5daa8876bbed0ca9bbc9
Test_VM_report3_loop_5_default 0d5d504884172ef8513757d7f6b2a3870dbd28efd5960857441c032e1c67d836
Test_VM_report3_loop_6_default 5c35b92144debdb61b2020d690669bffbdd96f75ecde827fd0c75c05da22b5a0
Test_VM_report3_qnot_default dc280444c7e3886cc3412f96f44c803c45287a07fcb9c638643e21bcdfe3905d
Test_VM_simple_default f6733549069427c2beb1a85ee25635540e27aa68cb8ad101d8435e19afeae862
Test_VM_unhandled_exception_1_default 0abe2740dd3b6a6b91eb67fee573f638086fecc72653d2d81c956782186b5d78
Test_VM_unhandled_exception_2_default 5ca67db5a0e957cc106bb47b744177ca959632a352f3629df376c34cbf03d51b
Test_VM_unhandled_exception_3_default b354e897e35a1177fd66d2c6ad7d77ae33a4e18f8678a518d79fea1388853307
Test_VM_unhandled_exception_4_default 412cbfe13745fde55cdcc5e41d7b15ba4d09f0e723f8e4421ae0b7066ca07b8f
Test_VM_unhandled_exception_5_default d760e540cd9c200c207f71c540cdaf06d11c96e32ec19860b9c1046cb1e38855
Test_VM_bug_div_short_any_default 49c9588b2b25b08979016f8b7ca42ae9fa4904a1dc6a2093a7dae6dce0cdf42f
Test_VM_bug_exec_dict_getnear_default 0b0cb6c1fef773f8b5a4aab8d575ba941f3b85dd449f85051296954028e59781
Test_VM_bug_stack_overflow_default 31950eb2ed62bd1ce1c18e0031a81390ff3a3feee61ff23a09181995917137d0
Test_VM_infinity_loop_1_default 6b8cc0ff85efa6882ffdf6e9e4333967976a29c4ce32a25b42c4c53370ad3024
Test_VM_infinity_loop_2_default 4be08957dc86dfde3dfadd8c2f961ef2f1fa839788bbf7affea754115cee9e18
Test_VM_memory_leak_default da588f89f3bc3ef7496bbab61e2d993f0c84bba80bb28d9c20c6eac0f7f57dd3
Test_VM_memory_leak_new_default d25e8602c88c454ded6271d0f7afbc556820cc9942c56de9e0bd95b329f8783e
Test_VM_memory_leak_old_default 563f5a02130f231823099985c77d09913db07d2d8782edf431822f6afe4911b8
Test_VM_oom_1_default 354934173c82e4f7bca5063846abd35cb47c4fcf1c3ba8c2fd04a4b186fcbf18
Test_VM_report3_1_default 26bb43b5100e94791911a66226ec6545422749e0ea9e6279983b00ef4b506601
Test_VM_report3_2_default 07a84726217f362fd71b3ceab96112ffc7aa40ed44636cf0128205d85798c66c
Test_VM_report3_3_default 0d9a92491c88ada92283691debd123724db2b7c1bd345200a53c057032e9cc07
Test_VM_report3_4_default eb23c8e1219aed91b1b4f519efcac87018a5cf8e0ce473cfa641f8221f3c5d20
Test_VM_report3_6_default 769ce8f9bb6fb9b8619afdb8e9d621b6199466f07c37eeea8edf3c21bf05a101
Test_VM_report3_int_overflow_1_default 7aaf32ec7ace54b93d6b55f3ac9642572f348ebd64412afdda24849f8e4eb1dc
Test_VM_report3_int_overflow_2_default 572d197681654c94951280448ea3cf448613391633383c2424d719b03b6ec939
Test_VM_report3_loop_1_default c9b00b32a024c65e0a8019c86e94ee365a823ff26e2420e1797902841abab57c
Test_VM_report3_loop_2_default 3654949987ddb44d8e11e84fe907d43707eaed910b9d0ad15dd68b531df1444a
Test_VM_report3_loop_3_default c1fc7e0d160b334fe8a4735a2a9d36c3b10530edaad5c1859df88382ff82a2d9
Test_VM_report3_loop_4_default 5ad7cc51a6e553ee3d4a427229908a51692e117624838190311c7023df7a5e5b
Test_VM_report3_loop_5_default 068f81caecc344132a601259d9f73eea7089b1399793661ba1954483e0d5682c
Test_VM_report3_loop_6_default bf2e45709fceeed0192ec34af618cba3b85b90f71071e018afba686167618a90
Test_VM_report3_qnot_default 7fcbda7e3fc4853a36e6b02e9d346f039690b1879d40850f561ea4123452d3ec
Test_VM_simple_default c96d70ea853828c89cd38fcf22543289335f3086a53301a1d0f186753ba9975b
Test_VM_unhandled_exception_1_default 80fe0e4c2ae19ae73e67e4355548d0afa59ea286be2d75a91db4529618dba008
Test_VM_unhandled_exception_2_default 1362ba3a6ddbf5a30aba07ad58e8c24b0f85bdc53525e3eaa27af7248c62525a
Test_VM_unhandled_exception_3_default e381ce751cbd0e2994d7f60df7746b9ed7783198cfbcb31dccf02fafe68b6733
Test_VM_unhandled_exception_4_default 51dd501ec0514f3b388145761b252f09d6ef3e831ea450605ae30511688dd708
Test_VM_unhandled_exception_5_default 8231cfe1fb6ce6107b592f2c8f6a4eae0d123fc399163c81e8e0d5228b68bc91
Test_base64_main_default e90d541bd810871c4a81e162f1fffb555024b72807cb895414d16bc11494b789
Test_bigexp_main_default 45a1f51fb2abcc1ebf8569e1a57bebee04c334a15e03535ff5869bc9a9db8956
Test_bits256_scan_main_default 3ec7434e1cabc8e08eb2e79064e67747ffbfed177473c7873b88c144a7ed6f42

View file

@ -52,7 +52,7 @@ int main() {
td::to_integer_safe<td::uint32>("0").ensure();
std::string db_root_ = "tmp-ee";
std::string db_root_ = "tmp-dir-test-adnl";
td::rmrf(db_root_).ignore();
td::mkdir(db_root_).ensure();

View file

@ -219,7 +219,7 @@ int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_INFO);
td::set_default_failure_signal_handler().ensure();
std::string db_root_ = "tmp-ee";
std::string db_root_ = "tmp-dir-test-catchain";
td::rmrf(db_root_).ignore();
td::mkdir(db_root_).ensure();
@ -274,8 +274,6 @@ int main(int argc, char *argv[]) {
}
});
auto t = td::Timestamp::in(1.0);
ton::catchain::CatChainSessionId unique_id;
td::Random::secure_bytes(unique_id.as_slice());
@ -287,7 +285,7 @@ int main(int argc, char *argv[]) {
}
});
t = td::Timestamp::in(10.0);
auto t = td::Timestamp::in(10.0);
while (scheduler.run(1)) {
if (t.is_in_past()) {
break;
@ -300,7 +298,7 @@ int main(int argc, char *argv[]) {
scheduler.run_in_context([&] { td::actor::send_closure(inst[0], &CatChainInst::create_fork); });
t = td::Timestamp::in(10.0);
t = td::Timestamp::in(1.0);
while (scheduler.run(1)) {
if (t.is_in_past()) {
break;

View file

@ -41,7 +41,7 @@
int main() {
SET_VERBOSITY_LEVEL(verbosity_INFO);
std::string db_root_ = "tmp-ee";
std::string db_root_ = "tmp-dir-test-dht";
td::rmrf(db_root_).ignore();
td::mkdir(db_root_).ensure();

View file

@ -1,220 +0,0 @@
/*
This file is part of TON Blockchain source code.
TON Blockchain is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
TON Blockchain is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
You must obey the GNU General Public License in all respects for all
of the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version. If you delete this exception statement
from all source files in the program, then also delete it here.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl/adnl.h"
#include "adnl/utils.hpp"
#include "auto/tl/ton_api_json.h"
#include "dht/dht.h"
#include "overlay/overlays.h"
#include "td/utils/OptionParser.h"
#include "td/utils/Time.h"
#include "td/utils/filesystem.h"
#include "td/utils/format.h"
#include "td/utils/Random.h"
#include "td/utils/port/signals.h"
#include "td/utils/port/FileFd.h"
#include "adnl/adnl-ext-client.h"
#if TD_DARWIN || TD_LINUX
#include <unistd.h>
#endif
#include <iostream>
#include <sstream>
template <std::size_t size>
std::ostream &operator<<(std::ostream &stream, const td::UInt<size> &x) {
for (size_t i = 0; i < size / 8; i++) {
stream << td::format::hex_digit((x.raw[i] >> 4) & 15) << td::format::hex_digit(x.raw[i] & 15);
}
return stream;
}
class TestNode : public td::actor::Actor {
private:
std::string local_config_ = "ton-local.config";
std::string global_config_ = "ton-global.config";
td::actor::ActorOwn<ton::adnl::AdnlExtClient> client_;
std::unique_ptr<ton::adnl::AdnlExtClient::Callback> make_callback() {
class Callback : public ton::adnl::AdnlExtClient::Callback {
public:
void on_ready() override {
td::actor::send_closure(id_, &TestNode::conn_ready);
}
void on_stop_ready() override {
td::actor::send_closure(id_, &TestNode::conn_closed);
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
bool ready_ = false;
std::string db_root_;
public:
void conn_ready() {
LOG(ERROR) << "conn ready";
ready_ = true;
}
void conn_closed() {
ready_ = false;
}
void set_local_config(std::string str) {
local_config_ = str;
}
void set_global_config(std::string str) {
global_config_ = str;
}
void set_db_root(std::string db_root) {
db_root_ = db_root;
}
void start_up() override {
}
void alarm() override {
if (ready_ && !client_.empty()) {
LOG(ERROR) << "sending query";
auto P = td::PromiseCreator::lambda([](td::Result<td::BufferSlice> R) {
if (R.is_error()) {
LOG(ERROR) << "failed query: " << R.move_as_error();
return;
}
auto F = ton::fetch_tl_object<ton::ton_api::Object>(R.move_as_ok(), true);
if (F.is_error()) {
LOG(ERROR) << "failed to pasrse answer: " << F.move_as_error();
return;
}
auto obj = F.move_as_ok();
LOG(ERROR) << "got answer: " << ton::ton_api::to_string(obj);
});
td::BufferSlice b = ton::serialize_tl_object(ton::create_tl_object<ton::ton_api::getTestObject>(), true);
td::actor::send_closure(client_, &ton::adnl::AdnlExtClient::send_query, "query", std::move(b),
td::Timestamp::in(10.0), std::move(P));
}
alarm_timestamp() = td::Timestamp::in(2.0);
}
TestNode() {
}
void run() {
auto L = td::read_file(local_config_).move_as_ok();
auto lc_j = td::json_decode(L.as_slice()).move_as_ok();
ton::ton_api::config_local lc;
ton::ton_api::from_json(lc, lc_j.get_object()).ensure();
auto G = td::read_file(global_config_).move_as_ok();
auto gc_j = td::json_decode(G.as_slice()).move_as_ok();
ton::ton_api::config_global gc;
ton::ton_api::from_json(gc, gc_j.get_object()).ensure();
CHECK(gc.liteclients_.size() > 0);
auto &cli = gc.liteclients_[0];
td::IPAddress addr;
addr.init_host_port(td::IPAddress::ipv4_to_str(cli->ip_), cli->port_).ensure();
client_ = ton::adnl::AdnlExtClient::create(ton::adnl::AdnlNodeIdFull::create(cli->id_).move_as_ok(), addr,
make_callback());
alarm_timestamp() = td::Timestamp::in(2.0);
}
};
td::Result<td::UInt256> get_uint256(std::string str) {
if (str.size() != 64) {
return td::Status::Error("uint256 must have 64 bytes");
}
td::UInt256 res;
for (size_t i = 0; i < 32; i++) {
res.raw[i] = static_cast<td::uint8>(td::hex_to_int(str[2 * i]) * 16 + td::hex_to_int(str[2 * i + 1]));
}
return res;
}
int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_DEBUG);
td::set_default_failure_signal_handler().ensure();
td::actor::ActorOwn<TestNode> x;
td::OptionParser p;
p.set_description("test basic adnl functionality");
p.add_option('h', "help", "prints_help", [&]() {
char b[10240];
td::StringBuilder sb(td::MutableSlice{b, 10000});
sb << p;
std::cout << sb.as_cslice().c_str();
std::exit(2);
return td::Status::OK();
});
p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_global_config, fname.str());
return td::Status::OK();
});
p.add_option('c', "local-config", "file to read local config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_local_config, fname.str());
return td::Status::OK();
});
p.add_option('D', "db", "root for dbs", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_db_root, fname.str());
return td::Status::OK();
});
p.add_option('d', "daemonize", "set SIGHUP", [&]() {
td::set_signal_handler(td::SignalType::HangUp, [](int sig) {
#if TD_DARWIN || TD_LINUX
close(0);
setsid();
#endif
}).ensure();
return td::Status::OK();
});
#if TD_DARWIN || TD_LINUX
p.add_option('l', "logname", "log to file", [&](td::Slice fname) {
auto FileLog = td::FileFd::open(td::CSlice(fname.str().c_str()),
td::FileFd::Flags::Create | td::FileFd::Flags::Append | td::FileFd::Flags::Write)
.move_as_ok();
dup2(FileLog.get_native_fd().fd(), 1);
dup2(FileLog.get_native_fd().fd(), 2);
return td::Status::OK();
});
#endif
td::actor::Scheduler scheduler({2});
scheduler.run_in_context([&] { x = td::actor::create_actor<TestNode>("testnode"); });
scheduler.run_in_context([&] { p.run(argc, argv).ensure(); });
scheduler.run_in_context([&] { td::actor::send_closure(x, &TestNode::run); });
scheduler.run();
return 0;
}

View file

@ -1,221 +0,0 @@
/*
This file is part of TON Blockchain source code.
TON Blockchain is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
TON Blockchain is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
You must obey the GNU General Public License in all respects for all
of the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version. If you delete this exception statement
from all source files in the program, then also delete it here.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl/adnl.h"
#include "adnl/utils.hpp"
#include "auto/tl/ton_api_json.h"
#include "dht/dht.h"
#include "overlay/overlays.h"
#include "td/utils/OptionParser.h"
#include "td/utils/Time.h"
#include "td/utils/filesystem.h"
#include "td/utils/format.h"
#include "td/utils/Random.h"
#include "td/utils/port/signals.h"
#include "td/utils/port/FileFd.h"
#if TD_DARWIN || TD_LINUX
#include <unistd.h>
#endif
#include <iostream>
#include <sstream>
template <std::size_t size>
std::ostream &operator<<(std::ostream &stream, const td::UInt<size> &x) {
for (size_t i = 0; i < size / 8; i++) {
stream << td::format::hex_digit((x.raw[i] >> 4) & 15) << td::format::hex_digit(x.raw[i] & 15);
}
return stream;
}
class TestNode : public td::actor::Actor {
private:
td::actor::ActorOwn<ton::keyring::Keyring> keyring_;
td::actor::ActorOwn<ton::adnl::Adnl> adnl_;
std::string local_config_ = "ton-local.config";
std::string global_config_ = "ton-global.config";
std::unique_ptr<ton::adnl::Adnl::Callback> make_callback() {
class Callback : public ton::adnl::Adnl::Callback {
public:
void receive_message(ton::adnl::AdnlNodeIdShort src, ton::adnl::AdnlNodeIdShort dst,
td::BufferSlice data) override {
td::actor::send_closure(id_, &TestNode::adnl_receive_message, src, dst, std::move(data));
}
void receive_query(ton::adnl::AdnlNodeIdShort src, ton::adnl::AdnlNodeIdShort dst, td::BufferSlice data,
td::Promise<td::BufferSlice> promise) override {
td::actor::send_closure(id_, &TestNode::adnl_receive_query, src, dst, std::move(data), std::move(promise));
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
std::string db_root_;
public:
void adnl_receive_message(ton::adnl::AdnlNodeIdShort src, ton::adnl::AdnlNodeIdShort dst, td::BufferSlice data) {
LOG(ERROR) << "ADNL MESSAGE FROM " << src << ": size=" << data.size() << "\n";
}
void adnl_receive_query(ton::adnl::AdnlNodeIdShort src, ton::adnl::AdnlNodeIdShort dst, td::BufferSlice data,
td::Promise<td::BufferSlice> promise) {
LOG(ERROR) << "ADNL QUERY FROM " << src << ": size=" << data.size() << "\n";
promise.set_value(ton::serialize_tl_object(ton::create_tl_object<ton::ton_api::testString>("xxx"), true));
}
void set_local_config(std::string str) {
local_config_ = str;
}
void set_global_config(std::string str) {
global_config_ = str;
}
void set_db_root(std::string db_root) {
db_root_ = db_root;
}
void start_up() override {
}
void alarm() override {
}
TestNode() {
}
void run() {
keyring_ = ton::keyring::Keyring::create(db_root_ + "/keyring/");
adnl_ = ton::adnl::Adnl::create(db_root_, keyring_.get());
auto L = td::read_file(local_config_).move_as_ok();
auto lc_j = td::json_decode(L.as_slice()).move_as_ok();
ton::ton_api::config_local lc;
ton::ton_api::from_json(lc, lc_j.get_object()).ensure();
auto G = td::read_file(global_config_).move_as_ok();
auto gc_j = td::json_decode(G.as_slice()).move_as_ok();
ton::ton_api::config_global gc;
ton::ton_api::from_json(gc, gc_j.get_object()).ensure();
for (auto &port : lc.udp_ports_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_listening_udp_port, "0.0.0.0",
static_cast<td::uint16>(port));
}
//td::actor::send_closure(network_manager_, &ton::adnl::AdnlNetworkManager::load_local_config, std::move(lc.net_));
//td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ids_from_config, std::move(lc.local_ids_));
if (gc.adnl_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_static_nodes_from_config,
std::move(gc.adnl_->static_nodes_));
}
for (auto &x : lc.liteservers_) {
auto pk = ton::PrivateKey{x->id_};
auto pub_k = ton::adnl::AdnlNodeIdFull{pk.compute_public_key()};
auto id = pub_k.compute_short_id();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key, std::move(pk), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, pub_k, ton::adnl::AdnlAddressList{});
td::actor::send_closure(adnl_, &ton::adnl::Adnl::subscribe, id,
ton::adnl::Adnl::int_to_bytestring(ton::ton_api::getTestObject::ID), make_callback());
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ext_local_id, id);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ext_tcp_port, static_cast<td::uint16>(x->port_));
}
}
};
td::Result<td::UInt256> get_uint256(std::string str) {
if (str.size() != 64) {
return td::Status::Error("uint256 must have 64 bytes");
}
td::UInt256 res;
for (size_t i = 0; i < 32; i++) {
res.raw[i] = static_cast<td::uint8>(td::hex_to_int(str[2 * i]) * 16 + td::hex_to_int(str[2 * i + 1]));
}
return res;
}
int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_DEBUG);
td::set_default_failure_signal_handler().ensure();
td::actor::ActorOwn<TestNode> x;
td::OptionParser p;
p.set_description("test basic adnl functionality");
p.add_option('h', "help", "prints_help", [&]() {
char b[10240];
td::StringBuilder sb(td::MutableSlice{b, 10000});
sb << p;
std::cout << sb.as_cslice().c_str();
std::exit(2);
return td::Status::OK();
});
p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_global_config, fname.str());
return td::Status::OK();
});
p.add_option('c', "local-config", "file to read local config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_local_config, fname.str());
return td::Status::OK();
});
p.add_option('D', "db", "root for dbs", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_db_root, fname.str());
return td::Status::OK();
});
p.add_option('d', "daemonize", "set SIGHUP", [&]() {
td::set_signal_handler(td::SignalType::HangUp, [](int sig) {
#if TD_DARWIN || TD_LINUX
close(0);
setsid();
#endif
}).ensure();
return td::Status::OK();
});
#if TD_DARWIN || TD_LINUX
p.add_option('l', "logname", "log to file", [&](td::Slice fname) {
auto FileLog = td::FileFd::open(td::CSlice(fname.str().c_str()),
td::FileFd::Flags::Create | td::FileFd::Flags::Append | td::FileFd::Flags::Write)
.move_as_ok();
dup2(FileLog.get_native_fd().fd(), 1);
dup2(FileLog.get_native_fd().fd(), 2);
return td::Status::OK();
});
#endif
td::actor::Scheduler scheduler({2});
scheduler.run_in_context([&] { x = td::actor::create_actor<TestNode>("testnode"); });
scheduler.run_in_context([&] { p.run(argc, argv).ensure(); });
scheduler.run_in_context([&] { td::actor::send_closure(x, &TestNode::run); });
scheduler.run();
return 0;
}

View file

@ -1,376 +0,0 @@
/*
This file is part of TON Blockchain source code.
TON Blockchain is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
TON Blockchain is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
You must obey the GNU General Public License in all respects for all
of the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version. If you delete this exception statement
from all source files in the program, then also delete it here.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl/adnl.h"
#include "adnl/utils.hpp"
#include "auto/tl/ton_api_json.h"
#include "dht/dht.h"
#include "overlay/overlays.h"
#include "td/utils/OptionParser.h"
#include "td/utils/Time.h"
#include "td/utils/filesystem.h"
#include "td/utils/format.h"
#include "td/utils/Random.h"
#include "td/utils/port/signals.h"
#include "td/utils/port/FileFd.h"
#include "catchain/catchain.h"
#include "crypto/common/refvector.hpp"
#if TD_DARWIN || TD_LINUX
#include <unistd.h>
#endif
#include <iostream>
#include <sstream>
template <std::size_t size>
std::ostream &operator<<(std::ostream &stream, const td::UInt<size> &x) {
for (size_t i = 0; i < size / 8; i++) {
stream << td::format::hex_digit((x.raw[i] >> 4) & 15) << td::format::hex_digit(x.raw[i] & 15);
}
return stream;
}
class TestNode : public td::actor::Actor {
private:
std::vector<td::UInt256> ping_ids_;
td::Timestamp next_dht_dump_;
td::actor::ActorOwn<ton::adnl::Adnl> adnl_;
std::vector<td::actor::ActorOwn<ton::dht::Dht>> dht_nodes_;
td::actor::ActorOwn<ton::overlay::Overlays> overlay_manager_;
std::vector<std::pair<td::UInt256, td::UInt256>> overlays_;
std::vector<td::actor::ActorOwn<ton::CatChain>> catchains_;
std::string local_config_ = "ton-local.config";
std::string global_config_ = "ton-global.config";
td::int32 broadcast_size_ = 100;
void receive_message(td::UInt256 src, td::UInt256 dst, td::BufferSlice data) {
LOG(ERROR) << "MESSAGE FROM " << src << " to " << dst << " of size " << std::to_string(data.size()) << "\n";
}
void receive_broadcast(td::UInt256 overlay_id, td::BufferSlice data) {
LOG(ERROR) << "BROADCAST IN " << overlay_id << " hash=" << td::sha256(data.as_slice()) << "\n";
}
void receive_query(td::UInt256 src, td::UInt256 dst, td::BufferSlice data, td::Promise<td::BufferSlice> promise) {
auto Q = ton::fetch_tl_object<ton::ton_api::getTestObject>(std::move(data), true);
CHECK(Q.is_ok());
auto R = Q.move_as_ok();
LOG(ERROR) << "QUERY "
<< " FROM " << src << " to " << dst << ": " << ton::ton_api::to_string(R) << "\n";
promise.set_value(serialize_tl_object(ton::create_tl_object<ton::ton_api::testObject>(), true));
}
void catchain_new_block(td::UInt256 src, td::uint64 height, td::BufferSlice data) {
LOG(ERROR) << "CATCHAIN BLOCK: " << src << "@" << height << ": " << td::sha256_uint256(data.as_slice()) << "\n";
}
void catchain_bad_block(td::UInt256 src) {
LOG(ERROR) << "CATCHAIN BAD BLOCK\n";
}
void catchain_broadcast(td::BufferSlice data) {
LOG(ERROR) << "CATCHAIN BROADCAST " << td::sha256_uint256(data.as_slice()) << "\n";
}
std::unique_ptr<ton::adnl::Adnl::Callback> make_callback() {
class Callback : public ton::adnl::Adnl::Callback {
public:
void receive_message(td::UInt256 src, td::UInt256 dst, td::BufferSlice data) override {
td::actor::send_closure(id_, &TestNode::receive_message, src, dst, std::move(data));
}
void receive_query(td::UInt256 src, td::UInt256 dst, td::BufferSlice data,
td::Promise<td::BufferSlice> promise) override {
td::actor::send_closure(id_, &TestNode::receive_query, src, dst, std::move(data), std::move(promise));
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
std::unique_ptr<ton::CatChainActor::Callback> make_catchain_callback() {
class Callback : public ton::CatChainActor::Callback {
public:
void new_block(td::UInt256 src, td::uint64 height, td::BufferSlice data) override {
td::actor::send_closure(id_, &TestNode::catchain_new_block, src, height, std::move(data));
}
void bad_block(td::UInt256 src) override {
td::actor::send_closure(id_, &TestNode::catchain_bad_block, src);
}
void broadcast(td::BufferSlice data) override {
td::actor::send_closure(id_, &TestNode::catchain_broadcast, std::move(data));
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
std::unique_ptr<ton::overlay::Overlays::Callback> make_overlay_callback() {
class Callback : public ton::overlay::Overlays::Callback {
public:
void receive_message(td::UInt256 src, td::UInt256 overlay_id, td::BufferSlice data) override {
}
void receive_query(td::UInt256 src, td::uint64 query_id, td::UInt256 overlay_id, td::BufferSlice data) override {
}
void receive_broadcast(td::UInt256 overlay_id, td::BufferSlice data) override {
td::actor::send_closure(id_, &TestNode::receive_broadcast, overlay_id, std::move(data));
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
public:
void set_broadcast_size(td::int32 size) {
broadcast_size_ = size;
}
void set_local_config(std::string str) {
local_config_ = str;
}
void set_global_config(std::string str) {
global_config_ = str;
}
void start_up() override {
alarm_timestamp() = td::Timestamp::in(1);
}
void alarm() override {
/*if (overlays_.size() > 0 && broadcast_size_ > 0) {
td::BufferSlice s(broadcast_size_);
td::Random::secure_bytes(s.as_slice());
td::actor::send_closure(overlay_manager_, &ton::overlay::OverlayManager::send_broadcast_fer, overlays_[0].first,
overlays_[0].second, ton::create_tl_object<ton::ton_api::testString>(s.as_slice().str()));
}*/
for (auto &chain : catchains_) {
td::BufferSlice s(broadcast_size_);
td::Random::secure_bytes(s.as_slice());
td::actor::send_closure(chain, &ton::CatChainActor::add_event, std::move(s));
}
alarm_timestamp() = td::Timestamp::in(1.0);
if (next_dht_dump_.is_in_past()) {
/*for (auto &node : dht_nodes_) {
char b[10240];
td::StringBuilder sb({b, 10000});
node->get_actor_unsafe().dump(sb);
LOG(DEBUG) << sb.as_cslice().c_str();
}*/
next_dht_dump_ = td::Timestamp::in(60.0);
}
}
TestNode() {
adnl_ = ton::adnl::Adnl::create("/var/ton-work/db.adnl");
}
void run() {
auto L = td::read_file(local_config_).move_as_ok();
auto lc_j = td::json_decode(L.as_slice()).move_as_ok();
ton::ton_api::config_local lc;
ton::ton_api::from_json(lc, lc_j.get_object()).ensure();
auto G = td::read_file(global_config_).move_as_ok();
auto gc_j = td::json_decode(G.as_slice()).move_as_ok();
ton::ton_api::config_global gc;
ton::ton_api::from_json(gc, gc_j.get_object()).ensure();
for (auto &port : lc.udp_ports_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_listening_udp_port, "0.0.0.0",
static_cast<td::uint16>(port));
}
/*if (!lc.net_) {
LOG(FATAL) << "local config does not contain NET section";
}*/
//td::actor::send_closure(network_manager_, &ton::adnl::AdnlNetworkManager::load_local_config, std::move(lc.net_));
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ids_from_config, std::move(lc.local_ids_));
if (gc.adnl_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_static_nodes_from_config,
std::move(gc.adnl_->static_nodes_));
}
if (!gc.dht_) {
LOG(FATAL) << "global config does not contain dht section";
}
for (auto &it : lc.dht_) {
if (it->get_id() == ton::ton_api::dht_config_local::ID) {
auto R = ton::dht::Dht::create_from_json(
ton::clone_tl_object(gc.dht_), ton::move_tl_object_as<ton::ton_api::dht_config_local>(it), adnl_.get());
if (R.is_error()) {
LOG(FATAL) << "fail creating dht node: " << R.move_as_error();
}
dht_nodes_.push_back(R.move_as_ok());
} else {
auto I = ton::move_tl_object_as<ton::ton_api::dht_config_random_local>(it);
for (int i = 0; i < I->cnt_; i++) {
auto R = ton::dht::Dht::create_random(ton::clone_tl_object(gc.dht_), ton::clone_tl_object(I->addr_list_),
adnl_.get());
if (R.is_error()) {
LOG(FATAL) << "fail creating dht node: " << R.move_as_error();
}
dht_nodes_.push_back(R.move_as_ok());
}
}
}
CHECK(dht_nodes_.size() > 0);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::register_dht_node, dht_nodes_[0].get());
//td::actor::send_closure(overlay_manager_, &ton::overlay::Overlays::register_dht_node, dht_nodes_[0].get());
overlay_manager_ = ton::overlay::Overlays::create(adnl_.get(), dht_nodes_[0].get());
for (auto &it : lc.public_overlays_) {
if (it->get_id() == ton::ton_api::overlay_config_local::ID) {
auto X = ton::move_tl_object_as<ton::ton_api::overlay_config_local>(it);
auto id = ton::create_tl_object<ton::ton_api::adnl_id_overlay>(X->name_.clone());
auto Id = ton::move_tl_object_as<ton::ton_api::adnl_id_Full>(id);
auto sid = ton::adnl_short_id(Id);
overlays_.emplace_back(X->id_->id_, sid);
td::actor::send_closure(overlay_manager_, &ton::overlay::Overlays::create_public_overlay, X->id_->id_,
std::move(Id), make_overlay_callback());
} else {
auto X = ton::move_tl_object_as<ton::ton_api::overlay_config_random_local>(it);
for (int i = 0; i < X->cnt_; i++) {
auto pk = ton::adnl_generate_random_pk();
auto local_id = ton::adnl_short_id(ton::get_public_key(pk));
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, std::move(pk), ton::clone_tl_object(X->addr_list_));
auto id = ton::create_tl_object<ton::ton_api::adnl_id_overlay>(X->name_.clone());
auto Id = ton::move_tl_object_as<ton::ton_api::adnl_id_Full>(id);
auto sid = ton::adnl_short_id(Id);
overlays_.emplace_back(local_id, sid);
td::actor::send_closure(overlay_manager_, &ton::overlay::Overlays::create_public_overlay, local_id,
std::move(Id), make_overlay_callback());
}
}
}
//auto C = ton::CatChainActor::create(nullptr, adnl_.get(), overlay_manager_.get(),
// std::vector<ton::tl_object_ptr<ton::ton_api::adnl_id_Full>>());
for (auto &it : lc.catchains_) {
auto tag = it->tag_;
for (auto &V : gc.catchains_) {
if (V->tag_ == tag) {
auto v = std::move(clone_tl_object(V)->nodes_);
auto C = ton::CatChainActor::create(make_catchain_callback(), adnl_.get(), overlay_manager_.get(),
std::move(v), it->id_->id_, tag);
catchains_.push_back(std::move(C));
}
}
}
}
};
td::Result<td::UInt256> get_uint256(std::string str) {
if (str.size() != 64) {
return td::Status::Error("uint256 must have 64 bytes");
}
td::UInt256 res;
for (size_t i = 0; i < 32; i++) {
res.raw[i] = static_cast<td::uint8>(td::hex_to_int(str[2 * i]) * 16 + td::hex_to_int(str[2 * i + 1]));
}
return res;
}
int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_DEBUG);
td::set_default_failure_signal_handler().ensure();
td::actor::ActorOwn<TestNode> x;
td::OptionParser p;
p.set_description("test basic adnl functionality");
p.add_option('h', "help", "prints_help", [&]() {
char b[10240];
td::StringBuilder sb({b, 10000});
sb << p;
std::cout << sb.as_cslice().c_str();
std::exit(2);
return td::Status::OK();
});
p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_global_config, fname.str());
return td::Status::OK();
});
p.add_option('c', "local-config", "file to read local config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_local_config, fname.str());
return td::Status::OK();
});
p.add_option('s', "broadcast-size", "size of broadcast", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_broadcast_size, std::atoi(fname.str().c_str()));
return td::Status::OK();
});
p.add_option('d', "daemonize", "set SIGHUP", [&]() {
td::set_signal_handler(td::SignalType::HangUp, [](int sig) {
#if TD_DARWIN || TD_LINUX
close(0);
setsid();
#endif
}).ensure();
return td::Status::OK();
});
#if TD_DARWIN || TD_LINUX
p.add_option('l', "logname", "log to file", [&](td::Slice fname) {
auto FileLog = td::FileFd::open(td::CSlice(fname.str().c_str()),
td::FileFd::Flags::Create | td::FileFd::Flags::Append | td::FileFd::Flags::Write)
.move_as_ok();
dup2(FileLog.get_native_fd().fd(), 1);
dup2(FileLog.get_native_fd().fd(), 2);
return td::Status::OK();
});
#endif
td::actor::Scheduler scheduler({2});
scheduler.run_in_context([&] { x = td::actor::create_actor<TestNode>("testnode"); });
scheduler.run_in_context([&] { p.run(argc, argv).ensure(); });
scheduler.run_in_context([&] { td::actor::send_closure(x, &TestNode::run); });
scheduler.run();
return 0;
}

View file

@ -40,7 +40,7 @@
int main() {
SET_VERBOSITY_LEVEL(verbosity_INFO);
std::string db_root_ = "tmp-ee";
std::string db_root_ = "tmp-dir-test-rldp";
td::rmrf(db_root_).ignore();
td::mkdir(db_root_).ensure();

View file

@ -40,7 +40,7 @@
int main() {
SET_VERBOSITY_LEVEL(verbosity_INFO);
std::string db_root_ = "tmp-ee";
std::string db_root_ = "tmp-dir-test-rldp2";
td::rmrf(db_root_).ignore();
td::mkdir(db_root_).ensure();

View file

@ -50,7 +50,7 @@
#include "validator/fabric.h"
#include "validator/impl/collator.h"
#include "crypto/vm/cp0.h"
#include "crypto/vm/vm.h"
#include "crypto/block/block-db.h"
#include "common/errorlog.h"
@ -408,7 +408,7 @@ int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_INFO);
td::set_default_failure_signal_handler().ensure();
CHECK(vm::init_op_cp0());
vm::init_vm().ensure();
td::actor::ActorOwn<TestNode> x;

View file

@ -48,6 +48,7 @@ class Description : public ton::validatorsession::ValidatorSessionDescription {
return 0;
}
void *alloc(size_t size, size_t align, bool temp) override {
size = (size + 15) / 16 * 16;
td::uint32 idx = temp ? 1 : 0;
auto s = pdata_cur_[idx].fetch_add(size);
CHECK(s + size <= pdata_size_[idx]);

View file

@ -1,356 +0,0 @@
/*
This file is part of TON Blockchain source code.
TON Blockchain is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
TON Blockchain is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
You must obey the GNU General Public License in all respects for all
of the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version. If you delete this exception statement
from all source files in the program, then also delete it here.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl/adnl.h"
#include "rldp/rldp.h"
#include "adnl/utils.hpp"
#include "auto/tl/ton_api_json.h"
#include "dht/dht.h"
#include "overlay/overlays.h"
#include "td/utils/OptionParser.h"
#include "td/utils/Time.h"
#include "td/utils/filesystem.h"
#include "td/utils/format.h"
#include "td/utils/Random.h"
#include "td/utils/port/signals.h"
#include "td/utils/port/FileFd.h"
#include "td/utils/overloaded.h"
#include "catchain/catchain.h"
#include "validator-session/validator-session.h"
#if TD_DARWIN || TD_LINUX
#include <unistd.h>
#endif
#include <iostream>
#include <sstream>
class TestNode : public td::actor::Actor {
private:
td::actor::ActorOwn<ton::keyring::Keyring> keyring_;
td::actor::ActorOwn<ton::adnl::Adnl> adnl_;
td::actor::ActorOwn<ton::rldp::Rldp> rldp_;
std::vector<td::actor::ActorOwn<ton::dht::Dht>> dht_nodes_;
td::actor::ActorOwn<ton::overlay::Overlays> overlay_manager_;
std::vector<td::actor::ActorOwn<ton::validatorsession::ValidatorSession>> validator_sessions_;
std::string local_config_ = "ton-local.config";
std::string global_config_ = "ton-global.config";
std::unique_ptr<ton::validatorsession::ValidatorSession::Callback> make_vs_callback() {
class Callback : public ton::validatorsession::ValidatorSession::Callback {
public:
void on_candidate(td::uint32 round, ton::PublicKeyHash source,
ton::validatorsession::ValidatorSessionRootHash root_hash, td::BufferSlice data,
td::BufferSlice extra,
td::Promise<ton::validatorsession::ValidatorSession::CandidateDecision> promise) override {
td::actor::send_closure(id_, &TestNode::on_candidate, round, source, root_hash, std::move(data),
std::move(extra), std::move(promise));
}
void on_generate_slot(td::uint32 round, td::Promise<ton::BlockCandidate> promise) override {
td::actor::send_closure(id_, &TestNode::on_generate_slot, round, std::move(promise));
}
void on_block_committed(td::uint32 round, ton::PublicKeyHash src,
ton::validatorsession::ValidatorSessionRootHash root_hash,
ton::validatorsession::ValidatorSessionFileHash file_hash, td::BufferSlice data,
std::vector<std::pair<ton::PublicKeyHash, td::BufferSlice>> signatures,
ton::validatorsession::ValidatorSessionStats stats) override {
td::actor::send_closure(id_, &TestNode::on_block_committed, round, root_hash, std::move(data),
std::move(signatures));
}
/*void on_missing_block_committed(
td::uint32 round, ton::validatorsession::ValidatorSessionRootHash root_hash, ton::validatorsession::ValidatorSessionFileHash file_hash,
td::BufferSlice data, std::vector<std::pair<ton::adnl::AdnlNodeIdShort, td::BufferSlice>> signatures) override {
td::actor::send_closure(id_, &TestNode::on_block_committed_abscent, round, root_hash, file_hash,
std::move(data), std::move(signatures));
}*/
void on_block_skipped(td::uint32 round) override {
td::actor::send_closure(id_, &TestNode::on_block_skipped, round);
}
void get_approved_candidate(ton::validatorsession::ValidatorSessionRootHash root_hash,
ton::validatorsession::ValidatorSessionFileHash file_hash,
ton::validatorsession::ValidatorSessionFileHash collated_data_file_hash,
td::Promise<ton::BlockCandidate> promise) override {
UNREACHABLE();
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
td::uint64 height_ = 0;
public:
void on_candidate(td::uint32 round, ton::PublicKeyHash source,
ton::validatorsession::ValidatorSessionRootHash root_hash, td::BufferSlice data,
td::BufferSlice collated,
td::Promise<ton::validatorsession::ValidatorSession::CandidateDecision> promise) {
auto sh = sha256_bits256(data.as_slice());
auto B = ton::fetch_tl_object<ton::ton_api::test_validatorSession_block>(std::move(data), true);
if (B.is_error()) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{B.move_as_error().to_string(), td::BufferSlice()});
return;
}
if (collated.size() != 32) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{"bad collated data length", td::BufferSlice()});
return;
}
td::Bits256 x;
x.as_slice().copy_from(collated.as_slice().truncate(32));
if (x != sh) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{"bad block hash", td::BufferSlice()});
return;
}
auto block = B.move_as_ok();
if (block->root_hash_ != root_hash) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{"bad root hash", td::BufferSlice()});
return;
}
if (block->root_hash_ != sha256_bits256(block->data_.as_slice())) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{"bad root hash (2)", td::BufferSlice()});
return;
}
if (block->height_ != static_cast<td::int64>(height_) + 1) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{"bad root height", td::BufferSlice()});
return;
}
promise.set_result(ton::validatorsession::ValidatorSession::CandidateDecision{0});
}
void on_generate_slot(td::uint32 round, td::Promise<ton::BlockCandidate> promise) {
auto data = td::BufferSlice{10000};
td::Random::secure_bytes(data.as_slice());
auto root_hash = sha256_bits256(data.as_slice());
auto block =
ton::create_tl_object<ton::ton_api::test_validatorSession_block>(root_hash, height_ + 1, std::move(data));
auto B = ton::serialize_tl_object(block, true);
auto hash = sha256_bits256(B.as_slice());
auto collated = td::BufferSlice{32};
collated.as_slice().copy_from(as_slice(hash));
/*BlockId id;
BlockStatus status;
RootHash root_hash;
FileHash file_hash;
FileHash collated_file_hash;
td::BufferSlice data;
td::BufferSlice collated_data;*/
auto collated_file_hash = td::sha256_bits256(collated.as_slice());
ton::BlockCandidate candidate{ton::BlockIdExt{ton::BlockId{0, 0, 0}, root_hash, td::sha256_bits256(B.as_slice())},
collated_file_hash, std::move(B), std::move(collated)};
promise.set_result(std::move(candidate));
}
void on_block_committed(td::uint32 round, ton::validatorsession::ValidatorSessionRootHash root_hash,
td::BufferSlice data,
std::vector<std::pair<ton::PublicKeyHash, td::BufferSlice>> signatures) {
LOG(ERROR) << "COMITTED BLOCK: ROUND=" << round << " ROOT_HASH=" << root_hash
<< " DATA_HASH=" << sha256_bits256(data.as_slice()) << " SIGNED BY " << signatures.size();
}
void on_block_skipped(td::uint32 round) {
LOG(ERROR) << "SKIPPED ROUND=" << round;
}
void set_local_config(std::string str) {
local_config_ = str;
}
void set_global_config(std::string str) {
global_config_ = str;
}
void start_up() override {
}
void alarm() override {
}
TestNode() {
}
void run() {
keyring_ = ton::keyring::Keyring::create("/var/ton-work/db.keyring");
adnl_ = ton::adnl::Adnl::create("/var/ton-work/db.adnl", keyring_.get());
rldp_ = ton::rldp::Rldp::create(adnl_.get());
auto L = td::read_file(local_config_).move_as_ok();
auto lc_j = td::json_decode(L.as_slice()).move_as_ok();
ton::ton_api::config_local lc;
ton::ton_api::from_json(lc, lc_j.get_object()).ensure();
auto G = td::read_file(global_config_).move_as_ok();
auto gc_j = td::json_decode(G.as_slice()).move_as_ok();
ton::ton_api::config_global gc;
ton::ton_api::from_json(gc, gc_j.get_object()).ensure();
for (auto &port : lc.udp_ports_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_listening_udp_port, "0.0.0.0",
static_cast<td::uint16>(port));
}
/*if (!lc.net_) {
LOG(FATAL) << "local config does not contain NET section";
}*/
//td::actor::send_closure(network_manager_, &ton::adnl::AdnlNetworkManager::load_local_config, std::move(lc.net_));
//td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ids_from_config, std::move(lc.local_ids_));
if (gc.adnl_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_static_nodes_from_config,
std::move(gc.adnl_->static_nodes_));
}
if (!gc.dht_) {
LOG(FATAL) << "global config does not contain dht section";
}
auto dhtR = ton::dht::Dht::create_global_config(std::move(gc.dht_));
if (dhtR.is_error()) {
LOG(FATAL) << "bad dht config: " << dhtR.move_as_error();
}
auto dht = dhtR.move_as_ok();
for (auto &it : lc.dht_) {
std::vector<ton::adnl::AdnlNodeIdShort> adnl_ids;
ton::ton_api::downcast_call(
*it.get(), td::overloaded(
[&](ton::ton_api::dht_config_local &obj) {
adnl_ids.push_back(ton::adnl::AdnlNodeIdShort{obj.id_->id_});
},
[&](ton::ton_api::dht_config_random_local &obj) {
auto addrR = ton::adnl::AdnlAddressList::create(std::move(obj.addr_list_));
addrR.ensure();
auto addr = addrR.move_as_ok();
for (td::int32 i = 0; i < obj.cnt_; i++) {
auto pk = ton::PrivateKey{ton::privkeys::Ed25519::random()};
auto pub = pk.compute_public_key();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key, std::move(pk), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, ton::adnl::AdnlNodeIdFull{pub},
addr);
auto adnl_id = ton::adnl::AdnlNodeIdShort{pub.compute_short_id()};
adnl_ids.push_back(adnl_id);
}
}));
for (auto &id : adnl_ids) {
auto R = ton::dht::Dht::create(id, "/var/ton-work/db/", dht, keyring_.get(), adnl_.get());
R.ensure();
dht_nodes_.push_back(R.move_as_ok());
}
}
CHECK(dht_nodes_.size() > 0);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::register_dht_node, dht_nodes_[0].get());
//td::actor::send_closure(overlay_manager_, &ton::overlay::Overlays::register_dht_node, dht_nodes_[0].get());
overlay_manager_ =
ton::overlay::Overlays::create("/var/ton-work/db.overlays", keyring_.get(), adnl_.get(), dht_nodes_[0].get());
//auto C = ton::CatChainActor::create(nullptr, adnl_.get(), overlay_manager_.get(),
// std::vector<ton::tl_object_ptr<ton::ton_api::adnl_id_Full>>());
for (auto &it : lc.catchains_) {
auto tag = it->tag_;
for (auto &V : gc.catchains_) {
if (V->tag_ == tag) {
auto v = std::move(clone_tl_object(V)->nodes_);
std::vector<ton::validatorsession::ValidatorSessionNode> w;
w.resize(v.size());
for (size_t i = 0; i < w.size(); i++) {
w[i].pub_key = ton::PublicKey{v[i]};
w[i].adnl_id = ton::adnl::AdnlNodeIdShort{w[i].pub_key.compute_short_id()};
w[i].weight = 1;
}
auto C = ton::validatorsession::ValidatorSession::create(
tag, ton::PublicKeyHash{it->id_->id_}, std::move(w), make_vs_callback(), keyring_.get(), adnl_.get(),
rldp_.get(), overlay_manager_.get(), "/var/ton-work/db/");
td::actor::send_closure(C, &ton::validatorsession::ValidatorSession::start);
validator_sessions_.emplace_back(std::move(C));
}
}
}
}
};
int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_INFO);
td::set_default_failure_signal_handler().ensure();
td::actor::ActorOwn<TestNode> x;
td::OptionParser p;
p.set_description("test basic adnl functionality");
p.add_option('h', "help", "prints_help", [&]() {
char b[10240];
td::StringBuilder sb(td::MutableSlice{b, 10000});
sb << p;
std::cout << sb.as_cslice().c_str();
std::exit(2);
return td::Status::OK();
});
p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_global_config, fname.str());
return td::Status::OK();
});
p.add_option('c', "local-config", "file to read local config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_local_config, fname.str());
return td::Status::OK();
});
p.add_option('d', "daemonize", "set SIGHUP", [&]() {
td::set_signal_handler(td::SignalType::HangUp, [](int sig) {
#if TD_DARWIN || TD_LINUX
close(0);
setsid();
#endif
}).ensure();
return td::Status::OK();
});
#if TD_DARWIN || TD_LINUX
p.add_option('l', "logname", "log to file", [&](td::Slice fname) {
auto FileLog = td::FileFd::open(td::CSlice(fname.str().c_str()),
td::FileFd::Flags::Create | td::FileFd::Flags::Append | td::FileFd::Flags::Write)
.move_as_ok();
dup2(FileLog.get_native_fd().fd(), 1);
dup2(FileLog.get_native_fd().fd(), 2);
return td::Status::OK();
});
#endif
td::actor::Scheduler scheduler({7});
scheduler.run_in_context([&] { x = td::actor::create_actor<TestNode>("testnode"); });
scheduler.run_in_context([&] { p.run(argc, argv).ensure(); });
scheduler.run_in_context([&] { td::actor::send_closure(x, &TestNode::run); });
scheduler.run();
return 0;
}

View file

@ -1,356 +0,0 @@
/*
This file is part of TON Blockchain source code.
TON Blockchain is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
TON Blockchain is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
You must obey the GNU General Public License in all respects for all
of the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version. If you delete this exception statement
from all source files in the program, then also delete it here.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl/adnl.h"
#include "rldp/rldp.h"
#include "adnl/utils.hpp"
#include "auto/tl/ton_api_json.h"
#include "auto/tl/ton_api.hpp"
#include "dht/dht.h"
#include "overlay/overlays.h"
#include "td/utils/OptionParser.h"
#include "td/utils/Time.h"
#include "td/utils/TsFileLog.h"
#include "td/utils/filesystem.h"
#include "td/utils/format.h"
#include "td/utils/Random.h"
#include "td/utils/port/signals.h"
#include "td/utils/port/FileFd.h"
#include "catchain/catchain.h"
#include "validator-session/validator-session.h"
#include "ton-node/ton-node.h"
#include "validator/manager.h"
#include "td/utils/filesystem.h"
#include "td/utils/ThreadSafeCounter.h"
#include "td/utils/port/path.h"
#include "crypto/vm/cp0.h"
#include "td/utils/overloaded.h"
#include "memprof/memprof.h"
#if TD_DARWIN || TD_LINUX
#include <unistd.h>
#endif
#include <algorithm>
#include <iostream>
#include <sstream>
class TestNode : public td::actor::Actor {
private:
td::actor::ActorOwn<ton::keyring::Keyring> keyring_;
td::actor::ActorOwn<ton::adnl::Adnl> adnl_;
td::actor::ActorOwn<ton::rldp::Rldp> rldp_;
std::vector<td::actor::ActorOwn<ton::dht::Dht>> dht_nodes_;
td::actor::ActorOwn<ton::overlay::Overlays> overlay_manager_;
td::actor::ActorOwn<ton::ValidatorManager> validator_manager_;
td::actor::ActorOwn<ton::TonNodeManager> ton_node_;
std::string local_config_ = "ton-local.config";
std::string global_config_ = "ton-global.config";
std::string db_root_ = "/var/ton-work/db/";
std::string zero_state_ = "";
public:
void set_local_config(std::string str) {
local_config_ = str;
}
void set_global_config(std::string str) {
global_config_ = str;
}
void set_db_root(std::string db_root) {
db_root_ = db_root;
}
void set_zero_state(std::string zero_state) {
zero_state_ = zero_state;
}
void start_up() override {
}
void alarm() override {
}
TestNode() {
}
void run() {
td::mkdir(db_root_).ensure();
keyring_ = ton::keyring::Keyring::create(db_root_ + "/keyring");
adnl_ = ton::adnl::Adnl::create(db_root_, keyring_.get());
rldp_ = ton::rldp::Rldp::create(adnl_.get());
auto L = td::read_file(local_config_).move_as_ok();
auto lc_j = td::json_decode(L.as_slice()).move_as_ok();
ton::ton_api::config_local lc;
ton::ton_api::from_json(lc, lc_j.get_object()).ensure();
auto G = td::read_file(global_config_).move_as_ok();
auto gc_j = td::json_decode(G.as_slice()).move_as_ok();
ton::ton_api::config_global gc;
ton::ton_api::from_json(gc, gc_j.get_object()).ensure();
for (auto &port : lc.udp_ports_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_listening_udp_port, "0.0.0.0",
static_cast<td::uint16>(port));
}
/*if (!lc.net_) {
LOG(FATAL) << "local config does not contain NET section";
}*/
//td::actor::send_closure(network_manager_, &ton::adnl::AdnlNetworkManager::load_local_config, std::move(lc.net_));
//td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ids_from_config, std::move(lc.local_ids_));
for (auto &local_id : lc.local_ids_) {
auto pk = ton::PrivateKey{local_id->id_};
auto pub = pk.compute_public_key();
auto addr_list = ton::adnl::AdnlAddressList::create(local_id->addr_list_);
addr_list.ensure();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key, std::move(pk), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, ton::adnl::AdnlNodeIdFull{pub}, addr_list.move_as_ok());
}
if (gc.adnl_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_static_nodes_from_config,
std::move(gc.adnl_->static_nodes_));
}
if (!gc.dht_) {
LOG(FATAL) << "global config does not contain dht section";
}
auto dhtR = ton::dht::Dht::create_global_config(std::move(gc.dht_));
if (dhtR.is_error()) {
LOG(FATAL) << "bad dht config: " << dhtR.move_as_error();
}
auto dht = dhtR.move_as_ok();
for (auto &it : lc.dht_) {
std::vector<ton::adnl::AdnlNodeIdShort> adnl_ids;
ton::ton_api::downcast_call(
*it.get(), td::overloaded(
[&](ton::ton_api::dht_config_local &obj) {
adnl_ids.push_back(ton::adnl::AdnlNodeIdShort{obj.id_->id_});
},
[&](ton::ton_api::dht_config_random_local &obj) {
auto addrR = ton::adnl::AdnlAddressList::create(std::move(obj.addr_list_));
addrR.ensure();
auto addr = addrR.move_as_ok();
for (td::int32 i = 0; i < obj.cnt_; i++) {
auto pk = ton::PrivateKey{ton::privkeys::Ed25519::random()};
auto pub = pk.compute_public_key();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key, std::move(pk), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, ton::adnl::AdnlNodeIdFull{pub},
addr);
auto adnl_id = ton::adnl::AdnlNodeIdShort{pub.compute_short_id()};
adnl_ids.push_back(adnl_id);
}
}));
for (auto &id : adnl_ids) {
auto R = ton::dht::Dht::create(id, db_root_, dht, keyring_.get(), adnl_.get());
R.ensure();
dht_nodes_.push_back(R.move_as_ok());
}
}
CHECK(dht_nodes_.size() > 0);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::register_dht_node, dht_nodes_[0].get());
overlay_manager_ = ton::overlay::Overlays::create(db_root_, keyring_.get(), adnl_.get(), dht_nodes_[0].get());
CHECK(lc.validators_.size() <= 1);
CHECK(gc.validators_.size() <= 1);
bool is_validator = false;
if (lc.validators_.size() == 1) {
CHECK(gc.validators_.size() == 1);
auto zero_state_id =
ton::BlockIdExt{ton::masterchainId, ton::shardIdAll, 0, gc.validators_[0]->zero_state_root_hash_,
gc.validators_[0]->zero_state_file_hash_};
ton::PublicKeyHash id;
ton::adnl::AdnlNodeIdShort adnl_id;
ton::ton_api::downcast_call(*lc.validators_[0].get(),
td::overloaded(
[&](ton::ton_api::validator_config_local &cfg) {
id = ton::PublicKeyHash{cfg.id_->id_};
adnl_id = ton::adnl::AdnlNodeIdShort{id};
is_validator = true;
},
[&](ton::ton_api::validator_config_random_local &cfg) {
auto privkey = ton::PrivateKey{ton::privkeys::Ed25519::random()};
auto pubkey = ton::adnl::AdnlNodeIdFull{privkey.compute_public_key()};
auto addrR = ton::adnl::AdnlAddressList::create(std::move(cfg.addr_list_));
addrR.ensure();
auto addr = addrR.move_as_ok();
id = privkey.compute_short_id();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key,
std::move(privkey), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, pubkey, addr);
adnl_id = ton::adnl::AdnlNodeIdShort{id};
}));
auto opts = ton::ValidatorManagerOptions::create(
zero_state_id, std::vector<ton::ShardIdFull>{ton::ShardIdFull{ton::basechainId, ton::shardIdAll}});
CHECK(!opts.is_null());
opts.write().set_allow_blockchain_init(is_validator);
validator_manager_ =
ton::ValidatorManagerFactory::create(is_validator ? id : ton::PublicKeyHash::zero(), opts, db_root_,
keyring_.get(), adnl_.get(), rldp_.get(), overlay_manager_.get());
ton_node_ =
ton::TonNodeManager::create(adnl_id, gc.validators_[0]->zero_state_file_hash_, adnl_.get(), rldp_.get(),
dht_nodes_[0].get(), overlay_manager_.get(), validator_manager_.get(), db_root_);
for (auto &x : lc.liteservers_) {
auto pk = ton::PrivateKey{x->id_};
auto pub_k = ton::adnl::AdnlNodeIdFull{pk.compute_public_key()};
auto id = pub_k.compute_short_id();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key, std::move(pk), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, pub_k, ton::adnl::AdnlAddressList{});
td::actor::send_closure(validator_manager_, &ton::ValidatorManager::add_ext_server_id, id);
td::actor::send_closure(validator_manager_, &ton::ValidatorManager::add_ext_server_port,
static_cast<td::uint16>(x->port_));
}
}
}
};
td::Result<td::UInt256> get_uint256(std::string str) {
if (str.size() != 64) {
return td::Status::Error("uint256 must have 64 bytes");
}
td::UInt256 res;
for (size_t i = 0; i < 32; i++) {
res.raw[i] = static_cast<td::uint8>(td::hex_to_int(str[2 * i]) * 16 + td::hex_to_int(str[2 * i + 1]));
}
return res;
}
std::atomic<bool> need_stats_flag{false};
void need_stats(int sig) {
need_stats_flag.store(true);
}
void dump_memory_stats() {
if (!is_memprof_on()) {
return;
}
LOG(WARNING) << "memory_dump";
std::vector<AllocInfo> v;
dump_alloc([&](const AllocInfo &info) { v.push_back(info); });
std::sort(v.begin(), v.end(), [](const AllocInfo &a, const AllocInfo &b) { return a.size > b.size; });
size_t total_size = 0;
size_t other_size = 0;
int cnt = 0;
for (auto &info : v) {
if (cnt++ < 50) {
LOG(WARNING) << td::format::as_size(info.size) << td::format::as_array(info.backtrace);
} else {
other_size += info.size;
}
total_size += info.size;
}
LOG(WARNING) << td::tag("other", td::format::as_size(other_size));
LOG(WARNING) << td::tag("total", td::format::as_size(total_size));
LOG(WARNING) << td::tag("total traces", get_ht_size());
LOG(WARNING) << td::tag("fast_backtrace_success_rate", get_fast_backtrace_success_rate());
}
void dump_stats() {
dump_memory_stats();
LOG(WARNING) << td::NamedThreadSafeCounter::get_default();
}
int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_INFO);
td::set_default_failure_signal_handler().ensure();
CHECK(vm::init_op_cp0());
td::actor::ActorOwn<TestNode> x;
td::unique_ptr<td::LogInterface> logger_;
SCOPE_EXIT {
td::log_interface = td::default_log_interface;
};
td::OptionParser p;
p.set_description("test basic adnl functionality");
p.add_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) {
int v = VERBOSITY_NAME(FATAL) + (td::to_integer<int>(arg));
SET_VERBOSITY_LEVEL(v);
return td::Status::OK();
});
p.add_option('h', "help", "prints_help", [&]() {
char b[10240];
td::StringBuilder sb(td::MutableSlice{b, 10000});
sb << p;
std::cout << sb.as_cslice().c_str();
std::exit(2);
return td::Status::OK();
});
p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_global_config, fname.str());
return td::Status::OK();
});
p.add_option('c', "local-config", "file to read local config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_local_config, fname.str());
return td::Status::OK();
});
p.add_option('i', "id", "id of instance", [&](td::Slice fname) { return td::Status::OK(); });
p.add_option('D', "db", "root for dbs", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_db_root, fname.str());
return td::Status::OK();
});
p.add_option('z', "zero-state", "file with serialized zero state", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_zero_state, fname.str());
return td::Status::OK();
});
p.add_option('d', "daemonize", "set SIGHUP", [&]() {
td::set_signal_handler(td::SignalType::HangUp, [](int sig) {
#if TD_DARWIN || TD_LINUX
close(0);
setsid();
#endif
}).ensure();
return td::Status::OK();
});
#if TD_DARWIN || TD_LINUX
p.add_option('l', "logname", "log to file", [&](td::Slice fname) {
logger_ = td::TsFileLog::create(fname.str()).move_as_ok();
td::log_interface = logger_.get();
return td::Status::OK();
});
#endif
td::set_runtime_signal_handler(1, need_stats).ensure();
td::actor::Scheduler scheduler({7});
scheduler.run_in_context([&] { x = td::actor::create_actor<TestNode>("testnode"); });
scheduler.run_in_context([&] { p.run(argc, argv).ensure(); });
scheduler.run_in_context([&] { td::actor::send_closure(x, &TestNode::run); });
while (scheduler.run(1)) {
if (need_stats_flag.exchange(false)) {
dump_stats();
}
}
return 0;
}

Some files were not shown because too many files have changed in this diff Show more