From d924a7b03d195a1cfcf529da17d8619d4120917f Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Fri, 23 Oct 2026 18:51:09 +0200 Subject: [PATCH] packaging, solver: compatible_version=true for mainnet; warn when a replayed contract state is lost Replaying some contracts while syncing is not reproducible (official behaviour): a game contract that reads its own balance sees it after the block's payout, the re-execution fails, the contract state stays out of date and a later payout's fee can be charged to an earlier caller. A syncing node then disagrees with the network on that caller's balance by a fee, and with compatible_version=false (the official config.ini) stops for good at the first block whose transaction those balances reject. The packaged config now uses the binary's default, true, which logs and stores such a block. get_actual_state warns when a state the block declares is not available, and a replayed state with a wrong hash is a warning instead of a debug line. Co-Authored-By: Claude Opus 5.5 --- docs/CHANGES.md | 1 + docs/differences.md | 14 +++++++++++++- packaging/mainnet/config.ini | 6 +++++- solver/src/smartcontracts.cpp | 13 ++++++++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 66fca2a23..3781b26d4 100644 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -35,6 +35,7 @@ lines under the new release. | PR | Change | |---|---| | #82 | csnode: a node still syncing logs a missing round table of the network's current round as a warning (the block comes with the sync); an error only when it is not behind | +| #83 | packaging, solver: `compatible_version=true` in the mainnet `config.ini` (the binary's default; the official file's `false` stops a syncing node for good at a block whose transaction its replayed balances reject); a warning when a contract state declared by a block is not available while replaying | ## community.10 — 2026-10-23 diff --git a/docs/differences.md b/docs/differences.md index a8a0aebfe..546eef112 100644 --- a/docs/differences.md +++ b/docs/differences.md @@ -105,6 +105,14 @@ quick-starts after a conversion. memory and retries. - **Pruned storage.** A pruned node answers NoSuchBlocks for blocks it has pruned, so a peer asks another node for them. `TransactionsListGet` skips pruned blocks. +- **Contract replay.** A node that syncs re-executes contract calls to recover their states. + For some contracts this is not reproducible (official behaviour): a game that reads its own + balance sees it after the block's payout. The state then stays out of date, and the fee of a + later payout of the contract can be charged to an earlier caller. Such a node can disagree with + the network on a caller's balance by a fee, and mainnet nodes already disagree among themselves + on some of these wallets. The node now logs a warning when a state declared by a block is not + available; with `compatible_version=false` it would stop at the first block whose transaction + its own balances reject. ## Security and correctness fixes @@ -158,9 +166,13 @@ rounds for both). Each package includes the JDK of the official release and the community build of the contract executor. -- **`config.ini` in the packages.** It is the official one, with three changes: +- **`config.ini` in the packages.** It is the official one, with four changes: - `[event_report]` is commented out (it reports node events to a fixed address); - `executor_commit_max` accepts the community executor; + - `compatible_version=true`, the default of the node binary (the official file sets `false`): + a synced block that fails the node's own transaction check is logged + (`skip block validation`) and stored, instead of stopping the node at it for good. See + "Contract replay" below; - the pruned package adds a `[storage]` section. The executor listens on 127.0.0.1 only. diff --git a/packaging/mainnet/config.ini b/packaging/mainnet/config.ini index c2f57eada..adb180eac 100644 --- a/packaging/mainnet/config.ini +++ b/packaging/mainnet/config.ini @@ -3,7 +3,11 @@ hosts_filename=known_hosts.txt init_trusted_filename=default_confidants.txt ipv6=false min_compatible_version=503 -compatible_version=false +; true (the default of the node binary): a synced block that fails this node's own transaction +; check is logged ("skip block validation") and stored. With false the node stops at it for good: +; replaying some contracts (games that read their own balance) is not reproducible, so a syncing +; node can disagree with the network on a few balances by a fee and would then reject valid blocks +compatible_version=true [host_input] port=9510 diff --git a/solver/src/smartcontracts.cpp b/solver/src/smartcontracts.cpp index 5b6790471..f07737a7e 100644 --- a/solver/src/smartcontracts.cpp +++ b/solver/src/smartcontracts.cpp @@ -1237,6 +1237,8 @@ csdb::Transaction SmartContracts::get_actual_state(const csdb::Transaction& hash std::string hash_string = fld.value(); cs::Hash hash; + // the block declares a new state that this node has to obtain (cache, execution or network) + bool state_expected = false; csdb::Transaction tr_state(0, hashed_state.source(), hashed_state.target(), hashed_state.currency(), hashed_state.amount(), hashed_state.max_fee(), hashed_state.counted_fee(), hashed_state.signature()); @@ -1255,6 +1257,7 @@ csdb::Transaction SmartContracts::get_actual_state(const csdb::Transaction& hash else { std::copy(hash_string.cbegin(), hash_string.cend(), hash.begin()); if (hash != cs::Zero::hash) { + state_expected = true; fld = hashed_state.user_field(new_state::RefStart); if (!fld.is_valid()) { cserror() << kLogPrefix << "hashed_state does not refer to start transaction, use empty new_state"; @@ -1349,7 +1352,7 @@ csdb::Transaction SmartContracts::get_actual_state(const csdb::Transaction& hash << " has updated, stored hash is OK, new size is " << state.size(); } else { - csdebug() << kLogPrefix << to_base58(req_abs_addr) << " state after " << ref_start + cswarning() << kLogPrefix << to_base58(req_abs_addr) << " state after " << ref_start << " has updated, stored hash is WRONG: " << cs::Utils::byteStreamToHex(hash.data(), hash.size()) << " (expected " << cs::Utils::byteStreamToHex(actual_hash.data(), actual_hash.size()) << "), new size is " << state.size(); @@ -1389,6 +1392,14 @@ csdb::Transaction SmartContracts::get_actual_state(const csdb::Transaction& hash if (tr_state.user_field_ids().count(new_state::Value) == 0) { tr_state.add_user_field(new_state::Value, std::string{}); } + // a contract whose execution is not reproducible (e.g. one that reads its own balance) leaves its + // state unknown here, and the fees of its later emitted transactions can then be charged to an + // earlier initiator: this node's balances may differ from the network's by such fees + if (state_expected && tr_state.user_field(new_state::Value).value().empty()) { + cswarning() << kLogPrefix << "state of " << to_base58(absolute_address(hashed_state.target())) + << " declared by the block is not available" << (reading_db ? " while reading the blockchain" : "") + << ", the contract state is out of date"; + } return tr_state; }