Skip to content

Commit

Permalink
fullnode: support for TCP master/slave replication
Browse files Browse the repository at this point in the history
  • Loading branch information
ton committed Sep 19, 2019
1 parent bfa166d commit f40822b
Show file tree
Hide file tree
Showing 50 changed files with 1,111 additions and 246 deletions.
22 changes: 19 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ else()
endif()

#BEGIN internal
option(TON_USE_ROCKSDB "Use \"ON\" to enable RocksDb." ON)
option(TON_USE_ABSEIL "Use \"ON\" to enable Abseil." ON)
option(TON_ONLY_TONLIB "Use \"ON\" to build only tonlib." OFF)
if (TON_ONLY_TONBLIB)
set(NOT_TON_ONLY_TONLIB false)
else()
set(NOT_TON_ONLY_TONLIB true)
endif()
option(TON_USE_ROCKSDB "Use \"ON\" to enable RocksDb." ${NOT_TON_ONLY_TONLIB})
option(TON_USE_ABSEIL "Use \"ON\" to enable Abseil." ${NOT_TON_ONLY_TONLIB})
option(TON_USE_JEMALLOC "Use \"ON\" to enable JeMalloc." OFF)
#END internal

Expand Down Expand Up @@ -328,6 +334,7 @@ function(target_link_libraries_system target)
endforeach(lib)
endfunction(target_link_libraries_system)

set(TDUTILS_MIME_TYPE OFF CACHE BOOL "Generate mime type conversion")
add_subdirectory(tdutils)
add_subdirectory(memprof)
add_subdirectory(tdactor)
Expand All @@ -350,6 +357,7 @@ add_subdirectory(tonlib)
#END tonlib

#BEGIN internal
if (NOT TON_ONLY_TONLIB)
add_subdirectory(common)
add_subdirectory(tdfec)
add_subdirectory(keyring)
Expand All @@ -365,10 +373,14 @@ add_subdirectory(validator-engine)
add_subdirectory(validator-engine-console)
add_subdirectory(dht-server)
add_subdirectory(utils)
endif()
#END internal

if (NOT CMAKE_CROSSCOMPILING)
add_custom_target(prepare_cross_compiling DEPENDS tl_generate_common tdmime_auto tlb_generate_block)
if (TDUTILS_MIME_TYPE)
set(TDMIME_AUTO tdmime_auto)
endif()
add_custom_target(prepare_cross_compiling DEPENDS tl_generate_common tlb_generate_block ${TDMIME_AUTO})
endif()

#TESTS
Expand Down Expand Up @@ -406,6 +418,7 @@ target_link_libraries(test-tonlib-offline tdutils tdactor adnllite tl_api ton_cr
#END tonlib

#BEGIN internal
if (NOT TON_ONLY_TONLIB)
add_executable(test-db test/test-td-main.cpp ${TONDB_TEST_SOURCE})
target_link_libraries(test-db PRIVATE ton_db memprof)

Expand Down Expand Up @@ -467,6 +480,7 @@ if (HAS_PARENT)
endif()
add_library(all_tests INTERFACE)
target_link_libraries(all_tests INTERFACE tdutils tdactor tdnet tdfec ton_db ton_crypto fift-lib)
endif()
#END internal

enable_testing()
Expand All @@ -485,8 +499,10 @@ add_test(test-tonlib-offline test-tonlib-offline)
#END tonlib

#BEGIN internal
if (NOT TON_ONLY_TONLIB)
add_test(test-fec test-fec)
add_test(test-tddb test-tddb ${TEST_OPTIONS})
add_test(test-db test-db ${TEST_OPTIONS})
endif()
#END internal

4 changes: 4 additions & 0 deletions adnl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)

#BEGIN internal
if (NOT TON_ONLY_TONLIB)
set(ADNL_HEADERS
adnl-address-list.h
adnl-address-list.hpp
Expand Down Expand Up @@ -66,6 +67,7 @@ set(ADNL_PROXY_SOURCE

#FIXME
set(ADNL_LITE_HEADERS ${ADNL_HEADERS})
endif()
#END internal

set(ADNL_LITE_SOURCE
Expand All @@ -77,6 +79,7 @@ set(ADNL_LITE_SOURCE
)

#BEGIN internal
if (NOT TON_ONLY_TONLIB)
add_library(adnl STATIC ${ADNL_SOURCE})

target_include_directories(adnl PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
Expand All @@ -95,6 +98,7 @@ target_link_libraries(adnl-pong PUBLIC tdactor ton_crypto tl_api tdnet common
add_library(adnltest STATIC ${ADNL_TEST_SOURCE})
target_include_directories(adnltest PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
target_link_libraries(adnltest PUBLIC adnl )
endif()
#END internal

add_library(adnllite STATIC ${ADNL_LITE_SOURCE})
Expand Down
3 changes: 2 additions & 1 deletion crypto/openssl/bignum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ Bignum& Bignum::import_lsb(const unsigned char* buffer, std::size_t size) {
size--;
}
if (!size) {
bn_assert(BN_zero(val));
// Use BN_set_word, because from 1.1.0 BN_zero may return void
bn_assert(BN_set_word(val, 0));
return *this;
}
unsigned char tmp_buff[1024];
Expand Down
2 changes: 1 addition & 1 deletion crypto/openssl/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Bignum {
}
Bignum(const bin_string& bs) {
val = BN_new();
set_dec_str(bs.str);
set_raw_bytes(bs.str);
}
Bignum(const dec_string& ds) {
val = BN_new();
Expand Down
3 changes: 2 additions & 1 deletion crypto/smartcont/gen-zerostate.fif
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ Masterchain over

// SmartContract #2 (Simple money giver for test network)
<{ SETCP0 DUP IFNOTRET // return if recv_internal
DUP 85143 INT EQUAL IFJMP:<{ // "seqno" get-method
DUP 85143 INT EQUAL IFJMP:<{ // "seqno" get-method
DROP c4 PUSHCTR CTOS 32 PLDU // cnt
}>
INC 32 THROWIF // fail unless recv_external
32 LDU SWAP // cs cnt
c4 PUSHCTR CTOS 32 LDU ENDS // cs cnt cnt'
TUCK EQUAL 33 THROWIFNOT // ( seqno mismatch? )
Expand Down
50 changes: 50 additions & 0 deletions crypto/smartcont/new-testgiver.fif
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env fift -s
"TonUtil.fif" include
"Asm.fif" include

{ ."usage: " @' $0 type ." <workchain-id> [<filename-base>]" cr
."Creates a new money giver in specified workchain, with address saved to <filename-base>.addr" cr
."('new-testgiver.addr' by default)" cr 1 halt
} : usage
$# 1- -2 and ' usage if

$1 parse-workchain-id =: wc // set workchain id from command line argument
def? $2 { @' $2 } { "new-testgiver" } cond constant file-base

."Creating new money giver in workchain " wc . cr
0 constant init_seqno

// Create new simple money giver
<{ SETCP0 DUP IFNOTRET // return if recv_internal
DUP 85143 INT EQUAL IFJMP:<{ // "seqno" get-method
DROP c4 PUSHCTR CTOS 32 PLDU // cnt
}>
INC 32 THROWIF // fail unless recv_external
32 LDU SWAP // cs cnt
c4 PUSHCTR CTOS 32 LDU ENDS // cs cnt cnt'
TUCK EQUAL 33 THROWIFNOT // ( seqno mismatch? )
ACCEPT // cs cnt'
SWAP DUP SREFS // cnt' cs msg?
IF:<{
8 LDU LDREF -ROT // cnt'' cs mode msg
GR$20 INT 3 INT RAWRESERVE // reserve all but 20 Grams from the balance
SWAP SENDRAWMSG
}>
ENDS INC NEWC 32 STU ENDC c4 POPCTR // store cnt''
}>c
// code
<b init_seqno 32 u, b> // data
null // no libraries
<b b{0011} s, 3 roll ref, rot ref, swap dict, b> // create StateInit
dup ."StateInit: " <s csr. cr
dup hash wc swap 2dup 2constant wallet_addr
."new money giver address = " 2dup .addr cr
2dup file-base +".addr" save-address-verbose
."Non-bounceable address (for init): " 2dup 7 .Addr cr
."Bounceable address (for later access): " 6 .Addr cr
// ???
<b b{1000100} s, wallet_addr addr, b{000010} s, swap <s s, b{0} s, init_seqno 32 u, b>
dup ."External message for initialization is " <s csr. cr
2 boc+>B dup Bx. cr
file-base +"-query.boc" tuck B>file
."(Saved money giver creating query to file " type .")" cr
2 changes: 1 addition & 1 deletion crypto/smartcont/testgiver.fif
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$# 3 - -2 and ' usage if

// "testgiver.addr" load-address
Masterchain 0x8156775b79325e5d62e742d9b96c30b6515a5cd2f1f64c5da4b193c03f070e0d
Masterchain 0xfcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260
2constant giver_addr
."Test giver address = " giver_addr 2dup .addr cr 6 .Addr cr

Expand Down
2 changes: 1 addition & 1 deletion crypto/test/test-cells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ TEST(bits256_scan, main) {
}

bool check_exp(std::ostream& stream, const td::NegExpBinTable& tab, double x) {
long long xx = lround(x * (1LL << 52));
long long xx = llround(x * (1LL << 52));
td::BigInt256 yy;
if (!tab.nexpf(yy, -xx, 52)) {
stream << "cannot compute exp(" << x << ") = exp(" << xx << " * 2^(-52))" << std::endl;
Expand Down
6 changes: 5 additions & 1 deletion dht-server/dht-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ ton::tl_object_ptr<ton::ton_api::engine_validator_config> Config::tl() const {

std::vector<ton::tl_object_ptr<ton::ton_api::engine_validator>> val_vec;

ton::tl_object_ptr<ton::ton_api::engine_validator_fullNodeSlave> full_node_slave_ = nullptr;
std::vector<ton::tl_object_ptr<ton::ton_api::engine_validator_fullNodeMaster>> full_node_masters_;

std::vector<ton::tl_object_ptr<ton::ton_api::engine_liteServer>> liteserver_vec;

std::vector<ton::tl_object_ptr<ton::ton_api::engine_controlInterface>> control_vec;
Expand All @@ -157,7 +160,8 @@ ton::tl_object_ptr<ton::ton_api::engine_validator_config> Config::tl() const {
}
return ton::create_tl_object<ton::ton_api::engine_validator_config>(
out_port, std::move(addrs_vec), std::move(adnl_vec), std::move(dht_vec), std::move(val_vec),
ton::PublicKeyHash::zero().tl(), std::move(liteserver_vec), std::move(control_vec), std::move(gc_vec));
ton::PublicKeyHash::zero().tl(), std::move(full_node_slave_), std::move(full_node_masters_),
std::move(liteserver_vec), std::move(control_vec), std::move(gc_vec));
}

td::Result<bool> Config::config_add_network_addr(td::IPAddress in_ip, td::IPAddress out_ip,
Expand Down
2 changes: 1 addition & 1 deletion doc/FullNode-HOWTO
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Notice that you need a machine with a public IP address and a high-bandwidth net
0. Downloading and compiling
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The complete TON Blockchain Library and Validator software is downloaded and compiled similarly to the Lite Client. This process is outlined in the corresponding README file. The most important difference is that you have to download the complete source archive available at https://test.ton.org/ton-blockchain-full.tar.xz instead of the smaller Lite Client source archive. You should also build all goals defined in CMakeLists.txt (e.g. by running `cmake <path-to-source-directory>` and `make` in your build directory), not only those specifically related to the Lite Client (which is also included in the larger distribution; you don't have to download and build it separately). We strongly recommend building a "release" or a "release with debug information" version of the TON Blockchain Library and especially of the Validator/Full Node by passing `-DCMAKE_BUILD_TYPE=Release` or `-DCMAKE_BUILD_TYPE=RelWithDebInfo` as an extra argument to `cmake` during its first run (if you forgot to do this, you can later delete file `CMakeCache.txt` from your build directory and re-run `cmake` with the appropriate options).
The complete TON Blockchain Library and Validator software is downloaded and compiled similarly to the Lite Client. This process is outlined in the corresponding README file. The most important difference is that you have to download the complete sources from public GitHub repository https://github.com/ton-blockchain/ton (e.g., by running `git clone https://github.com/ton-blockchain/ton`) instead of downloading the smaller Lite Client source archive. You should also build all goals defined in CMakeLists.txt (e.g. by running `cmake <path-to-source-directory>` and `make` in your build directory), not only those specifically related to the Lite Client (which is also included in the larger distribution; you don't have to download and build it separately). We strongly recommend building a "release" or a "release with debug information" version of the TON Blockchain Library and especially of the Validator/Full Node by passing `-DCMAKE_BUILD_TYPE=Release` or `-DCMAKE_BUILD_TYPE=RelWithDebInfo` as an extra argument to `cmake` during its first run (if you forgot to do this, you can later delete file `CMakeCache.txt` from your build directory and re-run `cmake` with the appropriate options).

1. Full Node binaries
~~~~~~~~~~~~~~~~~~~~~
Expand Down
Loading

0 comments on commit f40822b

Please sign in to comment.