From 1bad858506f22eb34b7902ebd288d3d67c092129 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 03:58:16 +0100 Subject: [PATCH 01/12] ci: the platform check keeps the node logs and a macOS stack sample of a node that did not reach the head Co-Authored-By: Claude Opus 5.5 --- .github/workflows/platform-sync.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/platform-sync.yml b/.github/workflows/platform-sync.yml index eb2256f96..84261e238 100644 --- a/.github/workflows/platform-sync.yml +++ b/.github/workflows/platform-sync.yml @@ -140,6 +140,11 @@ jobs: env: OS: ${{ matrix.os }} run: | + mkdir -p result + # a node that never reached the head: where its threads are + if [ "$OS" = macos ] && [ -n "${NODE_PID:-}" ] && kill -0 "$NODE_PID" 2>/dev/null; then + sample "$NODE_PID" 5 -file result/sample-macos.txt >/dev/null 2>&1 || true + fi if [ "$OS" = windows ]; then taskkill //F //IM node.exe >/dev/null 2>&1 || true taskkill //F //IM java.exe >/dev/null 2>&1 || true @@ -148,10 +153,10 @@ jobs: for _ in $(seq 1 120); do [ -z "${NODE_PID:-}" ] || kill -0 "$NODE_PID" 2>/dev/null || break; sleep 1; done pkill -f '[c]ontract-executor[.]jar' || true fi - mkdir -p result cat csnode/log/log_*.txt 2>/dev/null | grep -a "STATE DIGEST #" > "result/digests-$OS.txt" || true cat csnode/log/log_*.txt 2>/dev/null | grep -aE "counted transactions is different|Couldn't save block|is not on this chain|but its caches already hold block|snapshot.verified|snapshot.mismatch" | head -50 > "result/problems-$OS.txt" || true tail -c 2000000 csnode/stdout.log > "result/stdout-$OS.log" 2>/dev/null || true + for f in csnode/log/*; do [ -f "$f" ] && tail -c 3000000 "$f" > "result/$OS-$(basename "$f")"; done 2>/dev/null || true echo "$(wc -l < "result/digests-$OS.txt") digest lines"; tail -3 "result/digests-$OS.txt" - name: Upload the digests From a4a41f667d9b40ac27f27c832c0e32c283889c70 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 04:05:26 +0100 Subject: [PATCH 02/12] Checkpoints load on Windows, Linux and macOS whichever system wrote them A boost binary archive header records sizeof(long), 8 on Linux and macOS and 4 on Windows, and binary_iarchive refuses another size: a Windows node could not load the published snapshot's checkpoint. No checkpoint field is a long (64-bit fields are int64_t/uint64_t, 8 bytes on every system), so only that header byte differs: - cs::ArchiveInput reads it as this system's value (4 or 8 only; anything else as before) - cs::ArchiveOutput writes 8 on every system, so a checkpoint and a snapshot made of it have the same bytes everywhere and nodes without this change read them The hashes of the caches are computed without a header and do not change. Co-Authored-By: Claude Opus 5.5 --- csnode/include/csnode/archive_stream.hpp | 189 +++++++++++++++++++++++ csnode/src/apihandler_serializer.cpp | 7 +- csnode/src/blockchain_serializer.cpp | 13 +- csnode/src/roundstat_serializer.cpp | 7 +- csnode/src/smartcontracts_serializer.cpp | 7 +- csnode/src/walletsids_serializer.cpp | 7 +- tests/csnode/archive_stream_tests.cpp | 154 ++++++++++++++++++ 7 files changed, 372 insertions(+), 12 deletions(-) create mode 100644 csnode/include/csnode/archive_stream.hpp create mode 100644 tests/csnode/archive_stream_tests.cpp diff --git a/csnode/include/csnode/archive_stream.hpp b/csnode/include/csnode/archive_stream.hpp new file mode 100644 index 000000000..c78231670 --- /dev/null +++ b/csnode/include/csnode/archive_stream.hpp @@ -0,0 +1,189 @@ +#ifndef ARCHIVE_STREAM_HPP +#define ARCHIVE_STREAM_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace cs { + +// The input of a boost binary_iarchive that reads a checkpoint written on another system. +// +// A binary_oarchive header records the native sizes of int, long, float and double, and +// binary_iarchive refuses a header whose sizes differ from its own: long is 8 bytes on Linux and +// macOS, 4 on Windows, so a checkpoint (or a snapshot made of one) from one system did not load on +// the other. No checkpoint field is a long: 64-bit fields are int64_t/uint64_t, written as 8 bytes +// on every system, and boost writes its own counts as 8-byte size_t on 64-bit systems. The size of +// long in the header is the only difference, and it is read here as this system's own. +// +// Header of boost 1.83: size_t length (22) | "serialization::archive" | uint16 library version | +// sizeof(int) | sizeof(long) | sizeof(float) | sizeof(double) | int 1 (byte order). Anything else is +// passed through unchanged, for binary_iarchive to accept or refuse as before. +class ArchiveInputBuf : public std::streambuf { +public: + explicit ArchiveInputBuf(std::streambuf* source) + : source_(source) { + head_.resize(kHeaderSize); + head_.resize(static_cast(source_->sgetn(head_.data(), static_cast(kHeaderSize)))); + patchHeader(); + setg(head_.data(), head_.data(), head_.data() + head_.size()); + } + + static constexpr size_t kSignatureSize = 22; + static constexpr size_t kLongSizeOffset = sizeof(uint64_t) + kSignatureSize + sizeof(uint16_t) + 1; + static constexpr size_t kHeaderSize = kLongSizeOffset + 3 + sizeof(int32_t); + +protected: + int_type underflow() override { + if (gptr() < egptr()) { + return traits_type::to_int_type(*gptr()); + } + buffer_.resize(kChunk); + const auto n = source_->sgetn(buffer_.data(), static_cast(buffer_.size())); + if (n <= 0) { + return traits_type::eof(); + } + setg(buffer_.data(), buffer_.data(), buffer_.data() + n); + return traits_type::to_int_type(*gptr()); + } + +private: + static constexpr size_t kChunk = 1 << 16; + + void patchHeader() { + if (head_.size() < kHeaderSize) { + return; + } + uint64_t length = 0; + for (size_t i = 0; i < sizeof(length); ++i) { + length |= static_cast(static_cast(head_[i])) << (8 * i); + } + static const char kSignature[] = "serialization::archive"; + if (length != kSignatureSize || std::memcmp(head_.data() + sizeof(uint64_t), kSignature, kSignatureSize) != 0) { + return; + } + auto byteAt = [this](size_t i) { return static_cast(head_[i]); }; + const bool sizesAsExpected = byteAt(kLongSizeOffset - 1) == sizeof(int32_t) && byteAt(kLongSizeOffset + 1) == sizeof(float) && + byteAt(kLongSizeOffset + 2) == sizeof(double); + const auto longSize = byteAt(kLongSizeOffset); + if (sizesAsExpected && (longSize == 4 || longSize == 8)) { + head_[kLongSizeOffset] = static_cast(sizeof(long)); + } + } + + std::streambuf* source_; + std::vector head_; + std::vector buffer_; +}; + +// usage: std::ifstream ifs(path, std::ios::binary); cs::ArchiveInput in(ifs); boost::archive::binary_iarchive ia(in); +class ArchiveInput : public std::istream { +public: + explicit ArchiveInput(std::istream& source) + : std::istream(nullptr) + , buf_(source.rdbuf()) { + rdbuf(&buf_); + if (!source) { + setstate(std::ios::badbit); + } + } + +private: + ArchiveInputBuf buf_; +}; + +// The output of a boost binary_oarchive for a checkpoint: the header records long as 8 bytes on +// every system, so that a checkpoint (and a snapshot made of one) has the same bytes on Windows as +// on Linux and macOS, and nodes without ArchiveInput read it too. Only that header byte changes. +class ArchiveOutputBuf : public std::streambuf { +public: + explicit ArchiveOutputBuf(std::streambuf* target) + : target_(target) { + } + +protected: + int_type overflow(int_type c) override { + if (traits_type::eq_int_type(c, traits_type::eof())) { + return traits_type::not_eof(c); + } + const char ch = traits_type::to_char_type(c); + return xsputn(&ch, 1) == 1 ? c : traits_type::eof(); + } + + std::streamsize xsputn(const char* s, std::streamsize n) override { + if (n <= 0) { + return 0; + } + const auto count = static_cast(n); + if (written_ > ArchiveInputBuf::kLongSizeOffset) { + return put(s, n); + } + std::vector copy(s, s + count); + for (size_t i = 0; i < count && written_ + i <= ArchiveInputBuf::kLongSizeOffset; ++i) { + const auto at = written_ + i; + if (at < ArchiveInputBuf::kLongSizeOffset) { + head_[at] = copy[i]; + } + else if (signatureWritten() && (copy[i] == 4 || copy[i] == 8)) { + copy[i] = 8; + } + } + return put(copy.data(), n); + } + + int sync() override { + return target_->pubsync(); + } + +private: + std::streamsize put(const char* s, std::streamsize n) { + const auto done = target_->sputn(s, n); + written_ += static_cast(done > 0 ? done : 0); + return done; + } + + bool signatureWritten() const { + static const char kSignature[] = "serialization::archive"; + for (size_t i = 1; i < sizeof(uint64_t); ++i) { + if (head_[i] != 0) { + return false; + } + } + return static_cast(head_[0]) == ArchiveInputBuf::kSignatureSize && + std::memcmp(head_.data() + sizeof(uint64_t), kSignature, ArchiveInputBuf::kSignatureSize) == 0 && + static_cast(head_[ArchiveInputBuf::kLongSizeOffset - 1]) == sizeof(int32_t); + } + + std::streambuf* target_; + size_t written_ = 0; + std::array head_{}; +}; + +// usage: std::ofstream ofs(path, std::ios::binary); cs::ArchiveOutput out(ofs); boost::archive::binary_oarchive oa(out); +class ArchiveOutput : public std::ostream { +public: + explicit ArchiveOutput(std::ostream& target) + : std::ostream(nullptr) + , buf_(target.rdbuf()) { + rdbuf(&buf_); + if (!target) { + setstate(std::ios::badbit); + } + } + + ~ArchiveOutput() override { + flush(); + } + +private: + ArchiveOutputBuf buf_; +}; + +} // namespace cs + +#endif // ARCHIVE_STREAM_HPP diff --git a/csnode/src/apihandler_serializer.cpp b/csnode/src/apihandler_serializer.cpp index 2befc9258..16bc2fb5e 100644 --- a/csnode/src/apihandler_serializer.cpp +++ b/csnode/src/apihandler_serializer.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -28,7 +29,8 @@ void APIHandler_Serializer::bind(api::APIHandler& apih) { void APIHandler_Serializer::save(const std::filesystem::path& rootDir) { std::ofstream ofs(rootDir / kDataFileName, std::ios::binary); - boost::archive::binary_oarchive oa(ofs); + cs::ArchiveOutput out(ofs); // the same header bytes on every system + boost::archive::binary_oarchive oa(out); auto saveHelper = [&](auto& entity) { auto ref = lockedReference(entity); @@ -45,7 +47,8 @@ void APIHandler_Serializer::save(const std::filesystem::path& rootDir) { void APIHandler_Serializer::load(const std::filesystem::path& rootDir) { std::ifstream ifs(rootDir / kDataFileName, std::ios::binary); - boost::archive::binary_iarchive ia(ifs); + cs::ArchiveInput in(ifs); // also a checkpoint written on another system + boost::archive::binary_iarchive ia(in); auto loadHelper = [&](auto& entity) { auto ref = lockedReference(entity); diff --git a/csnode/src/blockchain_serializer.cpp b/csnode/src/blockchain_serializer.cpp index 7bd2da180..b9ac2b4d5 100644 --- a/csnode/src/blockchain_serializer.cpp +++ b/csnode/src/blockchain_serializer.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -69,7 +70,8 @@ void BlockChain_Serializer::clear(const std::filesystem::path& rootDir) { void BlockChain_Serializer::save(const std::filesystem::path& rootDir) { std::ofstream ofs(rootDir / kDataFileName, std::ios::binary); - boost::archive::binary_oarchive oa(ofs); + cs::ArchiveOutput out(ofs); // the same header bytes on every system + boost::archive::binary_oarchive oa(out); oa << *previousNonEmpty_; oa << *lastNonEmptyBlock_; oa << *totalTransactionsCount_; @@ -88,7 +90,8 @@ void BlockChain_Serializer::save(const std::filesystem::path& rootDir) { void BlockChain_Serializer::savePending(const std::filesystem::path& rootDir) { std::ofstream ofs(rootDir / kPendingFileName, std::ios::binary); - boost::archive::binary_oarchive oa(ofs); + cs::ArchiveOutput out(ofs); // the same header bytes on every system + boost::archive::binary_oarchive oa(out); oa << kPendingFormat; oa << *pendingRound_; oa << *pendingStakingOn_ << *pendingMiningOn_; @@ -105,7 +108,8 @@ void BlockChain_Serializer::loadPending(const std::filesystem::path& rootDir) { return; } std::ifstream ifs(path, std::ios::binary); - boost::archive::binary_iarchive ia(ifs); + cs::ArchiveInput in(ifs); // also a checkpoint written on another system + boost::archive::binary_iarchive ia(in); uint8_t format = 0; ia >> format; if (format != 1 && format != kPendingFormat) { @@ -146,7 +150,8 @@ ::cscrypto::Hash BlockChain_Serializer::hash() { void BlockChain_Serializer::load(const std::filesystem::path& rootDir) { std::ifstream ifs(rootDir / kDataFileName, std::ios::binary); - boost::archive::binary_iarchive ia(ifs); + cs::ArchiveInput in(ifs); // also a checkpoint written on another system + boost::archive::binary_iarchive ia(in); ia >> *previousNonEmpty_; ia >> *lastNonEmptyBlock_; ia >> *totalTransactionsCount_; diff --git a/csnode/src/roundstat_serializer.cpp b/csnode/src/roundstat_serializer.cpp index 87f26f374..df4b0e878 100644 --- a/csnode/src/roundstat_serializer.cpp +++ b/csnode/src/roundstat_serializer.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -35,7 +36,8 @@ namespace cs { void RoundStat_Serializer::save(const std::filesystem::path& rootDir) { std::ofstream ofs(rootDir / kDataFileName, std::ios::binary); - boost::archive::binary_oarchive oa(ofs); + cs::ArchiveOutput out(ofs); // the same header bytes on every system + boost::archive::binary_oarchive oa(out); csdebug() << kLogPrefix << __func__; roundStat_->printClassInfo(); oa << roundStat_->serialize(); @@ -62,7 +64,8 @@ namespace cs { void RoundStat_Serializer::load(const std::filesystem::path& rootDir) { std::ifstream ifs(rootDir / kDataFileName, std::ios::binary); - boost::archive::binary_iarchive ia(ifs); + cs::ArchiveInput in(ifs); // also a checkpoint written on another system + boost::archive::binary_iarchive ia(in); csdebug() << kLogPrefix << __func__; Bytes data; ia >> data; diff --git a/csnode/src/smartcontracts_serializer.cpp b/csnode/src/smartcontracts_serializer.cpp index 4e1c613be..691803b50 100644 --- a/csnode/src/smartcontracts_serializer.cpp +++ b/csnode/src/smartcontracts_serializer.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -32,7 +33,8 @@ void SmartContracts_Serializer::clear(const std::filesystem::path& rootDir) { void SmartContracts_Serializer::save(const std::filesystem::path& rootDir) { std::ofstream ofs(rootDir / kDataFileName, std::ios::binary); - boost::archive::binary_oarchive oa(ofs); + cs::ArchiveOutput out(ofs); // the same header bytes on every system + boost::archive::binary_oarchive oa(out); csdebug() << kLogPrefix << __func__; contracts_->printClassInfo(); oa << contracts_->serialize(); @@ -60,7 +62,8 @@ ::cscrypto::Hash SmartContracts_Serializer::hash() { void SmartContracts_Serializer::load(const std::filesystem::path& rootDir) { std::ifstream ifs(rootDir / kDataFileName, std::ios::binary); - boost::archive::binary_iarchive ia(ifs); + cs::ArchiveInput in(ifs); // also a checkpoint written on another system + boost::archive::binary_iarchive ia(in); csdebug() << kLogPrefix << __func__; Bytes data; ia >> data; diff --git a/csnode/src/walletsids_serializer.cpp b/csnode/src/walletsids_serializer.cpp index fc61467f6..c5827fe2d 100644 --- a/csnode/src/walletsids_serializer.cpp +++ b/csnode/src/walletsids_serializer.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -33,7 +34,8 @@ void WalletsIds_Serializer::clear(const std::filesystem::path& rootDir) { void WalletsIds_Serializer::save(const std::filesystem::path& rootDir) { std::ofstream ofs(rootDir / kDataFileName, std::ios::binary); - boost::archive::binary_oarchive oa(ofs); + cs::ArchiveOutput out(ofs); // the same header bytes on every system + boost::archive::binary_oarchive oa(out); oa << *data_; oa << *nextId_; } @@ -65,7 +67,8 @@ ::cscrypto::Hash WalletsIds_Serializer::hash() { void WalletsIds_Serializer::load(const std::filesystem::path& rootDir) { std::ifstream ifs(rootDir / kDataFileName, std::ios::binary); - boost::archive::binary_iarchive ia(ifs); + cs::ArchiveInput in(ifs); // also a checkpoint written on another system + boost::archive::binary_iarchive ia(in); ia >> *data_; ia >> *nextId_; } diff --git a/tests/csnode/archive_stream_tests.cpp b/tests/csnode/archive_stream_tests.cpp new file mode 100644 index 000000000..ebf57519c --- /dev/null +++ b/tests/csnode/archive_stream_tests.cpp @@ -0,0 +1,154 @@ +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +namespace { +struct Data { + uint64_t sequence = 0; + int64_t signedValue = 0; + std::map counts; + std::vector bytes; + + template + void serialize(Archive& ar, const unsigned int) { + ar & sequence; + ar & signedValue; + ar & counts; + ar & bytes; + } +}; + +Data sample() { + Data d; + d.sequence = 186600000; + d.signedValue = -1234567890123; + d.counts = {{"a", 1}, {"contract", 1ll << 40}}; + d.bytes.assign(200000, 0x5a); // more than one chunk of the reader + d.bytes[123456] = 7; + return d; +} + +// an archive written here, with the header the other kind of system writes +std::string archiveWithLongSize(unsigned char longSize) { + std::ostringstream out(std::ios::binary); + { + boost::archive::binary_oarchive oa(out); + const auto d = sample(); + oa << d; + } + auto bytes = out.str(); + EXPECT_EQ(static_cast(bytes[cs::ArchiveInputBuf::kLongSizeOffset]), sizeof(long)); + bytes[cs::ArchiveInputBuf::kLongSizeOffset] = static_cast(longSize); + return bytes; +} + +void expectSample(const Data& d) { + const auto want = sample(); + EXPECT_EQ(d.sequence, want.sequence); + EXPECT_EQ(d.signedValue, want.signedValue); + EXPECT_EQ(d.counts, want.counts); + EXPECT_EQ(d.bytes, want.bytes); +} +} // namespace + +// a checkpoint from Windows (long of 4 bytes) on Linux/macOS, and from Linux/macOS on Windows +TEST(ArchiveInput, ReadsTheHeaderOfEitherSystem) { + for (unsigned char longSize : {4, 8}) { + std::istringstream source(archiveWithLongSize(longSize), std::ios::binary); + cs::ArchiveInput in(source); + boost::archive::binary_iarchive ia(in); + Data d; + ia >> d; + expectSample(d); + } +} + +TEST(ArchiveInput, PlainReaderRefusesTheOtherSystem) { + const unsigned char other = sizeof(long) == 8 ? 4 : 8; + std::istringstream source(archiveWithLongSize(other), std::ios::binary); + EXPECT_THROW(boost::archive::binary_iarchive ia(source), boost::archive::archive_exception); +} + +// other sizes than the two systems' are left for binary_iarchive to refuse +TEST(ArchiveInput, OtherHeadersPassUnchanged) { + std::istringstream source(archiveWithLongSize(2), std::ios::binary); + cs::ArchiveInput in(source); + EXPECT_THROW(boost::archive::binary_iarchive ia(in), boost::archive::archive_exception); + + std::istringstream garbage(std::string("not an archive at all, just bytes"), std::ios::binary); + cs::ArchiveInput in2(garbage); + EXPECT_ANY_THROW(boost::archive::binary_iarchive ia(in2)); // as without ArchiveInput + + std::istringstream empty(std::string(), std::ios::binary); + cs::ArchiveInput in3(empty); + EXPECT_ANY_THROW(boost::archive::binary_iarchive ia(in3)); +} + +// written through ArchiveOutput, the header says long is 8 bytes on every system and the rest is unchanged +TEST(ArchiveOutput, WritesTheSameHeaderOnEverySystem) { + std::ostringstream plain(std::ios::binary); + { + boost::archive::binary_oarchive oa(plain); + const auto d = sample(); + oa << d; + } + std::ostringstream canonical(std::ios::binary); + { + cs::ArchiveOutput out(canonical); + boost::archive::binary_oarchive oa(out); + const auto d = sample(); + oa << d; + } + auto expected = plain.str(); + expected[cs::ArchiveInputBuf::kLongSizeOffset] = 8; + EXPECT_EQ(canonical.str(), expected); + + std::istringstream source(canonical.str(), std::ios::binary); + cs::ArchiveInput in(source); + boost::archive::binary_iarchive ia(in); + Data d; + ia >> d; + expectSample(d); +} + +// the header of a Windows node (long of 4 bytes), written byte by byte or at once +TEST(ArchiveOutput, RewritesAFourByteLong) { + const auto windows = archiveWithLongSize(4); + for (bool byByte : {false, true}) { + std::ostringstream target(std::ios::binary); + { + cs::ArchiveOutput out(target); + if (byByte) { + for (char c : windows) { + out.put(c); + } + } + else { + out.write(windows.data(), static_cast(windows.size())); + } + } + auto expected = windows; + expected[cs::ArchiveInputBuf::kLongSizeOffset] = 8; + EXPECT_EQ(target.str(), expected); + } + // not an archive header: passed through + std::ostringstream target(std::ios::binary); + { + cs::ArchiveOutput out(target); + out << std::string(40, '\x04'); + } + EXPECT_EQ(target.str(), std::string(40, '\x04')); +} From ca695d875782fa5600663bb6e23b4aaf301131b9 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 04:15:41 +0100 Subject: [PATCH 03/12] Hash checkpoint files read in binary mode (the same bytes on Windows as on Linux) Co-Authored-By: Claude Opus 5.5 --- csnode/include/csnode/serializers_helper.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csnode/include/csnode/serializers_helper.hpp b/csnode/include/csnode/serializers_helper.hpp index 55232131b..0800ad669 100644 --- a/csnode/include/csnode/serializers_helper.hpp +++ b/csnode/include/csnode/serializers_helper.hpp @@ -12,7 +12,7 @@ class SerializersHelper { static const size_t kBufSize = 1 << 27; std::vector buf(::cscrypto::kHashSize + kBufSize, 0); { - std::ifstream ifs(fileName); + std::ifstream ifs(fileName, std::ios::binary); // text mode on Windows would change the bytes hashed while (!ifs.eof()) { ifs.read( reinterpret_cast(buf.data() + ::cscrypto::kHashSize), From aa7d588d80142a9a2f010ec9b879573a008b7a85 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 04:23:44 +0100 Subject: [PATCH 04/12] ci: the platform check records how the node exited and keeps macOS crash reports Co-Authored-By: Claude Opus 5.5 --- .github/workflows/platform-sync.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/platform-sync.yml b/.github/workflows/platform-sync.yml index 84261e238..d87797d44 100644 --- a/.github/workflows/platform-sync.yml +++ b/.github/workflows/platform-sync.yml @@ -130,8 +130,11 @@ jobs: TIMEOUT_MIN: ${{ inputs.timeout_min || '180' }} run: | cd csnode - ${{ matrix.node }} --config-file config.ini stdout.log 2>&1 & - echo "NODE_PID=$!" >> "$GITHUB_ENV" + # how the node ended, if it ends before the head + ( ${{ matrix.node }} --config-file config.ini stdout.log 2>&1; echo "the node exited with status $?" > node-exit.txt ) & + sleep 2 + pid=$(pgrep -n -f -- '--config-file config.ini' || true) + echo "NODE_PID=$pid" >> "$GITHUB_ENV" cd .. python ci/snapshot/check_node.py wait-head --api 127.0.0.1:9090 --timeout-min "$TIMEOUT_MIN" @@ -156,6 +159,11 @@ jobs: cat csnode/log/log_*.txt 2>/dev/null | grep -a "STATE DIGEST #" > "result/digests-$OS.txt" || true cat csnode/log/log_*.txt 2>/dev/null | grep -aE "counted transactions is different|Couldn't save block|is not on this chain|but its caches already hold block|snapshot.verified|snapshot.mismatch" | head -50 > "result/problems-$OS.txt" || true tail -c 2000000 csnode/stdout.log > "result/stdout-$OS.log" 2>/dev/null || true + cat csnode/node-exit.txt 2>/dev/null | tee result/exit-$OS.txt || true + if [ "$OS" = macos ]; then + cp ~/Library/Logs/DiagnosticReports/node*.ips result/ 2>/dev/null || true + ls ~/Library/Logs/DiagnosticReports/ 2>/dev/null | head || true + fi for f in csnode/log/*; do [ -f "$f" ] && tail -c 3000000 "$f" > "result/$OS-$(basename "$f")"; done 2>/dev/null || true echo "$(wc -l < "result/digests-$OS.txt") digest lines"; tail -3 "result/digests-$OS.txt" From 18421a9aba20fc6d382deca2a7a96a8a2ec893c1 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 07:14:16 +0100 Subject: [PATCH 05/12] ci: the platform check fails at once on a node that ends, has no API or syncs too slowly Linux reaches the head in about 5 minutes at 30000+ blocks/min. wait-head now fails when the node process ends (exit file), its API is not up after 4 minutes, or the speed over 2 minutes is below 3000 blocks/min while far from the head, and the workflow prints the end of the node's output. The timeouts drop from 150/300 minutes to 30/90. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/platform-sync.yml | 17 +++++++++++----- ci/snapshot/check_node.py | 31 ++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/.github/workflows/platform-sync.yml b/.github/workflows/platform-sync.yml index d87797d44..a0d6d6c46 100644 --- a/.github/workflows/platform-sync.yml +++ b/.github/workflows/platform-sync.yml @@ -16,8 +16,8 @@ on: description: 'Id of a Release workflow run whose artifacts hold the Linux, Windows and macOS packages (empty = the latest successful one)' default: '' timeout_min: - description: 'Minutes each node has to reach the head' - default: '180' + description: 'Minutes each node has to reach the head (Linux needs about 5)' + default: '30' min_common: description: 'Blocks with a digest from all three systems needed to pass' default: '5' @@ -74,7 +74,7 @@ jobs: package: '*-macos-arm64.tar.gz' node: ./node runs-on: ${{ matrix.runner }} - timeout-minutes: 300 + timeout-minutes: 90 defaults: run: shell: bash @@ -127,7 +127,7 @@ jobs: - name: Sync to the head env: - TIMEOUT_MIN: ${{ inputs.timeout_min || '180' }} + TIMEOUT_MIN: ${{ inputs.timeout_min || '30' }} run: | cd csnode # how the node ended, if it ends before the head @@ -136,7 +136,14 @@ jobs: pid=$(pgrep -n -f -- '--config-file config.ini' || true) echo "NODE_PID=$pid" >> "$GITHUB_ENV" cd .. - python ci/snapshot/check_node.py wait-head --api 127.0.0.1:9090 --timeout-min "$TIMEOUT_MIN" + # Linux syncs this stretch at 30000+ blocks/min and reaches the head in about 5 minutes: a node + # that ends, has no API after 4 minutes or moves at less than a tenth of that speed is + # looked at at once, not after the timeout + python ci/snapshot/check_node.py wait-head --api 127.0.0.1:9090 --timeout-min "$TIMEOUT_MIN" \ + --exit-file csnode/node-exit.txt --api-grace-min 4 --min-rate 3000 --window-min 2 || { + echo "---- the end of the node's output"; tail -n 60 csnode/stdout.log + exit 1 + } - name: Stop and collect the digests if: always() diff --git a/ci/snapshot/check_node.py b/ci/snapshot/check_node.py index e33707865..1463b616f 100755 --- a/ci/snapshot/check_node.py +++ b/ci/snapshot/check_node.py @@ -60,18 +60,42 @@ def monitor(path): def wait_head(args): node = None - deadline = time.time() + args.timeout_min * 60 + started = time.time() + deadline = started + args.timeout_min * 60 near_since = None + api_up_since = None + window = [] # (time, block) of the last --window-min minutes while time.time() < deadline: + # a node that ended is not waited for + if args.exit_file and os.path.exists(args.exit_file): + print(f"FAIL: {open(args.exit_file).read().strip()}", flush=True) + return 1 try: # the node opens its API only once its database is loaded: connect (again) until it does node = node or client(args.api) s = node.SyncStateGet() gap = s.currRound - s.lastBlock + api_up_since = api_up_since or time.time() except Exception as e: # the node may still be starting print(f"sync state unavailable: {e}", flush=True) node = None gap = None + if api_up_since is None and args.api_grace_min and time.time() - started > args.api_grace_min * 60: + print(f"FAIL: the node's API is not up {args.api_grace_min} min after the start", flush=True) + return 1 + if gap is not None: + # the speed of the sync: a node far behind has to move, and at a speed in line with the + # others (Linux: 30000 blocks/min and more); near the head the chain sets the pace + now = time.time() + window.append((now, s.lastBlock)) + while window and now - window[0][0] > args.window_min * 60 + 1: + window.pop(0) + if args.min_rate and gap > args.near_gap and now - window[0][0] >= args.window_min * 60: + rate = (s.lastBlock - window[0][1]) / ((now - window[0][0]) / 60) + print(f"speed over the last {args.window_min} min: {rate:.0f} blocks/min (at least {args.min_rate} wanted)", flush=True) + if rate < args.min_rate: + print(f"FAIL: the sync is too slow: {rate:.0f} blocks/min, {gap} blocks behind", flush=True) + return 1 if gap is not None and s.lastBlock > 0 and gap <= 3: near_since = near_since or time.time() if time.time() - near_since >= 180: @@ -189,6 +213,11 @@ def main(): w = sub.add_parser("wait-head") w.add_argument("--api", required=True) w.add_argument("--timeout-min", type=int, default=90) + w.add_argument("--exit-file", help="a file the caller writes when the node process ends: the wait fails at once") + w.add_argument("--api-grace-min", type=int, default=0, help="minutes the node's API may take to come up (0 = no limit)") + w.add_argument("--min-rate", type=int, default=0, help="blocks per minute the sync must keep while far behind (0 = no check)") + w.add_argument("--window-min", type=int, default=2, help="minutes the speed is measured over") + w.add_argument("--near-gap", type=int, default=3000, help="no speed check this close to the head, in blocks") b = sub.add_parser("balances") b.add_argument("--api", required=True) b.add_argument("--count", type=int, default=50) From a9f496581e386d3645589faba0c75cf45f472a7e Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 07:29:53 +0100 Subject: [PATCH 06/12] Windows: checkpoint text files read and written in binary mode; platform check exit file walletscache and tokens are text archives: in text mode Windows writes \r\n, so the hashes of the loaded state differed from the ones written by Linux and the checkpoint was refused ("invalid hashes on load"). All of them are binary now (the same bytes on Linux). The platform check records the node's exit status (the subshell no longer ends at the failing node under -e) and does not use pgrep on Windows. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/platform-sync.yml | 6 ++++-- csnode/src/caches_serialization_manager.cpp | 5 +++-- csnode/src/tokens_serializer.cpp | 6 +++--- csnode/src/walletscache_serializer.cpp | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/platform-sync.yml b/.github/workflows/platform-sync.yml index a0d6d6c46..f7715ea15 100644 --- a/.github/workflows/platform-sync.yml +++ b/.github/workflows/platform-sync.yml @@ -131,9 +131,11 @@ jobs: run: | cd csnode # how the node ended, if it ends before the head - ( ${{ matrix.node }} --config-file config.ini stdout.log 2>&1; echo "the node exited with status $?" > node-exit.txt ) & + # (not "cmd; echo $?": with -e the subshell would end at the failing node) + ( rc=0; ${{ matrix.node }} --config-file config.ini stdout.log 2>&1 || rc=$?; echo "the node exited with status $rc" > node-exit.txt ) & sleep 2 - pid=$(pgrep -n -f -- '--config-file config.ini' || true) + pid= + [ "${{ matrix.os }}" = windows ] || pid=$(pgrep -n -f -- '--config-file config.ini' || true) echo "NODE_PID=$pid" >> "$GITHUB_ENV" cd .. # Linux syncs this stretch at 30000+ blocks/min and reaches the head in about 5 minutes: a node diff --git a/csnode/src/caches_serialization_manager.cpp b/csnode/src/caches_serialization_manager.cpp index 7d36dec5d..68c1e85f0 100644 --- a/csnode/src/caches_serialization_manager.cpp +++ b/csnode/src/caches_serialization_manager.cpp @@ -212,7 +212,7 @@ struct CachesSerializationManager::Impl { } void saveHashes(const std::filesystem::path& dir) { - std::ofstream f(dir / kHashesFile); + std::ofstream f(dir / kHashesFile, std::ios::binary); f << getHashes(); } @@ -293,7 +293,8 @@ struct CachesSerializationManager::Impl { std::ifstream f( std::filesystem::path(kQuickStartRoot) / std::to_string(version) / - kHashesFile + kHashesFile, + std::ios::binary ); std::string writtenHashes; diff --git a/csnode/src/tokens_serializer.cpp b/csnode/src/tokens_serializer.cpp index 9ab9da1c2..af4bce46f 100644 --- a/csnode/src/tokens_serializer.cpp +++ b/csnode/src/tokens_serializer.cpp @@ -30,7 +30,7 @@ void TokensMaster_Serializer::clear(const std::filesystem::path& rootDir) { } void TokensMaster_Serializer::save(const std::filesystem::path& rootDir) { - std::ofstream ofs(rootDir / kDataFileName); + std::ofstream ofs(rootDir / kDataFileName, std::ios::binary); boost::archive::text_oarchive oa(ofs); oa << *tokens_; oa << *holders_; @@ -38,7 +38,7 @@ void TokensMaster_Serializer::save(const std::filesystem::path& rootDir) { ::cscrypto::Hash TokensMaster_Serializer::hash() { { - std::ofstream ofs(kDataFileName); + std::ofstream ofs(kDataFileName, std::ios::binary); // text mode on Windows would write \r\n and change the hash boost::archive::text_oarchive oa( ofs, boost::archive::no_header | boost::archive::no_codecvt @@ -60,7 +60,7 @@ ::cscrypto::Hash TokensMaster_Serializer::hash() { } void TokensMaster_Serializer::load(const std::filesystem::path& rootDir) { - std::ifstream ifs(rootDir / kDataFileName); + std::ifstream ifs(rootDir / kDataFileName, std::ios::binary); boost::archive::text_iarchive ia(ifs); ia >> *tokens_; ia >> *holders_; diff --git a/csnode/src/walletscache_serializer.cpp b/csnode/src/walletscache_serializer.cpp index 18a6d347b..f4980377e 100644 --- a/csnode/src/walletscache_serializer.cpp +++ b/csnode/src/walletscache_serializer.cpp @@ -63,7 +63,7 @@ void WalletsCache_Serializer::save(const std::filesystem::path& rootDir) { ::cscrypto::Hash WalletsCache_Serializer::hash() { { - std::ofstream ofs(kTmpDataFile); + std::ofstream ofs(kTmpDataFile, std::ios::binary); // text mode on Windows would write \r\n and change the hash boost::archive::text_oarchive oa( ofs, boost::archive::no_header | boost::archive::no_codecvt From c17bb6dfeec17e1d7e8e7f1f3cfb8384f725e28c Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 07:53:20 +0100 Subject: [PATCH 07/12] ci: macOS Boost is built as C++17, like the node Apple clang compiles C++ as C++98 unless told otherwise, so the Boost built by b2 held definitions of header templates that differ from the node's C++17 ones: the Asio code in Boost.Log's syslog backend has a run-time initialised static (boost::source_location in reactive_socket_service ::open) where the node's has a constant one in __DATA_CONST, and the linker kept the code of one with the constant of the other. The node died with SIGBUS at the first UDP socket it opened. A macOS build with cxxstd=17 starts and passes that point (debug run 40462211836). Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/build-platforms.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-platforms.yml b/.github/workflows/build-platforms.yml index 8d4931d39..0cc333270 100644 --- a/.github/workflows/build-platforms.yml +++ b/.github/workflows/build-platforms.yml @@ -157,7 +157,7 @@ jobs: uses: actions/cache/restore@v4 with: path: ${{ env.BOOST_PREFIX }} - key: boost-${{ env.BOOST_VERSION }}-static-macos-14-v1 + key: boost-${{ env.BOOST_VERSION }}-static-cxx17-macos-14-v1 - name: Build Boost if: steps.cache-boost.outputs.cache-hit != 'true' @@ -168,8 +168,11 @@ jobs: tar xjf boost.tar.bz2 cd "boost_${v}" ./bootstrap.sh --with-libraries=system,filesystem,program_options,date_time,regex,log,iostreams,thread,serialization,atomic,chrono + # cxxstd=17: Apple clang compiles C++ as C++98 unless told otherwise; Boost built that way + # holds definitions of header templates (Asio in Boost.Log's syslog backend) that differ from + # the node's C++17 ones, and the linker keeps one of each ./b2 -j"$(sysctl -n hw.ncpu)" -d0 toolset=clang variant=release link=static threading=multi \ - cxxflags=-fPIC --layout=tagged -sNO_BZIP2=1 -sNO_ZSTD=1 -sNO_LZMA=1 \ + cxxstd=17 cxxflags=-fPIC --layout=tagged -sNO_BZIP2=1 -sNO_ZSTD=1 -sNO_LZMA=1 \ install --prefix="${BOOST_PREFIX}" - name: Save Boost From ae9e8f8cf19806b9586ff7e7faaad0faee309051 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 08:54:59 +0100 Subject: [PATCH 08/12] ci: the platform check keeps the snapshot import out of the job log and saves the wait-head output The import prints hundreds of thousands of debug lines to the console and the job log was cut before the sync step. The wait-head lines and the download log go to the artifact instead. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/platform-sync.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/platform-sync.yml b/.github/workflows/platform-sync.yml index f7715ea15..1e1326a30 100644 --- a/.github/workflows/platform-sync.yml +++ b/.github/workflows/platform-sync.yml @@ -123,7 +123,12 @@ jobs: - name: Restore the published snapshot working-directory: csnode - run: ${{ matrix.node }} --config-file config.ini --download-snapshot download.log 2>&1 || { tail -n 60 download.log | cut -c1-300; exit 1; } + grep -aE '^(download-snapshot|import-snapshot|snapshot)' download.log | cut -c1-250 + tail -n 3 download.log | cut -c1-250 - name: Sync to the head env: @@ -142,7 +147,7 @@ jobs: # that ends, has no API after 4 minutes or moves at less than a tenth of that speed is # looked at at once, not after the timeout python ci/snapshot/check_node.py wait-head --api 127.0.0.1:9090 --timeout-min "$TIMEOUT_MIN" \ - --exit-file csnode/node-exit.txt --api-grace-min 4 --min-rate 3000 --window-min 2 || { + --exit-file csnode/node-exit.txt --api-grace-min 4 --min-rate 3000 --window-min 2 2>&1 | tee csnode/waithead.txt || { echo "---- the end of the node's output"; tail -n 60 csnode/stdout.log exit 1 } @@ -169,7 +174,10 @@ jobs: cat csnode/log/log_*.txt 2>/dev/null | grep -aE "counted transactions is different|Couldn't save block|is not on this chain|but its caches already hold block|snapshot.verified|snapshot.mismatch" | head -50 > "result/problems-$OS.txt" || true tail -c 2000000 csnode/stdout.log > "result/stdout-$OS.log" 2>/dev/null || true cat csnode/node-exit.txt 2>/dev/null | tee result/exit-$OS.txt || true + cp csnode/waithead.txt "result/waithead-$OS.txt" 2>/dev/null || true + cp csnode/download.log "result/download-$OS.log" 2>/dev/null || true if [ "$OS" = macos ]; then + sleep 15 # the crash report is written a moment after the process ends cp ~/Library/Logs/DiagnosticReports/node*.ips result/ 2>/dev/null || true ls ~/Library/Logs/DiagnosticReports/ 2>/dev/null | head || true fi From 8d4325757714fc696bb9560ea930cff4134c2c0a Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 09:01:40 +0100 Subject: [PATCH 09/12] Checkpoint archives: the input is the plain one on Linux and macOS; classic locale for the hashed text; header test From the impact review of the branch: - ArchiveInput only changes the header where long is 4 bytes (Windows) and the archive says 8; on Linux and macOS the bytes are passed through, so boost keeps refusing a 32-bit archive and the read is exactly the plain one - the two text archives whose hash is computed with no_codecvt (tokens, wallets cache) are written through a stream imbued with the classic locale, so a global locale could never change them - tests: the 40-byte header the node writes is compared with the Boost 1.83 one, byte by byte; the input is checked to behave as the plain reader where long is 8 bytes Co-Authored-By: Claude Sonnet 5.5 --- csnode/include/csnode/archive_stream.hpp | 8 +++-- csnode/src/tokens_serializer.cpp | 2 ++ csnode/src/walletscache_serializer.cpp | 2 ++ tests/csnode/archive_stream_tests.cpp | 43 ++++++++++++++++++++++-- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/csnode/include/csnode/archive_stream.hpp b/csnode/include/csnode/archive_stream.hpp index c78231670..8505358f2 100644 --- a/csnode/include/csnode/archive_stream.hpp +++ b/csnode/include/csnode/archive_stream.hpp @@ -19,7 +19,10 @@ namespace cs { // macOS, 4 on Windows, so a checkpoint (or a snapshot made of one) from one system did not load on // the other. No checkpoint field is a long: 64-bit fields are int64_t/uint64_t, written as 8 bytes // on every system, and boost writes its own counts as 8-byte size_t on 64-bit systems. The size of -// long in the header is the only difference, and it is read here as this system's own. +// long in the header is the only difference. Archives are written with 8 there on every system +// (ArchiveOutput), so only Windows has anything to change on read: it takes an 8 as its own 4. On +// Linux and macOS the input is passed through untouched, the plain read, and boost keeps refusing +// an archive of a 32-bit system. // // Header of boost 1.83: size_t length (22) | "serialization::archive" | uint16 library version | // sizeof(int) | sizeof(long) | sizeof(float) | sizeof(double) | int 1 (byte order). Anything else is @@ -70,8 +73,7 @@ class ArchiveInputBuf : public std::streambuf { auto byteAt = [this](size_t i) { return static_cast(head_[i]); }; const bool sizesAsExpected = byteAt(kLongSizeOffset - 1) == sizeof(int32_t) && byteAt(kLongSizeOffset + 1) == sizeof(float) && byteAt(kLongSizeOffset + 2) == sizeof(double); - const auto longSize = byteAt(kLongSizeOffset); - if (sizesAsExpected && (longSize == 4 || longSize == 8)) { + if (sizesAsExpected && sizeof(long) == 4 && byteAt(kLongSizeOffset) == 8) { head_[kLongSizeOffset] = static_cast(sizeof(long)); } } diff --git a/csnode/src/tokens_serializer.cpp b/csnode/src/tokens_serializer.cpp index af4bce46f..39be7b973 100644 --- a/csnode/src/tokens_serializer.cpp +++ b/csnode/src/tokens_serializer.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -39,6 +40,7 @@ void TokensMaster_Serializer::save(const std::filesystem::path& rootDir) { ::cscrypto::Hash TokensMaster_Serializer::hash() { { std::ofstream ofs(kDataFileName, std::ios::binary); // text mode on Windows would write \r\n and change the hash + ofs.imbue(std::locale::classic()); // with no_codecvt the archive formats numbers in the stream's locale boost::archive::text_oarchive oa( ofs, boost::archive::no_header | boost::archive::no_codecvt diff --git a/csnode/src/walletscache_serializer.cpp b/csnode/src/walletscache_serializer.cpp index f4980377e..f3d199637 100644 --- a/csnode/src/walletscache_serializer.cpp +++ b/csnode/src/walletscache_serializer.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -64,6 +65,7 @@ void WalletsCache_Serializer::save(const std::filesystem::path& rootDir) { ::cscrypto::Hash WalletsCache_Serializer::hash() { { std::ofstream ofs(kTmpDataFile, std::ios::binary); // text mode on Windows would write \r\n and change the hash + ofs.imbue(std::locale::classic()); // with no_codecvt the archive formats numbers in the stream's locale boost::archive::text_oarchive oa( ofs, boost::archive::no_header | boost::archive::no_codecvt diff --git a/tests/csnode/archive_stream_tests.cpp b/tests/csnode/archive_stream_tests.cpp index ebf57519c..9da944596 100644 --- a/tests/csnode/archive_stream_tests.cpp +++ b/tests/csnode/archive_stream_tests.cpp @@ -64,11 +64,18 @@ void expectSample(const Data& d) { } } // namespace -// a checkpoint from Windows (long of 4 bytes) on Linux/macOS, and from Linux/macOS on Windows -TEST(ArchiveInput, ReadsTheHeaderOfEitherSystem) { +// A checkpoint is written with a long of 8 bytes everywhere: Windows (long of 4) reads it, and +// Linux/macOS read it as they always did. A header with a 4 is refused where long is 8, as by the +// plain reader: nothing is rewritten there. +TEST(ArchiveInput, ReadsTheHeaderTheNodeWrites) { for (unsigned char longSize : {4, 8}) { std::istringstream source(archiveWithLongSize(longSize), std::ios::binary); cs::ArchiveInput in(source); + const bool accepted = longSize == sizeof(long) || (sizeof(long) == 4 && longSize == 8); + if (!accepted) { + EXPECT_THROW(boost::archive::binary_iarchive ia(in), boost::archive::archive_exception) << int(longSize); + continue; + } boost::archive::binary_iarchive ia(in); Data d; ia >> d; @@ -76,6 +83,23 @@ TEST(ArchiveInput, ReadsTheHeaderOfEitherSystem) { } } +// where long is 8 bytes the input is the plain one: the same result for a header of any long size +TEST(ArchiveInput, PassesTheHeaderThroughWhereLongIsEightBytes) { + if (sizeof(long) != 8) { + GTEST_SKIP() << "long is 4 bytes here"; + } + for (unsigned char longSize : {1, 2, 4, 8, 16}) { + const auto bytes = archiveWithLongSize(longSize); + std::istringstream plainSource(bytes, std::ios::binary); + std::istringstream wrappedSource(bytes, std::ios::binary); + cs::ArchiveInput in(wrappedSource); + bool plainThrew = false, wrappedThrew = false; + try { boost::archive::binary_iarchive ia(plainSource); } catch (const boost::archive::archive_exception&) { plainThrew = true; } + try { boost::archive::binary_iarchive ia(in); } catch (const boost::archive::archive_exception&) { wrappedThrew = true; } + EXPECT_EQ(plainThrew, wrappedThrew) << int(longSize); + } +} + TEST(ArchiveInput, PlainReaderRefusesTheOtherSystem) { const unsigned char other = sizeof(long) == 8 ? 4 : 8; std::istringstream source(archiveWithLongSize(other), std::ios::binary); @@ -152,3 +176,18 @@ TEST(ArchiveOutput, RewritesAFourByteLong) { } EXPECT_EQ(target.str(), std::string(40, '\x04')); } + +// The header the node writes, byte by byte: what every node, old ones included, reads. A change of +// the Boost version or of the format shows up here first. +TEST(ArchiveOutput, HeaderIsTheOneOfBoost183) { + std::ostringstream out(std::ios::binary); + { + cs::ArchiveOutput stream(out); + boost::archive::binary_oarchive oa(stream); + const uint32_t value = 1; + oa << value; + } + const std::string header = out.str().substr(0, cs::ArchiveInputBuf::kHeaderSize); + const std::string expected("\x16\0\0\0\0\0\0\0serialization::archive\x13\0\x04\x08\x04\x08\x01\0\0\0", cs::ArchiveInputBuf::kHeaderSize); + EXPECT_EQ(header, expected); +} From cbd55044d847e496ff229503937e413f56927160 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 09:44:41 +0100 Subject: [PATCH 10/12] Transport: the routing table goes with the p2p host, not at static destruction p2p's Network singleton keeps a shared_ptr to the host's routing table (Host::Run). It kept the routing table alive after net::Host and its io_context were destroyed; ~Network at static destruction then destroyed the routing table's UDP socket against the io_context's freed reactor: SIGSEGV in kqueue_reactor::deregister_descriptor at exit on macOS (status 139), undefined behaviour elsewhere. ~Transport now clears that reference before host_ (its last member) is destroyed, so the routing table, its socket and its pinger and explorer threads end within ~Host, while the io_context still exists. Co-Authored-By: Claude Opus 5.5 --- net/src/transport.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/src/transport.cpp b/net/src/transport.cpp index c1b501ee3..85aa443d1 100644 --- a/net/src/transport.cpp +++ b/net/src/transport.cpp @@ -121,6 +121,13 @@ Transport::~Transport() { if (processorThread_.joinable()) { processorThread_.join(); } + // p2p's Network singleton keeps a reference to the host's routing table (Host::Run). Left there, + // the routing table (its UDP socket, pinger and explorer threads) would outlive host_ and its + // io_context and be destroyed at static destruction, against the io_context's freed reactor: + // SIGSEGV in kqueue_reactor::deregister_descriptor at exit on macOS, undefined behaviour on the + // other systems. Without it the routing table goes with host_ (just below, as host_ is the last + // member), after ~Host has stopped its io_context and before the io_context is destroyed. + net::Network::Instance().SetRoutingTable(nullptr); } void Transport::run() { From 2855f96bd07adc47a5118e8907f157fb5d34f46f Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 11:08:22 +0100 Subject: [PATCH 11/12] ci: wait-head polls the node's API on a new connection each time The node closes an API connection idle for server_receive_timeout (30 s), the interval of the wait-head polls. The kept connection raced that close: on macOS the node's close won every time, so every other poll failed with 'TSocket read 0 bytes' and reset the 3 minutes at the head the check waits for; Windows lost it now and then. A connection per poll, closed after it, has no such race. The node's API was never at fault. Co-Authored-By: Claude Sonnet 5.5 --- ci/snapshot/check_node.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ci/snapshot/check_node.py b/ci/snapshot/check_node.py index 1463b616f..e91ba37dc 100755 --- a/ci/snapshot/check_node.py +++ b/ci/snapshot/check_node.py @@ -59,7 +59,6 @@ def monitor(path): def wait_head(args): - node = None started = time.time() deadline = started + args.timeout_min * 60 near_since = None @@ -71,14 +70,19 @@ def wait_head(args): print(f"FAIL: {open(args.exit_file).read().strip()}", flush=True) return 1 try: - # the node opens its API only once its database is loaded: connect (again) until it does - node = node or client(args.api) - s = node.SyncStateGet() + # a new connection for every poll: the node closes a connection idle for its + # server_receive_timeout (30 s), the interval of these polls, and a kept connection would + # race that close (lost on macOS every time, sometimes on Windows: "TSocket read 0 bytes"). + # The node opens its API only once its database is loaded: connect until it does. + node = client(args.api) + try: + s = node.SyncStateGet() + finally: + node.close() gap = s.currRound - s.lastBlock api_up_since = api_up_since or time.time() except Exception as e: # the node may still be starting print(f"sync state unavailable: {e}", flush=True) - node = None gap = None if api_up_since is None and args.api_grace_min and time.time() - started > args.api_grace_min * 60: print(f"FAIL: the node's API is not up {args.api_grace_min} min after the start", flush=True) From a92750c7da1f1e98ef63dca6f00b8bc8259f635b Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 27 Oct 2026 11:09:41 +0100 Subject: [PATCH 12/12] docs: CHANGES line for #115 Co-Authored-By: Claude Sonnet 5.5 --- docs/CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 86deeb078..eebd7bcc4 100644 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -39,6 +39,7 @@ lines under the new release. |---|---| | #113 | packaging: one package per build for full and pruned storage (`config.ini` full, `config.pruned.ini` pruned on LMDB), half the release size; the workflows that take the latest package accept both layouts | | #114 | the node builds and passes its tests on Windows (MSVC, x64) and macOS (Apple Silicon): POSIX-only code behind `lib/system/platform.hpp`, the database lock now also on Windows, a new `build-platforms.yml` workflow; the release workflow also makes a Windows `.zip` and a macOS package (with Eclipse Temurin 11), kept as artifacts until a mainnet state-digest check on each system | +| #115 | Windows and macOS nodes load the checkpoints and snapshots of Linux and sync mainnet with the same state digests: the binary checkpoint header records `long` as 8 bytes on every system (`cs::ArchiveOutput`, read back by `cs::ArchiveInput`), checkpoint text files are read and written in binary mode, macOS Boost is built as C++17; `Transport` releases the routing table with the p2p host, fixing a use-after-free at exit (a crash on macOS); a platform consensus check in CI | ## community.13 — 2026-10-26