Skip to content

Commit b083624

Browse files
authored
Some standalone fixes from new consensus dev branch (#1895)
* Compile libraries in third-party/ with sanitizers as well This is not a complete solution (with sanitizers, you ideally need a build-the-world-with-sanitizers approach) but is good enough for abseil to stop producing memory errors. * First reset td::Promise and then execute callback Callback can override promise inplace, so doing it the other way can reset a newly created PromiseInterface. * [tontester] Allow to run node under `rr record`
1 parent b008305 commit b083624

File tree

3 files changed

+55
-31
lines changed

3 files changed

+55
-31
lines changed

CMakeLists.txt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ if (TON_WERROR_BUILD)
9999
add_compile_options(-Werror)
100100
endif()
101101

102+
if (TON_USE_ASAN)
103+
add_compile_options(-fsanitize=address)
104+
add_link_options(-fsanitize=address)
105+
add_definitions(-DTD_USE_ASAN=1)
106+
endif()
107+
if (TON_USE_TSAN)
108+
add_compile_options(-fsanitize=thread)
109+
add_link_options(-fsanitize=thread)
110+
endif()
111+
if (TON_USE_UBSAN)
112+
add_compile_options(-fsanitize=undefined)
113+
add_link_options(-fsanitize=undefined)
114+
endif()
115+
102116
if (TON_USE_ABSEIL)
103117
message("Add abseil-cpp")
104118
function(abseil_scope)
@@ -338,19 +352,6 @@ if (GCC OR CLANG)
338352
endif()
339353
endif()
340354

341-
if (TON_USE_ASAN)
342-
add_compile_options(-fsanitize=address)
343-
add_link_options(-fsanitize=address)
344-
add_definitions(-DTD_USE_ASAN=1)
345-
endif()
346-
if (TON_USE_TSAN)
347-
add_compile_options(-fsanitize=thread)
348-
add_link_options(-fsanitize=thread)
349-
endif()
350-
if (TON_USE_UBSAN)
351-
add_compile_options(-fsanitize=undefined)
352-
add_link_options(-fsanitize=undefined)
353-
endif()
354355
if (TON_USE_COVERAGE)
355356
add_cxx_compiler_flag("-fprofile-arcs")
356357
add_cxx_compiler_flag("-ftest-coverage")

tdactor/td/actor/PromiseFuture.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,31 +232,31 @@ class Promise {
232232
if (!promise_) {
233233
return;
234234
}
235-
promise_->set_value(std::move(value));
236-
promise_.reset();
235+
auto promise = std::exchange(promise_, nullptr);
236+
promise->set_value(std::move(value));
237237
}
238238
void set_error(Status &&error) {
239239
if (!promise_) {
240240
return;
241241
}
242-
promise_->set_error(std::move(error));
243-
promise_.reset();
242+
auto promise = std::exchange(promise_, nullptr);
243+
promise->set_error(std::move(error));
244244
}
245245

246246
void set_result(Result<T> &&result) {
247247
if (!promise_) {
248248
return;
249249
}
250-
promise_->set_result(std::move(result));
251-
promise_.reset();
250+
auto promise = std::exchange(promise_, nullptr);
251+
promise->set_result(std::move(result));
252252
}
253253
template <class S>
254254
void operator()(S &&result) {
255255
if (!promise_) {
256256
return;
257257
}
258-
promise_->operator()(std::forward<S>(result));
259-
promise_.reset();
258+
auto promise = std::exchange(promise_, nullptr);
259+
promise->operator()(std::forward<S>(result));
260260
}
261261
void reset() {
262262
promise_.reset();

test/tontester/src/tontester/network.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from enum import IntEnum, auto
99
from ipaddress import IPv4Address
1010
from pathlib import Path
11-
from typing import cast, final, override
11+
from typing import Literal, cast, final, override
1212

1313
from pytonlib import TonlibClient, TonlibError # pyright: ignore[reportMissingTypeStubs]
1414

@@ -39,6 +39,9 @@ def _write_model(file: Path, model: TLObject):
3939
_ = file.write_text(model.to_json())
4040

4141

42+
type DebugType = None | Literal["rr"]
43+
44+
4245
@final
4346
class Network:
4447
class Node(ABC):
@@ -88,6 +91,8 @@ async def _run(
8891
local_config: ton_api.Engine_validator_config,
8992
validator_config: ton_api.Validator_config_global | None,
9093
additional_args: list[str],
94+
*,
95+
debug: DebugType = None,
9196
):
9297
async def process_watcher():
9398
assert self.__process is not None
@@ -121,18 +126,35 @@ async def process_watcher():
121126
log_path = self._directory / "log"
122127
l.info(f"Running {self.name} and saving its raw log to {log_path}")
123128

124-
self.__process = await asyncio.create_subprocess_exec(
125-
executable,
129+
cmd_flags = [
126130
"--global-config",
127131
global_config_file,
128132
"--local-config",
129133
local_config_file,
130134
"--db",
131135
".",
132136
*additional_args,
133-
cwd=self._directory,
134-
stderr=asyncio.subprocess.PIPE,
135-
)
137+
]
138+
139+
match debug:
140+
case None:
141+
self.__process = await asyncio.create_subprocess_exec(
142+
executable,
143+
*cmd_flags,
144+
cwd=self._directory,
145+
stderr=asyncio.subprocess.PIPE,
146+
)
147+
case "rr":
148+
l.info(f"Recording {self.name} with rr")
149+
self.__process = await asyncio.create_subprocess_exec(
150+
"rr",
151+
"record",
152+
executable,
153+
*cmd_flags,
154+
cwd=self._directory,
155+
stderr=asyncio.subprocess.PIPE,
156+
)
157+
136158
assert self.__process.stderr is not None # to placate pyright
137159
self.__process_watcher = asyncio.create_task(process_watcher())
138160

@@ -146,7 +168,7 @@ def announce_to(self, dht: "DHTNode"):
146168
self._static_nodes.append(dht)
147169

148170
@abstractmethod
149-
async def run(self):
171+
async def run(self, *, debug: DebugType = None):
150172
pass
151173

152174
async def stop(self):
@@ -321,8 +343,8 @@ def signed_address(self):
321343
return self._signed_address
322344

323345
@override
324-
async def run(self):
325-
await self._run(self._install.dht_server_exe, self._local_config, None, [])
346+
async def run(self, *, debug: DebugType = None):
347+
await self._run(self._install.dht_server_exe, self._local_config, None, [], debug=debug)
326348

327349

328350
@final
@@ -399,7 +421,7 @@ def validator_key(self):
399421
return self._validator_key
400422

401423
@override
402-
async def run(self):
424+
async def run(self, *, debug: DebugType = None):
403425
zerostate = self._get_or_generate_zerostate()
404426

405427
static_dir = self._directory / "static"
@@ -412,6 +434,7 @@ async def run(self):
412434
self._local_config,
413435
zerostate.as_validator_config(),
414436
["--initial-sync-delay", "5"],
437+
debug=debug,
415438
)
416439

417440
async def tonlib_client(self) -> TonlibClient:

0 commit comments

Comments
 (0)