Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/randprotocol-client/tests/wallet_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ async fn start_configured(dir: &tempfile::TempDir, key: &Keypair, genesis: Genes
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history: None,
// Final review I2: the node runs the default gas policy (what `rand-node run` carries
// unless told `--gas-price 0 --byte-price 0`), so every real call proof in these flows is
Expand Down
2 changes: 2 additions & 0 deletions crates/randprotocol-node/src/admission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,8 @@ pub fn acceptance_for_pool(e: &MempoolError, hash: Hash, refused: &mut RefusedCa
// PERP-6: this node's pool policy; the proof is valid on a chain without `bound_payouts`,
// and a peer on an older build relays it honestly.
| MempoolError::StateProofOverpays { .. }
// MSA-4: this node's `--max-multisig-accounts`; the create is valid on the chain.
| MempoolError::MultisigAtNodeCap { .. }
| MempoolError::AdmissionBusy(_) => Acceptance::Ignore,
}
}
Expand Down
25 changes: 25 additions & 0 deletions crates/randprotocol-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,13 @@ enum Cmd {
/// (CON-701; 16 from ~1.43 GB left, 18 from ~5.73 GB, 20 from ~22.9 GB).
#[arg(long, value_name = "TIER", value_parser = parse_state_proof_tier)]
max_state_proof_tier: Option<u8>,
/// MSA-4: stop pooling `CreateMultisig` once the chain's multisig register holds this
/// many accounts (the genesis-seeded ones included): such a create is not verified,
/// pooled, relayed or proposed here. Node policy only, for a chain whose genesis sets no
/// `multisig.max_accounts` (chain 21): a block carrying a create still applies, so the
/// cap holds only as far as the proposers run it. Default: no cap.
#[arg(long, value_name = "COUNT")]
max_multisig_accounts: Option<u64>,
/// Admission memory budget in MiB (issue #157): one byte budget over RPC request bodies
/// and transactions waiting for verification, gossiped or submitted. Past it,
/// `rand_sendTransaction` answers -32005 (busy, retry) and gossiped transactions are shed
Expand Down Expand Up @@ -3301,6 +3308,7 @@ async fn main() -> Result<()> {
prover_threads,
verify_workers,
max_state_proof_tier,
max_multisig_accounts,
admission_budget_mb,
disable_scan_leaves,
apply_proposals_inline,
Expand Down Expand Up @@ -3374,6 +3382,7 @@ async fn main() -> Result<()> {
min_free_disk_bytes: min_free_disk_mb << 20,
verify_workers,
state_proof_tier_cap: max_state_proof_tier,
multisig_account_cap: max_multisig_accounts,
apply_inline: apply_proposals_inline,
prune_history,
gas_policy: randprotocol_core::gas::GasPolicy::from_prices(gas_price, byte_price),
Expand Down Expand Up @@ -4853,6 +4862,22 @@ mod tests {
}
}

/// MSA-4: `--max-multisig-accounts` is unset by default (no cap) and takes a count.
#[test]
fn msa4_the_multisig_accounts_flag_takes_a_count_and_defaults_to_none() {
let run = |extra: &[&str]| {
let args = ["rand-node", "run", "--datadir", "d", "--key", "k.json"].into_iter().chain(extra.iter().copied());
match Cli::try_parse_from(args).map(|c| c.cmd) {
Ok(Cmd::Run { max_multisig_accounts, .. }) => Ok(max_multisig_accounts),
Ok(_) => unreachable!("a run"),
Err(e) => Err(e.to_string()),
}
};
assert_eq!(run(&[]).unwrap(), None, "default: no cap");
assert_eq!(run(&["--max-multisig-accounts", "64"]).unwrap(), Some(64));
assert!(run(&["--max-multisig-accounts", "many"]).is_err());
}

/// CON-601: `--max-state-proof-tier` is unset by default (the node sizes the cap from its
/// memory) and takes a perps proof tier, nothing else.
#[test]
Expand Down
70 changes: 70 additions & 0 deletions crates/randprotocol-node/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ pub enum MempoolError {
/// penalised, and a block carrying one still applies.
#[error("the state proof pays {want} collateral units, more than the {ceiling} the exchange can hold; this node does not pool it")]
StateProofOverpays { want: u128, ceiling: u128 },
/// MSA-4, node policy: a `CreateMultisig` while the register already holds this node's
/// `--max-multisig-accounts` ([`Mempool::set_multisig_account_cap`]). The ledger refuses a
/// create itself only past genesis `multisig.max_accounts` (`RegisterFull`), which chain 21
/// does not set; this is what this node pools, relays and proposes, never a verdict on the
/// transaction: not cached, no peer penalised, and a block carrying one still applies.
#[error("the multisig register holds {held} accounts, this node's limit of {cap} for new ones; it does not pool a CreateMultisig")]
MultisigAtNodeCap { held: u64, cap: u64 },
/// Issue #157: the admission byte budget ([`crate::admission::AdmissionBudget`]) cannot take
/// this transaction now. Retryable, never cached, no peer penalised; `rand_sendTransaction`
/// answers it as `-32005`.
Expand Down Expand Up @@ -470,6 +477,9 @@ pub struct Mempool {
/// CON-601: the highest state-proof tier this node verifies for its pool when the key is not
/// built ([`MempoolError::StateProofAboveNodeTier`]); `u8::MAX`, no cap, unless set.
state_proof_tier_cap: u8,
/// MSA-4: the register size at which this node stops pooling `CreateMultisig`
/// ([`MempoolError::MultisigAtNodeCap`], `--max-multisig-accounts`); `None`, no cap.
multisig_account_cap: Option<u64>,
}

/// CON-60 (b): the burst of verifier-key builds for state-proof shapes this node has no key for
Expand Down Expand Up @@ -745,9 +755,28 @@ impl Mempool {
lineage_keys: ColdKeyBudget::default(),
last_cost: std::sync::Mutex::new(None),
state_proof_tier_cap: u8::MAX,
multisig_account_cap: None,
}
}

/// MSA-4: refuse, at the pre-screen and the direct insert, every `CreateMultisig` while the
/// ledger's multisig register holds `cap` accounts or more
/// ([`MempoolError::MultisigAtNodeCap`]); `None`, the default, is no cap. Node policy, never
/// a validity rule: for a chain whose genesis sets no `multisig.max_accounts`.
pub fn set_multisig_account_cap(&mut self, cap: Option<u64>) {
self.multisig_account_cap = cap;
}

/// MSA-4: `Err` for a `CreateMultisig` on a register at this node's cap — one length read.
fn multisig_create_gate(&self, tx: &Transaction, ledger: &Ledger) -> Result<(), MempoolError> {
let (Some(cap), Action::CreateMultisig { .. }) = (self.multisig_account_cap, &tx.action) else { return Ok(()) };
let held = ledger.multisig().map_or(0, |r| r.len() as u64);
if held >= cap {
return Err(MempoolError::MultisigAtNodeCap { held, cap });
}
Ok(())
}

/// CON-601: refuse, at the pre-screen, every state proof above `tier` whose key this node has
/// not built ([`MempoolError::StateProofAboveNodeTier`]). Node policy, never a validity rule.
pub fn set_state_proof_tier_cap(&mut self, tier: u8) {
Expand Down Expand Up @@ -1148,6 +1177,8 @@ impl Mempool {
ledger.validate(&tx, executor).map_err(MempoolError::Invalid)?;
// PERP-6: after the ledger's own verdict, so a `bound_payouts` chain answers by its rule.
Self::state_proof_payout_gate(&tx, ledger)?;
// MSA-4: after the ledger's own verdict (a chain with `max_accounts` answers by its rule).
self.multisig_create_gate(&tx, ledger)?;
// The pool's policies (the faucet minter rule, COV-2's call screen) after the ledger's own
// verdict: this path runs no `precheck`, and it is the one a local `rand_mint` takes.
self.pool_policy(&tx, ledger).map_err(MempoolError::Invalid)?;
Expand Down Expand Up @@ -1295,6 +1326,7 @@ impl Mempool {
) -> Result<Claims, MempoolError> {
self.state_proof_tier_gate(tx, executor)?;
Self::state_proof_payout_gate(tx, ledger)?;
self.multisig_create_gate(tx, ledger)?;
let c = self.pool_conflicts(tx, ledger, executor)?;
Self::applies(tx, &c.commitments, c.claim, ledger).map_err(MempoolError::Invalid)?;
self.pool_policy(tx, ledger).map_err(MempoolError::Invalid)?;
Expand Down Expand Up @@ -5095,6 +5127,44 @@ mod tests {
assert_eq!(Mempool::payout_ceiling(&fixtures::genesis_with(1, vec![]).ledger), None);
}

/// MSA-4, node policy for a chain without genesis `multisig.max_accounts` (chain 21): with
/// `--max-multisig-accounts` set, a `CreateMultisig` is not pooled once the register holds
/// that many accounts — at the pre-screen and on the direct insert — while the ledger still
/// finds it valid. `Ignore` to gossip, not cached, not retryable. Under the cap, or with no
/// cap (the default), a create is pooled; other multisig actions are never gated.
#[test]
fn msa4_a_create_multisig_past_the_node_cap_is_not_pooled() {
use fixtures::{bundle, key, multisig_genesis, multisig_id, multisig_pay_tx, MULTISIG_CREATE_FEE};
let gs = multisig_genesis(7);
let l = gs.ledger.clone();
assert_eq!(l.multisig().unwrap().len(), 1, "the fixture's one seeded account");
assert!(l.multisig().unwrap().max_accounts.is_none(), "chain 21's shape: no genesis cap");
let create = StubExecutor::bound(Transaction::shielded(
7,
bundle(&l, [[1; 8], [2; 8]], [[3; 8], [4; 8]], randprotocol_core::gas::BUNDLE_BASE + MULTISIG_CREATE_FEE),
Action::CreateMultisig { salt: [5; 32], signers: vec![key(71).public_key().clone(), key(72).public_key().clone()], threshold: 1 },
));
let ex = &StubExecutor;
assert_eq!(l.validate(&create, ex), Ok(()), "valid to the ledger");
let mut m = Mempool::new(100);
assert!(m.precheck(&create, &l, ex).is_ok(), "no cap by default");
m.set_multisig_account_cap(Some(1));
let refusal = MempoolError::MultisigAtNodeCap { held: 1, cap: 1 };
assert_eq!(m.precheck(&create, &l, ex).unwrap_err(), refusal);
assert_eq!(m.insert(create.clone(), &l, ex).unwrap_err(), refusal);
assert_eq!(m.insert_verified(create.clone(), &l, ex).unwrap_err(), refusal);
assert!(m.is_empty() && !refusal.is_retryable());
let mut refused = crate::admission::RefusedCache::new(8);
assert_eq!(crate::admission::acceptance_for_pool(&refusal, create.hash(), &mut refused), crate::admission::Acceptance::Ignore);
assert!(refused.get(&create.hash()).is_none(), "not cached: the create is valid on this chain");
// The existing account still pays: only a create is gated.
let pay = multisig_pay_tx(&l, multisig_id(7), 0, vec![fixtures::rpl2_payout(0, randprotocol_core::UNITS_PER_RAND, 1)], &[0, 1]);
assert!(m.insert(pay, &l, ex).is_ok());
// Under the cap a create is pooled.
m.set_multisig_account_cap(Some(2));
assert!(m.insert(create, &l, ex).is_ok());
}

/// CON-601: a node's state-proof tier cap refuses a cold proof above it at the pool's
/// pre-screen — before the ledger's segment, the executor's pre-key rules or a cold-build
/// token — so it is never queued for verification (the only road to a key build), pooled,
Expand Down
1 change: 1 addition & 0 deletions crates/randprotocol-node/src/msauth_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ mod tests {
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history: None,
gas_policy: None,
msauth,
Expand Down
5 changes: 5 additions & 0 deletions crates/randprotocol-node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub struct NodeConfig {
/// ([`crate::mempool::state_proof_tier_cap_for`]: the memory left for a key build, audit v13
/// CON-701).
pub state_proof_tier_cap: Option<u8>,
/// MSA-4: the multisig register size at which this node stops pooling `CreateMultisig`
/// (`--max-multisig-accounts`); `None`, the default, is no cap. Node policy only.
pub multisig_account_cap: Option<u64>,
/// Apply incoming proposals on the consensus loop, as before (`--apply-proposals-inline`,
/// spec 2026-10-11 off-loop apply §4.5); `false`, the default, applies them on a blocking
/// worker ([`OFFLOOP_APPLIES`]).
Expand Down Expand Up @@ -3145,6 +3148,7 @@ pub async fn start_with(cfg: NodeConfig, rpc_options: RpcOptions, net_options: N
mempool.set_faucet_minters(admission::faucet_minters(&gs));
mempool.set_state_proof_tier_cap(state_proof_tier_cap);
let pool_tier_cap = mempool.state_proof_tier_cap();
mempool.set_multisig_account_cap(cfg.multisig_account_cap);
if let Some(p) = cfg.gas_policy {
mempool.set_gas_policy(p);
}
Expand Down Expand Up @@ -8352,6 +8356,7 @@ mod tests {
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history: None,
gas_policy: None,
msauth: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions crates/randprotocol-node/tests/burst_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ async fn start_node(gen: &Genesis, key: &Keypair, budget: usize) -> (NodeHandle,
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history: None,
gas_policy: None,
msauth: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions crates/randprotocol-node/tests/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ async fn a_build_whose_bundle_guest_differs_from_genesis_refuses_to_start() {
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history: None,
gas_policy: None,
msauth: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions crates/randprotocol-node/tests/common/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub async fn start_in_verify(
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history,
gas_policy: None,
msauth: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions crates/randprotocol-node/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ pub async fn start_one_validator_shaped(edit: impl FnOnce(&mut Genesis)) -> Test
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history: None,
gas_policy: None,
msauth: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions crates/randprotocol-node/tests/dandelion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async fn start_on_lanes(gen: &Genesis, seed: u8, bootstrap: Vec<libp2p::Multiadd
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history: None,
gas_policy: None,
msauth: Default::default(),
Expand Down
2 changes: 2 additions & 0 deletions crates/randprotocol-node/tests/prover_hosted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ async fn the_hosted_prover_answers_beside_the_node_and_its_exit_stops_the_node()
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history: None,
gas_policy: None,
msauth: Default::default(),
Expand Down Expand Up @@ -197,6 +198,7 @@ async fn the_node_stops_cleanly_on_shutdown_with_its_prover() {
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history: None,
gas_policy: None,
msauth: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions crates/randprotocol-node/tests/public_rpc_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async fn the_check_passes_on_the_public_listener_and_fails_on_the_operator_one()
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history: None,
gas_policy: None,
msauth: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions crates/randprotocol-node/tests/split_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ async fn a_v3_chain_admits_a_real_auth_proof_and_refuses_a_swapped_one() {
verify_workers: None,
apply_inline: false,
state_proof_tier_cap: None,
multisig_account_cap: None,
prune_history: None,
gas_policy: None,
msauth: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ one the cut announced; a mismatch on one node is almost always an old binary.
| `--prover-threads <N>` | the cores minus one, at most 8 | CPU threads the hosted prover's proofs use (`RAYON_NUM_THREADS` when set and no flag) |
| `--verify-workers <N>` | the cores minus two, at least four | the proof-verification workers of admission and the consensus loop's lookups; the queue and in-flight limits follow it (spec 2026-10-05 §6, `docs/compute-optimization.md` §3.3) |
| `--max-state-proof-tier <T>` | the highest tier whose key build fits in three quarters of the memory left: the host's RAM, or its cgroup's `memory.high`/`memory.max` if lower, less the node's resident size, re-measured every minute and held at 16 or lower for the first minute after a start (CON-701; 16 from ~1.43 GB left, 18 from ~5.73 GB, 20 from ~22.9 GB — so 14 or 12 on a 2 GB host under `MemoryHigh=85%`, CON-751; on macOS the host's RAM alone) | CON-601: a perps state proof above this tier whose shape the node holds no verifier key for is refused at the pool's pre-screen, before any verification or key build (`StateProofAboveNodeTier`); node policy only, a block carrying one still applies. One of 10, 12, 14, 16, 18, 20 (`docs/perps.md`) |
| `--max-multisig-accounts <COUNT>` | none | MSA-4: once the chain's multisig register holds this many accounts (the genesis-seeded ones included), a `CreateMultisig` is refused at the pool's pre-screen (`MultisigAtNodeCap`: not cached, no peer penalised) and is not verified, pooled, relayed or proposed by this node. Node policy only, for a chain whose genesis sets no `multisig.max_accounts` (chain 21); a block carrying a create still applies (`docs/multisig.md`) |
| `--admission-budget-mb <MIB>` | 1/16 of the host's RAM, within 64–256 MiB, never under one largest transaction | the admission byte budget (issue #157): RPC request bodies plus transactions waiting for verification. Past it `rand_sendTransaction` answers `-32005` (busy, retry) and gossiped transactions are shed with `Ignore`; a body is charged three times its length, the heap it is measured to hold (OPS-602); a value under one largest transaction (three times the body cap, plus the block cap: 129 MiB on chain 21) is refused at startup (`docs/rpc.md`) |
| `--disable-scan-leaves` | off (the method is served) | refuse `rand_getScanLeaves` on both listeners with `-32601` naming the flag (audit v12, RPC-201). A wallet before v0.8.3 scans with it and then reads only its own leaves, which tells the node which leaves it owns; `rand` v0.8.3+ never calls it. The default flips to off at the next minor (`docs/rpc.md`, `rand_getScanLeaves`) |
| `--apply-proposals-inline` | off | restore the inline apply: incoming proposals are applied on the consensus loop, as before v0.8.0's off-loop apply; by default the apply runs on a blocking thread (at most 4 at once, up to 8 waiting behind a parent, at most 2 per proposer), with the prechecks, `on_proposal`'s checks and the insert still on the loop (`docs/compute-optimization.md` §3.3). The by-hash fetch answer binding (an answer that is not the block asked for is dropped) is a separate fix and stays on with this flag |
Expand Down
Loading
Loading