Skip to content

Commit

Permalink
Reserving accounts 0-127 for users / actors
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 24, 2024
1 parent 4ed00de commit eccdc88
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public class CPoSConstants {
* Minimum milliseconds to retain a proposal before switching
*/
public static final long KEEP_PROPOSAL_TIME = 100;

/**
* Memory allowance for genesis user / peer accounts
*/
public static final long INITIAL_ACCOUNT_ALLOWANCE = 1000000;
public static final long INITIAL_ACCOUNT_ALLOWANCE = 10000;

/**
* Maximum allowed encoded peer message length in bytes (50mb)
Expand Down
32 changes: 32 additions & 0 deletions convex-core/src/main/java/convex/core/init/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public class Init {

public static final AccountKey DEFAULT_GOV_KEY = AccountKey.fromHex("12EF73ee900eD1FE78A188f59bF8CedE467bAA66f5b60368aFAaA3B9521aB94d");

private static final long RESERVED_USER_LIMIT = 64;
private static final long RESERVED_ACTOR_LIMIT = 128;


/**
* Creates the base genesis state (before deployment of standard libraries and actors). This is the minimum state required for Convex operation.
Expand Down Expand Up @@ -216,6 +219,11 @@ public static State createBaseState(AccountKey governanceKey, AccountKey genesis

// Initial user account, follows genesis peer controller(s)
accts=addAccount(accts,Address.create(accts.count()),FIRST_USER_KEY,0);

// Reserve user accounts in base state
while(accts.count()<RESERVED_USER_LIMIT) {
accts=addAccount(accts,Address.create(accts.count()),genesisKey,0);
}

// Finally add initial peers

Expand All @@ -237,6 +245,8 @@ public static State createBaseState(AccountKey governanceKey, AccountKey genesis
assert(peerFunds == 0L);
}



// Add the new accounts to the State
s = s.withAccounts(accts);
// Add peers to the State
Expand All @@ -261,10 +271,19 @@ public static AVector<AccountStatus> addAccount(AVector<AccountStatus> accts, Ad
long balance) {
if (accts.count() != a.longValue()) throw new Error("Incorrect account address: " + a);
AccountStatus as = AccountStatus.create(0L, balance, key);
as=as.withController(ADMIN_ADDRESS);
as = as.withMemory(CPoSConstants.INITIAL_ACCOUNT_ALLOWANCE);
accts = accts.conj(as);
return accts;
}

public static AVector<AccountStatus> addReservedActorAccount(AVector<AccountStatus> accts, Address a) {
if (accts.count() != a.longValue()) throw new Error("Incorrect account address: " + a);
AccountStatus as = AccountStatus.create(0L, 0L, null);
as=as.withController(ADMIN_ADDRESS);
accts = accts.conj(as);
return accts;
}


/**
Expand Down Expand Up @@ -308,6 +327,9 @@ public static State createState(AccountKey governanceKey, AccountKey genesisKey,
State s=createBaseState(governanceKey, genesisKey, peerKeys);

s = addStandardLibraries(s);

s=addReservedAccounts(s);

s = addTestingCurrencies(s);
s = addCNSExtraTree(s);

Expand All @@ -319,6 +341,16 @@ public static State createState(AccountKey governanceKey, AccountKey genesisKey,
return s;
}

private static State addReservedAccounts(State s) {
AVector<AccountStatus> accts = s.getAccounts();
while(accts.count()<RESERVED_ACTOR_LIMIT) {
accts=addReservedActorAccount(accts,Address.create(accts.count()));
}

s = s.withAccounts(accts);
return s;
}

private static State addTestingCurrencies(State s) {
try {
@SuppressWarnings("unchecked")
Expand Down

0 comments on commit eccdc88

Please sign in to comment.