Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 9f008b1

Browse files
author
ton
committed
updated submodules, bugfixes
- added new fift/func code for validator complaint creation - bugfixes in validator - updates in tonlib - new versions of rocksdb/abseil - hardfork support
1 parent 16a4566 commit 9f008b1

File tree

129 files changed

+8425
-866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+8425
-866
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ tl/generate/auto/
77
compile_commands.json
88
crypto/block/block-auto.cpp
99
crypto/block/block-auto.h
10-
crypto/smartcont/*-code.fif
1110
crypto/smartcont/auto/
1211
test/regression-tests.cache/
1312
*.swp

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ if (TON_USE_ROCKSDB)
115115
if (ANDROID)
116116
set(PORTABLE ON CACHE BOOL "portable")
117117
endif()
118+
set(WITH_GFLAGS OFF CACHE BOOL "build with GFlags")
118119
set(WITH_TESTS OFF CACHE BOOL "build with tests")
119120
set(WITH_TOOLS OFF CACHE BOOL "build with tools")
120121
set(FAIL_ON_WARNINGS OFF CACHE BOOL "fail on warnings")
@@ -231,7 +232,7 @@ elseif (CLANG OR GCC)
231232
if (APPLE)
232233
#use "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/export_list" for exported symbols
233234
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fvisibility=hidden -Wl,-dead_strip,-x,-S")
234-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fvisibility=hidden -Wl,-dead_strip,-x,-S")
235+
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fvisibility=hidden -Wl,-dead_strip,-x,-S")
235236
else()
236237
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections")
237238
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL")
@@ -385,6 +386,7 @@ add_subdirectory(validator)
385386
add_subdirectory(blockchain-explorer)
386387
add_subdirectory(validator-engine)
387388
add_subdirectory(validator-engine-console)
389+
add_subdirectory(create-hardfork)
388390
add_subdirectory(dht-server)
389391
add_subdirectory(utils)
390392
add_subdirectory(http)
@@ -445,6 +447,9 @@ if (NOT TON_ONLY_TONLIB)
445447
add_executable(test-db test/test-td-main.cpp ${TONDB_TEST_SOURCE})
446448
target_link_libraries(test-db PRIVATE ton_db memprof)
447449

450+
add_executable(test-rocksdb test/test-rocksdb.cpp)
451+
target_link_libraries(test-rocksdb PRIVATE memprof tddb tdutils)
452+
448453
add_executable(test-tddb test/test-td-main.cpp ${TDDB_TEST_SOURCE})
449454
target_link_libraries(test-tddb PRIVATE tdutils tddb ${CMAKE_THREAD_LIBS_INIT} memprof)
450455

blockchain-explorer/blockchain-explorer-query.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ void HttpQueryStatus::finish_query() {
15051505
td::uint32 j = 0;
15061506
for (auto &X : results_.results) {
15071507
if (!X->values_[i].is_valid()) {
1508-
A << "<td>FAIL</td>";
1508+
A << "<td class=\"table-danger\">FAIL</td>";
15091509
} else {
15101510
if (m[j].count(X->values_[i].id.seqno) == 0) {
15111511
m[j].insert(X->values_[i].id.seqno);

crypto/CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(TON_CRYPTO_SOURCE
4949
common/bigexp.h
5050
common/util.h
5151
common/linalloc.hpp
52+
common/promiseop.hpp
5253

5354
ellcurve/Ed25519.h
5455
ellcurve/Fp25519.h
@@ -212,6 +213,7 @@ set(SMC_ENVELOPE_SOURCE
212213
smc-envelope/HighloadWalletV2.cpp
213214
smc-envelope/ManualDns.cpp
214215
smc-envelope/MultisigWallet.cpp
216+
smc-envelope/PaymentChannel.cpp
215217
smc-envelope/SmartContract.cpp
216218
smc-envelope/SmartContractCode.cpp
217219
smc-envelope/TestGiver.cpp
@@ -341,7 +343,7 @@ if (NOT CMAKE_CROSSCOMPILING)
341343
set(multiValueArgs SOURCE)
342344
set(FUNC_LIB_SOURCE smartcont/stdlib.fc)
343345
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
344-
string(REGEX REPLACE "[^a-zA-Z_]" "_" ID ${ARG_DEST})
346+
string(REGEX REPLACE "[^0-9a-zA-Z_]" "_" ID ${ARG_DEST})
345347
set(ARG_DEST_FIF "${ARG_DEST}.fif")
346348
add_custom_command(
347349
COMMENT "Generate ${ARG_DEST_FIF}"
@@ -374,10 +376,13 @@ if (NOT CMAKE_CROSSCOMPILING)
374376
GenFif(DEST smartcont/auto/multisig-code SOURCE smartcont/multisig-code.fc NAME multisig)
375377
GenFif(DEST smartcont/auto/restricted-wallet-code SOURCE smartcont/restricted-wallet-code.fc NAME restricted-wallet)
376378
GenFif(DEST smartcont/auto/restricted-wallet2-code SOURCE smartcont/restricted-wallet2-code.fc NAME restricted-wallet2)
379+
GenFif(DEST smartcont/auto/restricted-wallet3-code SOURCE smartcont/restricted-wallet3-code.fc NAME restricted-wallet3)
377380

378381
GenFif(DEST smartcont/auto/dns-manual-code SOURCE smartcont/dns-manual-code.fc NAME dns-manual)
379382
GenFif(DEST smartcont/auto/dns-auto-code SOURCE smartcont/dns-auto-code.fc NAME dns-auto)
380383

384+
GenFif(DEST smartcont/auto/payment-channel-code SOURCE smartcont/payment-channel-code.fc NAME payment-channel)
385+
381386
GenFif(DEST smartcont/auto/simple-wallet-ext-code SOURCE smartcont/simple-wallet-ext-code.fc NAME simple-wallet-ext)
382387
endif()
383388

@@ -420,5 +425,13 @@ if (WINGETOPT_FOUND)
420425
target_link_libraries_system(dump-block wingetopt)
421426
endif()
422427

428+
add_executable(test-weight-distr block/test-weight-distr.cpp)
429+
target_include_directories(test-weight-distr PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
430+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
431+
target_link_libraries(test-weight-distr PUBLIC ton_crypto fift-lib ton_block)
432+
if (WINGETOPT_FOUND)
433+
target_link_libraries_system(test-weight-distr wingetopt)
434+
endif()
435+
423436
install(TARGETS fift func RUNTIME DESTINATION bin)
424437
install(DIRECTORY fift/lib/ DESTINATION lib/fift)

crypto/block/block-parse.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ bool MsgAddressInt::extract_std_address(vm::CellSlice& cs, ton::WorkchainId& wor
241241
return false;
242242
}
243243

244+
bool MsgAddressInt::extract_std_address(Ref<vm::CellSlice> cs_ref, block::StdAddress& addr, bool rewrite) const {
245+
return extract_std_address(std::move(cs_ref), addr.workchain, addr.addr, rewrite);
246+
}
247+
248+
bool MsgAddressInt::extract_std_address(vm::CellSlice& cs, block::StdAddress& addr, bool rewrite) const {
249+
return extract_std_address(cs, addr.workchain, addr.addr, rewrite);
250+
}
251+
244252
bool MsgAddressInt::store_std_address(vm::CellBuilder& cb, ton::WorkchainId workchain,
245253
const ton::StdSmcAddress& addr) const {
246254
if (workchain >= -128 && workchain < 128) {
@@ -263,6 +271,14 @@ Ref<vm::CellSlice> MsgAddressInt::pack_std_address(ton::WorkchainId workchain, c
263271
}
264272
}
265273

274+
bool MsgAddressInt::store_std_address(vm::CellBuilder& cb, const block::StdAddress& addr) const {
275+
return store_std_address(cb, addr.workchain, addr.addr);
276+
}
277+
278+
Ref<vm::CellSlice> MsgAddressInt::pack_std_address(const block::StdAddress& addr) const {
279+
return pack_std_address(addr.workchain, addr.addr);
280+
}
281+
266282
const MsgAddressInt t_MsgAddressInt;
267283

268284
bool MsgAddress::validate_skip(int* ops, vm::CellSlice& cs, bool weak) const {

crypto/block/block-parse.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,13 @@ struct MsgAddressInt final : TLB_Complex {
298298
bool rewrite = true) const;
299299
bool extract_std_address(vm::CellSlice& cs, ton::WorkchainId& workchain, ton::StdSmcAddress& addr,
300300
bool rewrite = true) const;
301+
bool extract_std_address(Ref<vm::CellSlice> cs_ref, block::StdAddress& addr, bool rewrite = true) const;
302+
bool extract_std_address(vm::CellSlice& cs, block::StdAddress& addr, bool rewrite = true) const;
301303
bool store_std_address(vm::CellBuilder& cb, ton::WorkchainId workchain, const ton::StdSmcAddress& addr) const;
302304
Ref<vm::CellSlice> pack_std_address(ton::WorkchainId workchain, const ton::StdSmcAddress& addr) const;
305+
306+
bool store_std_address(vm::CellBuilder& cb, const block::StdAddress& addr) const;
307+
Ref<vm::CellSlice> pack_std_address(const block::StdAddress& addr) const;
303308
};
304309

305310
extern const MsgAddressInt t_MsgAddressInt;

crypto/block/block.cpp

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "td/utils/crypto.h"
2828
#include "td/utils/tl_storers.h"
2929
#include "td/utils/misc.h"
30+
#include "td/utils/Random.h"
3031

3132
namespace block {
3233
using namespace std::literals::string_literals;
@@ -369,14 +370,14 @@ std::unique_ptr<MsgProcessedUptoCollection> MsgProcessedUptoCollection::unpack(t
369370
return v && v->valid ? std::move(v) : std::unique_ptr<MsgProcessedUptoCollection>{};
370371
}
371372

372-
bool MsgProcessedUpto::contains(const MsgProcessedUpto& other) const & {
373+
bool MsgProcessedUpto::contains(const MsgProcessedUpto& other) const& {
373374
return ton::shard_is_ancestor(shard, other.shard) && mc_seqno >= other.mc_seqno &&
374375
(last_inmsg_lt > other.last_inmsg_lt ||
375376
(last_inmsg_lt == other.last_inmsg_lt && !(last_inmsg_hash < other.last_inmsg_hash)));
376377
}
377378

378379
bool MsgProcessedUpto::contains(ton::ShardId other_shard, ton::LogicalTime other_lt, td::ConstBitPtr other_hash,
379-
ton::BlockSeqno other_mc_seqno) const & {
380+
ton::BlockSeqno other_mc_seqno) const& {
380381
return ton::shard_is_ancestor(shard, other_shard) && mc_seqno >= other_mc_seqno &&
381382
(last_inmsg_lt > other_lt || (last_inmsg_lt == other_lt && !(last_inmsg_hash < other_hash)));
382383
}
@@ -1546,6 +1547,89 @@ bool unpack_CreatorStats(Ref<vm::CellSlice> cs, DiscountedCounter& mc_cnt, Disco
15461547
}
15471548
}
15481549

1550+
/*
1551+
*
1552+
* Monte Carlo simulator for computing the share of shardchain blocks generated by each validator
1553+
*
1554+
*/
1555+
1556+
bool MtCarloComputeShare::compute() {
1557+
ok = false;
1558+
if (W.size() >= (1U << 31) || W.empty()) {
1559+
return false;
1560+
}
1561+
K = std::min(K, N);
1562+
if (K <= 0 || iterations <= 0) {
1563+
return false;
1564+
}
1565+
double tot_weight = 0., acc = 0.;
1566+
for (int i = 0; i < N; i++) {
1567+
if (W[i] <= 0.) {
1568+
return false;
1569+
}
1570+
tot_weight += W[i];
1571+
}
1572+
CW.resize(N);
1573+
RW.resize(N);
1574+
for (int i = 0; i < N; i++) {
1575+
CW[i] = acc;
1576+
acc += W[i] /= tot_weight;
1577+
RW[i] = 0.;
1578+
}
1579+
R0 = 0.;
1580+
H.resize(N);
1581+
A.resize(K);
1582+
for (long long it = 0; it < iterations; ++it) {
1583+
gen_vset();
1584+
}
1585+
for (int i = 0; i < N; i++) {
1586+
RW[i] = W[i] * (RW[i] + R0) / (double)iterations;
1587+
}
1588+
return ok = true;
1589+
}
1590+
1591+
void MtCarloComputeShare::gen_vset() {
1592+
double total_wt = 1.;
1593+
int hc = 0;
1594+
for (int i = 0; i < K; i++) {
1595+
CHECK(total_wt > 0);
1596+
double inv_wt = 1. / total_wt;
1597+
R0 += inv_wt;
1598+
for (int j = 0; j < i; j++) {
1599+
RW[A[j]] -= inv_wt;
1600+
}
1601+
// double p = drand48() * total_wt;
1602+
double p = (double)td::Random::fast_uint64() * total_wt / (1. * (1LL << 32) * (1LL << 32));
1603+
for (int h = 0; h < hc; h++) {
1604+
if (p < H[h].first) {
1605+
break;
1606+
}
1607+
p += H[h].second;
1608+
}
1609+
int a = -1, b = N, c;
1610+
while (b - a > 1) {
1611+
c = ((a + b) >> 1);
1612+
if (CW[c] <= p) {
1613+
a = c;
1614+
} else {
1615+
b = c;
1616+
}
1617+
}
1618+
CHECK(a >= 0 && a < N);
1619+
CHECK(total_wt >= W[a]);
1620+
total_wt -= W[a];
1621+
double x = CW[a];
1622+
c = hc++;
1623+
while (c > 0 && H[c - 1].first > x) {
1624+
H[c] = H[c - 1];
1625+
--c;
1626+
}
1627+
H[c].first = x;
1628+
H[c].second = W[a];
1629+
A[i] = a;
1630+
}
1631+
}
1632+
15491633
/*
15501634
*
15511635
* Other block-related functions
@@ -1723,7 +1807,7 @@ ton::AccountIdPrefixFull interpolate_addr(const ton::AccountIdPrefixFull& src, c
17231807
unsigned long long mask = (std::numeric_limits<td::uint64>::max() >> (d - 32));
17241808
return ton::AccountIdPrefixFull{dest.workchain, (dest.account_id_prefix & ~mask) | (src.account_id_prefix & mask)};
17251809
} else {
1726-
int mask = (-1 >> d);
1810+
int mask = (int)(~0U >> d);
17271811
return ton::AccountIdPrefixFull{(dest.workchain & ~mask) | (src.workchain & mask), src.account_id_prefix};
17281812
}
17291813
}

crypto/block/block.h

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ struct MsgProcessedUpto {
163163
MsgProcessedUpto(ton::ShardId _shard, ton::BlockSeqno _mcseqno, ton::LogicalTime _lt, td::ConstBitPtr _hash)
164164
: shard(_shard), mc_seqno(_mcseqno), last_inmsg_lt(_lt), last_inmsg_hash(_hash) {
165165
}
166-
bool operator<(const MsgProcessedUpto& other) const & {
166+
bool operator<(const MsgProcessedUpto& other) const& {
167167
return shard < other.shard || (shard == other.shard && mc_seqno < other.mc_seqno);
168168
}
169-
bool contains(const MsgProcessedUpto& other) const &;
169+
bool contains(const MsgProcessedUpto& other) const&;
170170
bool contains(ton::ShardId other_shard, ton::LogicalTime other_lt, td::ConstBitPtr other_hash,
171-
ton::BlockSeqno other_mc_seqno) const &;
171+
ton::BlockSeqno other_mc_seqno) const&;
172172
// NB: this is for checking whether we have already imported an internal message
173173
bool already_processed(const EnqueuedMsgDescr& msg) const;
174174
bool can_check_processed() const {
@@ -596,6 +596,62 @@ struct BlockProofChain {
596596
td::Status validate(td::CancellationToken cancellation_token = {});
597597
};
598598

599+
// compute the share of shardchain blocks generated by each validator using Monte Carlo method
600+
class MtCarloComputeShare {
601+
int K, N;
602+
long long iterations;
603+
std::vector<double> W;
604+
std::vector<double> CW, RW;
605+
std::vector<std::pair<double, double>> H;
606+
std::vector<int> A;
607+
double R0;
608+
bool ok;
609+
610+
public:
611+
MtCarloComputeShare(int subset_size, const std::vector<double>& weights, long long iteration_count = 1000000)
612+
: K(subset_size), N((int)weights.size()), iterations(iteration_count), W(weights), ok(false) {
613+
compute();
614+
}
615+
MtCarloComputeShare(int subset_size, int set_size, const double* weights, long long iteration_count = 1000000)
616+
: K(subset_size), N(set_size), iterations(iteration_count), W(weights, weights + set_size), ok(false) {
617+
compute();
618+
}
619+
bool is_ok() const {
620+
return ok;
621+
}
622+
const double* share_array() const {
623+
return ok ? RW.data() : nullptr;
624+
}
625+
const double* weights_array() const {
626+
return ok ? W.data() : nullptr;
627+
}
628+
double operator[](int i) const {
629+
return ok ? RW.at(i) : -1.;
630+
}
631+
double share(int i) const {
632+
return ok ? RW.at(i) : -1.;
633+
}
634+
double weight(int i) const {
635+
return ok ? W.at(i) : -1.;
636+
}
637+
int size() const {
638+
return N;
639+
}
640+
int subset_size() const {
641+
return K;
642+
}
643+
long long performed_iterations() const {
644+
return iterations;
645+
}
646+
647+
private:
648+
bool set_error() {
649+
return ok = false;
650+
}
651+
bool compute();
652+
void gen_vset();
653+
};
654+
599655
int filter_out_msg_queue(vm::AugmentedDictionary& out_queue, ton::ShardIdFull old_shard, ton::ShardIdFull subshard);
600656

601657
std::ostream& operator<<(std::ostream& os, const ShardId& shard_id);

crypto/block/block.tlb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ transaction$0111 account_addr:bits256 lt:uint64
272272
old:^X new:^X = MERKLE_UPDATE X;
273273
update_hashes#72 {X:Type} old_hash:bits256 new_hash:bits256
274274
= HASH_UPDATE X;
275+
!merkle_proof#03 {X:Type} virtual_hash:bits256 depth:uint16 virtual_root:^X = MERKLE_PROOF X;
275276

276277
acc_trans#5 account_addr:bits256
277278
transactions:(HashmapAug 64 ^Transaction CurrencyCollection)
@@ -731,8 +732,11 @@ top_block_descr_set#4ac789f3 collection:(HashmapE 96 ^TopBlockDescr) = TopBlockD
731732
//
732733
// VALIDATOR MISBEHAVIOR COMPLAINTS
733734
//
734-
no_blk_gen mc_blk_ref:ExtBlkRef from_utime:uint32 to_utime:uint32 state_proof:^Cell prod_proof:^Cell = ComplaintDescr;
735-
validator_complaint#bc validator_pubkey:uint256 description:^ComplaintDescr created_at:uint32 severity:uint8 reward_addr:uint256 paid:Grams suggested_fine:Grams suggested_fine_part:uint32 = ValidatorComplaint;
735+
prod_info#34 utime:uint32 mc_blk_ref:ExtBlkRef state_proof:^(MERKLE_PROOF Block)
736+
prod_proof:^(MERKLE_PROOF ShardState) = ProducerInfo;
737+
no_blk_gen from_utime:uint32 prod_info:^ProducerInfo = ComplaintDescr;
738+
no_blk_gen_diff prod_info_old:^ProducerInfo prod_info_new:^ProducerInfo = ComplaintDescr;
739+
validator_complaint#bc validator_pubkey:bits256 description:^ComplaintDescr created_at:uint32 severity:uint8 reward_addr:uint256 paid:Grams suggested_fine:Grams suggested_fine_part:uint32 = ValidatorComplaint;
736740
complaint_status#2d complaint:^ValidatorComplaint voters:(HashmapE 16 True) vset_id:uint256 weight_remaining:int64 = ValidatorComplaintStatus;
737741

738742
//
@@ -808,3 +812,25 @@ cap_method_pubkey#71f4 = SmcCapability;
808812
cap_is_wallet#2177 = SmcCapability;
809813
cap_name#ff name:Text = SmcCapability;
810814

815+
//
816+
// PAYMENT CHANNELS
817+
//
818+
819+
chan_config$_ init_timeout:uint32 close_timeout:uint32 a_key:bits256 b_key:bits256
820+
a_addr:^MsgAddressInt b_addr:^MsgAddressInt channel_id:uint64 = ChanConfig;
821+
822+
chan_state_init$000 signed_A:Bool signed_B:Bool min_A:Grams min_B:Grams expire_at:uint32 A:Grams B:Grams = ChanState;
823+
chan_state_close$001 signed_A:Bool signed_B:Bool promise_A:Grams promise_B:Grams expire_at:uint32 A:Grams B:Grams = ChanState;
824+
chan_state_payout$010 A:Grams B:Grams = ChanState;
825+
826+
chan_promise$_ channel_id:uint64 promise_A:Grams promise_B:Grams = ChanPromise;
827+
chan_signed_promise#_ sig:(Maybe ^bits512) promise:ChanPromise = ChanSignedPromise;
828+
829+
chan_msg_init#27317822 inc_A:Grams inc_B:Grams min_A:Grams min_B:Grams channel_id:uint64 = ChanMsg;
830+
chan_msg_close#f28ae183 extra_A:Grams extra_B:Grams promise:ChanSignedPromise = ChanMsg;
831+
chan_msg_timeout#43278a28 = ChanMsg;
832+
833+
chan_signed_msg$_ sig_A:(Maybe ^bits512) sig_B:(Maybe ^bits512) msg:ChanMsg = ChanSignedMsg;
834+
835+
chan_data$_ config:^ChanConfig state:^ChanState = ChanData;
836+

0 commit comments

Comments
 (0)