Skip to content

solver: an emitted transaction's fee goes to the execution whose new_state precedes it in the block - #94

Merged
EnzinoBB merged 4 commits into
masterfrom
fix/emitted-fee-attribution
Oct 24, 2026
Merged

EnzinoBB merged 4 commits into
masterfrom
fix/emitted-fee-attribution

Conversation

@EnzinoBB

Copy link
Copy Markdown
Collaborator

Step 1 of the contract state sync plan (docs/specs/2026-10-24-contract-state-sync-design.md on docs/contract-state-sync). Consensus-relevant, approved by the user ("the rule of the live nodes").

Problem. A syncing node re-executes contract calls to rebuild their states, because blocks carry only the state hash. For a contract whose result depends on its own balance (dice games), the re-execution is not reproducible. The state stays stale, and the fee of a later payout was charged to the contract's last known execution, i.e. the previous player. This is how the local mainnet node came to differ by one fee on wallet 7hWM… (block 176,776,317); mainnet nodes disagree among themselves on such wallets.

Change. SmartContracts::emitting_new_state(block, index, contract) returns the RefStart of the contract's nearest new_state before the emitted transaction in the same block. The fee goes to that execution's initiator: the rule the live nodes follow, since they have the state before the block, and the one on_remove_block already applies to refunds. on_remove_block now uses the same helper, so the two cannot drift, and its search no longer runs past the start of the block when no new_state precedes. The last known execution remains the fallback when the block has none, with a warning.

Effect. A syncing node's balances change by one fee per affected payout compared with an official node that syncs the same blocks, and agree with the nodes that executed the contract. The contract's own state is still stale after a failed re-execution; that is steps 2–3.

Tests. A unit test of the helper. Contains #93 (step 0, the dice scenario): contracts-dice-join must now show identical STATE DIGESTs on every node, n8 included. The Dice state is still expected to differ.

🤖 Generated with Claude Code

EnzinoBB and others added 3 commits October 24, 2026 15:36
…ract

Dice reads its own balance and pays 10 CS when it holds at least 20: a
node re-executing it while it syncs sees the balance after the same
block's payout, throws, keeps a stale state and charges a later payout's
fee to the previous player. contracts.py --dice (run.sh CONTRACT_DICE=1)
deploys it, funds it, and has two players play it three times in turn
before the restart test; its state is compared on every node.
Scenario contracts-dice-join (manual): a node syncs from block 0 through
the plays. It is expected to fail until contract states are fetched
instead of re-executed (step 0 of the contract state sync plan).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…state precedes it in the block

A node that syncs re-executes contract calls to rebuild their states;
for a contract whose result depends on its own balance the re-execution
is not reproducible, the state stays stale and the contract's last known
execution is an earlier one: the fee of a later payout was charged to
the previous initiator, and the node's balances differed from the live
nodes', which have the new state before the block. The fee now goes to
the initiator of the contract's nearest new_state before the emitted
transaction in the same block, the rule the rollback already applies
(now through the same helper, which also bounds its search to the
block); the last known execution only when the block has no new_state.

Consensus-relevant: a syncing node's balances change by one fee per
affected payout compared with an official node that syncs the same
blocks, and agree with the nodes that executed the contract.

Step 1 of the contract state sync plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sful execution in the block

Review of step 1: a live node applies every new_state of the block
(Conveyer::statesCreated -> on_update) before it charges any emitted
transaction, so with several executions of one contract in a block it
charges all their payouts to the latest successful one, not to the
execution that precedes each payout. The helper now returns the highest
RefStart among the contract's new_states with a non-zero hash, wherever
the emitted transaction stands; the rollback uses the same rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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