Skip to content

Commit

Permalink
updated smartcontracts
Browse files Browse the repository at this point in the history
- updated smartcontracts
- updated fullnode database layout
- fixed memory leak in blockchain-explorer
- updated tonlib
  • Loading branch information
ton committed Oct 23, 2019
1 parent 9c9248a commit c860ce3
Show file tree
Hide file tree
Showing 104 changed files with 7,294 additions and 1,320 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Expand Up @@ -9,7 +9,7 @@ get_filename_component(TON_REAL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" REALPAT
get_filename_component(TON_REAL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" REALPATH)

if (TON_REAL_BINARY_DIR STREQUAL TON_REAL_SOURCE_DIR)
message(" Out-of-source build should be used to build TDLib.")
message(" Out-of-source build should be used to build TON.")
message(" You need to remove the files already created by CMake and")
message(" rerun CMake from a new directory:")
message(" rm -rf CMakeFiles CMakeCache.txt")
Expand Down Expand Up @@ -190,6 +190,7 @@ endif()
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)

if (TON_ARCH AND NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${TON_ARCH}")
Expand Down Expand Up @@ -380,7 +381,7 @@ if (NOT CMAKE_CROSSCOMPILING)
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})
add_custom_target(prepare_cross_compiling DEPENDS tl_generate_common tlb_generate_block gen_fif ${TDMIME_AUTO})
endif()

#TESTS
Expand All @@ -390,6 +391,9 @@ target_link_libraries(test-ed25519 PRIVATE ton_crypto)
add_executable(test-vm test/test-td-main.cpp ${TONVM_TEST_SOURCE})
target_link_libraries(test-vm PRIVATE ton_crypto fift-lib)

add_executable(test-smartcont test/test-td-main.cpp ${SMARTCONT_TEST_SOURCE})
target_link_libraries(test-smartcont PRIVATE smc-envelope fift-lib ton_db)

add_executable(test-cells test/test-td-main.cpp ${CELLS_TEST_SOURCE})
target_link_libraries(test-cells PRIVATE ton_crypto)

Expand Down Expand Up @@ -490,10 +494,12 @@ endif()
enable_testing()
set(TEST_OPTIONS "--regression ${CMAKE_CURRENT_SOURCE_DIR}/test/regression-tests.ans --filter -Bench")
separate_arguments(TEST_OPTIONS)
add_test(test-ed25519-crypto crypto/test-ed25519-crypto)
add_test(test-ed25519 test-ed25519)
add_test(test-vm test-vm ${TEST_OPTIONS})
add_test(test-fift test-fift ${TEST_OPTIONS})
add_test(test-cells test-cells ${TEST_OPTIONS})
add_test(test-smartcont test-smartcont)
add_test(test-net test-net)
add_test(test-actors test-tdactor)

Expand Down
4 changes: 2 additions & 2 deletions adnl/adnl-ext-server.cpp
Expand Up @@ -146,8 +146,8 @@ void AdnlExtServerImpl::add_tcp_port(td::uint16 port) {
}
};

auto act = td::actor::create_actor<TcpInfiniteListener>(td::actor::ActorOptions().with_name("listener").with_poll(),
port, std::make_unique<Callback>(actor_id(this)));
auto act = td::actor::create_actor<td::TcpInfiniteListener>(
td::actor::ActorOptions().with_name("listener").with_poll(), port, std::make_unique<Callback>(actor_id(this)));
listeners_.emplace(port, std::move(act));
}

Expand Down
65 changes: 1 addition & 64 deletions adnl/adnl-ext-server.hpp
Expand Up @@ -32,69 +32,6 @@ namespace ton {

namespace adnl {

class TcpInfiniteListener : public td::actor::Actor {
public:
TcpInfiniteListener(td::int32 port, std::unique_ptr<td::TcpListener::Callback> callback)
: port_(port), callback_(std::move(callback)) {
}

private:
td::int32 port_;
std::unique_ptr<td::TcpListener::Callback> callback_;
td::actor::ActorOwn<td::TcpListener> tcp_listener_;
td::int32 refcnt_{0};
bool close_flag_{false};

void start_up() override {
loop();
}

void hangup() override {
close_flag_ = true;
tcp_listener_.reset();
if (refcnt_ == 0) {
stop();
}
}

void loop() override {
if (!tcp_listener_.empty()) {
return;
}
class Callback : public td::TcpListener::Callback {
public:
Callback(td::actor::ActorShared<TcpInfiniteListener> parent) : parent_(std::move(parent)) {
}
void accept(td::SocketFd fd) override {
td::actor::send_closure(parent_, &TcpInfiniteListener::accept, std::move(fd));
}

private:
td::actor::ActorShared<TcpInfiniteListener> parent_;
};
refcnt_++;
tcp_listener_ = td::actor::create_actor<td::TcpListener>(
td::actor::ActorOptions().with_name(PSLICE() << "TcpListener" << td::tag("port", port_)).with_poll(), port_,
std::make_unique<Callback>(actor_shared(this)));
}

void accept(td::SocketFd fd) {
callback_->accept(std::move(fd));
}

void hangup_shared() override {
refcnt_--;
tcp_listener_.reset();
if (close_flag_) {
if (refcnt_ == 0) {
stop();
}
} else {
alarm_timestamp() = td::Timestamp::in(5 /*5 seconds*/);
}
}
};

class AdnlExtServerImpl;

class AdnlInboundConnection : public AdnlExtConnection {
Expand Down Expand Up @@ -150,7 +87,7 @@ class AdnlExtServerImpl : public AdnlExtServer {
td::actor::ActorId<AdnlPeerTable> peer_table_;
std::set<AdnlNodeIdShort> local_ids_;
std::set<td::uint16> ports_;
std::map<td::uint16, td::actor::ActorOwn<TcpInfiniteListener>> listeners_;
std::map<td::uint16, td::actor::ActorOwn<td::TcpInfiniteListener>> listeners_;
};

} // namespace adnl
Expand Down
4 changes: 2 additions & 2 deletions blockchain-explorer/blockchain-explorer.cpp
Expand Up @@ -393,8 +393,8 @@ class CoreActor : public CoreActorInterface {
clients_.emplace_back(ton::adnl::AdnlExtClient::create(ton::adnl::AdnlNodeIdFull{remote_public_key_},
remote_addr_, make_callback(0)));
}
daemon_ = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, static_cast<td::uint16>(http_port_), nullptr, nullptr,
&process_http_request, nullptr, MHD_OPTION_END);
daemon_ = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, static_cast<td::uint16>(http_port_), nullptr, nullptr,
&process_http_request, nullptr, MHD_OPTION_THREAD_POOL_SIZE, 16, MHD_OPTION_END);
CHECK(daemon_ != nullptr);
}
};
Expand Down
24 changes: 24 additions & 0 deletions common/int-to-string.hpp
@@ -0,0 +1,24 @@
#pragma once

#include "td/utils/int_types.h"
#include "td/utils/Slice.h"

namespace ton {

template <typename T>
typename std::enable_if_t<std::is_integral<T>::value, td::MutableSlice> store_int_to_slice(td::MutableSlice S,
const T &v) {
CHECK(S.size() >= sizeof(T));
S.copy_from(td::Slice(reinterpret_cast<const td::uint8 *>(&v), sizeof(T)));
return S.remove_prefix(sizeof(T));
}

template <typename T>
typename std::enable_if_t<std::is_integral<T>::value, T> fetch_int_from_slice(td::Slice S) {
CHECK(S.size() >= sizeof(T));
T v;
td::MutableSlice(reinterpret_cast<td::uint8 *>(&v), sizeof(T)).copy_from(S.truncate(sizeof(T)));
return v;
}

} // namespace ton
33 changes: 33 additions & 0 deletions crypto/CMakeLists.txt
Expand Up @@ -88,6 +88,7 @@ set(TON_CRYPTO_SOURCE
vm/cells/CellBuilder.cpp
vm/cells/CellHash.cpp
vm/cells/CellSlice.cpp
vm/cells/CellString.cpp
vm/cells/CellTraits.cpp
vm/cells/CellUsageTree.cpp
vm/cells/DataCell.cpp
Expand All @@ -99,6 +100,7 @@ set(TON_CRYPTO_SOURCE
vm/cells/CellBuilder.h
vm/cells/CellHash.h
vm/cells/CellSlice.h
vm/cells/CellString.h
vm/cells/CellTraits.h
vm/cells/CellUsageTree.h
vm/cells/CellWithStorage.h
Expand Down Expand Up @@ -197,6 +199,24 @@ set(BLOCK_SOURCE
block/transaction.h
)

set(SMC_ENVELOPE_SOURCE
smc-envelope/GenericAccount.cpp
smc-envelope/MultisigWallet.cpp
smc-envelope/SmartContract.cpp
smc-envelope/SmartContractCode.cpp
smc-envelope/TestGiver.cpp
smc-envelope/TestWallet.cpp
smc-envelope/Wallet.cpp

smc-envelope/GenericAccount.h
smc-envelope/MultisigWallet.h
smc-envelope/SmartContract.h
smc-envelope/SmartContractCode.h
smc-envelope/TestGiver.h
smc-envelope/TestWallet.h
smc-envelope/Wallet.h
)

set(ED25519_TEST_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/test/Ed25519.cpp
PARENT_SCOPE
Expand All @@ -217,6 +237,11 @@ set(TONVM_TEST_SOURCE
PARENT_SCOPE
)

set(SMARTCONT_TEST_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/test/test-smartcont.cpp
PARENT_SCOPE
)

set(FIFT_TEST_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/test/fift.cpp
PARENT_SCOPE
Expand Down Expand Up @@ -329,10 +354,18 @@ if (NOT CMAKE_CROSSCOMPILING)
GenFif(DEST smartcont/auto/highload-wallet-code SOURCE smartcont/highload-wallet-code.fc NAME highload-wallet)
GenFif(DEST smartcont/auto/highload-wallet-v2-code SOURCE smartcont/highload-wallet-v2-code.fc NAME highoad-wallet-v2)
GenFif(DEST smartcont/auto/elector-code SOURCE smartcont/elector-code.fc NAME elector-code)
GenFif(DEST smartcont/auto/multisig-code SOURCE smartcont/multisig-code.fc NAME multisig)
GenFif(DEST smartcont/auto/restricted-wallet-code SOURCE smartcont/restricted-wallet-code.fc NAME restricted-wallet)
GenFif(DEST smartcont/auto/restricted-wallet2-code SOURCE smartcont/restricted-wallet2-code.fc NAME restricted-wallet2)

GenFif(DEST smartcont/auto/simple-wallet-ext-code SOURCE smartcont/simple-wallet-ext-code.fc NAME simple-wallet-ext)
endif()

add_library(smc-envelope ${SMC_ENVELOPE_SOURCE})
target_include_directories(smc-envelope PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(smc-envelope PUBLIC ton_crypto PRIVATE tdutils ton_block)
add_dependencies(smc-envelope gen_fif)

add_executable(create-state block/create-state.cpp)
target_include_directories(create-state PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
Expand Down
3 changes: 3 additions & 0 deletions crypto/block/block.tlb
Expand Up @@ -551,6 +551,9 @@ validator_addr#73 public_key:SigPubKey weight:uint64 adnl_addr:bits256 = Validat
validators#11 utime_since:uint32 utime_until:uint32
total:(## 16) main:(## 16) { main <= total } { main >= 1 }
list:(Hashmap 16 ValidatorDescr) = ValidatorSet;
validators_ext#12 utime_since:uint32 utime_until:uint32
total:(## 16) main:(## 16) { main <= total } { main >= 1 }
total_weight:uint64 list:(HashmapE 16 ValidatorDescr) = ValidatorSet;

_ config_addr:bits256 = ConfigParam 0;
_ elector_addr:bits256 = ConfigParam 1;
Expand Down
2 changes: 0 additions & 2 deletions crypto/block/check-proof.cpp
Expand Up @@ -221,8 +221,6 @@ td::Status check_account_proof(td::Slice proof, ton::BlockIdExt shard_blk, const
td::Result<AccountState::Info> AccountState::validate(ton::BlockIdExt ref_blk, block::StdAddress addr) const {
TRY_RESULT_PREFIX(root, vm::std_boc_deserialize(state.as_slice(), true), "cannot deserialize account state");

LOG(INFO) << "got account state for " << addr << " with respect to blocks " << blk.to_str()
<< (shard_blk == blk ? "" : std::string{" and "} + shard_blk.to_str());
if (blk != ref_blk && ref_blk.id.seqno != ~0U) {
return td::Status::Error(PSLICE() << "obtained getAccountState() for a different reference block " << blk.to_str()
<< " instead of requested " << ref_blk.to_str());
Expand Down
77 changes: 73 additions & 4 deletions crypto/block/mc-config.cpp
Expand Up @@ -387,11 +387,25 @@ td::Result<std::unique_ptr<ValidatorSet>> Config::unpack_validator_set(Ref<vm::C
if (vset_root.is_null()) {
return td::Status::Error("validator set is absent");
}
gen::ValidatorSet::Record rec;
if (!tlb::unpack_cell(std::move(vset_root), rec)) {
return td::Status::Error("validator set is invalid");
gen::ValidatorSet::Record_validators_ext rec;
Ref<vm::Cell> dict_root;
if (!tlb::unpack_cell(vset_root, rec)) {
gen::ValidatorSet::Record_validators rec0;
if (!tlb::unpack_cell(std::move(vset_root), rec0)) {
return td::Status::Error("validator set is invalid");
}
rec.utime_since = rec0.utime_since;
rec.utime_until = rec0.utime_until;
rec.total = rec0.total;
rec.main = rec0.main;
dict_root = vm::Dictionary::construct_root_from(*rec0.list);
rec.total_weight = 0;
} else if (rec.total_weight) {
dict_root = rec.list->prefetch_ref();
} else {
return td::Status::Error("validator set cannot have zero total weight");
}
vm::Dictionary dict{vm::Dictionary::construct_root_from(*rec.list), 16};
vm::Dictionary dict{std::move(dict_root), 16};
td::BitArray<16> key_buffer;
auto last = dict.get_minmax_key(key_buffer.bits(), 16, true);
if (last.is_null() || (int)key_buffer.to_ulong() != rec.total - 1) {
Expand Down Expand Up @@ -428,6 +442,9 @@ td::Result<std::unique_ptr<ValidatorSet>> Config::unpack_validator_set(Ref<vm::C
ptr->list.emplace_back(sig_pubkey.pubkey, descr.weight, ptr->total_weight, descr.adnl_addr);
ptr->total_weight += descr.weight;
}
if (rec.total_weight && rec.total_weight != ptr->total_weight) {
return td::Status::Error("validator set declares incorrect total weight");
}
return std::move(ptr);
}

Expand Down Expand Up @@ -517,6 +534,58 @@ td::Result<std::vector<StoragePrices>> Config::get_storage_prices() const {
return std::move(res);
}

td::Result<GasLimitsPrices> Config::get_gas_limits_prices(bool is_masterchain) const {
GasLimitsPrices res;
auto id = is_masterchain ? 20 : 21;
auto cell = get_config_param(id);
if (cell.is_null()) {
return td::Status::Error(PSLICE() << "configuration parameter " << id << " with gas prices is absent");
}
auto cs = vm::load_cell_slice(std::move(cell));
block::gen::GasLimitsPrices::Record_gas_flat_pfx flat;
if (tlb::unpack(cs, flat)) {
cs = *flat.other;
res.flat_gas_limit = flat.flat_gas_limit;
res.flat_gas_price = flat.flat_gas_price;
}
auto f = [&](const auto& r, td::uint64 spec_limit) {
res.gas_limit = r.gas_limit;
res.special_gas_limit = spec_limit;
res.gas_credit = r.gas_credit;
res.gas_price = r.gas_price;
res.freeze_due_limit = r.freeze_due_limit;
res.delete_due_limit = r.delete_due_limit;
};
block::gen::GasLimitsPrices::Record_gas_prices_ext rec;
if (tlb::unpack(cs, rec)) {
f(rec, rec.special_gas_limit);
} else {
block::gen::GasLimitsPrices::Record_gas_prices rec0;
if (tlb::unpack(cs, rec0)) {
f(rec0, rec0.gas_limit);
} else {
return td::Status::Error(PSLICE() << "configuration parameter " << id
<< " with gas prices is invalid - can't parse");
}
}
return res;
}

td::Result<MsgPrices> Config::get_msg_prices(bool is_masterchain) const {
auto id = is_masterchain ? 24 : 25;
auto cell = get_config_param(id);
if (cell.is_null()) {
return td::Status::Error(PSLICE() << "configuration parameter " << id << " with msg prices is absent");
}
auto cs = vm::load_cell_slice(std::move(cell));
block::gen::MsgForwardPrices::Record rec;
if (!tlb::unpack(cs, rec)) {
return td::Status::Error(PSLICE() << "configuration parameter " << id
<< " with msg prices is invalid - can't parse");
}
return MsgPrices(rec.lump_price, rec.bit_price, rec.cell_price, rec.ihr_price_factor, rec.first_frac, rec.next_frac);
}

CatchainValidatorsConfig Config::unpack_catchain_validators_config(Ref<vm::Cell> cell) {
block::gen::CatchainConfig::Record cfg;
if (cell.is_null() || !tlb::unpack_cell(std::move(cell), cfg)) {
Expand Down

1 comment on commit c860ce3

@Danyalkasiri
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMakeLists.txt

Please sign in to comment.