Skip to content

feat(chainspec): add TempoFeatures bitfield and require_feature! macro#2887

Draft
decofe wants to merge 3 commits intomainfrom
zygis/feature-flags
Draft

feat(chainspec): add TempoFeatures bitfield and require_feature! macro#2887
decofe wants to merge 3 commits intomainfrom
zygis/feature-flags

Conversation

@decofe
Copy link
Member

@decofe decofe commented Feb 26, 2026

Adds TempoFeature / TempoFeatures — a growable bitset-based feature flag system layered on top of the existing TempoHardfork enum. Each protocol change gets its own numeric ID with explicit dependency requirements via a DAG (requires() / can_activate()). No upper bound on feature count.

Also adds:

  • spec.has(TempoFeature::REPLAY_HASH_V2) for ergonomic feature checks in handler/consensus code
  • require_feature! macro for precompile dispatch gating

Design decisions:

  • TempoFeatures is a Vec<u64>-backed bitset — grows dynamically, no cap
  • TempoHardfork::has() derives features from the hardfork for backward compat
  • No upstream reth/revm changes needed — ChainSpec stays static, features will live in CfgEnv (already per-block) when on-chain activation lands
  • Dependencies enforced via requires() DAG, validated with can_activate()

Migration path for existing code:

// before
if spec.is_t1b() { ... }

// after
if spec.has(TempoFeature::REPLAY_HASH_V2) { ... }

Phased rollout:

  1. ✅ This PR: TempoFeatures + spec.has() + require_feature! macro
  2. Next: migrate existing spec.is_tN() callsites
  3. Later: add TempoFeatures field to CfgEnv, compute per-block from on-chain state
  4. Later: FeatureRegistry precompile for validator signaling + 80% threshold activation

Prompted by: zygis

Adds independent feature flags as a layer on top of the existing
TempoHardfork enum. Each feature is a single bit with explicit
dependency requirements via a DAG. Existing hardforks map to feature
sets for backward compatibility.

Also adds require_feature! macro for ergonomic feature gating in
precompile dispatch arms.

Co-authored-by: Zygis <zygis@tempo.xyz>
Co-authored-by: Georgios <georgios@tempo.xyz>
Amp-Thread-ID: https://ampcode.com/threads/T-019c9ad6-7f63-70b7-8ba2-bd1433803493
Co-authored-by: Amp <amp@ampcode.com>
@github-actions
Copy link

github-actions bot commented Feb 26, 2026

📊 Tempo Precompiles Coverage

precompiles

Coverage: 20839/21903 lines (95.14%)

File details
File Lines Coverage
src/account_keychain/dispatch.rs 36/41 87.80%
src/account_keychain/mod.rs 1131/1150 98.35%
src/error.rs 139/158 87.97%
src/ip_validation.rs 10/10 100.00%
src/lib.rs 356/367 97.00%
src/nonce/dispatch.rs 19/23 82.61%
src/nonce/mod.rs 252/260 96.92%
src/stablecoin_dex/dispatch.rs 349/353 98.87%
src/stablecoin_dex/error.rs 51/51 100.00%
src/stablecoin_dex/mod.rs 2997/3093 96.90%
src/stablecoin_dex/order.rs 362/362 100.00%
src/stablecoin_dex/orderbook.rs 651/683 95.31%
src/storage/evm.rs 321/347 92.51%
src/storage/hashmap.rs 128/140 91.43%
src/storage/mod.rs 5/5 100.00%
src/storage/packing.rs 526/552 95.29%
src/storage/thread_local.rs 146/195 74.87%
src/storage/types/array.rs 211/262 80.53%
src/storage/types/bytes_like.rs 323/338 95.56%
src/storage/types/mapping.rs 148/148 100.00%
src/storage/types/mod.rs 67/91 73.63%
src/storage/types/primitives.rs 564/567 99.47%
src/storage/types/set.rs 454/474 95.78%
src/storage/types/slot.rs 282/296 95.27%
src/storage/types/vec.rs 1078/1095 98.45%
src/test_util.rs 194/231 83.98%
src/tip20/dispatch.rs 584/616 94.81%
src/tip20/mod.rs 1783/1854 96.17%
src/tip20/rewards.rs 444/487 91.17%
src/tip20/roles.rs 187/206 90.78%
src/tip20_factory/dispatch.rs 26/29 89.66%
src/tip20_factory/mod.rs 543/555 97.84%
src/tip403_registry/dispatch.rs 406/443 91.65%
src/tip403_registry/mod.rs 1338/1423 94.03%
src/tip_fee_manager/amm.rs 1111/1147 96.86%
src/tip_fee_manager/dispatch.rs 330/343 96.21%
src/tip_fee_manager/mod.rs 501/516 97.09%
src/validator_config/dispatch.rs 210/221 95.02%
src/validator_config/mod.rs 606/692 87.57%
src/validator_config_v2/dispatch.rs 201/214 93.93%
src/validator_config_v2/mod.rs 1769/1865 94.85%

contracts

Coverage: 209/383 lines (54.57%)

File details
File Lines Coverage
src/lib.rs 1/71 1.41%
src/precompiles/account_keychain.rs 24/30 80.00%
src/precompiles/nonce.rs 9/18 50.00%
src/precompiles/stablecoin_dex.rs 36/48 75.00%
src/precompiles/tip20.rs 52/70 74.29%
src/precompiles/tip20_factory.rs 6/12 50.00%
src/precompiles/tip403_registry.rs 12/15 80.00%
src/precompiles/tip_fee_manager.rs 21/45 46.67%
src/precompiles/validator_config.rs 12/26 46.15%
src/precompiles/validator_config_v2.rs 36/48 75.00%

Total: 21048/22286 lines (94.44%)

📦 Download full HTML report

decofe and others added 2 commits February 26, 2026 19:42
Covers: cycle detection, hardfork dependency consistency, high-bit
usage, feature count, display formatting, and base feature independence.

Amp-Thread-ID: https://ampcode.com/threads/T-019c9ad6-7f63-70b7-8ba2-bd1433803493
Co-authored-by: Amp <amp@ampcode.com>
…has()

Drops the u128 bitflags in favor of a Vec<u64>-backed TempoFeatures
with no upper bound on feature count. Adds TempoHardfork::has() for
ergonomic feature checks in handler/consensus code:

  if spec.has(TempoFeature::REPLAY_HASH_V2) { ... }

Tests include handler migration patterns and multi-feature gating.

Amp-Thread-ID: https://ampcode.com/threads/T-019c9ad6-7f63-70b7-8ba2-bd1433803493
Co-authored-by: Amp <amp@ampcode.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.

2 participants