Skip to main content

ir_console/
ir_console.rs

1//! Deterministic instruction-count driver for the operator console and local
2//! settlement (callgrind Ir): many observations, repeated actors and customers,
3//! assembled and rendered repeatedly. The rendered length, alert counts and
4//! settled totals are the work-parity anchors.
5
6use spacedb_console::*;
7use spacedb_meter::{LocalSettlement, Settlement};
8use spacedb_meter::{RateCard, Usage, UsageClaim};
9
10fn main() {
11    let homes = (0..50)
12        .map(|i| HomeObs {
13            id: format!("home-{i:03}"),
14            region: ["us-east", "us-west", "eu"][i % 3].into(),
15            online: i % 7 != 0,
16        })
17        .collect();
18    let shards = (0..300u32)
19        .map(|i| ShardObs {
20            id: format!("shard-{i:04}"),
21            collection: ["profiles", "photos", "ledger", "notes"][i as usize % 4].into(),
22            reachable_replicas: i % 4,
23            target_replicas: 3,
24            durable_floor: 1,
25            size_bytes: (i as u64 + 1) << 24,
26        })
27        .collect();
28    let strong = (0..10u32)
29        .map(|i| StrongObs {
30            collection: format!("strong-{i}"),
31            members_online: i % 4,
32            members_total: 3,
33        })
34        .collect();
35    let lags = (0..20u64)
36        .map(|i| LagObs {
37            collection: format!("col-{i}"),
38            lag_ops: i * 37,
39            region: Some("us-west".into()),
40        })
41        .collect();
42    let capabilities = (0..50u64)
43        .map(|i| CapabilityObs {
44            bearer: format!("did:agent:a{}", i % 12),
45            scope: "profiles".into(),
46            ops: "rw".into(),
47            expiry: Some(1_700_000_000 + i * 600),
48            budget_micro_mata: Some(1_000_000),
49            revoked: i % 9 == 0,
50        })
51        .collect();
52    let audit = (0..3000u64)
53        .map(|i| AuditObs {
54            actor: format!("did:agent:a{}", i % 12),
55            action: "write".into(),
56            at: 1_700_000_000 + i,
57            allowed: i % 5 != 0,
58        })
59        .collect();
60    let settled = (0..2000u64)
61        .map(|i| SettledObs {
62            host_did: format!("home-{:03}", i % 50),
63            settles_to_did: format!("customer-{}", i % 25),
64            resource: [Resource::Storage, Resource::Compute, Resource::Transit][i as usize % 3],
65            micro_mata: 1_000 + i,
66        })
67        .collect();
68    let budgets = (0..30u64)
69        .map(|i| AgentBudgetObs {
70            agent: format!("did:agent:a{i}"),
71            remaining: i * 10_000,
72            limit: 1_000_000,
73        })
74        .collect();
75    let obs = Observations {
76        homes,
77        shards,
78        strong,
79        lags,
80        capabilities,
81        audit,
82        settled,
83        budgets,
84        unsettled_claims: 12,
85    };
86
87    let mut rendered = 0usize;
88    let mut critical = 0usize;
89    for _ in 0..20 {
90        let dash = Dashboard::assemble(&obs, &Config::at(1_700_000_100));
91        critical += dash.critical_count();
92        rendered += dash.render_text().len();
93    }
94
95    let mut settlement = LocalSettlement::new(RateCard {
96        storage_per_gib_month: 5_000_000,
97        compute_per_megafuel: 1_000_000,
98        compute_per_invocation: 1_000,
99        transit_per_gib: 1_000_000,
100    });
101    let mut total = 0u64;
102    for i in 0..2000u64 {
103        let claim = UsageClaim::new(
104            format!("home-{:03}", i % 50),
105            format!("customer-{}", i % 25),
106            Usage::compute(1_000_000 + i, 1),
107            i,
108            i + 60,
109        );
110        total += settlement.settle(&claim).unwrap().micro_mata;
111    }
112    println!(
113        "rendered {rendered} critical {critical} settled {total} receipts {}",
114        settlement.receipts().len()
115    );
116}