Skip to content

solver: accept a contract state from a peer only in answer to a request - #94

Open
EnzinoBB wants to merge 1 commit into
CREDITSCOM:masterfrom
CreditsCommunity:official/unsolicited-contract-state
Open

EnzinoBB wants to merge 1 commit into
CREDITSCOM:masterfrom
CreditsCommunity:official/unsolicited-contract-state

Conversation

@EnzinoBB

@EnzinoBB EnzinoBB commented Nov 1, 2026

Copy link
Copy Markdown

Why this PR

getStateReply accepts a contract state from any signed peer, and SmartContracts::net_update_contract_state caches it whenever no new_state with the same reference is found in the following MaxRoundsCancelContract blocks. A state with a reference in the future is cached too, and then every real update of that contract looks outdated: the node can keep a contract state that is not the one the chain declares. Found while auditing the node and reported to the Credits team.

What changes

solver/src/smartcontracts.cpp, solver/include/solver/smartcontracts.hpp: the node remembers the contracts it asked the confidants about (the round of the last request, kept for 1000 rounds because several confidants answer) and ignores states of any other contract, or with a reference later than the current round. A state whose new_state is not stored yet is still accepted, as a lagging node needs it.

Effect on the network

None on the wire: requests and replies are unchanged; a node only refuses states it did not ask for.

Note: the PR "fetch stale contract states from the confidants, verified against the chain" replaces this bookkeeping with its own request tracking; if that one is taken, this one is not needed.

Tests

Built and run on 4a95aaa (GCC 13).

Same change in the community fork: CreditsCommunity#32, running on mainnet community nodes.

getStateReply accepted a contract state from any signed peer, and
net_update_contract_state cached it whenever no new_state with the same ref
was found in the following MaxRoundsCancelContract blocks. A state with a
future ref was cached too, and then every real update looked outdated, so a
single message froze the contract on this node.

Remember the contracts this node asked the confidants about (the round of
the last request, kept for 1000 rounds because several confidants answer)
and ignore states for any other contract, or with a ref later than the
current round. A state whose new_state is not stored yet is still accepted:
that is how a lagging node catches up, and refusing it would leave it
without the state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant