Skip to content

Commit 30891a1

Browse files
Merge pull request #4 from toncenter/develop
Added support for custom TON submodule
2 parents e91c633 + bbc015e commit 30891a1

File tree

10 files changed

+61
-16
lines changed

10 files changed

+61
-16
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,4 @@ sandbox/
219219
.vscode/
220220
.idea/
221221
.DS_Store
222+
.git/

Dockerfile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,36 @@ RUN DEBIAN_FRONTEND=noninteractive apt update -y \
1010
libhiredis-dev libidn11-dev libjemalloc2 libjemalloc-dev libkrb5-dev libldap2-dev liblz4-dev \
1111
libnghttp2-dev libpugixml-dev libsnappy-dev libsasl2-dev libssl-dev libxxhash-dev libyaml-cpp0.8 libyaml-cpp-dev \
1212
libzstd-dev libssh2-1-dev netbase python3-dev python3-jinja2 python3-venv python3-yaml \
13-
ragel yasm zlib1g-dev liblzma-dev libre2-dev clang-format gcc g++ yq \
13+
ragel yasm zlib1g-dev liblzma-dev libre2-dev clang-format gcc g++ yq gdb \
1414
&& rm -rf /var/lib/apt/lists/*
1515

1616
ENV CC=/usr/bin/clang
1717
ENV CXX=/usr/bin/clang++
1818
ENV CCACHE_DISABLE=1
19-
ENV USERVER_FEATURE_CRYPTOPP_BLAKE2=0
2019
ENV BUILD_TON_PLAYGROUND=1
20+
ENV USERVER_FEATURE_STACK_USAGE_MONITOR=1
2121

2222
COPY examples/ /app/examples/
2323
COPY py/ /app/py/
24-
COPY external/ /app/external/
2524
COPY tonlib-multiclient/ /app/tonlib-multiclient/
2625
COPY ton-http-api/ /app/ton-http-api/
2726
COPY playground/ /app/playground/
2827
COPY CMakeLists.txt /app/CMakeLists.txt
28+
COPY external/ /app/external/
29+
30+
ARG TON_REPO
31+
ARG TON_BRANCH
32+
RUN if [ -n "$TON_REPO" ]; then \
33+
echo "Using ton from ${TON_REPO}:${TON_BRANCH:-master}"; \
34+
rm -rf /app/external/ton/ && \
35+
git clone --recursive --branch ${TON_BRANCH:-master} ${TON_REPO} /app/external/ton; \
36+
else \
37+
echo "Using ton submodule"; \
38+
fi
2939

3040
WORKDIR /app/build
3141
RUN cmake -DCMAKE_BUILD_TYPE=Release -DPORTABLE=1 .. && make -j$(nproc) && make install
32-
RUN apt update -y && apt install -y gdb && mkdir -p /root/.config/gdb && echo "set auto-load safe-path /" > /root/.config/gdb/gdbinit
42+
RUN mkdir -p /root/.config/gdb && echo "set auto-load safe-path /" > /root/.config/gdb/gdbinit
3343
COPY ton-http-api/static/ /app/static/
3444
COPY config/static_config.yaml /app/static_config.yaml
3545
ENTRYPOINT [ "ton-http-api-cpp" ]

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ There are two main ways to run TON HTTP API:
5959
export THACPP_GLOBAL_CONFIG_PATH=private/testnet.json
6060
# or
6161
echo "THACPP_GLOBAL_CONFIG_PATH=private/testnet.json" > .env
62+
```
63+
- To build an image using custom TON monorepo:
64+
```
65+
export TON_REPO=https://github.com/ton-blockchain/ton
66+
export TON_BRANCH=testnet
67+
# or
68+
echo "TON_REPO=https://github.com/ton-blockchain/ton" >> .env
69+
export TON_BRANCH=testnet
70+
```
6271
- Pull or build docker image:
6372
```bash
6473
docker compose pull

config/static_config.yaml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
components_manager:
2+
coro_pool:
3+
initial_size: 1000
4+
max_size: 10000
5+
stack_size: 4194304
6+
stack_usage_monitor_enabled: true
7+
event_thread_pool:
8+
threads: 2
29
task_processors:
310
main-task-processor:
411
worker_threads: $main_worker_threads
@@ -19,7 +26,7 @@ components_manager:
1926
port#fallback: 8081
2027
connection:
2128
in_buffer_size: 1048576
22-
requests_queue_size_threshold: 1024
29+
requests_queue_size_threshold: 16384
2330
task_processor: main-task-processor
2431
handler-defaults:
2532
max_url_size: 8192
@@ -66,20 +73,27 @@ components_manager:
6673
keystore#fallback: /tmp/keystore/
6774
threads: $tonlib_threads
6875
threads#fallback: 4
69-
# external_message_endpoints: $tonlib_boc_endpoints
70-
# external_message_endpoints#fallback: []
7176
task_processor: main-task-processor
7277
dns-client:
7378
fs-task-processor: fs-task-processor
7479
http-client:
75-
pool-statistics-disable: false
80+
pool-statistics-disable: true
7681
thread-name-prefix: http-client
7782
threads: $http_worker_threads
7883
threads#fallback: 2
7984
fs-task-processor: fs-task-processor
8085
destination-metrics-auto-max-size: 100
8186
user-agent: $http_worker_user_agent
8287
user-agent#fallback: empty
88+
jsonrpc-http-client:
89+
pool-statistics-disable: true
90+
thread-name-prefix: jsonrpc-http-client
91+
threads: $http_worker_threads
92+
threads#fallback: 2
93+
fs-task-processor: fs-task-processor
94+
destination-metrics-auto-max-size: 0
95+
user-agent: $http_worker_user_agent
96+
user-agent#fallback: empty
8397
fs-cache-main:
8498
dir: $static_content_dir
8599
dir#fallback: /app/static/
@@ -342,6 +356,7 @@ components_manager:
342356
logger: api-v2-jsonrpc
343357
port: $server_port
344358
port#fallback: 8081
359+
log-level: error
345360

346361
#
347362
# service handlers

docker-compose.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ services:
55
context: .
66
dockerfile: Dockerfile
77
target: http-api-cpp
8+
args:
9+
- TON_REPO
10+
- TON_BRANCH
811
command: --config /app/static_config.yaml --config_vars /run/secrets/config-vars
912
ports:
1013
- ${THACPP_PORT:-8081}:8081

ton-http-api/src/converters/transactions.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,16 @@ inline schemas::v2::Message Convert<schemas::v2::Message>(
111111
auto r_body_cell = vm::std_boc_deserialize(data.body_);
112112
if (r_body_cell.is_ok()) {
113113
auto body_cell = r_body_cell.move_as_ok();
114-
vm::CellSlice cs = vm::load_cell_slice(body_cell);
115-
if (auto r_body = td::hex_decode(cs.as_bitslice().to_hex()); r_body.is_ok()) {
116-
result.message = td::base64_encode(r_body.move_as_ok());
117-
} else {
118-
result.message_decode_error = r_body.move_as_error_suffix("failed to decode msg body hex: ").to_string();
114+
auto r_loaded_cell = body_cell->load_cell();
115+
if (r_loaded_cell.is_ok()) {
116+
auto loaded_cell = r_loaded_cell.move_as_ok();
117+
const size_t n_bytes = (loaded_cell.data_cell->get_bits() + 7) / 8;
118+
const size_t n_trailing_bits = 8 - loaded_cell.data_cell->get_bits() % 8;
119+
std::string buffer(n_bytes, 0);
120+
std::memcpy(buffer.data(), loaded_cell.data_cell->get_data(), n_bytes);
121+
// this zeroes last 1 bit which is 1 in C++ and 0 in python implementation
122+
buffer[buffer.length() - 1] = static_cast<char>(buffer.back() & ~static_cast<char>((1 << n_trailing_bits) - 1));
123+
result.message = td::base64_encode(buffer) + "\n"; // this is back compatibility
119124
}
120125
} else {
121126
result.message_decode_error = "Failed to load cell or get body slice. But why?";

ton-http-api/src/handlers/JsonRpcHandler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "schemas/v2.hpp"
44
#include "userver/clients/http/component.hpp"
5+
#include <userver/server/component.hpp>
56
#include "utils/exceptions.hpp"
67

78
namespace ton_http::handlers {
@@ -13,7 +14,7 @@ JsonRpcHandler::JsonRpcHandler(
1314
logger_(context.FindComponent<userver::components::Logging>().GetLogger(
1415
config["logger"].As<std::string>("api-v2-jsonrpc")
1516
)),
16-
http_client_(context.FindComponent<userver::components::HttpClient>("http-client").GetHttpClient()),
17+
http_client_(context.FindComponent<userver::components::HttpClient>("jsonrpc-http-client").GetHttpClient()),
1718
base_url_("http://localhost:" + std::to_string(config["port"].As<std::int32_t>()) + "/api/v2/") {
1819
}
1920
std::string JsonRpcHandler::HandleRequestThrow(

ton-http-api/src/handlers/runmethod/RunGetMethodHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ td::Result<ton_http::schemas::v2::RunGetMethodResult> ton_http::handlers::RunGet
4949
);
5050
auto result_object = converters::Convert(result);
5151
if (!checkStackDepth(result_object.stack)) {
52-
throw utils::TonlibException{"result stack depth >= " + std::to_string(max_stack_entry_depth_), 533};
52+
return td::Status::Error(533, "Result stack depth >= " + std::to_string(max_stack_entry_depth_));
5353
}
5454
return result_object;
5555
}

ton-http-api/src/handlers/runmethod/RunGetMethodStdHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ton_http::handlers::RunGetMethodStdHandler::HandleRequestTonlibThrow(
4949
);
5050
auto result_object = converters::Convert<schemas::v2::RunGetMethodStdResult>(result.result);
5151
if (!checkStackDepth(result_object.stack)) {
52-
throw utils::TonlibException{"Result stack depth >= " + std::to_string(max_stack_entry_depth_), 533};
52+
return td::Status::Error(533, "Result stack depth >= " + std::to_string(max_stack_entry_depth_));
5353
}
5454
return result_object;
5555
}

ton-http-api/src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ int main(int argc, char* argv[]) {
5353
// components
5454
component_list.Append<userver::clients::dns::Component>();
5555
component_list.Append<userver::components::HttpClient>();
56+
component_list.Append<userver::components::HttpClient>("jsonrpc-http-client");
5657
component_list.Append<userver::components::FsCache>("fs-cache-main");
5758
component_list.Append<ton_http::core::TonlibComponent>();
5859
// common handlers

0 commit comments

Comments
 (0)