Skip to content
Merged
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
697f696
add disk pricing to virtual server
James-Mart Apr 25, 2026
71c6460
settle virtual billing cost when enabling billing
James-Mart Apr 25, 2026
92cd806
config ui - show missing subjective storage config
James-Mart Apr 25, 2026
3eba32d
add proposal pusher test helper
James-Mart Apr 25, 2026
b04fcfb
add disk usage trace helpers
James-Mart Apr 25, 2026
28055f7
add virtual server disk billing tests
James-Mart Apr 25, 2026
de0da83
fix typo
James-Mart May 1, 2026
ff7684a
Merge remote-tracking branch 'origin/main' into disk-billing
James-Mart May 1, 2026
88cc456
fix merge
James-Mart May 1, 2026
e5c5915
Merge remote-tracking branch 'origin/main' into disk-billing
James-Mart Jun 8, 2026
5dacc5c
pr feedback - fix capacity limit pricing curve comments
James-Mart Jun 9, 2026
c0c6bc8
minor cleanup - capacity-limit-pricing is generic (not specifically d…
James-Mart Jun 9, 2026
ad779e3
pr feedback - avoid potential overflow
James-Mart Jun 9, 2026
fb6329c
reject quotes for consuming more than remaining capacity
James-Mart Jun 9, 2026
5362018
pr feedback - improve documentation
James-Mart Jun 9, 2026
2d800db
pr feedback - improve var naming clarity
James-Mart Jun 9, 2026
f9923b7
pr feedback - avoid another potential overflow
James-Mart Jun 9, 2026
29c9868
pr feedback - fix another potential overflow
James-Mart Jun 9, 2026
cde1edd
pr feedback - use AccountNumber(0) instead of harcoding 'system' account
James-Mart Jun 9, 2026
32ee5c4
fix virtual-server tests
James-Mart Jun 9, 2026
09ceaac
move txid included table tracking to after action processing (and the…
James-Mart Jun 9, 2026
41a4b62
fix diagram
James-Mart Jun 12, 2026
47f3efa
fix prealloc accounting
James-Mart Jun 14, 2026
5ff08ce
eliminate separate tracking of VirtualBalance
James-Mart Jun 15, 2026
cc0abad
derive reserve from curve position
James-Mart Jun 15, 2026
8a0e961
remove unnecessary debug print in transact
James-Mart Jun 15, 2026
932dc18
improve skip-billing flow to detect unexpected db writes
James-Mart Jun 16, 2026
a477990
improve overflow protection - restore u128 intermediates in average c…
James-Mart Jun 16, 2026
254f792
remove unnecessary Cell usage
James-Mart Jun 16, 2026
a08b251
allow 0 fee_ppm for disk billing
James-Mart Jun 16, 2026
bd1f2f7
fix relay subaccount: prevent subaccount overlap with user subaccounts
James-Mart Jun 16, 2026
ede707d
improve tests
James-Mart Jun 17, 2026
8ceca56
fix the disk accounting tests (properly subtract the status row from …
James-Mart Jun 19, 2026
a09df40
Merge remote-tracking branch 'origin/main' into disk-billing
James-Mart Jun 19, 2026
5b527ed
merge fixes
James-Mart Jun 19, 2026
c95e649
fix enable-billing token credit flow
James-Mart Jun 22, 2026
1cddee1
remove obselete key size check
James-Mart Jun 22, 2026
89bd6af
don't strip extra trailing newlines from console trace
James-Mart Jun 23, 2026
e7c0f92
use the + format flag for signed disk amounts
James-Mart Jun 23, 2026
5d39775
drop unneeded guard in curve endpoint test
James-Mart Jun 23, 2026
82704e9
check disk accounting invariant at the end of each chain test
James-Mart Jun 23, 2026
1e463b4
replace ProposeExt trait with a generic Chain::propose method
James-Mart Jun 23, 2026
e2f2746
more sane free-into-prealloc-region handling
James-Mart Jun 24, 2026
faf85cd
formatting
James-Mart Jun 24, 2026
77446a1
tighten no-arbitrage test
James-Mart Jun 24, 2026
95d67cd
Merge remote-tracking branch 'origin/main' into disk-billing
James-Mart Jun 26, 2026
dca0b09
accrue mid-tx billing transfers until settlement at end-of-tx
James-Mart Jun 26, 2026
b50e1af
expose transact system write overrides to vserver
James-Mart Jun 29, 2026
b09e3ed
schedule fee receiver credit from vserver as a system write
James-Mart Jun 29, 2026
af2522c
move skipBilling logic to transact
James-Mart Jun 30, 2026
60f6714
remove redundant systemWriteEnabled bool
James-Mart Jul 2, 2026
7d04ee7
lock billing caches via Option::take instead of a bool
James-Mart Jul 2, 2026
a4e1f59
reject del_res_sub for a sub with pending billing
James-Mart Jul 2, 2026
c18cbd8
route balance reads through the billing cache
James-Mart Jul 2, 2026
05e1e13
require the billing sub-account to exist in bill_to_sub
James-Mart Jul 2, 2026
732d4cf
Merge pull request #1925 from gofractally/skip-billing-refactor
James-Mart Jul 2, 2026
6c2ba8b
Merge remote-tracking branch 'origin/disk-billing' into accrue-pendin…
James-Mart Jul 2, 2026
c7a7be1
Merge pull request #1920 from gofractally/accrue-pending-transfers-pe…
James-Mart Jul 2, 2026
c20f956
improve errors
James-Mart Jul 3, 2026
060f600
remove unused vserver actions
James-Mart Jul 3, 2026
48e9664
harden spot_price against u64 overflow
James-Mart Jul 6, 2026
0dfcc38
improve dx overflow error message
James-Mart Jul 6, 2026
342a372
make abort messages more consistent
James-Mart Jul 6, 2026
b345290
Curve::new better param naming
James-Mart Jul 6, 2026
13eccbc
rename pos_from_resources -> pos_from_remaining_capacity
James-Mart Jul 6, 2026
7bd885e
standardize on 'capacity' nomenclature for the curve y axis
James-Mart Jul 6, 2026
39ef9cf
improve the k overflow comment in Curve::new
James-Mart Jul 6, 2026
27f187c
move curve-derivation doc onto the Curve struct
James-Mart Jul 6, 2026
6a6723f
split finishTx hook from useCpuSys
James-Mart Jul 7, 2026
2e72aaf
Merge pull request #1928 from gofractally/vserver-cleanups
James-Mart Jul 8, 2026
9e39988
warm relay collateral into the billing cache at bill start
James-Mart Jul 3, 2026
37db4dc
socialize relay balance record creation as a system write
James-Mart Jul 3, 2026
93b33e9
add [DB_WRITE] explanation for end-of-tx reconciliation db write mana…
James-Mart Jul 7, 2026
75ee7bc
add prestartTx - prewarm billable resource subaccount balances
James-Mart Jul 8, 2026
4bfcca6
move prestartTx call location
James-Mart Jul 8, 2026
83f5855
warm relay collateral into the billing cache at bill start
James-Mart Jul 3, 2026
03992ee
clamp user refund and fee-receiver fee by available collateral
James-Mart Jul 7, 2026
08b3342
enabling billing no longer requires a payer
James-Mart Jul 7, 2026
50fa51b
fix free-into-prealloc test - we can no longer rely on the refund fro…
James-Mart Jul 7, 2026
3b945a9
add capacity limited curve collateralization documentation
James-Mart Jul 7, 2026
4248eda
make enable-billing one-way (no longer can disable billing)
James-Mart Jul 8, 2026
2f5ed9a
fix enable-billing usage in the UI
James-Mart Jul 8, 2026
b289509
fix merge
James-Mart Jul 8, 2026
0ede2bf
handle prealloc via consume rather than a capacity offset
James-Mart Jul 8, 2026
f6984ef
only consider the sender of the first action as a trx actor for now
James-Mart Jul 14, 2026
10efed9
update prestartTx interface to only accept one primary actor
James-Mart Jul 14, 2026
34ea726
Merge branch 'relay-billing' into new-enable-billing-strategy
James-Mart Jul 14, 2026
8c26579
Merge pull request #1930 from gofractally/relay-billing
James-Mart Jul 14, 2026
d60e585
update fee/refund behavior
James-Mart Jul 15, 2026
860c1f7
fix recollateralization
James-Mart Jul 16, 2026
a927a9c
Merge pull request #1931 from gofractally/new-enable-billing-strategy
James-Mart Jul 16, 2026
64e979d
Merge remote-tracking branch 'origin/main' into disk-billing
James-Mart Jul 20, 2026
d52c35f
prefer reading transact table via action interface over direct table …
James-Mart Jul 20, 2026
4c947a2
allow privileged services to read db from any service prefix
James-Mart Jul 20, 2026
d322011
make virtual-server privileged
James-Mart Jul 20, 2026
53940a4
prefer inline actions over direct table reads
James-Mart Jul 20, 2026
55a75b9
fix system token rendering
James-Mart Jul 20, 2026
e28ef80
allow pending page to render when an account has no other balances
James-Mart Jul 20, 2026
3c27e29
sync under-collateralization diagram in vserver docs
James-Mart Jul 20, 2026
67b519f
collapse disk-usage total into a single writeln
James-Mart Jul 20, 2026
96318a3
stop recursing into useDiskSys
James-Mart Jul 20, 2026
77f9772
unpack useDiskSys via action_structs
James-Mart Jul 20, 2026
61f21d0
open prealloc scans via native kvOpen
James-Mart Jul 20, 2026
7655e4a
fix vserver tests
James-Mart Jul 20, 2026
263274d
Merge remote-tracking branch 'origin/main' into disk-billing
James-Mart Jul 20, 2026
4aacda1
move open_direct onto KvHandle
James-Mart Jul 20, 2026
82e34a9
fix merge
James-Mart Jul 20, 2026
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
9 changes: 0 additions & 9 deletions libraries/psibase/native/src/NativeFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,6 @@ namespace psibase
abortMessage("Cannot read from this db handle " + bucket.to_string());
auto fullKey = bucket.key(key);
auto fullMatchSize = bucket.prefix.size() + matchKeySize;
if (keyHasServicePrefix(bucket.db))
check(fullMatchSize >= sizeof(AccountNumber::value),
"matchKeySize is smaller than 8 bytes");
return setResult(*this, bucket.trimResult(database.kvGreaterEqualRaw(
bucket.db, fullKey, fullMatchSize)));
});
Expand All @@ -895,9 +892,6 @@ namespace psibase
abortMessage("Cannot read from this db handle " + bucket.to_string());
auto fullKey = bucket.key(key);
auto fullMatchSize = bucket.prefix.size() + matchKeySize;
if (keyHasServicePrefix(bucket.db))
check(fullMatchSize >= sizeof(AccountNumber::value),
"matchKeySize is smaller than 8 bytes");
return setResult(*this, bucket.trimResult(database.kvLessThanRaw(bucket.db, fullKey,
fullMatchSize)));
});
Expand All @@ -913,9 +907,6 @@ namespace psibase
if (!bucket.isRead())
abortMessage("Cannot read from this db handle " + bucket.to_string());
auto fullKey = bucket.key(key);
if (keyHasServicePrefix(bucket.db))
check(fullKey.size() >= sizeof(AccountNumber::value),
"key is shorter than 8 bytes");
return setResult(*this, bucket.trimResult(database.kvMaxRaw(bucket.db, fullKey)));
});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/local/XAdmin/ui/src/hooks/use-network-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ interface NetworkVariables {
blockReplayFactor: number;
perBlockSysCpuNs: number;
objStorageBytes: number;
subjStorageBytes: number;
}

const zNetworkVariablesResponse = z.object({
getNetworkVariables: z.object({
blockReplayFactor: z.number(),
perBlockSysCpuNs: z.string(),
objStorageBytes: z.string(),
subjStorageBytes: z.string(),
}),
});

Expand All @@ -28,6 +30,7 @@ export const useNetworkVariables = () => {
blockReplayFactor
perBlockSysCpuNs
objStorageBytes
subjStorageBytes
}
}`;
const res = await graphql(query, { service: "vserver" });
Expand All @@ -43,6 +46,9 @@ export const useNetworkVariables = () => {
objStorageBytes: Number(
response.getNetworkVariables.objStorageBytes,
),
subjStorageBytes: Number(
response.getNetworkVariables.subjStorageBytes,
),
};
},
});
Expand Down
25 changes: 0 additions & 25 deletions packages/system/Accounts/plugin/accounts/wit/admin.wit

This file was deleted.

26 changes: 25 additions & 1 deletion packages/system/Accounts/plugin/accounts/wit/world.wit
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface api {

/// Sets the auth service used to authenticate the currently logged-in user
/// Currently calling this is restricted to the homepage app.
set-auth-service: func(service-name: string) -> result<_, error>;
set-auth-service: func(service-name: string) -> result<_, error>;

/// Gets the account name of the user logged into the active application.
/// May also return None if no user is logged in.
Expand All @@ -60,6 +60,30 @@ interface api {
gen-rand-account: func(prefix: option<string>) -> result<string, error>;
}

/// This interface is only callable by the accounts app itself.
interface admin {
use host:types/types.{error};

/// Gets the names of all apps to which the user has connected
get-connected-apps: func(user: string) -> list<string>;

/// Adds an account into the accounts table so that it can be used on this device.
import-account: func(account: string);

/// Removes an account from the accounts table and disconnects it from any connected
/// apps so that it can no longer be used on this device.
remove-account: func(account: string);

/// Gets a list of all accounts that are known by the accounts app on this device.
get-all-accounts: func() -> list<string>;

/// Get a list of auth accounts
get-auth-services: func() -> result<list<string>, error>;

/// preapprove an account for creation within this transaction
preapprove-account: func(account: string);
}

world imports {
import api;
import active-app;
Expand Down
15 changes: 9 additions & 6 deletions packages/system/Db/src/Db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ UniqueKvHandle Db::open(DbId db, psio::view<const std::vector<char>> prefixView,
}
else
{
auto expected = psio::convert_to_key(sender);
// Subaccounts of the same primary account, all have
// shared read access
expected.pop_back();
if (!std::ranges::starts_with(prefix, expected))
if (!isPrivileged(sender))
Comment thread
swatanabe marked this conversation as resolved.
Outdated
{
prefixError(sender, prefix, "read from");
auto expected = psio::convert_to_key(sender);
// Subaccounts of the same primary account, all have
// shared read access
expected.pop_back();
if (!std::ranges::starts_with(prefix, expected))
{
prefixError(sender, prefix, "read from");
}
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions packages/system/Producers/src/Producers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ using namespace SystemService;

namespace
{
bool isResMonitoring()
{
return to<Transact>().isResMonitoring();
}

void skipBilling()
{
if (isResMonitoring())
to<Transact>().skipBilling(1);
}

void endSkipBilling()
{
if (isResMonitoring())
to<Transact>().endSkipBilling();
}

auto compare_claim = [](const Claim& lhs, const Claim& rhs)
{ return std::tie(lhs.service, lhs.rawData) < std::tie(rhs.service, rhs.rawData); };

Expand Down Expand Up @@ -112,7 +129,9 @@ namespace SystemService
status->consensus.next = {{std::move(consensus), status->consensus.current.services,
status->consensus.current.wasmConfig},
status->current.blockNum};
skipBilling();
table.put(*status);
endSkipBilling();
}

void Producers::setProducers(std::vector<psibase::Producer> prods)
Expand All @@ -139,7 +158,9 @@ namespace SystemService
status->consensus.current.data),
status->consensus.current.services, status->consensus.current.wasmConfig},
status->current.blockNum};
skipBilling();
table.put(*status);
endSkipBilling();
}

void Producers::regCandidate(const std::string& endpoint, psibase::Claim claim)
Expand Down
2 changes: 1 addition & 1 deletion packages/system/StagedTx/service/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pub mod impls {
}

impl LastUsed {
fn get_next_id() -> u32 {
pub fn get_next_id() -> u32 {
let table = LastUsedTable::new();
let mut last_used = table.get_index_pk().get(&()).unwrap_or_default();
last_used.id += 1;
Expand Down
6 changes: 5 additions & 1 deletion packages/system/StagedTx/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ pub mod service {
#[action]
fn init() {
let table = InitTable::new();
table.put(&InitRow {}).unwrap();

if table.get_index_pk().get(&()).is_none() {
table.put(&InitRow {}).unwrap();
let _ = LastUsed::get_next_id(); // Create this singleton on init instead of first use.
}

let updated = MethodNumber::from("updated");
Events::call().addIndex(EventDb::HistoryEvent, SERVICE, updated, 0); // Index events related to specific txid
Expand Down
27 changes: 27 additions & 0 deletions packages/system/Transact/include/services/system/Transact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,28 @@ namespace SystemService
/// Enable/disable resource monitoring
void resMonitoring(bool enable);

/// Returns true if resource monitoring is enabled
bool isResMonitoring();

/// Suppress billing/tracking for the next `numWrites` disk writes.
///
/// Intended for wrapping privileged-service writes that are modified
/// by both wasm and native code (e.g. status row). The caller is expected
/// to perform exactly `numWrites` writes/frees and then call `endSkipBilling`.
///
/// Only callable by privileged services.
void skipBilling(uint32_t numWrites);

/// Asserts that all writes promised by `skipBilling` were consumed.
///
/// Only callable by privileged services.
void endSkipBilling();

/// Attribute subsequent disk writes to the system account until `numBytes`
/// bytes have been written or the transaction ends. `numBytes = 0` clears
/// the override. Callable only by the VirtualServer service.
void systemWrite(uint64_t numBytes);

/// Get the currently executing transaction
psio::view<const psibase::Transaction> getTransaction() const;

Expand Down Expand Up @@ -485,6 +507,7 @@ namespace SystemService
};
};
PSIO_REFLECT(Transact,
allowHashedMethods(),
method(startBoot, bootTransactions),
method(finishBoot),
method(startBlock),
Expand All @@ -497,6 +520,10 @@ namespace SystemService
method(runAs, action, allowedActions),
method(checkFirstAuth, id, transaction),
method(resMonitoring, enable),
method(isResMonitoring),
method(skipBilling, numWrites),
method(endSkipBilling),
method(systemWrite, numBytes),
method(getTransaction),
method(isTransaction),
method(currentBlock),
Expand Down
Loading
Loading