Introducing a new way to review your PRs.

Read the announcement

near / nearcore

Reference client for NEAR Protocol

View on GitHub

20 documents · Updated Nov 23, 2026

docs / protocol-parameters-and-upgrades

Protocol parameters and upgrades

Protocol parameters and upgrades define the versioned rules that make validating nodes reach the same result. The system combines typed runtime settings with protocol-version gates, protects stored and network data from unsafe schema changes, and activates new consensus behavior at an epoch boundary. See Protocol configuration for the wider map of protocol types and configuration boundaries. For the relationship with validator and epoch changes, see Epoch and validator management.

Parameter definitions and configuration

Parameter domains

Parameter is the catalogue of values that may change with a protocol version. It covers economic rules, contract execution costs and limits, account rules, congestion and witness controls, bandwidth scheduling, global contract costs, signature costs, and feature flags for new runtime behavior. These values become a RuntimeConfig, which gives runtime and chain services one shared view of the active rules.

The parameter model keeps values typed while allowing source files to use integers, ratios, fees, flags, and lists. Fees can carry separate gas and compute values. A missing value or a wrong type stops configuration assembly instead of silently selecting a default. VM limits and runtime feature flags use the same versioned path.

References: core/…/parameter.rs• L4-18 core/…/parameter.rs• L211-331 core/…/vm.rs• L47-204

Versioned runtime configuration

The runtime configuration starts with one base parameter set and applies retained version-specific changes. Each change states the old value and the new value. The old-value check makes the history self-checking: if an earlier change or the base file differs, the node fails while building its configuration instead of using an unintended rule set.

The retained configuration boundaries are protocol versions 87, 88, 89, and 157. Version 85 is the minimum supported protocol version. Versions below that floor use the base-era values because their old diffs are no longer retained. A request for an intermediate version uses the most recent configuration at or below that version. The first retained diff stays above the support floor because older values have been folded into the base configuration.

The store also records the protocol versions that change the consensus VM generation. This history lets the node use a distinct VM generation when a VM rule changes. It also marks when consensus-level Wasm cache entries need new rules.

References: core/…/config_store.rs• L18-38 core/…/config_store.rs• L47-87 core/…/config_store.rs• L152-189 core/…/config_store.rs• L442-477 core/…/parameters.yaml• L1-3 core/…/parameter.rs• L261-331

The configuration files express protocol history rather than only current node settings. The base file defines initial values. Retained version files record later changes. For example, protocol 89 raises the maximum number of globals in a contract to 65,536, enables corrected contract-loading cost, raises the per-receipt storage proof limit to 4,500,000, enables several runtime fixes, and enables external contract calls with per-call and per-chunk limits. Later retained values also tighten receipt input limits at protocol 157.

Configuration snapshots record the public view for each retained version. They make an intended parameter change visible in both the accumulated parameter values and the configuration contract exposed to clients. The retained snapshots cover the active boundaries, including 87, 88, 89, and 157. They show the staged activation of runtime features: protocol 87 enables selected host functions, protocol 88 enables universal accounts, protocol 89 enables runtime fixes and external calls, and protocol 157 applies the newer receipt input limit.

References: core/…/89.yaml• L1-40 core/…/parameters.yaml• L1-3 core/…/parameters.snap• L1-20 core/…/config_store.rs• L299-347 core/…/near_parameters__config_store__tests__87.json.snap• L208-265 core/…/near_parameters__config_store__tests__88.json.snap• L206-264 core/…/near_parameters__config_store__tests__89.json.snap• L208-304 core/…/near_parameters__config_store__tests__157.json.snap• L208-308

Chain-specific configuration

The shared protocol history supports different needs without changing production rules. Benchmarknet raises limits for throughput tests. The congestion-control test chain keeps calibrated congestion values. Testnet uses the shared configuration and is checked against mainnet for every supported version.

References: core/…/config_store.rs• L89-121 core/…/config_store.rs• L350-367

Parameter cost estimation

The parameter cost estimator measures runtime work against the active parameter model. It uses the protocol configuration as a controlled starting point, then removes unrelated limits and fees so measurements describe the workload rather than the test bed. The estimator can inform later calibration, but the versioned configuration remains the authority used by the protocol.

References: runtime/…/estimator_context.rs• L38-73 runtime/…/estimator_context.rs• L153-215 runtime/…/estimator_context.rs• L315-355 runtime/…/Cargo.toml• L14-17

Protocol versions and feature gates

Protocol and client versions

A protocol version names the consensus rules used by an epoch. It is separate from the client version, which can change local code or data handling without changing the rules shared by validators. The binary exposes the highest protocol version that it can process and vote for.

The source defines a production genesis version of 29, a minimum supported version of 85, a stable version of 89, a nightly ceiling of 158, and a Spice ceiling of 200. These values describe binary capability. The active network version still comes from epoch data and upgrade voting. A feature can activate below the build ceiling; Spice, for example, activates at version 180.

References: core/…/version.rs• L164-214

Runtime feature gates

ProtocolFeature is the registry for behavior that must change as one network-wide rule. Each feature maps to an activation version. The runtime enables it when the epoch protocol version reaches that value. This rule is monotonic, so a feature does not turn off after activation.

Runtime settings and feature gates must describe the same behavior. Stable gates currently reach version 89. Nightly gates cover later behavior such as external contract calls, receipt input limits, ML-DSA cost fixes, and contract compilation status. Build features choose a binary's version ceiling or test behavior. They do not replace the protocol-version check used for consensus behavior.

References: core/…/version.rs• L3-162 core/…/parameter.rs• L263-331 core/…/vm.rs• L206-285

Supported historical versions

Read-only work may need to inspect data from before the binary's support floor. Such paths can clamp the requested version to the minimum supported version when the call cannot change chain state. State-changing or consensus-sensitive paths instead reject an unsupported version so an old rule cannot be used as if it were current.

References: core/…/version.rs• L167-193 core/…/config_store.rs• L152-189

Upgrade voting

The upgrade flow separates binary release from network activation. A node first runs a binary that knows the new version. It then places that version in the latest_protocol_version field of produced blocks according to a time-ordered schedule. The epoch manager weights reported versions by validator stake and selects the leading version only after it passes the configured stake threshold.

The default threshold is 8/10. A successful vote in the last block of epoch X takes effect in the first block of epoch X+2. This gives operators time to update nodes. Validators that continue to report a version below the selected network version can be removed from the validator set.

References: core/…/genesis_config.rs• L63-65 core/…/genesis_config.rs• L108-129 chain/…/client.rs• L1172-1176 chain/…/epoch_info_aggregator.rs• L194-199 chain/…/lib.rs• L840-924

The schedule is deliberately narrow. Its final version must match the client ceiling. Dates must increase. Versions must advance one step at a time. An empty schedule means that the node votes for its client version at once. These checks prevent a release from asking the network to skip a version or vote for a version the binary cannot provide.

References: core/…/upgrade_schedule.rs• L24-40 core/…/upgrade_schedule.rs• L42-63 core/…/upgrade_schedule.rs• L65-160 core/…/version.rs• L189-214

This diagram shows how a new rule moves from a binary release to an active epoch rule.

flowchart LR
    A[New protocol behavior] --> B[Binary supports new version]
    B --> C[Feature gate and parameter history]
    C --> D[Validator blocks carry upgrade votes]
    D --> E[Stake threshold reached]
    E --> F[Version selected for a future epoch]
    F --> G[Runtime uses versioned rules]

Schema compatibility

Protected protocol schema

The protocol schema check protects structures stored in the database or exchanged between nodes. Types register their schema. The checker compares the current registered structures with an approved baseline. The comparison covers structure shape, names, fields, variants, and nested type information.

The check guards against two risks: a new binary may be unable to read old local data, or old and new nodes may disagree about a wire format. It also protects block replay because serialized protocol data must keep its meaning across a rolling upgrade. The latest baseline refresh updates fingerprints for action and execution error types, execution outcome types, receipt validation errors, server errors, and transaction execution errors. These entries record the schema contract for the changed serialized forms; they do not activate a new protocol rule. Public enum entries such as VM kinds and serialized cost categories therefore need stable identities. VMKind keeps old entries even when a VM is no longer used, because those entries remain part of the serialization protocol.

References: tools/…/protocol_schema.toml• L1-20 tools/…/protocol_schema.toml• L167-175 tools/…/protocol_schema.toml• L279-291 tools/…/protocol_schema.toml• L406-424 core/…/vm.rs• L9-39 core/…/cost.rs• L261-379 core/…/lib.rs• L9-81

Public configuration view

The runtime configuration has a JSON view used by configuration RPC output. This view keeps field names and old fields stable so external clients can continue to read responses after a protocol change. New fields can use defaults when older data lacks them. Existing fields must not be renamed or removed.

The configuration snapshots test this contract for retained protocol versions and for the general runtime view. They also show that protocol changes can update values while preserving the public shape. The external-call fields are an example: older views report zero limits, while the protocol-89 view reports the enabled limits. Runtime feature fields follow the same pattern as later protocol versions enable them.

References: core/…/view.rs• L8-37 core/…/view.rs• L159-227 core/…/view.rs• L795-820 core/…/near_parameters__config_store__tests__0.json.snap• L208-224 core/…/near_parameters__config_store__tests__89.json.snap• L208-224 core/…/near_parameters__view__tests__runtime_config_view.snap• L1-308

Compatibility decisions

When a stored or network structure must change, the safe boundary is an explicit versioned form that can decode the old and new representations. Internal code can use the current form while the older form remains available for hash checks, replay, storage reads, or mixed-version communication.

When the schema checker finds a new, removed, or changed structure, it writes a candidate baseline and fails. Engineers must first decide whether the change needs a database migration or a compatible protocol representation. Only after that decision should the approved schema baseline be refreshed.

References: tools/…/protocol_schema.toml• L391-437 tools/…/main.rs• L107-155 docs/…/Upgradability.md• L35-56

Safe protocol behavior introduction

Change boundaries

Every proposed change must first be placed in the boundary that controls when it takes effect. A client-only change takes effect when operators deploy the binary. A parameter change takes effect for the protocol version that owns its diff. A consensus behavior change needs a feature gate and a network upgrade. A stored or network type change also needs a compatibility plan.

These boundaries can overlap. A new runtime rule may need both a parameter diff and a ProtocolFeature. A new block field may need a versioned representation plus an activation rule. Treating the boundaries separately prevents a local migration or a binary release from being mistaken for network-wide activation.

References: core/…/config_store.rs• L18-38 core/…/version.rs• L118-162 docs/…/Upgradability.md• L5-9

Upgrade sequence

The normal sequence for a consensus-visible change is:

  1. Define the behavior and its compatibility needs.
  2. Add the parameter history or versioned data form that represents the new rule.
  3. Add a protocol feature with an activation version and use the epoch version at each consensus decision.
  4. Run schema checks and review any database migration or wire compatibility work.
  5. Test the behavior on nightly or another controlled network.
  6. Release a binary that supports the new version and set a valid voting schedule.
  7. Wait for the stake threshold and epoch-boundary activation before treating the new rule as network-wide.

Nightly versions provide a controlled path for unfinished protocol behavior. Stabilization moves the feature into the supported release path and requires code-owner review plus a delay before a non-security feature can ship.

References: core/…/version.rs• L144-155 core/…/upgrade_schedule.rs• L73-124 docs/…/protocol_upgrade.md• L53-72 docs/…/protocol_upgrade.md• L127-160

Change checklist

When these files or sections are changed, remember to consider these:

  • A Parameter change must stay aligned with the base YAML, every retained version diff, the typed RuntimeConfig conversion, and any fee or cost map that uses the parameter.
  • Removing an old version diff must preserve its accumulated values in the base configuration or in a retained later diff. Historical replay must still resolve the same rules for every supported protocol version.
  • A new runtime flag or cost must agree across the parameter catalogue, YAML history, runtime conversion, public configuration view when exposed, and the feature gate that controls behavior.
  • The first retained configuration diff must remain above MIN_SUPPORTED_PROTOCOL_VERSION. Removing a diff at the support boundary must leave its values in the base configuration or a later retained diff.
  • A VM config change must add its protocol boundary to VM_GENERATION_VERSIONS so consensus-level Wasm cache invalidation follows the rule change.
  • A new feature activation must agree across the feature registry, the binary version ceiling, the voting schedule, and every consensus decision that uses the gate.
  • A change to a stored or network type must have an explicit migration or versioned representation before the protocol schema baseline is refreshed.
  • When the schema baseline changes, verify that every changed fingerprint matches the intended registered type and that the baseline update does not replace a needed migration or wire-version plan.
  • A release schedule must end at the binary's supported version and leave enough time for the X-to-X+2 activation path.
  • A change to a public runtime configuration field must preserve existing JSON names and fields because RPC clients consume that view independently of consensus activation.
  • A benchmark or congestion-control chain override must remain isolated from the shared protocol history. Testnet must continue to match mainnet.
  • A cost measurement change must keep the estimator's measured configuration aligned with the protocol cost model. Estimator-only limits must not become protocol defaults.

Important failure modes

TriggerConsequenceGuard
A parameter diff declares an old value that does not match accumulated historyConfiguration assembly stops instead of producing an untrusted runtime configurationStrict old-value checks when a diff is applied
A parameter is missing from the base or required versioned configurationRuntime configuration construction fails instead of using an implicit valueRequired-value checks and exhaustive typed conversion
An old version diff is deleted without carrying its values into the base or a retained diffHistorical replay can use the wrong rulesRetained version mapping and per-version configuration snapshots
A retained diff is at or below the minimum supported protocol versionUnsupported historical configuration remains activeThe no-deprecated-config check requires the first diff to be above the support floor
A VM config changes without a matching VM generation boundaryConsensus-level Wasm cache entries can use the wrong VM rulesVM generation checks compare each config transition with its boundary
A schedule skips a protocol version or ends below the client versionNode startup rejects the scheduleSchedule validation requires ordered dates, one-step versions, and a matching final version
A validator reports a version below the selected network versionThe validator can be removed from the validator setVersion voting and epoch-manager kickout logic
A registered protocol type or public enum entry changes without a compatibility planNodes may fail to read data, communicate, or replay blocksProtocol schema comparison plus migration or versioned-data review
A schema fingerprint is refreshed for the wrong registered typeThe baseline can hide an unintended serialized-data change or leave the intended change unapprovedCandidate baseline review against the registered type and its compatibility plan
A state-changing request uses a protocol version below the support floorThe node may apply a rule it no longer supportsSupport-floor assertion; clamping is limited to read-only paths
A public runtime configuration field is renamed or removedRPC clients can no longer decode configuration responsesStable RuntimeConfigView fields and snapshot coverage
A chain-specific test override enters shared protocol historyTest behavior can leak into production configurationNamed chain overrides and the testnet-mainnet equality check

Key files

FileWhy to read it
core/…/parameter.rsDefines the versioned protocol parameter catalogue
core/…/config.rsShows the main runtime configuration domains
core/…/config_store.rsShows how base values and retained diffs become per-version configurations
core/…/parameter_table.rsShows typed values and strict diff validation
core/…/view.rsDefines the stable public JSON configuration view
core/…/vm.rsDefines VM limits, feature settings, and serialized VM kinds
core/…/parameters.yamlRecords the base protocol parameter set
core/…/89.yamlIllustrates the stable protocol boundary for runtime fixes and external calls
core/parameters/res/runtime_configs/parameters.snapRecords generated accumulated parameter values
core/parameters/src/snapshots/near_parameters__config_store__tests__89.json.snapShows the public configuration after protocol 89
core/parameters/src/snapshots/near_parameters__config_store__tests__157.json.snapShows the latest retained configuration snapshot
core/parameters/src/snapshots/near_parameters__view__tests__runtime_config_view.snapShows the stable public configuration shape
core/…/version.rsDefines protocol versions, feature activation, and support limits
core/…/upgrade_schedule.rsDefines and validates validator voting schedules
chain/…/lib.rsSelects the future epoch version from stake-weighted votes
tools/…/protocol_schema.tomlStores the approved protocol schema fingerprints
docs/…/Upgradability.mdExplains client, data, and protocol upgrade boundaries
docs/…/protocol_upgrade.mdDescribes release, testing, and stabilization steps