Skip to content

Conversation

@m2ux
Copy link
Contributor

@m2ux m2ux commented Jan 28, 2026

Overview

Implement treasury initialization for the Midnight mainnet genesis block. The treasury is initialized from observed cNight deposits in the ICS (Illiquid Circulation Supply) contract on Cardano, configured through a new cnight-treasury-config.json file.

JIRA: PM-20981
Epic: PM-20554 - Mainnet Genesis Block

Changes

New Files

File Description
util/toolkit/src/treasury_config.rs Config struct, validation logic, unit tests
res/dev/cnight-treasury-config.json Dev placeholder config
res/preview/cnight-treasury-config.json Preview placeholder config

Modified Files

File Changes
util/toolkit/src/lib.rs Export treasury_config module
util/toolkit/src/genesis_generator.rs Add fund_treasury() method, integration test
util/toolkit/src/commands/generate_genesis.rs Add --cnight-treasury-config CLI argument

Implementation Details

  1. Configuration file (cnight-treasury-config.json):

    • ics_contract_address: ICS contract address on Cardano
    • utxos[]: List of UTxOs with tx_hash, output_index, expected_amount
    • total_night_amount: Must equal sum of UTxO amounts
  2. Two-step transfer via block reward pool:

    • DistributeReserve(amount) - Move from reserve pool to block_reward_pool
    • PayBlockRewardsToTreasury { amount } - Move from block_reward_pool to treasury
  3. Validation:

    • Config-time validation ensures total matches sum of UTxOs
    • Overflow handling for large amounts

🗹 TODO before merging

  • Ready

📌 Submission Checklist

  • Changes are backward-compatible (or flagged if breaking)
  • Pull request description explains why the change is needed
  • Self-reviewed the diff
  • I have included a change file, or skipped for this reason:
  • If the changes introduce a new feature, I have bumped the node minor version
  • Update documentation (if relevant)
  • Updated AGENTS.md if build commands, architecture, or workflows changed
  • No new todos introduced

🧪 Testing Evidence

cargo test -p midnight-toolkit treasury
   running 8 tests
   test treasury_config::tests::test_parse_valid_config ... ok
   test treasury_config::tests::test_validate_total_matches_sum ... ok
   test treasury_config::tests::test_validate_total_mismatch_fails ... ok
   test treasury_config::tests::test_validate_zero_total_empty_utxos ... ok
   test treasury_config::tests::test_validate_overflow_handling ... ok
   test treasury_config::tests::test_error_message_total_mismatch ... ok
   test treasury_config::tests::test_treasury_amount ... ok
   test genesis_generator::test::test_genesis_with_treasury_config ... ok

   test result: ok. 8 passed; 0 failed; 0 ignored

🔱 Fork Strategy

  • Node Runtime Update
  • Node Client Update
  • Other:
  • N/A

Links

m2ux added 2 commits January 28, 2026 16:58
Add change file documenting the upcoming treasury initialization feature
for the mainnet genesis block.

JIRA: PM-20981
@m2ux m2ux self-assigned this Jan 28, 2026
m2ux added 4 commits January 29, 2026 14:28
Add support for initializing the Midnight treasury from observed cNight
deposits in the ICS (Illiquid Circulation Supply) contract on Cardano.

- Add CnightTreasuryConfig type with validation for config files
- Add --cnight-treasury-config CLI argument to generate-genesis command
- Add fund_treasury() method using DistributeReserve and PayBlockRewardsToTreasury
- Integrate treasury funding early in genesis flow (before wallet distribution)
- Add example config files for dev and preview environments
Add #[allow(clippy::too_many_arguments)] to init() method. The parameter
count is a pre-existing issue; refactoring to a config struct is deferred.
Add test_genesis_with_treasury_config that verifies end-to-end treasury
funding during genesis generation. The test creates a treasury config
with multiple UTxOs, passes it to GenesisGenerator, and verifies the
resulting state.treasury contains the expected NIGHT balance.
Merged ledger-parameters-config feature with treasury-config feature.
Both CLI arguments are now supported:
- --cnight-treasury-config: Initialize treasury from ICS observations
- --ledger-parameters-config: Custom ledger parameters
@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2026

kics-logo

KICS version: v2.1.16

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 94
LOW LOW 12
INFO INFO 83
TRACE TRACE 0
TOTAL TOTAL 189
Metric Values
Files scanned placeholder 28
Files parsed placeholder 28
Files failed to scan placeholder 0
Total executed queries placeholder 73
Queries failed to execute placeholder 0
Execution time placeholder 7

m2ux added 2 commits January 29, 2026 17:11
Updated treasury.json to cnight-treasury-config.json to match
the actual implementation.
@m2ux m2ux marked this pull request as ready for review January 29, 2026 17:12
@m2ux m2ux requested a review from a team as a code owner January 29, 2026 17:12
m2ux added 2 commits January 29, 2026 17:15
Removed 4 tests that provided minimal value:
- test_error_message_total_mismatch: only tests Display impl
- test_treasury_amount: trivial accessor test
- test_validate_total_matches_sum: redundant with test_parse_valid_config
- test_validate_zero_total_empty_utxos: trivial edge case

Remaining tests (3 unit + 1 integration) cover critical paths.
- Added #[allow(clippy::too_many_arguments)] to GenesisGenerator::new()
- Removed 4 low-value tests from treasury_config.rs
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