From 0cf930ccedd77dd3df25a4ab3ab2f90866ba15a7 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Thu, 22 Oct 2026 23:11:46 +0200 Subject: [PATCH 1/2] api: contract getters on pruned nodes take the deploy the smart contracts keep A pruned node answered every getter (TransactionFlow with forgetNewState) for a contract whose deploy block it had pruned with status 0 and no result: smartTransactionFlow loaded the deploy transaction from the block storage, got none, ran nothing and reported success (robustness contracts-pruned-join and contracts-pruned-term-kill). The smart contracts already keep each deploy in memory and in every checkpoint and snapshot (known_contracts, smartcontracts.dat), and SmartContractGet / SmartContractDataGet use it. - smartTransactionFlow: the deploy from SmartContracts::get_contract_deploy, the storage as fallback - a getter with no byte code to run fails ("contract byte code is not available on this node") - Executor::executeByteCode: no byte code, or no executor connection, is an error, not a success without a result (as executeByteCodeMultiple already reports) - SmartContractsListGet(deployer): a deploy no longer in the storage comes from the same copy Only API answers change; consensus execution already uses the kept deploy. Contract-to-contract calls (APIEXEC SmartContractGet) are left for a separate change. Co-Authored-By: Claude Opus 5.5 --- api/src/apihandler.cpp | 33 ++++++++++++++++++++++++++++++++- api/src/executor.cpp | 9 +++++++++ docs/CHANGES.md | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/api/src/apihandler.cpp b/api/src/apihandler.cpp index d63fb6d1d..906ddd852 100644 --- a/api/src/apihandler.cpp +++ b/api/src/apihandler.cpp @@ -1178,7 +1178,13 @@ void APIHandler::smartTransactionFlow(api::TransactionFlowResult& _return, const decltype(auto) lockedSmartOrigin = lockedReference(this->smart_origin); auto it = lockedSmartOrigin->find(smart_addr); if (it != lockedSmartOrigin->end()) { - origin_bytecode = fetch_smart(executor_.loadTransactionApi(it->second)).smartContractDeploy.byteCodeObjects; + // the deploy the smart contracts keep (in memory and in every checkpoint): a pruned node + // no longer has the deploy's block; the storage is the fallback, as in SmartContractGet + csdb::Transaction deploy_tr = solver_.smart_contracts().get_contract_deploy(smart_addr); + if (!deploy_tr.is_valid()) { + deploy_tr = executor_.loadTransactionApi(it->second); + } + origin_bytecode = fetch_smart(deploy_tr).smartContractDeploy.byteCodeObjects; } else { SetResponseStatus(_return.status, APIRequestStatusType::FAILURE); @@ -1227,6 +1233,12 @@ void APIHandler::smartTransactionFlow(api::TransactionFlowResult& _return, const auto target_pk = blockchain_.getAddressByType(send_transaction.target(), BlockChain::AddressType::PublicKey).to_api_addr(); executor::ExecuteByteCodeResult api_resp; const std::vector& bytecode = deploy ? input_smart.smartContractDeploy.byteCodeObjects : origin_bytecode; + if (!deploy && bytecode.empty()) { + // nothing to execute: an answer without a result must not read as a success + SetResponseStatus(_return.status, APIRequestStatusType::FAILURE, "contract byte code is not available on this node"); + hashStateEntry->yield(); + return; + } if (!deploy || !input_smart.smartContractDeploy.byteCodeObjects.empty()) { std::vector methodHeaders; { @@ -2197,6 +2209,25 @@ size_t APIHandler::getMappedDeployerSmart(const csdb::Address& deployer, Mapper auto begIt = element.begin() + offset; for (auto trid = begIt; trid != begIt + limit && trid != element.end(); ++trid) { auto tr = executor_.loadTransactionApi(*trid); + if (!tr.is_valid()) { + // a pruned node no longer has the deploy's block: the copy the smart contracts keep + csdb::Address contract; + { + decltype(auto) origins = lockedReference(this->smart_origin); + for (const auto& [address, id] : *origins) { + if (id == *trid) { + contract = address; + break; + } + } + } + if (contract.is_valid()) { + tr = solver_.smart_contracts().get_contract_deploy(contract); + } + if (!tr.is_valid()) { + continue; + } + } if (cs::SmartContracts::get_contract_state(blockchain_, tr.target()).empty()) { continue; diff --git a/api/src/executor.cpp b/api/src/executor.cpp index 170b38c7a..c68ece055 100644 --- a/api/src/executor.cpp +++ b/api/src/executor.cpp @@ -48,6 +48,15 @@ void cs::Executor::executeByteCode(executor::ExecuteByteCodeResult& resp, const if (auto optOriginRes = execute(address, smartContractBinary, methodHeader, isGetter, sequence)) { resp = optOriginRes.value().resp; } + else { + // as executeByteCodeMultiple: an unexecuted call is not a success without a result + resp.status.code = 1; + resp.status.message = "No executor connection!"; + } + } + else { + resp.status.code = 1; + resp.status.message = "no contract byte code"; } } diff --git a/docs/CHANGES.md b/docs/CHANGES.md index b39102762..7688568de 100644 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -37,6 +37,7 @@ lines under the new release. | #67 | csdb, ci, docs: conversion follow-ups from the review of #65 (contract-records message, keep a copy of `db/` before converting from berkeleydb, sturdier db-convert scenario) | | #70 | csnode: bootstrap tables of 9 to 25 confidants are accepted (the official node silently drops them, so a network of 9 or more initial confidants never starts); the same choice as the official node up to 8 | | #71 | csnode: a bootstrap round table is taken only for a round next to the node's own, and, unless signed with the blockchain key, only once the node's own round has stalled; the block-removal request it set (never effective) is gone | +| #74 | api: contract getters and the deployer's contract list take the deploy the smart contracts keep (a pruned node no longer has its block, and answered getters with an empty success); a getter with nothing to execute, or no executor, now fails | ## community.9 — 2026-10-22 From 1d550d8445d1b03371e19699d72f93fdb2639b21 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Fri, 23 Oct 2026 00:16:55 +0200 Subject: [PATCH 2/2] =?UTF-8?q?api:=20review=20of=20#74=20=E2=80=94=20a=20?= =?UTF-8?q?call=20to=20a=20blacklisted=20contract=20fails=20instead=20of?= =?UTF-8?q?=20an=20empty=20success?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- api/src/apihandler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/apihandler.cpp b/api/src/apihandler.cpp index 906ddd852..d22504379 100644 --- a/api/src/apihandler.cpp +++ b/api/src/apihandler.cpp @@ -1165,6 +1165,8 @@ void APIHandler::smartTransactionFlow(api::TransactionFlowResult& _return, const //auto send_transaction = makeTransaction(transaction); const auto smart_addr = blockchain_.getAddressByType(send_transaction.target(), BlockChain::AddressType::PublicKey); if (solver_.smart_contracts().isBlacklisted(smart_addr)) { + // not an empty success: the caller must see that nothing ran + SetResponseStatus(_return.status, APIRequestStatusType::FAILURE, "contract is blacklisted"); return; } bool deploy = transaction.__isset.smartContract ? is_smart_deploy(input_smart) : false;