#2702·node

Support account code upgrades from protocol

Author: PhilippGackstatterCreated Sep 28, 2026Updated Sep 28, 2026
Labelsstore

Context

The protocol PR 0xMiden/protocol#3949 adds account code upgrades. A transaction can call native_account::upgrade to replace the code of the native account. Storage upgrades are not supported at this time.

This issue posts the results from investigating if the removal of is_full_state creates problems for the node. In essence, the answer is no.

The account patch now carries an AccountCodePatch instead of Option<AccountCode>. This patch holds the code of a new account or of an upgraded account. As a result, the patch alone no longer differentiates between creation and an upgrade:

  • AccountPatch::is_full_state and AccountDelta::is_full_state are removed.
  • TryFrom<&AccountPatch> for Account and TryFrom<&AccountDelta> for Account are replaced by AccountPatch::try_to_new_account and AccountDelta::try_to_new_account. The caller must know from its own context that the account is new. Examples of such context are an empty initial state commitment at the transaction or batch level, or an account that is not yet in local state.
  • Account::apply_patch now accepts an account-creating patch. This is the recommended replacement when the initial account (nonce 0, with seed) is available.
  • Account::apply_patch now replaces the account code when the patch carries code.

The node uses is_full_state and Account::try_from(patch) in several places. Each place already has the context to tell a creation from an upgrade, so the migration is small. But a mechanical replacement of is_full_state() with "the patch carries code" is incorrect. It sends upgrade patches down the creation path, and the store then fails to apply the block.

Required changes

Store: code upgrades in the partial account update (high priority)

prepare_partial_account_update copies code_commitment from the existing row. It does not write new code to account_codes.

  • If patch.code().as_code() is present, use its commitment for the new row and insert the code into account_codes.
  • The schema already stores the code commitment per account row and stores code by commitment, so no migration is necessary.

Store: creation detection in the account state forest

AccountStateForest uses is_full_state() in add_vault_updates and in prepare_block_update_batch.

  • Decide from local state if the account is new. Every public account gets a vault lineage when it is created, so a missing vault lineage identifies a new account.
  • apply_rebuild_updates in the loader only creates accounts, so it does not need a change.

Store: creation detection in upsert_accounts

upsert_accounts branches on patch.is_full_state(). It already computes account_is_new = existing.is_none(), so use that value for the branch.

Recommendation: decide once in the store writer (crates/store/src/state/writer/worker.rs) which accounts are new. Give this set to the forest and to the database update. Keep the existing lineage and row checks as consistency checks. Then the forest and the database cannot make different decisions for the same account.

ntx-builder: network account effects

NetworkAccountEffect::from_protocol receives only the AccountUpdateDetails, so it cannot tell a creation from an upgrade.

  • Add a parameter that tells if the account is new.
  • Compute the set of new accounts in CommittedBlockEffects from body.transactions(): a transaction header with an empty initial_state_commitment() creates an account. crates/store/src/state/block_lifecycle.rs uses the same rule.
  • The genesis block has no transactions, so treat all genesis account updates as creations.
  • The Updated path calls Account::apply_patch, which now replaces the code. Network account upgrades therefore need no further change to support code upgrades.
  • An upgrade cannot change the network account classification, because NetworkAccount::new only examines storage and storage upgrades are not supported.

RPC: account admission

crates/rpc/src/server/admission.rs already returns early if the initial state commitment is not empty.

Network monitor and benchmark

bin/network-monitor/src/counter.rs (handle_increment_success) and bin/benchmark/src/create_proofs.rs keep the initial account in memory. Remove the is_full_state branch and always call apply_patch. This was requested in https://github.com/0xMiden/protocol/issues/3292.