From 79442d527cd3767b2128d27ccb035683f484998b Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Wed, 12 Jan 2022 15:35:15 +0200 Subject: [PATCH 01/29] add native-lib --- .github/workflows/macos-10.15-compile.yml | 13 ++++++++++-- .github/workflows/ubuntu-18.04-compile.yml | 13 ++++++++++-- .github/workflows/windows2019x64-compile.yml | 21 +++++++++++++++----- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.github/workflows/macos-10.15-compile.yml b/.github/workflows/macos-10.15-compile.yml index 3165d39df..2db7c859a 100644 --- a/.github/workflows/macos-10.15-compile.yml +++ b/.github/workflows/macos-10.15-compile.yml @@ -20,13 +20,22 @@ jobs: ./Configure --prefix=/usr/local/macos darwin64-x86_64-cc -static -mmacosx-version-min=10.15 make build_libs -j4 - - name: Build TON + - name: Build all run: | rootPath=`pwd` mkdir build cd build cmake -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=10.15 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release .. make -j4 + + - name: Build native-lib + run: | + rootPath=`pwd` + mkdir build + cd build + cmake -DTON_ONLY_TONLIB=ON -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=10.15 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release .. + make -j4 prepare_cross_compiling + make -j4 native-lib - name: Find & copy binaries run: | @@ -37,4 +46,4 @@ jobs: uses: actions/upload-artifact@master with: name: ton-macos-binaries - path: artifacts + path: artifacts \ No newline at end of file diff --git a/.github/workflows/ubuntu-18.04-compile.yml b/.github/workflows/ubuntu-18.04-compile.yml index 6a6546651..a949e39be 100644 --- a/.github/workflows/ubuntu-18.04-compile.yml +++ b/.github/workflows/ubuntu-18.04-compile.yml @@ -26,14 +26,23 @@ jobs: - name: mkdir run: | mkdir build - - name: cmake + - name: cmake all run: | cd build cmake .. - - name: make -j4 + - name: make all run: | cd build make -j4 + - name: cmake ton only + run: | + cd build + cmake -DTON_ONLY_TONLIB=ON .. + - name: make native-lib + run: | + cd build + make -j4 prepare_cross_compiling + make -j4 native-lib - name: find & copy binaries run: | mkdir artifacts diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 54bfa1d62..631a0bc5b 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -38,7 +38,7 @@ jobs: - name: Install OpenSSL Win64 run: | - curl -o openssl.msi https://slproweb.com/download/Win64OpenSSL-1_1_1L.msi + curl -o openssl.msi https://slproweb.com/download/Win64OpenSSL-1_1_1m.msi msiexec /i openssl.msi /quiet /qn /norestart - name: Build ton @@ -52,13 +52,23 @@ jobs: - name: Compile ton run: | cd build - cmake --build . - continue-on-error: true + cmake --build . --config Release + continue-on-error: true + + - name: Compile native-lib + run: | + cd build + cmake -DZLIB_FOUND=1 -DTON_ONLY_TONLIB=ON -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DCMAKE_BUILD_TYPE=Release .. + cmake --build . --target prepare_cross_compiling --config Release + cmake --build . --target native-lib --config Release + continue-on-error: true - name: Show executables run: | - cd build + cd build + del Release\test-* dir *.exe /a-D /S /B + dir *.dll /a-D /S /B - name: Check if validator-engine.exe exists run: | @@ -69,9 +79,10 @@ jobs: run: | mkdir artifacts for /f %%a in ('dir *.exe /b /a /s') do copy /Y %%a artifacts + copy build\tonlib\Release\tonlibjson.dll artifacts - name: Upload artifacts uses: actions/upload-artifact@master with: name: ton-win64-binaries - path: artifacts + path: artifacts \ No newline at end of file From 856e2818012819b8ebad5eaf5d9dbf0608ff55e6 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Wed, 12 Jan 2022 15:40:18 +0200 Subject: [PATCH 02/29] add native-lib --- .github/workflows/windows2019x64-compile.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 631a0bc5b..a4fad7064 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -33,8 +33,8 @@ jobs: - name: Compile zlib Win64 run: | cd zlib\contrib\vstudio\vc14 - msbuild zlibstat.vcxproj /p:Configuration=Debug /p:platform=x64 - msbuild zlibstat.vcxproj /p:Configuration=ReleaseWithoutAsm /p:platform=x64 + msbuild zlibstat.vcxproj /p:Configuration=Debug /p:platform=x64 -p:PlatformToolset=v142 + msbuild zlibstat.vcxproj /p:Configuration=ReleaseWithoutAsm /p:platform=x64 -p:PlatformToolset=v142 - name: Install OpenSSL Win64 run: | From 103211c7da4be27d705537088d2ebdd713523212 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Thu, 13 Jan 2022 09:59:08 +0200 Subject: [PATCH 03/29] check wallet branch --- .github/workflows/macos-10.15-compile.yml | 20 ++++++++++++++----- .github/workflows/ubuntu-18.04-compile.yml | 21 ++++++++++++++------ .github/workflows/windows2019x64-compile.yml | 16 ++++++++++++--- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/.github/workflows/macos-10.15-compile.yml b/.github/workflows/macos-10.15-compile.yml index 2db7c859a..99e24394e 100644 --- a/.github/workflows/macos-10.15-compile.yml +++ b/.github/workflows/macos-10.15-compile.yml @@ -31,17 +31,27 @@ jobs: - name: Build native-lib run: | rootPath=`pwd` + + export JAVA_AWT_LIBRARY=NotNeeded + export JAVA_JVM_LIBRARY=NotNeeded + export JAVA_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + git checkout wallets + cd example/android/ mkdir build cd build - cmake -DTON_ONLY_TONLIB=ON -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=10.15 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release .. - make -j4 prepare_cross_compiling - make -j4 native-lib - + cmake -DTON_ONLY_TONLIB=ON .. + cmake --build . --target prepare_cross_compiling + cmake --build . --target native-lib + - name: Find & copy binaries run: | mkdir artifacts rsync -r --exclude 'CMakeFiles' --exclude 'Makefile' --exclude '*.a' --exclude '*.cmake' --exclude 'third-party' --exclude 'test-*' --exclude '*.cc' --exclude '*.json' --exclude '*.txt' build/* artifacts/ - + cp example/android/src/drinkless/org/ton/TonApi.java artifacts/ + cp example/android/build/libnative-lib.so artifacts/ + - name: Upload artifacts uses: actions/upload-artifact@master with: diff --git a/.github/workflows/ubuntu-18.04-compile.yml b/.github/workflows/ubuntu-18.04-compile.yml index a949e39be..d642ba4d3 100644 --- a/.github/workflows/ubuntu-18.04-compile.yml +++ b/.github/workflows/ubuntu-18.04-compile.yml @@ -34,19 +34,28 @@ jobs: run: | cd build make -j4 - - name: cmake ton only + - name: build native-lib run: | + export JAVA_AWT_LIBRARY=NotNeeded + export JAVA_JVM_LIBRARY=NotNeeded + export JAVA_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + git checkout wallets + cd example/android/ + mkdir build cd build cmake -DTON_ONLY_TONLIB=ON .. - - name: make native-lib - run: | - cd build - make -j4 prepare_cross_compiling - make -j4 native-lib + cmake --build . --target prepare_cross_compiling + cmake --build . --target native-lib + - name: find & copy binaries run: | mkdir artifacts cp --parents build/crypto/fift build/crypto/adjust-block build/crypto/dump-block 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/tddb/io-bench build/http/http-proxy build/tdnet/udp_ping_pong build/tdnet/tcp_ping_pong 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/pack-viewer build/utils/json2tlo build/adnl/adnl-proxy build/adnl/adnl-pong artifacts + cp example/android/src/drinkless/org/ton/TonApi.java artifacts + cp example/android/build/libnative-lib.so artifacts + - name: Upload artifacts uses: actions/upload-artifact@master with: diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index a4fad7064..f2521ae15 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -57,10 +57,18 @@ jobs: - name: Compile native-lib run: | + export JAVA_AWT_LIBRARY=NotNeeded + export JAVA_JVM_LIBRARY=NotNeeded + export JAVA_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + git checkout wallets + cd example/android/ + mkdir build cd build - cmake -DZLIB_FOUND=1 -DTON_ONLY_TONLIB=ON -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DCMAKE_BUILD_TYPE=Release .. - cmake --build . --target prepare_cross_compiling --config Release - cmake --build . --target native-lib --config Release + cmake -DTON_ONLY_TONLIB=ON .. + cmake --build . --target prepare_cross_compiling + cmake --build . --target native-lib continue-on-error: true - name: Show executables @@ -80,6 +88,8 @@ jobs: mkdir artifacts for /f %%a in ('dir *.exe /b /a /s') do copy /Y %%a artifacts copy build\tonlib\Release\tonlibjson.dll artifacts + copy example\android\src\drinkless\org\ton\TonApi.java artifacts + copy example\android\build\libnative-lib.dll artifacts - name: Upload artifacts uses: actions/upload-artifact@master From 7e1b9ecb289fc6e7f716d6437299e3789950221b Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Thu, 13 Jan 2022 12:12:24 +0200 Subject: [PATCH 04/29] added wallets branch --- .github/workflows/ubuntu-18.04-compile.yml | 2 +- .github/workflows/windows2019x64-compile.yml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ubuntu-18.04-compile.yml b/.github/workflows/ubuntu-18.04-compile.yml index d642ba4d3..51387450d 100644 --- a/.github/workflows/ubuntu-18.04-compile.yml +++ b/.github/workflows/ubuntu-18.04-compile.yml @@ -60,4 +60,4 @@ jobs: uses: actions/upload-artifact@master with: name: ton-binaries - path: artifacts + path: artifacts \ No newline at end of file diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index f2521ae15..31d1cd1c8 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -57,11 +57,11 @@ jobs: - name: Compile native-lib run: | - export JAVA_AWT_LIBRARY=NotNeeded - export JAVA_JVM_LIBRARY=NotNeeded - export JAVA_INCLUDE_PATH=${JAVA_HOME}/include - export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include - export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + set JAVA_AWT_LIBRARY=NotNeeded + set JAVA_JVM_LIBRARY=NotNeeded + set JAVA_INCLUDE_PATH=${JAVA_HOME}/include + set JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include + set JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux git checkout wallets cd example/android/ mkdir build From de618292711805e9aed662fe86e82fb4526c55c8 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Thu, 13 Jan 2022 20:34:24 +0200 Subject: [PATCH 05/29] fetch all branches --- .github/workflows/macos-10.15-compile.yml | 2 ++ .github/workflows/ubuntu-18.04-compile.yml | 2 ++ .github/workflows/windows2019x64-compile.yml | 2 ++ 3 files changed, 6 insertions(+) diff --git a/.github/workflows/macos-10.15-compile.yml b/.github/workflows/macos-10.15-compile.yml index 99e24394e..193889ba4 100644 --- a/.github/workflows/macos-10.15-compile.yml +++ b/.github/workflows/macos-10.15-compile.yml @@ -37,6 +37,8 @@ jobs: export JAVA_INCLUDE_PATH=${JAVA_HOME}/include export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + git fetch --all + git pull --all git checkout wallets cd example/android/ mkdir build diff --git a/.github/workflows/ubuntu-18.04-compile.yml b/.github/workflows/ubuntu-18.04-compile.yml index 51387450d..bc5f56844 100644 --- a/.github/workflows/ubuntu-18.04-compile.yml +++ b/.github/workflows/ubuntu-18.04-compile.yml @@ -41,6 +41,8 @@ jobs: export JAVA_INCLUDE_PATH=${JAVA_HOME}/include export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + git fetch --all + git pull --all git checkout wallets cd example/android/ mkdir build diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 31d1cd1c8..4854c432b 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -62,6 +62,8 @@ jobs: set JAVA_INCLUDE_PATH=${JAVA_HOME}/include set JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include set JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + git fetch --all + git pull --all git checkout wallets cd example/android/ mkdir build From 5fc7876a4bc0413b5b7a3efced47ecb48fd9fcb4 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Fri, 14 Jan 2022 09:57:34 +0200 Subject: [PATCH 06/29] adjust java include path --- .github/workflows/macos-10.15-compile.yml | 10 ++++------ .github/workflows/ubuntu-18.04-compile.yml | 8 ++++---- .github/workflows/windows2019x64-compile.yml | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/macos-10.15-compile.yml b/.github/workflows/macos-10.15-compile.yml index 193889ba4..980b46ce0 100644 --- a/.github/workflows/macos-10.15-compile.yml +++ b/.github/workflows/macos-10.15-compile.yml @@ -30,13 +30,11 @@ jobs: - name: Build native-lib run: | - rootPath=`pwd` - export JAVA_AWT_LIBRARY=NotNeeded export JAVA_JVM_LIBRARY=NotNeeded export JAVA_INCLUDE_PATH=${JAVA_HOME}/include export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include - export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/darwin git fetch --all git pull --all git checkout wallets @@ -49,10 +47,10 @@ jobs: - name: Find & copy binaries run: | - mkdir artifacts + mkdir -p artifacts/tonlib-java rsync -r --exclude 'CMakeFiles' --exclude 'Makefile' --exclude '*.a' --exclude '*.cmake' --exclude 'third-party' --exclude 'test-*' --exclude '*.cc' --exclude '*.json' --exclude '*.txt' build/* artifacts/ - cp example/android/src/drinkless/org/ton/TonApi.java artifacts/ - cp example/android/build/libnative-lib.so artifacts/ + cp example/android/src/drinkless/org/ton/TonApi.java artifacts/tonlib-java/ + cp example/android/build/libnative-lib.so artifacts/tonlib-java/ - name: Upload artifacts uses: actions/upload-artifact@master diff --git a/.github/workflows/ubuntu-18.04-compile.yml b/.github/workflows/ubuntu-18.04-compile.yml index bc5f56844..9ef4ea7f1 100644 --- a/.github/workflows/ubuntu-18.04-compile.yml +++ b/.github/workflows/ubuntu-18.04-compile.yml @@ -29,7 +29,7 @@ jobs: - name: cmake all run: | cd build - cmake .. + cmake -DCMAKE_BUILD_TYPE=Release .. - name: make all run: | cd build @@ -53,10 +53,10 @@ jobs: - name: find & copy binaries run: | - mkdir artifacts + mkdir -p artifacts/tonlib-java cp --parents build/crypto/fift build/crypto/adjust-block build/crypto/dump-block 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/tddb/io-bench build/http/http-proxy build/tdnet/udp_ping_pong build/tdnet/tcp_ping_pong 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/pack-viewer build/utils/json2tlo build/adnl/adnl-proxy build/adnl/adnl-pong artifacts - cp example/android/src/drinkless/org/ton/TonApi.java artifacts - cp example/android/build/libnative-lib.so artifacts + cp example/android/src/drinkless/org/ton/TonApi.java artifacts/tonlib-java/ + cp example/android/build/libnative-lib.so artifacts/tonlib-java/ - name: Upload artifacts uses: actions/upload-artifact@master diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 4854c432b..002ee4129 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -61,7 +61,7 @@ jobs: set JAVA_JVM_LIBRARY=NotNeeded set JAVA_INCLUDE_PATH=${JAVA_HOME}/include set JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include - set JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + set JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/win32 git fetch --all git pull --all git checkout wallets From dfb18b083009a6b5cb649770acf97c5da12eb433 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Fri, 14 Jan 2022 11:25:05 +0200 Subject: [PATCH 07/29] fix --- .github/workflows/macos-10.15-compile.yml | 2 +- .github/workflows/ubuntu-18.04-compile.yml | 4 ++-- .github/workflows/windows2019x64-compile.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/macos-10.15-compile.yml b/.github/workflows/macos-10.15-compile.yml index 980b46ce0..718858dca 100644 --- a/.github/workflows/macos-10.15-compile.yml +++ b/.github/workflows/macos-10.15-compile.yml @@ -41,7 +41,7 @@ jobs: cd example/android/ mkdir build cd build - cmake -DTON_ONLY_TONLIB=ON .. + cmake -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=10.15 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DTON_ONLY_TONLIB=ON .. cmake --build . --target prepare_cross_compiling cmake --build . --target native-lib diff --git a/.github/workflows/ubuntu-18.04-compile.yml b/.github/workflows/ubuntu-18.04-compile.yml index 9ef4ea7f1..9aefb5c8c 100644 --- a/.github/workflows/ubuntu-18.04-compile.yml +++ b/.github/workflows/ubuntu-18.04-compile.yml @@ -29,7 +29,7 @@ jobs: - name: cmake all run: | cd build - cmake -DCMAKE_BUILD_TYPE=Release .. + cmake .. - name: make all run: | cd build @@ -54,7 +54,7 @@ jobs: - name: find & copy binaries run: | mkdir -p artifacts/tonlib-java - cp --parents build/crypto/fift build/crypto/adjust-block build/crypto/dump-block 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/tddb/io-bench build/http/http-proxy build/tdnet/udp_ping_pong build/tdnet/tcp_ping_pong 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/pack-viewer build/utils/json2tlo build/adnl/adnl-proxy build/adnl/adnl-pong artifacts + cp --parents 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 artifacts cp example/android/src/drinkless/org/ton/TonApi.java artifacts/tonlib-java/ cp example/android/build/libnative-lib.so artifacts/tonlib-java/ diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 002ee4129..aec5ee265 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -52,7 +52,7 @@ jobs: - name: Compile ton run: | cd build - cmake --build . --config Release + cmake --config Release --build . continue-on-error: true - name: Compile native-lib From 5b925ca1e2909807ea60c7d0a5e8fa0eb4a446b0 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Fri, 14 Jan 2022 12:39:10 +0200 Subject: [PATCH 08/29] adjust java include path --- .github/workflows/macos-10.15-compile.yml | 1 + .github/workflows/windows2019x64-compile.yml | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/macos-10.15-compile.yml b/.github/workflows/macos-10.15-compile.yml index 718858dca..7811f1a31 100644 --- a/.github/workflows/macos-10.15-compile.yml +++ b/.github/workflows/macos-10.15-compile.yml @@ -30,6 +30,7 @@ jobs: - name: Build native-lib run: | + rootPath=`pwd` export JAVA_AWT_LIBRARY=NotNeeded export JAVA_JVM_LIBRARY=NotNeeded export JAVA_INCLUDE_PATH=${JAVA_HOME}/include diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index aec5ee265..d91830457 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -52,7 +52,7 @@ jobs: - name: Compile ton run: | cd build - cmake --config Release --build . + cmake --build . continue-on-error: true - name: Compile native-lib @@ -71,8 +71,7 @@ jobs: cmake -DTON_ONLY_TONLIB=ON .. cmake --build . --target prepare_cross_compiling cmake --build . --target native-lib - continue-on-error: true - + - name: Show executables run: | cd build From 7e21422461cac034b350a1870a586fa8e03236c1 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Fri, 14 Jan 2022 13:27:21 +0200 Subject: [PATCH 09/29] fix macos --- .github/workflows/macos-10.15-compile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos-10.15-compile.yml b/.github/workflows/macos-10.15-compile.yml index 7811f1a31..41cd96e97 100644 --- a/.github/workflows/macos-10.15-compile.yml +++ b/.github/workflows/macos-10.15-compile.yml @@ -51,7 +51,7 @@ jobs: mkdir -p artifacts/tonlib-java rsync -r --exclude 'CMakeFiles' --exclude 'Makefile' --exclude '*.a' --exclude '*.cmake' --exclude 'third-party' --exclude 'test-*' --exclude '*.cc' --exclude '*.json' --exclude '*.txt' build/* artifacts/ cp example/android/src/drinkless/org/ton/TonApi.java artifacts/tonlib-java/ - cp example/android/build/libnative-lib.so artifacts/tonlib-java/ + cp example/android/build/libnative-lib.dylib artifacts/tonlib-java/ - name: Upload artifacts uses: actions/upload-artifact@master From fca1216a37b8c960c6780ed3ec3c4b48eb7663b3 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Fri, 14 Jan 2022 13:28:28 +0200 Subject: [PATCH 10/29] fix win build --- .github/workflows/windows2019x64-compile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index d91830457..0f7c7dc3b 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -68,7 +68,7 @@ jobs: cd example/android/ mkdir build cd build - cmake -DTON_ONLY_TONLIB=ON .. + cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DTON_ONLY_TONLIB=ON .. cmake --build . --target prepare_cross_compiling cmake --build . --target native-lib From 75a05b4db2167ce1f1f9dd56eb3e9d706652b91a Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Fri, 14 Jan 2022 15:10:30 +0200 Subject: [PATCH 11/29] fix win java build --- .github/workflows/windows2019x64-compile.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 0f7c7dc3b..6faf88905 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -68,9 +68,9 @@ jobs: cd example/android/ mkdir build cd build - cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DTON_ONLY_TONLIB=ON .. - cmake --build . --target prepare_cross_compiling - cmake --build . --target native-lib + cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DTON_ONLY_TONLIB=ON -DCMAKE_BUILD_TYPE=Release .. + cmake --target prepare_cross_compiling --build . + cmake --target native-lib --build . - name: Show executables run: | From 9ff171f84f597a95cd830ad63c41ec56ea9fe25e Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Fri, 14 Jan 2022 16:09:24 +0200 Subject: [PATCH 12/29] win build --- .github/workflows/windows2019x64-compile.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 6faf88905..a017ef14c 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -57,6 +57,7 @@ jobs: - name: Compile native-lib run: | + set root=%cd% set JAVA_AWT_LIBRARY=NotNeeded set JAVA_JVM_LIBRARY=NotNeeded set JAVA_INCLUDE_PATH=${JAVA_HOME}/include From 6ebf6c22658729ebda618c6af71ef05dc392bdba Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Fri, 14 Jan 2022 17:18:25 +0200 Subject: [PATCH 13/29] fix win --- .github/workflows/windows2019x64-compile.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index a017ef14c..4b3b325dc 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -69,9 +69,8 @@ jobs: cd example/android/ mkdir build cd build - cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DTON_ONLY_TONLIB=ON -DCMAKE_BUILD_TYPE=Release .. - cmake --target prepare_cross_compiling --build . - cmake --target native-lib --build . + cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DTON_ONLY_TONLIB=ON .. + cmake --build . - name: Show executables run: | From 41bc39a8e271282e3d6230f36fe6112665814d34 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Fri, 14 Jan 2022 18:16:20 +0200 Subject: [PATCH 14/29] adjust java include path --- .github/workflows/windows2019x64-compile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 4b3b325dc..9c01c4fcc 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -69,7 +69,7 @@ jobs: cd example/android/ mkdir build cd build - cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DTON_ONLY_TONLIB=ON .. + cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DTON_ONLY_TONLIB=ON .. cmake --build . - name: Show executables From 93cbbb447af80a7df5af0be9020b631c679d0b9c Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Fri, 14 Jan 2022 18:20:21 +0200 Subject: [PATCH 15/29] with only gcc --- .github/workflows/windows2019x64-compile.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 9c01c4fcc..6ff8271e8 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -70,7 +70,8 @@ jobs: mkdir build cd build cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DTON_ONLY_TONLIB=ON .. - cmake --build . + cmake --build . --target prepare_cross_compiling + cmake --build . --target native-lib - name: Show executables run: | From 6a5b73b14b3716895bcd0333ae3c8e76df572ba4 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Sat, 15 Jan 2022 19:23:04 +0200 Subject: [PATCH 16/29] adjust java include path --- .github/workflows/windows2019x64-compile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 6ff8271e8..316e24a39 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -97,4 +97,4 @@ jobs: uses: actions/upload-artifact@master with: name: ton-win64-binaries - path: artifacts \ No newline at end of file + path: artifacts From 0ec65ac64e7c2f2659472cf63adde683f2c18e71 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Sun, 16 Jan 2022 10:50:19 +0200 Subject: [PATCH 17/29] new win condition --- .github/workflows/windows2019x64-compile.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 316e24a39..05eb26776 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -69,9 +69,9 @@ jobs: cd example/android/ mkdir build cd build - cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DTON_ONLY_TONLIB=ON .. - cmake --build . --target prepare_cross_compiling - cmake --build . --target native-lib + cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DTON_ONLY_TONLIB=ON .. + cmake --build . --target prepare_cross_compiling --config Release + cmake --build . --target native-lib --config Release - name: Show executables run: | From 7e5bc120d4124168fed5278609cf57bb1f6268aa Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Mon, 17 Jan 2022 09:40:26 +0200 Subject: [PATCH 18/29] fix dll path, release ubuntu --- .github/workflows/ubuntu-18.04-compile.yml | 3 ++- .github/workflows/windows2019x64-compile.yml | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ubuntu-18.04-compile.yml b/.github/workflows/ubuntu-18.04-compile.yml index 9aefb5c8c..0721c9e92 100644 --- a/.github/workflows/ubuntu-18.04-compile.yml +++ b/.github/workflows/ubuntu-18.04-compile.yml @@ -29,11 +29,12 @@ jobs: - name: cmake all run: | cd build - cmake .. + cmake -DCMAKE_BUILD_TYPE=Release .. - name: make all run: | cd build make -j4 + - name: build native-lib run: | export JAVA_AWT_LIBRARY=NotNeeded diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 05eb26776..8a15c99e3 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -70,7 +70,7 @@ jobs: mkdir build cd build cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DTON_ONLY_TONLIB=ON .. - cmake --build . --target prepare_cross_compiling --config Release +# cmake --build . --target prepare_cross_compiling --config Release cmake --build . --target native-lib --config Release - name: Show executables @@ -79,19 +79,19 @@ jobs: del Release\test-* dir *.exe /a-D /S /B dir *.dll /a-D /S /B - + - name: Check if validator-engine.exe exists run: | set root=%cd% copy %root%\build\validator-engine\Debug\validator-engine.exe test - + - name: Find & copy binaries run: | mkdir artifacts for /f %%a in ('dir *.exe /b /a /s') do copy /Y %%a artifacts copy build\tonlib\Release\tonlibjson.dll artifacts - copy example\android\src\drinkless\org\ton\TonApi.java artifacts - copy example\android\build\libnative-lib.dll artifacts +# copy example\android\src\drinkless\org\ton\TonApi.java artifacts + copy example\android\build\Release\native-lib.dll artifacts - name: Upload artifacts uses: actions/upload-artifact@master From 6384deed0ac07715b801ca5e9c137b62546ad8a8 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Mon, 17 Jan 2022 09:42:44 +0200 Subject: [PATCH 19/29] remove commented out win --- .github/workflows/windows2019x64-compile.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 8a15c99e3..6cd288987 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -70,7 +70,6 @@ jobs: mkdir build cd build cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DTON_ONLY_TONLIB=ON .. -# cmake --build . --target prepare_cross_compiling --config Release cmake --build . --target native-lib --config Release - name: Show executables @@ -90,7 +89,6 @@ jobs: mkdir artifacts for /f %%a in ('dir *.exe /b /a /s') do copy /Y %%a artifacts copy build\tonlib\Release\tonlibjson.dll artifacts -# copy example\android\src\drinkless\org\ton\TonApi.java artifacts copy example\android\build\Release\native-lib.dll artifacts - name: Upload artifacts From fa3857f6335578bc1513e0b033d9314ba98f9b8c Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Mon, 17 Jan 2022 09:57:10 +0200 Subject: [PATCH 20/29] add release to only-tonlib --- .github/workflows/macos-10.15-compile.yml | 2 +- .github/workflows/ubuntu-18.04-compile.yml | 2 +- .github/workflows/windows2019x64-compile.yml | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/macos-10.15-compile.yml b/.github/workflows/macos-10.15-compile.yml index 41cd96e97..99d231f65 100644 --- a/.github/workflows/macos-10.15-compile.yml +++ b/.github/workflows/macos-10.15-compile.yml @@ -42,7 +42,7 @@ jobs: cd example/android/ mkdir build cd build - cmake -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=10.15 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DTON_ONLY_TONLIB=ON .. + cmake -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=10.15 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release -DTON_ONLY_TONLIB=ON .. cmake --build . --target prepare_cross_compiling cmake --build . --target native-lib diff --git a/.github/workflows/ubuntu-18.04-compile.yml b/.github/workflows/ubuntu-18.04-compile.yml index 0721c9e92..25585cc9d 100644 --- a/.github/workflows/ubuntu-18.04-compile.yml +++ b/.github/workflows/ubuntu-18.04-compile.yml @@ -48,7 +48,7 @@ jobs: cd example/android/ mkdir build cd build - cmake -DTON_ONLY_TONLIB=ON .. + cmake -DCMAKE_BUILD_TYPE=Release -DTON_ONLY_TONLIB=ON .. cmake --build . --target prepare_cross_compiling cmake --build . --target native-lib diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 6cd288987..169c6656d 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -5,7 +5,7 @@ on: [push,workflow_dispatch] defaults: run: shell: cmd - + jobs: build: @@ -20,27 +20,27 @@ jobs: uses: actions/checkout@v2 with: submodules: 'recursive' - + - name: Check out zlib repository uses: actions/checkout@v2 with: repository: desktop-app/zlib path: zlib - + - name: Setup msbuild.exe uses: microsoft/setup-msbuild@v1.0.2 - + - name: Compile zlib Win64 run: | cd zlib\contrib\vstudio\vc14 msbuild zlibstat.vcxproj /p:Configuration=Debug /p:platform=x64 -p:PlatformToolset=v142 msbuild zlibstat.vcxproj /p:Configuration=ReleaseWithoutAsm /p:platform=x64 -p:PlatformToolset=v142 - + - name: Install OpenSSL Win64 run: | curl -o openssl.msi https://slproweb.com/download/Win64OpenSSL-1_1_1m.msi msiexec /i openssl.msi /quiet /qn /norestart - + - name: Build ton run: | set root=%cd% @@ -48,7 +48,7 @@ jobs: mkdir build cd build cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DCMAKE_BUILD_TYPE=Release .. - + - name: Compile ton run: | cd build @@ -90,9 +90,9 @@ jobs: for /f %%a in ('dir *.exe /b /a /s') do copy /Y %%a artifacts copy build\tonlib\Release\tonlibjson.dll artifacts copy example\android\build\Release\native-lib.dll artifacts - + - name: Upload artifacts uses: actions/upload-artifact@master with: name: ton-win64-binaries - path: artifacts + path: artifacts \ No newline at end of file From 5dd09145273fca7b674c7b05f57b60e118751bb5 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Mon, 17 Jan 2022 10:56:52 +0200 Subject: [PATCH 21/29] win release, ubuntu targets --- .github/workflows/macos-10.15-compile.yml | 2 +- .github/workflows/ubuntu-18.04-compile.yml | 2 +- .github/workflows/windows2019x64-compile.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/macos-10.15-compile.yml b/.github/workflows/macos-10.15-compile.yml index 99d231f65..be8e44e85 100644 --- a/.github/workflows/macos-10.15-compile.yml +++ b/.github/workflows/macos-10.15-compile.yml @@ -42,7 +42,7 @@ jobs: cd example/android/ mkdir build cd build - cmake -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=10.15 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release -DTON_ONLY_TONLIB=ON .. + cmake -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=10.15 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release -DTON_ONLY_TONLIB=ON .. cmake --build . --target prepare_cross_compiling cmake --build . --target native-lib diff --git a/.github/workflows/ubuntu-18.04-compile.yml b/.github/workflows/ubuntu-18.04-compile.yml index 25585cc9d..384b3726d 100644 --- a/.github/workflows/ubuntu-18.04-compile.yml +++ b/.github/workflows/ubuntu-18.04-compile.yml @@ -33,7 +33,7 @@ jobs: - name: make all run: | cd build - make -j4 + make -j4 fift func tonlib 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 - name: build native-lib run: | diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 169c6656d..ec51e9f0a 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -47,12 +47,12 @@ jobs: echo %root% mkdir build cd build - cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DCMAKE_BUILD_TYPE=Release .. + cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" .. - name: Compile ton run: | cd build - cmake --build . + cmake --build . --config Release continue-on-error: true - name: Compile native-lib From 5ba47923241e8e9dc0f6d1003c633d3933df26ea Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Mon, 17 Jan 2022 11:44:08 +0200 Subject: [PATCH 22/29] change debug to release in path --- .github/workflows/windows2019x64-compile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index ec51e9f0a..1f0c2a1ce 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -82,7 +82,7 @@ jobs: - name: Check if validator-engine.exe exists run: | set root=%cd% - copy %root%\build\validator-engine\Debug\validator-engine.exe test + copy %root%\build\validator-engine\Release\validator-engine.exe test - name: Find & copy binaries run: | From 68775bc367b28e574095d1b2eeb19e8bc12f6247 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Mon, 17 Jan 2022 13:26:44 +0200 Subject: [PATCH 23/29] add tonlibjson target --- .github/workflows/ubuntu-18.04-compile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ubuntu-18.04-compile.yml b/.github/workflows/ubuntu-18.04-compile.yml index 384b3726d..9a4abcc29 100644 --- a/.github/workflows/ubuntu-18.04-compile.yml +++ b/.github/workflows/ubuntu-18.04-compile.yml @@ -33,7 +33,7 @@ jobs: - name: make all run: | cd build - make -j4 fift func tonlib 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 + make -j4 fift func tonlib tonlibjson 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 - name: build native-lib run: | From 37c94435d63f270f93766a2d70dbdcb18f2d5934 Mon Sep 17 00:00:00 2001 From: Alex Melman Date: Wed, 12 Jan 2022 15:35:15 +0200 Subject: [PATCH 24/29] add java native-lib into git actions --- .github/workflows/macos-10.15-compile.yml | 30 ++++++++-- .github/workflows/ubuntu-18.04-compile.yml | 35 ++++++++--- .github/workflows/windows2019x64-compile.yml | 61 +++++++++++++------- 3 files changed, 94 insertions(+), 32 deletions(-) diff --git a/.github/workflows/macos-10.15-compile.yml b/.github/workflows/macos-10.15-compile.yml index 3165d39df..be8e44e85 100644 --- a/.github/workflows/macos-10.15-compile.yml +++ b/.github/workflows/macos-10.15-compile.yml @@ -20,21 +20,41 @@ jobs: ./Configure --prefix=/usr/local/macos darwin64-x86_64-cc -static -mmacosx-version-min=10.15 make build_libs -j4 - - name: Build TON + - name: Build all run: | rootPath=`pwd` mkdir build cd build cmake -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=10.15 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release .. make -j4 - + + - name: Build native-lib + run: | + rootPath=`pwd` + export JAVA_AWT_LIBRARY=NotNeeded + export JAVA_JVM_LIBRARY=NotNeeded + export JAVA_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/darwin + git fetch --all + git pull --all + git checkout wallets + cd example/android/ + mkdir build + cd build + cmake -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=10.15 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_BUILD_TYPE=Release -DTON_ONLY_TONLIB=ON .. + cmake --build . --target prepare_cross_compiling + cmake --build . --target native-lib + - name: Find & copy binaries run: | - mkdir artifacts + mkdir -p artifacts/tonlib-java rsync -r --exclude 'CMakeFiles' --exclude 'Makefile' --exclude '*.a' --exclude '*.cmake' --exclude 'third-party' --exclude 'test-*' --exclude '*.cc' --exclude '*.json' --exclude '*.txt' build/* artifacts/ - + cp example/android/src/drinkless/org/ton/TonApi.java artifacts/tonlib-java/ + cp example/android/build/libnative-lib.dylib artifacts/tonlib-java/ + - name: Upload artifacts uses: actions/upload-artifact@master with: name: ton-macos-binaries - path: artifacts + path: artifacts \ No newline at end of file diff --git a/.github/workflows/ubuntu-18.04-compile.yml b/.github/workflows/ubuntu-18.04-compile.yml index 6a6546651..46136fbfd 100644 --- a/.github/workflows/ubuntu-18.04-compile.yml +++ b/.github/workflows/ubuntu-18.04-compile.yml @@ -26,20 +26,41 @@ jobs: - name: mkdir run: | mkdir build - - name: cmake + - name: cmake all run: | cd build - cmake .. - - name: make -j4 + cmake -DCMAKE_BUILD_TYPE=Release .. + - name: make all run: | cd build - make -j4 + make -j4 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 + + - name: build native-lib + run: | + export JAVA_AWT_LIBRARY=NotNeeded + export JAVA_JVM_LIBRARY=NotNeeded + export JAVA_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + git fetch --all + git pull --all + git checkout wallets + cd example/android/ + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Release -DTON_ONLY_TONLIB=ON .. + cmake --build . --target prepare_cross_compiling + cmake --build . --target native-lib + - name: find & copy binaries run: | - mkdir artifacts - cp --parents build/crypto/fift build/crypto/adjust-block build/crypto/dump-block 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/tddb/io-bench build/http/http-proxy build/tdnet/udp_ping_pong build/tdnet/tcp_ping_pong 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/pack-viewer build/utils/json2tlo build/adnl/adnl-proxy build/adnl/adnl-pong artifacts + mkdir -p artifacts/tonlib-java + cp --parents 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 artifacts + cp example/android/src/drinkless/org/ton/TonApi.java artifacts/tonlib-java/ + cp example/android/build/libnative-lib.so artifacts/tonlib-java/ + - name: Upload artifacts uses: actions/upload-artifact@master with: name: ton-binaries - path: artifacts + path: artifacts \ No newline at end of file diff --git a/.github/workflows/windows2019x64-compile.yml b/.github/workflows/windows2019x64-compile.yml index 54bfa1d62..1f0c2a1ce 100644 --- a/.github/workflows/windows2019x64-compile.yml +++ b/.github/workflows/windows2019x64-compile.yml @@ -5,7 +5,7 @@ on: [push,workflow_dispatch] defaults: run: shell: cmd - + jobs: build: @@ -20,58 +20,79 @@ jobs: uses: actions/checkout@v2 with: submodules: 'recursive' - + - name: Check out zlib repository uses: actions/checkout@v2 with: repository: desktop-app/zlib path: zlib - + - name: Setup msbuild.exe uses: microsoft/setup-msbuild@v1.0.2 - + - name: Compile zlib Win64 run: | cd zlib\contrib\vstudio\vc14 - msbuild zlibstat.vcxproj /p:Configuration=Debug /p:platform=x64 - msbuild zlibstat.vcxproj /p:Configuration=ReleaseWithoutAsm /p:platform=x64 - + msbuild zlibstat.vcxproj /p:Configuration=Debug /p:platform=x64 -p:PlatformToolset=v142 + msbuild zlibstat.vcxproj /p:Configuration=ReleaseWithoutAsm /p:platform=x64 -p:PlatformToolset=v142 + - name: Install OpenSSL Win64 run: | - curl -o openssl.msi https://slproweb.com/download/Win64OpenSSL-1_1_1L.msi + curl -o openssl.msi https://slproweb.com/download/Win64OpenSSL-1_1_1m.msi msiexec /i openssl.msi /quiet /qn /norestart - + - name: Build ton run: | set root=%cd% echo %root% mkdir build cd build - cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" -DCMAKE_BUILD_TYPE=Release .. - + cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DCMAKE_CXX_FLAGS="/DTD_WINDOWS=1 /EHsc /bigobj /W0" .. + - name: Compile ton run: | cd build - cmake --build . - continue-on-error: true - + cmake --build . --config Release + continue-on-error: true + + - name: Compile native-lib + run: | + set root=%cd% + set JAVA_AWT_LIBRARY=NotNeeded + set JAVA_JVM_LIBRARY=NotNeeded + set JAVA_INCLUDE_PATH=${JAVA_HOME}/include + set JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include + set JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/win32 + git fetch --all + git pull --all + git checkout wallets + cd example/android/ + mkdir build + cd build + cmake -DZLIB_FOUND=1 -DZLIB_INCLUDE_DIR=%root%\zlib -DZLIB_LIBRARY=%root%\zlib\contrib\vstudio\vc14\x64\ZlibStatReleaseWithoutAsm\zlibstat.lib -DTON_ONLY_TONLIB=ON .. + cmake --build . --target native-lib --config Release + - name: Show executables run: | - cd build + cd build + del Release\test-* dir *.exe /a-D /S /B - + dir *.dll /a-D /S /B + - name: Check if validator-engine.exe exists run: | set root=%cd% - copy %root%\build\validator-engine\Debug\validator-engine.exe test - + copy %root%\build\validator-engine\Release\validator-engine.exe test + - name: Find & copy binaries run: | mkdir artifacts for /f %%a in ('dir *.exe /b /a /s') do copy /Y %%a artifacts - + copy build\tonlib\Release\tonlibjson.dll artifacts + copy example\android\build\Release\native-lib.dll artifacts + - name: Upload artifacts uses: actions/upload-artifact@master with: name: ton-win64-binaries - path: artifacts + path: artifacts \ No newline at end of file From b46941e50462b6d74806a9f4a49d6c001f60612c Mon Sep 17 00:00:00 2001 From: Starlight Duck Date: Thu, 20 Jan 2022 23:20:56 +0200 Subject: [PATCH 25/29] tonlib use correct c7: config and address when executing --- crypto/smc-envelope/SmartContract.cpp | 64 ++++++++++++++++++--------- crypto/smc-envelope/SmartContract.h | 18 ++++++++ crypto/vm/vm.cpp | 1 + crypto/vm/vm.h | 4 ++ tonlib/tonlib/LastConfig.cpp | 4 +- tonlib/tonlib/TonlibClient.cpp | 45 +++++++++++++------ tonlib/tonlib/TonlibClient.h | 1 + 7 files changed, 99 insertions(+), 38 deletions(-) diff --git a/crypto/smc-envelope/SmartContract.cpp b/crypto/smc-envelope/SmartContract.cpp index f3485be9b..30030aae0 100644 --- a/crypto/smc-envelope/SmartContract.cpp +++ b/crypto/smc-envelope/SmartContract.cpp @@ -52,30 +52,51 @@ td::Ref prepare_vm_stack(td::RefInt256 amount, td::Ref return stack_ref; } -td::Ref prepare_vm_c7(td::uint32 now, td::uint64 balance) { - // TODO: fix initialization of c7 +td::Ref prepare_vm_c7(SmartContract::Args args) { td::BitArray<256> rand_seed; rand_seed.as_slice().fill(0); td::RefInt256 rand_seed_int{true}; rand_seed_int.unique_write().import_bits(rand_seed.cbits(), 256, false); + + td::uint32 now = 0; + if (args.now) { + now = args.now.unwrap(); + } + + vm::CellBuilder cb; + if (args.address) { + td::BigInt256 dest_addr; + dest_addr.import_bits((*args.address).addr.as_bitslice()); + cb.store_ones(1) + .store_zeroes(2) + .store_long((*args.address).workchain, 8) + .store_int256(dest_addr, 256); + } + auto address = cb.finalize(); + auto config = td::Ref(); + + if (args.config) { + config = (*args.config)->get_root_cell(); + } + auto tuple = vm::make_tuple_ref( td::make_refint(0x076ef1ea), // [ magic:0x076ef1ea td::make_refint(0), // actions:Integer td::make_refint(0), // msgs_sent:Integer td::make_refint(now), // unixtime:Integer - td::make_refint(0), // block_lt:Integer - td::make_refint(0), // trans_lt:Integer + td::make_refint(0), //TODO: // block_lt:Integer + td::make_refint(0), //TODO: // trans_lt:Integer std::move(rand_seed_int), // rand_seed:Integer - block::CurrencyCollection(balance).as_vm_tuple(), // balance_remaining:[Integer (Maybe Cell)] - vm::load_cell_slice_ref(vm::CellBuilder().finalize()) // myself:MsgAddressInt - //vm::StackEntry::maybe(td::Ref()) + block::CurrencyCollection(args.balance).as_vm_tuple(), // balance_remaining:[Integer (Maybe Cell)] + vm::load_cell_slice_ref(address), // myself:MsgAddressInt + vm::StackEntry::maybe(config) //vm::StackEntry::maybe(td::Ref()) ); // global_config:(Maybe Cell) ] = SmartContractInfo; //LOG(DEBUG) << "SmartContractInfo initialized with " << vm::StackEntry(tuple).to_string(); return vm::make_tuple_ref(std::move(tuple)); } SmartContract::Answer run_smartcont(SmartContract::State state, td::Ref stack, td::Ref c7, - vm::GasLimits gas, bool ignore_chksig) { + vm::GasLimits gas, bool ignore_chksig, td::Ref libraries) { auto gas_credit = gas.gas_credit; vm::init_op_cp0(); vm::DictionaryBase::get_empty_dictionary(); @@ -108,11 +129,14 @@ SmartContract::Answer run_smartcont(SmartContract::State state, td::Ref SmartContract::get_init_state() const { } SmartContract::Answer SmartContract::run_method(Args args) { - td::uint32 now = 0; - if (args.now) { - now = args.now.unwrap(); - } if (!args.c7) { - args.c7 = prepare_vm_c7(now, args.balance); + args.c7 = prepare_vm_c7(args); } if (!args.limits) { bool is_internal = args.get_method_id().ok() == 0; @@ -193,18 +217,15 @@ SmartContract::Answer SmartContract::run_method(Args args) { CHECK(args.method_id); args.stack.value().write().push_smallint(args.method_id.unwrap()); auto res = - run_smartcont(get_state(), args.stack.unwrap(), args.c7.unwrap(), args.limits.unwrap(), args.ignore_chksig); + run_smartcont(get_state(), args.stack.unwrap(), args.c7.unwrap(), args.limits.unwrap(), args.ignore_chksig, + args.libraries ? args.libraries.unwrap().get_root_cell() : td::Ref{}); state_ = res.new_state; return res; } SmartContract::Answer SmartContract::run_get_method(Args args) const { - td::uint32 now = 0; - if (args.now) { - now = args.now.unwrap(); - } if (!args.c7) { - args.c7 = prepare_vm_c7(now, args.balance); + args.c7 = prepare_vm_c7(args); } if (!args.limits) { args.limits = vm::GasLimits{1000000}; @@ -214,7 +235,8 @@ SmartContract::Answer SmartContract::run_get_method(Args args) const { } CHECK(args.method_id); args.stack.value().write().push_smallint(args.method_id.unwrap()); - return run_smartcont(get_state(), args.stack.unwrap(), args.c7.unwrap(), args.limits.unwrap(), args.ignore_chksig); + return run_smartcont(get_state(), args.stack.unwrap(), args.c7.unwrap(), args.limits.unwrap(), args.ignore_chksig, + args.libraries ? args.libraries.unwrap().get_root_cell() : td::Ref{}); } SmartContract::Answer SmartContract::run_get_method(td::Slice method, Args args) const { diff --git a/crypto/smc-envelope/SmartContract.h b/crypto/smc-envelope/SmartContract.h index b26f4885e..95dd2e84a 100644 --- a/crypto/smc-envelope/SmartContract.h +++ b/crypto/smc-envelope/SmartContract.h @@ -26,6 +26,7 @@ #include "td/utils/crypto.h" #include "block/block.h" +#include "block/mc-config.h" namespace ton { class SmartContract : public td::CntObject { @@ -48,6 +49,7 @@ class SmartContract : public td::CntObject { td::Ref actions; td::int32 code; td::int64 gas_used; + td::ConstBitPtr missing_library{0}; static int output_actions_count(td::Ref list); }; @@ -61,6 +63,10 @@ class SmartContract : public td::CntObject { td::uint64 amount{0}; td::uint64 balance{0}; + td::optional address; + td::optional> config; + td::optional libraries; + Args() { } Args(std::initializer_list stack) @@ -106,6 +112,18 @@ class SmartContract : public td::CntObject { this->balance = balance; return std::move(*this); } + Args&& set_address(block::StdAddress address) { + this->address = address; + return std::move(*this); + } + Args&& set_config(std::shared_ptr& config) { + this->config = config; + return std::move(*this); + } + Args&& set_libraries(vm::Dictionary libraries) { + this->libraries = libraries; + return std::move(*this); + } td::Result get_method_id() const { if (!method_id) { diff --git a/crypto/vm/vm.cpp b/crypto/vm/vm.cpp index 038640a58..fb2f4d1e8 100644 --- a/crypto/vm/vm.cpp +++ b/crypto/vm/vm.cpp @@ -604,6 +604,7 @@ Ref VmState::load_library(td::ConstBitPtr hash) { return lib; } } + missing_library = hash; return {}; } diff --git a/crypto/vm/vm.h b/crypto/vm/vm.h index 0fef96428..44aa7f231 100644 --- a/crypto/vm/vm.h +++ b/crypto/vm/vm.h @@ -96,6 +96,7 @@ class VmState final : public VmStateInterface { td::int64 loaded_cells_count{0}; int stack_trace{0}, debug_off{0}; bool chksig_always_succeed{false}; + td::ConstBitPtr missing_library{0}; public: enum { @@ -321,6 +322,9 @@ class VmState final : public VmStateInterface { Ref ref_to_cont(Ref cell) const { return td::make_ref(load_cell_slice_ref(std::move(cell)), get_cp()); } + td::ConstBitPtr get_missing_library() const { + return missing_library; + } private: void init_cregs(bool same_c3 = false, bool push_0 = true); diff --git a/tonlib/tonlib/LastConfig.cpp b/tonlib/tonlib/LastConfig.cpp index d07482cec..0111095bc 100644 --- a/tonlib/tonlib/LastConfig.cpp +++ b/tonlib/tonlib/LastConfig.cpp @@ -62,9 +62,7 @@ void LastConfig::with_last_block(td::Result r_last_block) { } auto last_block = r_last_block.move_as_ok(); - auto params = params_; - client_.send_query(ton::lite_api::liteServer_getConfigParams(0, create_tl_lite_block_id(last_block.last_block_id), - std::move(params)), + client_.send_query(ton::lite_api::liteServer_getConfigAll(0, create_tl_lite_block_id(last_block.last_block_id)), [this](auto r_config) { this->on_config(std::move(r_config)); }); } diff --git a/tonlib/tonlib/TonlibClient.cpp b/tonlib/tonlib/TonlibClient.cpp index 1ac3a0d72..422dae125 100644 --- a/tonlib/tonlib/TonlibClient.cpp +++ b/tonlib/tonlib/TonlibClient.cpp @@ -861,13 +861,13 @@ class Query { } return res; } - td::Result>> estimate_fees(bool ignore_chksig, const block::Config& cfg) { + td::Result>> estimate_fees(bool ignore_chksig, std::shared_ptr& cfg, vm::Dictionary& libraries) { // gas fees bool is_masterchain = raw_.source->get_address().workchain == ton::masterchainId; - TRY_RESULT(gas_limits_prices, cfg.get_gas_limits_prices(is_masterchain)); - TRY_RESULT(storage_prices, cfg.get_storage_prices()); - TRY_RESULT(masterchain_msg_prices, cfg.get_msg_prices(true)); - TRY_RESULT(basechain_msg_prices, cfg.get_msg_prices(false)); + TRY_RESULT(gas_limits_prices, cfg->get_gas_limits_prices(is_masterchain)); + TRY_RESULT(storage_prices, cfg->get_storage_prices()); + TRY_RESULT(masterchain_msg_prices, cfg->get_msg_prices(true)); + TRY_RESULT(basechain_msg_prices, cfg->get_msg_prices(false)); block::MsgPrices* msg_prices[2] = {&basechain_msg_prices, &masterchain_msg_prices}; auto storage_fee_256 = block::StoragePrices::compute_storage_fees( raw_.source->get_sync_time(), storage_prices, raw_.source->raw().storage_stat, @@ -888,7 +888,9 @@ class Query { .set_limits(gas_limits) .set_balance(raw_.source->get_balance()) .set_now(raw_.source->get_sync_time()) - .set_ignore_chksig(ignore_chksig)); + .set_ignore_chksig(ignore_chksig) + .set_address(raw_.source->get_address()) + .set_config(cfg).set_libraries(libraries)); td::int64 fwd_fee = 0; if (res.success) { LOG(DEBUG) << "output actions:\n" @@ -910,7 +912,7 @@ class Query { for (auto& destination : raw_.destinations) { bool dest_is_masterchain = destination && destination->get_address().workchain == ton::masterchainId; - TRY_RESULT(dest_gas_limits_prices, cfg.get_gas_limits_prices(dest_is_masterchain)); + TRY_RESULT(dest_gas_limits_prices, cfg->get_gas_limits_prices(dest_is_masterchain)); auto dest_storage_fee_256 = destination ? block::StoragePrices::compute_storage_fees( destination->get_sync_time(), storage_prices, destination->raw().storage_stat, @@ -3266,7 +3268,7 @@ void TonlibClient::query_estimate_fees(td::int64 id, bool ignore_chksig, td::Res return; } TRY_RESULT_PROMISE(promise, state, std::move(r_state)); - TRY_RESULT_PROMISE_PREFIX(promise, fees, TRY_VM(it->second->estimate_fees(ignore_chksig, *state.config)), + TRY_RESULT_PROMISE_PREFIX(promise, fees, TRY_VM(it->second->estimate_fees(ignore_chksig, state.config, libraries)), TonlibError::Internal()); promise.set_value(tonlib_api::make_object( fees.first.to_tonlib_api(), td::transform(fees.second, [](auto& x) { return x.to_tonlib_api(); }))); @@ -3493,14 +3495,29 @@ td::Status TonlibClient::do_request(const tonlib_api::smc_runGetMethod& request, args.set_stack(std::move(stack)); args.set_balance(it->second->get_balance()); args.set_now(it->second->get_sync_time()); - auto res = smc->run_get_method(std::move(args)); + args.set_address(it->second->get_address()); - // smc.runResult gas_used:int53 stack:vector exit_code:int32 = smc.RunResult; - std::vector> res_stack; - for (auto& entry : res.stack->as_span()) { - res_stack.push_back(to_tonlib_api(entry)); + auto code = smc->get_state().code; + if (code.not_null()) { + std::vector libraryList; } - promise.set_value(tonlib_api::make_object(res.gas_used, std::move(res_stack), res.code)); + + args.set_libraries(libraries); + + client_.with_last_config([smc=std::move(smc), args=std::move(args), + promise = std::move(promise)](td::Result r_state) mutable { + TRY_RESULT_PROMISE(promise, state, std::move(r_state)); + args.set_config(state.config); + + auto res = smc->run_get_method(std::move(args)); + + // smc.runResult gas_used:int53 stack:vector exit_code:int32 = smc.RunResult; + std::vector> res_stack; + for (auto& entry : res.stack->as_span()) { + res_stack.push_back(to_tonlib_api(entry)); + } + promise.set_value(tonlib_api::make_object(res.gas_used, std::move(res_stack), res.code)); + }); return td::Status::OK(); } diff --git a/tonlib/tonlib/TonlibClient.h b/tonlib/tonlib/TonlibClient.h index bedc1d496..4dfbe8c60 100644 --- a/tonlib/tonlib/TonlibClient.h +++ b/tonlib/tonlib/TonlibClient.h @@ -107,6 +107,7 @@ class TonlibClient : public td::actor::Actor { td::optional block_id; }; QueryContext query_context_; + vm::Dictionary libraries{256}; // network td::actor::ActorOwn raw_client_; From d5881dfade8c741c579815b844f040d2d16c3cd5 Mon Sep 17 00:00:00 2001 From: Starlight Duck Date: Fri, 21 Jan 2022 03:43:35 +0200 Subject: [PATCH 26/29] Add liteapi method to get libraries --- tl/generate/scheme/lite_api.tl | 3 +++ tl/generate/scheme/lite_api.tlo | Bin 12416 -> 12896 bytes validator/impl/liteserver.cpp | 21 +++++++++++++++++++++ validator/impl/liteserver.hpp | 1 + 4 files changed, 25 insertions(+) diff --git a/tl/generate/scheme/lite_api.tl b/tl/generate/scheme/lite_api.tl index 7d4495e72..d31ef5695 100644 --- a/tl/generate/scheme/lite_api.tl +++ b/tl/generate/scheme/lite_api.tl @@ -25,6 +25,7 @@ adnl.message.answer query_id:int256 answer:bytes = adnl.Message; liteServer.error code:int message:string = liteServer.Error; liteServer.accountId workchain:int id:int256 = liteServer.AccountId; +liteServer.libraryEntry hash:int256 data:bytes = liteServer.LibraryEntry; liteServer.masterchainInfo last:tonNode.blockIdExt state_root_hash:int256 init:tonNode.zeroStateIdExt = liteServer.MasterchainInfo; liteServer.masterchainInfoExt mode:# version:int capabilities:long last:tonNode.blockIdExt last_utime:int now:int state_root_hash:int256 init:tonNode.zeroStateIdExt = liteServer.MasterchainInfoExt; @@ -50,6 +51,7 @@ liteServer.blockLinkForward to_key_block:Bool from:tonNode.blockIdExt to:tonNode liteServer.partialBlockProof complete:Bool from:tonNode.blockIdExt to:tonNode.blockIdExt steps:(vector liteServer.BlockLink) = liteServer.PartialBlockProof; liteServer.configInfo mode:# id:tonNode.blockIdExt state_proof:bytes config_proof:bytes = liteServer.ConfigInfo; liteServer.validatorStats mode:# id:tonNode.blockIdExt count:int complete:Bool state_proof:bytes data_proof:bytes = liteServer.ValidatorStats; +liteServer.libraryResult result:(vector liteServer.libraryEntry) = liteServer.LibraryResult; liteServer.debug.verbosity value:int = liteServer.debug.Verbosity; @@ -75,6 +77,7 @@ liteServer.getBlockProof mode:# known_block:tonNode.blockIdExt target_block:mode liteServer.getConfigAll mode:# id:tonNode.blockIdExt = liteServer.ConfigInfo; liteServer.getConfigParams mode:# id:tonNode.blockIdExt param_list:(vector int) = liteServer.ConfigInfo; liteServer.getValidatorStats#091a58bc mode:# id:tonNode.blockIdExt limit:int start_after:mode.0?int256 modified_after:mode.2?int = liteServer.ValidatorStats; +liteServer.getLibraries library_list:(vector int256) = liteServer.LibraryResult; liteServer.queryPrefix = Object; liteServer.query data:bytes = Object; diff --git a/tl/generate/scheme/lite_api.tlo b/tl/generate/scheme/lite_api.tlo index d524f54b71f56584a42886ea5715b9f4c04b8dfc..eb8e321137b650cc7badcf44cee0f92b7db944b6 100644 GIT binary patch delta 340 zcmZoje2~KXXtur;0~F|OE-j$d-O~Uz4o};u2{ISqYF?AaM{Va%R)v zux&dCQolJz)P|2yV)IJn-ON@=+mtRMdpJF{1mfq+)M9kQd7!q(=VTU_Fie(`kei$! NE5ZUcGeTX1697XhbTI$` delta 51 zcmaEm(vZmeXtur;0~F|Nperform_runSmcMethod(ton::create_block_id(q.id_), static_cast(q.account_->workchain_), q.account_->id_, q.mode_, q.method_id_, std::move(q.params_)); }, + [&](lite_api::liteServer_getLibraries& q) { + this->perform_getLibraries(q.library_list_); + }, [&](auto& obj) { this->abort_query(td::Status::Error(ErrorCode::protoviolation, "unknown query")); })); } @@ -743,6 +746,24 @@ void LiteQuery::perform_runSmcMethod(BlockIdExt blkid, WorkchainId workchain, St perform_getAccountState(blkid, workchain, addr, mode | 0x10000); } +void LiteQuery::perform_getLibraries(std::vector library_list) { + LOG(INFO) << "started a getLibraries() liteserver query"; + auto rconfig = block::ConfigInfo::extract_config(mc_state_->root_cell(), block::ConfigInfo::needLibraries); + if (rconfig.is_error()) { + fatal_error("cannot extract library list block configuration from masterchain state"); + return; + } + auto config = rconfig.move_as_ok(); + std::vector> a; + for (const auto& hash : library_list) { + auto data = vm::std_boc_serialize(config->lookup_library(hash)); + if (data.is_ok()) + a.push_back(ton::create_tl_object(hash, data.move_as_ok())); + } + auto b = ton::create_serialize_tl_object(std::move(a)); + finish_query(std::move(b)); +} + void LiteQuery::perform_getOneTransaction(BlockIdExt blkid, WorkchainId workchain, StdSmcAddress addr, LogicalTime lt) { LOG(INFO) << "started a getOneTransaction(" << blkid.to_str() << ", " << workchain << ", " << addr.to_hex() << "," << lt << ") liteserver query"; diff --git a/validator/impl/liteserver.hpp b/validator/impl/liteserver.hpp index f6353c41d..b928c4bc8 100644 --- a/validator/impl/liteserver.hpp +++ b/validator/impl/liteserver.hpp @@ -103,6 +103,7 @@ class LiteQuery : public td::actor::Actor { td::BufferSlice params); void finish_runSmcMethod(td::BufferSlice shard_proof, td::BufferSlice state_proof, Ref acc_root, UnixTime gen_utime, LogicalTime gen_lt); + void perform_getLibraries(std::vector library_list); void perform_getOneTransaction(BlockIdExt blkid, WorkchainId workchain, StdSmcAddress addr, LogicalTime lt); void continue_getOneTransaction(); void perform_getTransactions(WorkchainId workchain, StdSmcAddress addr, LogicalTime lt, Bits256 hash, unsigned count); From 18f3e73ed2072501d605a3964f6c777a60e1e0de Mon Sep 17 00:00:00 2001 From: Starlight Duck Date: Sun, 23 Jan 2022 01:25:19 +0200 Subject: [PATCH 27/29] Complete libraries in LS and request+caching in TLC --- crypto/block/mc-config.cpp | 2 +- tonlib/tonlib/TonlibClient.cpp | 160 +++++++++++++++++++++++++++++---- tonlib/tonlib/TonlibClient.h | 6 +- validator/impl/liteserver.cpp | 49 +++++++++- validator/impl/liteserver.hpp | 1 + 5 files changed, 197 insertions(+), 21 deletions(-) diff --git a/crypto/block/mc-config.cpp b/crypto/block/mc-config.cpp index 07574ef1b..003cd04bf 100644 --- a/crypto/block/mc-config.cpp +++ b/crypto/block/mc-config.cpp @@ -2100,7 +2100,7 @@ Ref ConfigInfo::lookup_library(td::ConstBitPtr root_hash) const { return {}; } auto csr = libraries_dict_->lookup(root_hash, 256); - if (csr.is_null() || csr->prefetch_ulong(8) != 0 || !csr->have_refs()) { // shared_lib_descr$00 lib:^Cell + if (csr.is_null() || csr->prefetch_ulong(2) != 0 || !csr->have_refs()) { // shared_lib_descr$00 lib:^Cell return {}; } auto lib = csr->prefetch_ref(); diff --git a/tonlib/tonlib/TonlibClient.cpp b/tonlib/tonlib/TonlibClient.cpp index 422dae125..3c4d56eaf 100644 --- a/tonlib/tonlib/TonlibClient.cpp +++ b/tonlib/tonlib/TonlibClient.cpp @@ -1889,6 +1889,8 @@ td::Status TonlibClient::do_request(const tonlib_api::init& request, TRY_RESULT(kv, std::move(r_kv)); kv_ = std::shared_ptr(kv.release()); + load_libs_from_disk(); + key_storage_.set_key_value(kv_); last_block_storage_.set_key_value(kv_); auto res = tonlib_api::make_object(); @@ -3474,6 +3476,30 @@ td::Result from_tonlib_api(tonlib_api::tvm_StackEntry& entry) { })); } +void deep_library_search(std::vector& list, vm::Dictionary libs, td::Ref cell, int depth) { + if (depth <= 0) + return; + auto r_loaded_cell = cell->load_cell(); + if (r_loaded_cell.is_error()) { + return; + } + auto loaded_cell = r_loaded_cell.move_as_ok(); + if (loaded_cell.data_cell->is_special()) { + if (loaded_cell.data_cell->special_type() == vm::DataCell::SpecialType::Library) { + vm::CellSlice cs(std::move(loaded_cell)); + if (cs.size() != vm::Cell::hash_bits + 8) + return; + auto key = td::Bits256(cs.data_bits() + 8); + if (libs.lookup(key).is_null()) + list.push_back(key); + } + return; + } + for (unsigned int i=0; iget_refs_cnt(); i++) { + deep_library_search(list, libs, loaded_cell.data_cell->get_ref(i), depth - 1); + } +} + td::Status TonlibClient::do_request(const tonlib_api::smc_runGetMethod& request, td::Promise>&& promise) { auto it = smcs_.find(request.id_); @@ -3497,30 +3523,114 @@ td::Status TonlibClient::do_request(const tonlib_api::smc_runGetMethod& request, args.set_now(it->second->get_sync_time()); args.set_address(it->second->get_address()); - auto code = smc->get_state().code; - if (code.not_null()) { - std::vector libraryList; - } - - args.set_libraries(libraries); - - client_.with_last_config([smc=std::move(smc), args=std::move(args), - promise = std::move(promise)](td::Result r_state) mutable { + client_.with_last_config([self = this, smc = std::move(smc), args = std::move(args), promise = std::move(promise) + ](td::Result r_state) mutable { TRY_RESULT_PROMISE(promise, state, std::move(r_state)); args.set_config(state.config); - auto res = smc->run_get_method(std::move(args)); - - // smc.runResult gas_used:int53 stack:vector exit_code:int32 = smc.RunResult; - std::vector> res_stack; - for (auto& entry : res.stack->as_span()) { - res_stack.push_back(to_tonlib_api(entry)); + auto code = smc->get_state().code; + if (code.not_null()) { + std::vector libraryList; + deep_library_search(libraryList, self->libraries, code, 20); + if (libraryList.size() > 0) { + LOG(DEBUG) << "Requesting found libraries in code (" << libraryList.size() << ")"; + self->client_.send_query(ton::lite_api::liteServer_getLibraries(std::move(libraryList)), + [self, smc = std::move(smc), args = std::move(args), promise = std::move(promise)] + (td::Result> r_libraries) mutable + { + if (r_libraries.is_error()) { + LOG(WARNING) << "cannot obtain found libraries: " << r_libraries.move_as_error().to_string(); + } else { + auto libraries = r_libraries.move_as_ok(); + bool updated = false; + for (auto& lr : libraries->result_) { + auto contents = vm::std_boc_deserialize(lr->data_); + if (contents.is_ok() && contents.ok().not_null()) { + if (contents.ok()->get_hash().bits().compare(lr->hash_.cbits(), 256)) { + LOG(WARNING) << "hash mismatch for library " << lr->hash_.to_hex(); + continue; + } + self->libraries.set_ref(lr->hash_, contents.move_as_ok()); + updated = true; + LOG(DEBUG) << "registered library " << lr->hash_.to_hex(); + } else { + LOG(WARNING) << "failed to deserialize library: " << lr->hash_.to_hex(); + } + } + if (updated) + self->store_libs_to_disk(); + } + self->perform_smc_execution(std::move(smc), std::move(args), std::move(promise)); + }); + } + else + self->perform_smc_execution(std::move(smc), std::move(args), std::move(promise)); } - promise.set_value(tonlib_api::make_object(res.gas_used, std::move(res_stack), res.code)); + else + self->perform_smc_execution(std::move(smc), std::move(args), std::move(promise)); }); return td::Status::OK(); } +void TonlibClient::perform_smc_execution(td::Ref smc, ton::SmartContract::Args args, + td::Promise>&& promise) { + + args.set_libraries(libraries); + + auto res = smc->run_get_method(args); + + // smc.runResult gas_used:int53 stack:vector exit_code:int32 = smc.RunResult; + std::vector> res_stack; + for (auto& entry : res.stack->as_span()) { + res_stack.push_back(to_tonlib_api(entry)); + } + + if (res.missing_library.not_null()) { + td::Bits256 hash = res.missing_library; + LOG(DEBUG) << "Requesting missing library: " << hash.to_hex(); + std::vector req = {std::move(hash)}; + client_.send_query(ton::lite_api::liteServer_getLibraries(std::move(req)), + [self = this, res = std::move(res), res_stack = std::move(res_stack), hash = std::move(hash), + smc = std::move(smc), args = std::move(args), promise = std::move(promise)] + (td::Result> r_libraries) mutable + { + if (r_libraries.is_error()) { + LOG(WARNING) << "cannot obtain missing library: " << r_libraries.move_as_error().to_string(); + promise.set_value(tonlib_api::make_object(res.gas_used, std::move(res_stack), res.code)); + return; + } + bool found = false, updated = false; + auto libraries = r_libraries.move_as_ok(); + for (auto& lr : libraries->result_) { + auto contents = vm::std_boc_deserialize(lr->data_); + if (contents.is_ok() && contents.ok().not_null()) { + if (contents.ok()->get_hash().bits().compare(lr->hash_.cbits(), 256)) { + LOG(WARNING) << "hash mismatch for library " << lr->hash_.to_hex(); + continue; + } + found |= (lr->hash_ == hash); + updated = true; + self->libraries.set_ref(lr->hash_, contents.move_as_ok()); + LOG(DEBUG) << "registered library " << lr->hash_.to_hex(); + } else { + LOG(WARNING) << "failed to deserialize library: " << lr->hash_.to_hex(); + } + } + if (updated) + self->store_libs_to_disk(); + if (!found) { + LOG(WARNING) << "cannot obtain library " << hash.to_hex() << ", it may not exist"; + promise.set_value(tonlib_api::make_object(res.gas_used, std::move(res_stack), res.code)); + } else { + self->perform_smc_execution(std::move(smc), std::move(args), std::move(promise)); + } + }); + } + else { + promise.set_value(tonlib_api::make_object(res.gas_used, std::move(res_stack), res.code)); + } +} + td::Result> to_tonlib_api( const ton::ManualDns::EntryData& entry_data) { td::Result> res; @@ -4246,6 +4356,24 @@ td::Status TonlibClient::do_request(const tonlib_api::blocks_getBlockHeader& req return td::Status::OK(); } +void TonlibClient::load_libs_from_disk() { + LOG(DEBUG) << "loading libraries from disk cache"; + auto r_data = kv_->get("tonlib.libcache"); + if (r_data.is_error()) return; + auto r_dict = vm::std_boc_deserialize(r_data.move_as_ok(), true); + if (r_dict.is_error()) return; + libraries = vm::Dictionary(vm::load_cell_slice(vm::CellBuilder().append_cellslice(vm::load_cell_slice( + r_dict.move_as_ok())).finalize()), 256); + int n = 0; for (auto&& lr : libraries) n++; + LOG(DEBUG) << "loaded " << n << " libraries from disk cache"; +} + +void TonlibClient::store_libs_to_disk() { // NB: Dictionary.get_root_cell does not compute_root, and it is protected + kv_->set("tonlib.libcache", vm::std_boc_serialize(vm::CellBuilder().append_cellslice(libraries.get_root()) + .finalize()).move_as_ok().as_slice()); + int n = 0; for (auto&& lr : libraries) n++; + LOG(DEBUG) << "stored " << n << " libraries to disk cache"; +} template td::Status TonlibClient::do_request(const tonlib_api::runTests& request, P&&) { diff --git a/tonlib/tonlib/TonlibClient.h b/tonlib/tonlib/TonlibClient.h index 4dfbe8c60..6d80c152a 100644 --- a/tonlib/tonlib/TonlibClient.h +++ b/tonlib/tonlib/TonlibClient.h @@ -322,7 +322,8 @@ class TonlibClient : public td::actor::Actor { td::Status do_request(tonlib_api::pchan_unpackPromise& request, td::Promise>&& promise); - + void perform_smc_execution(td::Ref smc, ton::SmartContract::Args args, + td::Promise>&& promise); void do_dns_request(std::string name, td::int32 category, td::int32 ttl, td::optional block_id, block::StdAddress address, td::Promise>&& promise); @@ -358,6 +359,9 @@ class TonlibClient : public td::actor::Actor { void proxy_request(td::int64 query_id, std::string data); + void load_libs_from_disk(); + void store_libs_to_disk(); + friend class TonlibQueryActor; struct Target { bool can_be_empty{true}; diff --git a/validator/impl/liteserver.cpp b/validator/impl/liteserver.cpp index 71263c735..079ea5cea 100644 --- a/validator/impl/liteserver.cpp +++ b/validator/impl/liteserver.cpp @@ -748,17 +748,60 @@ void LiteQuery::perform_runSmcMethod(BlockIdExt blkid, WorkchainId workchain, St void LiteQuery::perform_getLibraries(std::vector library_list) { LOG(INFO) << "started a getLibraries() liteserver query"; + td::actor::send_closure_later( + manager_, &ton::validator::ValidatorManager::get_top_masterchain_state_block, + [Self = actor_id(this), library_list](td::Result, BlockIdExt>> res) -> void { + if (res.is_error()) { + td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error()); + } else { + auto pair = res.move_as_ok(); + td::actor::send_closure_later(Self, &LiteQuery::continue_getLibraries, std::move(pair.first), + pair.second, library_list); + } + }); +} + +void LiteQuery::continue_getLibraries(Ref mc_state, BlockIdExt blkid, std::vector library_list) { + LOG(INFO) << "obtained last masterchain block = " << blkid.to_str(); + base_blk_id_ = blkid; + CHECK(mc_state.not_null()); + mc_state_ = Ref(std::move(mc_state)); + CHECK(mc_state_.not_null()); + auto rconfig = block::ConfigInfo::extract_config(mc_state_->root_cell(), block::ConfigInfo::needLibraries); if (rconfig.is_error()) { fatal_error("cannot extract library list block configuration from masterchain state"); return; } auto config = rconfig.move_as_ok(); + + if (false) { + std::ostringstream os; + vm::load_cell_slice(config->get_libraries_root()).print_rec(os); + LOG(INFO) << "\n" << os.str(); + + auto lib_dict = std::make_unique(config->get_libraries_root(), 256); + for (auto k: *lib_dict) { + std::ostringstream oss; + k.second->print_rec(oss); + LOG(INFO) << "library " << k.first.to_hex(256) << ": \n" << oss.str(); + } + } + std::vector> a; for (const auto& hash : library_list) { - auto data = vm::std_boc_serialize(config->lookup_library(hash)); - if (data.is_ok()) - a.push_back(ton::create_tl_object(hash, data.move_as_ok())); + LOG(INFO) << "looking for library " << hash.to_hex(); + auto libres = config->lookup_library(hash); + if (libres.is_null()) { + LOG(INFO) << "library lookup result is null"; + continue; + } + auto data = vm::std_boc_serialize(libres); + if (data.is_error()) { + LOG(WARNING) << "library serialization failed: " << data.move_as_error().to_string(); + continue; + } + a.push_back(ton::create_tl_object(hash, data.move_as_ok())); } auto b = ton::create_serialize_tl_object(std::move(a)); finish_query(std::move(b)); diff --git a/validator/impl/liteserver.hpp b/validator/impl/liteserver.hpp index b928c4bc8..aefa84e56 100644 --- a/validator/impl/liteserver.hpp +++ b/validator/impl/liteserver.hpp @@ -104,6 +104,7 @@ class LiteQuery : public td::actor::Actor { void finish_runSmcMethod(td::BufferSlice shard_proof, td::BufferSlice state_proof, Ref acc_root, UnixTime gen_utime, LogicalTime gen_lt); void perform_getLibraries(std::vector library_list); + void continue_getLibraries(Ref mc_state, BlockIdExt blkid, std::vector library_list); void perform_getOneTransaction(BlockIdExt blkid, WorkchainId workchain, StdSmcAddress addr, LogicalTime lt); void continue_getOneTransaction(); void perform_getTransactions(WorkchainId workchain, StdSmcAddress addr, LogicalTime lt, Bits256 hash, unsigned count); From e9c40b4ae940b695564d03dae031ac63322bf992 Mon Sep 17 00:00:00 2001 From: Starlight Duck Date: Tue, 25 Jan 2022 00:42:48 +0200 Subject: [PATCH 28/29] add some safeguards and fix code style --- crypto/smc-envelope/SmartContract.cpp | 3 +- tonlib/tonlib/TonlibClient.cpp | 54 ++++++++++++++++++--------- validator/impl/liteserver.cpp | 6 +++ 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/crypto/smc-envelope/SmartContract.cpp b/crypto/smc-envelope/SmartContract.cpp index 30030aae0..2e7e2cd28 100644 --- a/crypto/smc-envelope/SmartContract.cpp +++ b/crypto/smc-envelope/SmartContract.cpp @@ -129,8 +129,9 @@ SmartContract::Answer run_smartcont(SmartContract::State state, td::Ref from_tonlib_api(tonlib_api::tvm_StackEntry& entry) { })); } -void deep_library_search(std::vector& list, vm::Dictionary libs, td::Ref cell, int depth) { - if (depth <= 0) +void deep_library_search(std::set& set, std::set& visited, + vm::Dictionary libs, td::Ref cell, int depth) { + if (depth <= 0 || set.size() >= 127 || visited.size() >= 1000) { return; + } + auto ins = visited.insert(cell->get_hash()); + if (!ins.second) { + return; // already visited this cell + } auto r_loaded_cell = cell->load_cell(); if (r_loaded_cell.is_error()) { return; @@ -3487,16 +3493,18 @@ void deep_library_search(std::vector& list, vm::Dictionary libs, td if (loaded_cell.data_cell->is_special()) { if (loaded_cell.data_cell->special_type() == vm::DataCell::SpecialType::Library) { vm::CellSlice cs(std::move(loaded_cell)); - if (cs.size() != vm::Cell::hash_bits + 8) + if (cs.size() != vm::Cell::hash_bits + 8) { return; + } auto key = td::Bits256(cs.data_bits() + 8); - if (libs.lookup(key).is_null()) - list.push_back(key); + if (libs.lookup(key).is_null()) { + set.insert(key); + } } return; } for (unsigned int i=0; iget_refs_cnt(); i++) { - deep_library_search(list, libs, loaded_cell.data_cell->get_ref(i), depth - 1); + deep_library_search(set, visited, libs, loaded_cell.data_cell->get_ref(i), depth - 1); } } @@ -3530,8 +3538,10 @@ td::Status TonlibClient::do_request(const tonlib_api::smc_runGetMethod& request, auto code = smc->get_state().code; if (code.not_null()) { - std::vector libraryList; - deep_library_search(libraryList, self->libraries, code, 20); + std::set librarySet; + std::set visited; + deep_library_search(librarySet, visited, self->libraries, code, 20); + std::vector libraryList{librarySet.begin(), librarySet.end()}; if (libraryList.size() > 0) { LOG(DEBUG) << "Requesting found libraries in code (" << libraryList.size() << ")"; self->client_.send_query(ton::lite_api::liteServer_getLibraries(std::move(libraryList)), @@ -3557,17 +3567,20 @@ td::Status TonlibClient::do_request(const tonlib_api::smc_runGetMethod& request, LOG(WARNING) << "failed to deserialize library: " << lr->hash_.to_hex(); } } - if (updated) + if (updated) { self->store_libs_to_disk(); + } } self->perform_smc_execution(std::move(smc), std::move(args), std::move(promise)); }); } - else + else { self->perform_smc_execution(std::move(smc), std::move(args), std::move(promise)); + } } - else + else { self->perform_smc_execution(std::move(smc), std::move(args), std::move(promise)); + } }); return td::Status::OK(); } @@ -3616,8 +3629,9 @@ void TonlibClient::perform_smc_execution(td::Ref smc, ton::S LOG(WARNING) << "failed to deserialize library: " << lr->hash_.to_hex(); } } - if (updated) + if (updated) { self->store_libs_to_disk(); + } if (!found) { LOG(WARNING) << "cannot obtain library " << hash.to_hex() << ", it may not exist"; promise.set_value(tonlib_api::make_object(res.gas_used, std::move(res_stack), res.code)); @@ -4359,20 +4373,24 @@ td::Status TonlibClient::do_request(const tonlib_api::blocks_getBlockHeader& req void TonlibClient::load_libs_from_disk() { LOG(DEBUG) << "loading libraries from disk cache"; auto r_data = kv_->get("tonlib.libcache"); - if (r_data.is_error()) return; + if (r_data.is_error()) { + return; + } auto r_dict = vm::std_boc_deserialize(r_data.move_as_ok(), true); - if (r_dict.is_error()) return; + if (r_dict.is_error()) { + return; + } libraries = vm::Dictionary(vm::load_cell_slice(vm::CellBuilder().append_cellslice(vm::load_cell_slice( r_dict.move_as_ok())).finalize()), 256); - int n = 0; for (auto&& lr : libraries) n++; - LOG(DEBUG) << "loaded " << n << " libraries from disk cache"; + // int n = 0; for (auto&& lr : libraries) n++; + LOG(DEBUG) << "loaded libraries from disk cache"; } void TonlibClient::store_libs_to_disk() { // NB: Dictionary.get_root_cell does not compute_root, and it is protected kv_->set("tonlib.libcache", vm::std_boc_serialize(vm::CellBuilder().append_cellslice(libraries.get_root()) .finalize()).move_as_ok().as_slice()); - int n = 0; for (auto&& lr : libraries) n++; - LOG(DEBUG) << "stored " << n << " libraries to disk cache"; + // int n = 0; for (auto&& lr : libraries) n++; + LOG(DEBUG) << "stored libraries to disk cache"; } template diff --git a/validator/impl/liteserver.cpp b/validator/impl/liteserver.cpp index 079ea5cea..3f97c2060 100644 --- a/validator/impl/liteserver.cpp +++ b/validator/impl/liteserver.cpp @@ -748,6 +748,12 @@ void LiteQuery::perform_runSmcMethod(BlockIdExt blkid, WorkchainId workchain, St void LiteQuery::perform_getLibraries(std::vector library_list) { LOG(INFO) << "started a getLibraries() liteserver query"; + if (library_list.size() > 127) { + LOG(INFO) << "too many libraries requested, returning only first 127"; + library_list.resize(127); + } + sort( library_list.begin(), library_list.end() ); + library_list.erase( unique( library_list.begin(), library_list.end() ), library_list.end() ); td::actor::send_closure_later( manager_, &ton::validator::ValidatorManager::get_top_masterchain_state_block, [Self = actor_id(this), library_list](td::Result, BlockIdExt>> res) -> void { From a19d6bc3f8f0c12caa172453d076a2072fab322d Mon Sep 17 00:00:00 2001 From: Starlight Duck Date: Tue, 25 Jan 2022 20:16:26 +0200 Subject: [PATCH 29/29] adjust limits for new requests --- tonlib/tonlib/TonlibClient.cpp | 4 ++-- validator/impl/liteserver.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tonlib/tonlib/TonlibClient.cpp b/tonlib/tonlib/TonlibClient.cpp index 0b4d1dc3e..be2fe6c21 100644 --- a/tonlib/tonlib/TonlibClient.cpp +++ b/tonlib/tonlib/TonlibClient.cpp @@ -3478,7 +3478,7 @@ td::Result from_tonlib_api(tonlib_api::tvm_StackEntry& entry) { void deep_library_search(std::set& set, std::set& visited, vm::Dictionary libs, td::Ref cell, int depth) { - if (depth <= 0 || set.size() >= 127 || visited.size() >= 1000) { + if (depth <= 0 || set.size() >= 16 || visited.size() >= 256) { return; } auto ins = visited.insert(cell->get_hash()); @@ -3540,7 +3540,7 @@ td::Status TonlibClient::do_request(const tonlib_api::smc_runGetMethod& request, if (code.not_null()) { std::set librarySet; std::set visited; - deep_library_search(librarySet, visited, self->libraries, code, 20); + deep_library_search(librarySet, visited, self->libraries, code, 24); std::vector libraryList{librarySet.begin(), librarySet.end()}; if (libraryList.size() > 0) { LOG(DEBUG) << "Requesting found libraries in code (" << libraryList.size() << ")"; diff --git a/validator/impl/liteserver.cpp b/validator/impl/liteserver.cpp index 3f97c2060..b3bab00f4 100644 --- a/validator/impl/liteserver.cpp +++ b/validator/impl/liteserver.cpp @@ -748,9 +748,9 @@ void LiteQuery::perform_runSmcMethod(BlockIdExt blkid, WorkchainId workchain, St void LiteQuery::perform_getLibraries(std::vector library_list) { LOG(INFO) << "started a getLibraries() liteserver query"; - if (library_list.size() > 127) { - LOG(INFO) << "too many libraries requested, returning only first 127"; - library_list.resize(127); + if (library_list.size() > 16) { + LOG(INFO) << "too many libraries requested, returning only first 16"; + library_list.resize(16); } sort( library_list.begin(), library_list.end() ); library_list.erase( unique( library_list.begin(), library_list.end() ), library_list.end() );