Skip to content

Commit 0c21ce2

Browse files
authored
Merge pull request ton-blockchain#1139 from ton-blockchain/stable_testnet
Merge recent updates
2 parents 140320b + 97c57c3 commit 0c21ce2

Some content is hidden

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

55 files changed

+758
-205
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Docker Ubuntu 22.04 branch image
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches-ignore:
7+
- master
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build-and-push:
15+
runs-on: ubuntu-22.04
16+
steps:
17+
- name: Check out repository
18+
uses: actions/checkout@v3
19+
with:
20+
submodules: 'recursive'
21+
22+
- name: Set up QEMU
23+
uses: docker/setup-qemu-action@v3
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Login to GitHub Container Registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.repository_owner }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Get tag as branch name
36+
id: tag
37+
run: |
38+
echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
39+
40+
- name: Build and push
41+
id: docker_build
42+
uses: docker/build-push-action@v6
43+
with:
44+
platforms: linux/amd64
45+
push: true
46+
context: ./
47+
tags: |
48+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}

Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ RUN apt-get update && \
2727
apt-get install -y wget curl libatomic1 openssl libsecp256k1-dev libsodium-dev libmicrohttpd-dev liblz4-dev libjemalloc-dev htop net-tools netcat iptraf-ng jq tcpdump pv plzip && \
2828
rm -rf /var/lib/apt/lists/*
2929

30-
RUN mkdir -p /var/ton-work/db /var/ton-work/scripts
30+
RUN mkdir -p /var/ton-work/db /var/ton-work/scripts /usr/share/ton/smartcont/ /usr/lib/fift/
3131

3232
COPY --from=builder /ton/build/storage/storage-daemon/storage-daemon /usr/local/bin/
3333
COPY --from=builder /ton/build/storage/storage-daemon/storage-daemon-cli /usr/local/bin/
3434
COPY --from=builder /ton/build/lite-client/lite-client /usr/local/bin/
3535
COPY --from=builder /ton/build/validator-engine/validator-engine /usr/local/bin/
3636
COPY --from=builder /ton/build/validator-engine-console/validator-engine-console /usr/local/bin/
3737
COPY --from=builder /ton/build/utils/generate-random-id /usr/local/bin/
38+
COPY --from=builder /ton/build/crypto/fift /usr/local/bin/
39+
COPY --from=builder /ton/build/crypto/func /usr/local/bin/
40+
COPY --from=builder /ton/crypto/smartcont/* /usr/share/ton/smartcont/
41+
COPY --from=builder /ton/crypto/fift/lib/* /usr/lib/fift/
3842

3943
WORKDIR /var/ton-work/db
4044
COPY ./docker/init.sh ./docker/control.template /var/ton-work/scripts/

adnl/adnl-peer.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ void AdnlPeerPairImpl::send_messages_in(std::vector<OutboundAdnlMessage> message
269269
size_t ptr = 0;
270270
bool first = true;
271271
do {
272+
respond_with_nop_after_ = td::Timestamp::in(td::Random::fast(1.0, 2.0));
272273
bool try_reinit = try_reinit_at_ && try_reinit_at_.is_in_past();
274+
if (try_reinit) {
275+
try_reinit_at_ = td::Timestamp::in(td::Random::fast(0.5, 1.5));
276+
}
273277
bool via_channel = channel_ready_ && !try_reinit;
274278
size_t s = (via_channel ? channel_packet_header_max_size() : packet_header_max_size());
275279
if (first) {
@@ -504,12 +508,6 @@ void AdnlPeerPairImpl::create_channel(pubkeys::Ed25519 pub, td::uint32 date) {
504508

505509
void AdnlPeerPairImpl::process_message(const adnlmessage::AdnlMessageCreateChannel &message) {
506510
create_channel(message.key(), message.date());
507-
if (respond_to_channel_create_after_.is_in_past()) {
508-
respond_to_channel_create_after_ = td::Timestamp::in(td::Random::fast(1.0, 2.0));
509-
std::vector<OutboundAdnlMessage> messages;
510-
messages.emplace_back(adnlmessage::AdnlMessageNop{}, 0);
511-
send_messages(std::move(messages));
512-
}
513511
}
514512

515513
void AdnlPeerPairImpl::process_message(const adnlmessage::AdnlMessageConfirmChannel &message) {
@@ -526,6 +524,7 @@ void AdnlPeerPairImpl::process_message(const adnlmessage::AdnlMessageConfirmChan
526524
}
527525

528526
void AdnlPeerPairImpl::process_message(const adnlmessage::AdnlMessageCustom &message) {
527+
respond_with_nop();
529528
td::actor::send_closure(local_actor_, &AdnlLocalId::deliver, peer_id_short_, message.data());
530529
}
531530

@@ -538,6 +537,7 @@ void AdnlPeerPairImpl::process_message(const adnlmessage::AdnlMessageReinit &mes
538537
}
539538

540539
void AdnlPeerPairImpl::process_message(const adnlmessage::AdnlMessageQuery &message) {
540+
respond_with_nop();
541541
auto P = td::PromiseCreator::lambda([SelfId = actor_id(this), query_id = message.query_id(),
542542
flags = static_cast<td::uint32>(0)](td::Result<td::BufferSlice> R) {
543543
if (R.is_error()) {
@@ -556,6 +556,7 @@ void AdnlPeerPairImpl::process_message(const adnlmessage::AdnlMessageQuery &mess
556556
}
557557

558558
void AdnlPeerPairImpl::process_message(const adnlmessage::AdnlMessageAnswer &message) {
559+
respond_with_nop();
559560
auto Q = out_queries_.find(message.query_id());
560561

561562
if (Q == out_queries_.end()) {
@@ -573,6 +574,7 @@ void AdnlPeerPairImpl::process_message(const adnlmessage::AdnlMessageAnswer &mes
573574
}
574575

575576
void AdnlPeerPairImpl::process_message(const adnlmessage::AdnlMessagePart &message) {
577+
respond_with_nop();
576578
auto size = message.total_size();
577579
if (size > huge_packet_max_size()) {
578580
VLOG(ADNL_WARNING) << this << ": dropping too big huge message: size=" << size;
@@ -635,6 +637,14 @@ void AdnlPeerPairImpl::delete_query(AdnlQueryId id) {
635637
}
636638
}
637639

640+
void AdnlPeerPairImpl::respond_with_nop() {
641+
if (respond_with_nop_after_.is_in_past()) {
642+
std::vector<OutboundAdnlMessage> messages;
643+
messages.emplace_back(adnlmessage::AdnlMessageNop{}, 0);
644+
send_messages(std::move(messages));
645+
}
646+
}
647+
638648
void AdnlPeerPairImpl::reinit(td::int32 date) {
639649
if (reinit_date_ == 0) {
640650
reinit_date_ = date;

adnl/adnl-peer.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class AdnlPeerPairImpl : public AdnlPeerPair {
122122
}
123123

124124
private:
125+
void respond_with_nop();
125126
void reinit(td::int32 date);
126127
td::Result<std::pair<td::actor::ActorId<AdnlNetworkConnection>, bool>> get_conn(bool direct_only);
127128
void create_channel(pubkeys::Ed25519 pub, td::uint32 date);
@@ -214,7 +215,7 @@ class AdnlPeerPairImpl : public AdnlPeerPair {
214215
pubkeys::Ed25519 channel_pub_;
215216
td::int32 channel_pk_date_;
216217
td::actor::ActorOwn<AdnlChannel> channel_;
217-
td::Timestamp respond_to_channel_create_after_;
218+
td::Timestamp respond_with_nop_after_;
218219

219220
td::uint64 in_seqno_ = 0;
220221
td::uint64 out_seqno_ = 0;

assembly/wasm/fift-func-wasm-build-ubuntu.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ cd ..
8585
if [ ! -f "openssl/openssl_em" ]; then
8686
cd openssl
8787
make clean
88-
emconfigure ./Configure linux-generic32 no-shared no-dso no-engine no-unit-test
88+
emconfigure ./Configure linux-generic32 no-shared no-dso no-engine no-unit-test no-tests no-fuzz-afl no-fuzz-libfuzzer
8989
sed -i 's/CROSS_COMPILE=.*/CROSS_COMPILE=/g' Makefile
9090
sed -i 's/-ldl//g' Makefile
9191
sed -i 's/-O3/-Os/g' Makefile

catchain/catchain-receiver-source.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class CatChainReceiverSource {
6161
virtual td::BufferSlice fork_proof() const = 0;
6262
virtual bool fork_is_found() const = 0;
6363

64-
// One block can be sent to one node only a limited number of times to prevent DoS
64+
// One block can be sent to one node in catchain.getDifference only a limited number of times to prevent DoS
6565
virtual bool allow_send_block(CatChainBlockHash hash) = 0;
6666

6767
static td::Result<std::unique_ptr<CatChainReceiverSource>> create(CatChainReceiver *chain, PublicKey pub_key,

catchain/catchain-receiver.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,8 @@ void CatChainReceiverImpl::process_query(adnl::AdnlNodeIdShort src, ton_api::cat
697697
} else {
698698
CatChainReceiverSource *S = get_source_by_adnl_id(src);
699699
CHECK(S != nullptr);
700-
if (S->allow_send_block(it->second->get_hash())) {
701-
promise.set_value(serialize_tl_object(create_tl_object<ton_api::catchain_blockResult>(it->second->export_tl()),
702-
true, it->second->get_payload().as_slice()));
703-
} else {
704-
promise.set_error(td::Status::Error("block was requested too many times"));
705-
}
700+
promise.set_value(serialize_tl_object(create_tl_object<ton_api::catchain_blockResult>(it->second->export_tl()),
701+
true, it->second->get_payload().as_slice()));
706702
}
707703
}
708704

catchain/catchain.h

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class CatChain : public td::actor::Actor {
9696
virtual void send_query_via(const PublicKeyHash &dst, std::string name, td::Promise<td::BufferSlice> promise,
9797
td::Timestamp timeout, td::BufferSlice query, td::uint64 max_answer_size,
9898
td::actor::ActorId<adnl::AdnlSenderInterface> via) = 0;
99+
virtual void get_source_heights(td::Promise<std::vector<CatChainBlockHeight>> promise) = 0;
99100
virtual void destroy() = 0;
100101

101102
static td::actor::ActorOwn<CatChain> create(std::unique_ptr<Callback> callback, const CatChainOptions &opts,

catchain/catchain.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ class CatChainImpl : public CatChain {
115115
td::actor::send_closure(receiver_, &CatChainReceiverInterface::send_custom_query_data_via, dst, name,
116116
std::move(promise), timeout, std::move(query), max_answer_size, via);
117117
}
118+
void get_source_heights(td::Promise<std::vector<CatChainBlockHeight>> promise) override {
119+
std::vector<CatChainBlockHeight> heights(top_source_blocks_.size(), 0);
120+
for (size_t i = 0; i < top_source_blocks_.size(); ++i) {
121+
if (top_source_blocks_[i]) {
122+
heights[i] = top_source_blocks_[i]->height();
123+
}
124+
}
125+
promise.set_result(std::move(heights));
126+
}
118127
void destroy() override;
119128
CatChainImpl(std::unique_ptr<Callback> callback, const CatChainOptions &opts,
120129
td::actor::ActorId<keyring::Keyring> keyring, td::actor::ActorId<adnl::Adnl> adnl,

crypto/vm/bls.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ bool aggregate_verify(const std::vector<std::pair<P1, td::BufferSlice>> &pubs_ms
9393
return false;
9494
}
9595
std::unique_ptr<blst::Pairing> pairing = std::make_unique<blst::Pairing>(true, DST);
96+
blst::P2_Affine p2_zero;
9697
for (const auto &p : pubs_msgs) {
9798
blst::P1_Affine p1(p.first.data(), P1_SIZE);
9899
if (!p1.in_group() || p1.is_inf()) {
99100
return false;
100101
}
101-
pairing->aggregate(&p1, nullptr, (const td::uint8 *)p.second.data(), p.second.size());
102+
pairing->aggregate(&p1, &p2_zero, (const td::uint8 *)p.second.data(), p.second.size());
102103
}
103104
pairing->commit();
104105
blst::P2_Affine p2(sig.data(), P2_SIZE);

dht-server/dht-server.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -1231,15 +1231,19 @@ int main(int argc, char *argv[]) {
12311231
});
12321232
td::uint32 threads = 7;
12331233
p.add_checked_option(
1234-
't', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice fname) {
1234+
't', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice arg) {
12351235
td::int32 v;
12361236
try {
1237-
v = std::stoi(fname.str());
1237+
v = std::stoi(arg.str());
12381238
} catch (...) {
12391239
return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: not a number");
12401240
}
1241-
if (v < 1 || v > 256) {
1242-
return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be in range [1..256]");
1241+
if (v <= 0) {
1242+
return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be > 0");
1243+
}
1244+
if (v > 127) {
1245+
LOG(WARNING) << "`--threads " << v << "` is too big, effective value will be 127";
1246+
v = 127;
12431247
}
12441248
threads = v;
12451249
return td::Status::OK();

dht/dht-in.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class DhtMemberImpl : public DhtMember {
179179
void get_value(DhtKey key, td::Promise<DhtValue> result) override {
180180
get_value_in(key.compute_key_id(), std::move(result));
181181
}
182+
void get_value_many(DhtKey key, std::function<void(DhtValue)> callback, td::Promise<td::Unit> promise) override;
182183

183184
void alarm() override {
184185
alarm_timestamp() = td::Timestamp::in(1.0);

dht/dht-query.cpp

+31-3
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,11 @@ void DhtQueryFindValue::on_result(td::Result<td::BufferSlice> R, adnl::AdnlNodeI
210210
send_get_nodes = true;
211211
return;
212212
}
213-
promise_.set_value(std::move(value));
214-
need_stop = true;
213+
if (on_value_found(std::move(value))) {
214+
send_get_nodes = true;
215+
} else {
216+
need_stop = true;
217+
}
215218
},
216219
[&](ton_api::dht_valueNotFound &v) {
217220
add_nodes(DhtNodesList{std::move(v.nodes_), our_network_id()});
@@ -244,7 +247,32 @@ void DhtQueryFindValue::on_result_nodes(td::Result<td::BufferSlice> R, adnl::Adn
244247
}
245248

246249
void DhtQueryFindValue::finish(DhtNodesList list) {
247-
promise_.set_error(td::Status::Error(ErrorCode::notready, "dht key not found"));
250+
}
251+
252+
bool DhtQueryFindValueSingle::on_value_found(DhtValue value) {
253+
promise_.set_value(std::move(value));
254+
found_ = true;
255+
return false;
256+
}
257+
258+
void DhtQueryFindValueSingle::tear_down() {
259+
if (!found_) {
260+
promise_.set_error(td::Status::Error(ErrorCode::notready, "dht key not found"));
261+
}
262+
}
263+
264+
bool DhtQueryFindValueMany::on_value_found(DhtValue value) {
265+
callback_(std::move(value));
266+
found_ = true;
267+
return true;
268+
}
269+
270+
void DhtQueryFindValueMany::tear_down() {
271+
if (found_) {
272+
promise_.set_value(td::Unit());
273+
} else {
274+
promise_.set_error(td::Status::Error(ErrorCode::notready, "dht key not found"));
275+
}
248276
}
249277

250278
DhtQueryStore::DhtQueryStore(DhtValue key_value, DhtMember::PrintId print_id, adnl::AdnlNodeIdShort src,

dht/dht-query.hpp

+44-7
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,11 @@ class DhtQueryFindNodes : public DhtQuery {
126126
};
127127

128128
class DhtQueryFindValue : public DhtQuery {
129-
private:
130-
td::Promise<DhtValue> promise_;
131-
132129
public:
133130
DhtQueryFindValue(DhtKeyId key, DhtMember::PrintId print_id, adnl::AdnlNodeIdShort src, DhtNodesList list,
134131
td::uint32 k, td::uint32 a, td::int32 our_network_id, DhtNode self, bool client_only,
135-
td::actor::ActorId<DhtMember> node, td::actor::ActorId<adnl::Adnl> adnl,
136-
td::Promise<DhtValue> promise)
137-
: DhtQuery(key, print_id, src, k, a, our_network_id, std::move(self), client_only, node, adnl)
138-
, promise_(std::move(promise)) {
132+
td::actor::ActorId<DhtMember> node, td::actor::ActorId<adnl::Adnl> adnl)
133+
: DhtQuery(key, print_id, src, k, a, our_network_id, std::move(self), client_only, node, adnl) {
139134
add_nodes(std::move(list));
140135
}
141136
void send_one_query(adnl::AdnlNodeIdShort id) override;
@@ -146,6 +141,48 @@ class DhtQueryFindValue : public DhtQuery {
146141
std::string get_name() const override {
147142
return "find value";
148143
}
144+
145+
virtual bool on_value_found(DhtValue value) = 0;
146+
};
147+
148+
class DhtQueryFindValueSingle : public DhtQueryFindValue {
149+
public:
150+
DhtQueryFindValueSingle(DhtKeyId key, DhtMember::PrintId print_id, adnl::AdnlNodeIdShort src, DhtNodesList list,
151+
td::uint32 k, td::uint32 a, td::int32 our_network_id, DhtNode self, bool client_only,
152+
td::actor::ActorId<DhtMember> node, td::actor::ActorId<adnl::Adnl> adnl,
153+
td::Promise<DhtValue> promise)
154+
: DhtQueryFindValue(key, print_id, src, std::move(list), k, a, our_network_id, std::move(self), client_only, node,
155+
adnl)
156+
, promise_(std::move(promise)) {
157+
add_nodes(std::move(list));
158+
}
159+
bool on_value_found(DhtValue value) override;
160+
void tear_down() override;
161+
162+
private:
163+
td::Promise<DhtValue> promise_;
164+
bool found_ = false;
165+
};
166+
167+
class DhtQueryFindValueMany : public DhtQueryFindValue {
168+
public:
169+
DhtQueryFindValueMany(DhtKeyId key, DhtMember::PrintId print_id, adnl::AdnlNodeIdShort src, DhtNodesList list,
170+
td::uint32 k, td::uint32 a, td::int32 our_network_id, DhtNode self, bool client_only,
171+
td::actor::ActorId<DhtMember> node, td::actor::ActorId<adnl::Adnl> adnl,
172+
std::function<void(DhtValue)> callback, td::Promise<td::Unit> promise)
173+
: DhtQueryFindValue(key, print_id, src, std::move(list), k, a, our_network_id, std::move(self), client_only, node,
174+
adnl)
175+
, callback_(std::move(callback))
176+
, promise_(std::move(promise)) {
177+
add_nodes(std::move(list));
178+
}
179+
bool on_value_found(DhtValue value) override;
180+
void tear_down() override;
181+
182+
private:
183+
std::function<void(DhtValue)> callback_;
184+
td::Promise<td::Unit> promise_;
185+
bool found_ = false;
149186
};
150187

151188
class DhtQueryStore : public td::actor::Actor {

0 commit comments

Comments
 (0)