Skip to content

Commit

Permalink
More CLI genesis preparation for Protonet
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Aug 5, 2024
1 parent b0783cc commit c6448cf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class LocalPeerBenchmark {
public static ArrayList<AccountKey> PEER_KEYS=(ArrayList<AccountKey>) Arrays.asList(KEYPAIRS).stream().map(kp->kp.getAccountKey()).collect(Collectors.toList());


private static State GENESIS=Init.createBaseState(PEER_KEYS);
private static State GENESIS=Init.createState(PEER_KEYS);
private static Server SERVER;
private static Address HERO;
private static ConvexLocal PEER_CLIENT;
Expand Down
19 changes: 19 additions & 0 deletions convex-cli/src/main/java/convex/cli/peer/PeerGenesis.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import convex.cli.ExitCodes;
import convex.core.State;
import convex.core.crypto.AKeyPair;
import convex.core.data.AccountKey;
import convex.core.data.Keyword;
import convex.core.data.Keywords;
import convex.core.init.Init;
Expand All @@ -17,6 +18,7 @@
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
import picocli.CommandLine.ParentCommand;
import picocli.CommandLine.ScopeType;
import picocli.CommandLine.Spec;

/**
Expand All @@ -33,19 +35,36 @@ public class PeerGenesis extends APeerCommand {

@Spec
CommandSpec spec;

@Option(names = { "--governance-key" },
defaultValue = "${env:CONVEX_GOVERNANCE_KEY}",
scope = ScopeType.INHERIT,
description = "Governance Key. Should be a valid account key. Genesis key will be used if not specified (unless security is strict).")
protected String governanceKey;

@Override
public void run() {
storeMixin.loadKeyStore();

AKeyPair peerKey = ensurePeerKey();
AKeyPair genesisKey=ensureControllerKey();

AccountKey govKey=AccountKey.parse(governanceKey);
if (govKey==null) {
paranoia("--gioverannce-key must be specified in strict security mode");
if (governanceKey==null) {
govKey=genesisKey.getAccountKey();
} else {
throw new CLIError(ExitCodes.DATAERR,"Unable to parse --governance-key argument. Should be a 32-byte hex key.");
}
}

EtchStore store=getEtchStore();

State genesisState=Init.createState(List.of(peerKey.getAccountKey()));
inform("Created genesis state with hash: "+genesisState.getHash());

inform(2,"Testing genesis state peer initialisation");
HashMap<Keyword,Object> config=new HashMap<>();
config.put(Keywords.STORE, store);
config.put(Keywords.STATE, genesisState);
Expand Down
22 changes: 12 additions & 10 deletions convex-core/src/main/java/convex/core/init/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private static State addStaticLibraries(State s) {
}

public static State createState(List<AccountKey> genesisKeys) {
try {

State s=createBaseState(genesisKeys);
s = addStandardLibraries(s);
s = addTestingCurrencies(s);
Expand All @@ -265,18 +265,20 @@ public static State createState(List<AccountKey> genesisKeys) {
throw new Error("Bad total funds in init state amount: " + finalTotal);

return s;
} catch (Exception e) {
throw new RuntimeException("Unable to initialise core",e);
}


}

private static State addTestingCurrencies(State s) throws IOException {
@SuppressWarnings("unchecked")
AVector<AVector<ACell>> table = (AVector<AVector<ACell>>) Reader
.readResourceAsData("torus/genesis-currencies.cvx");
for (AVector<ACell> row : table) {
s = doCurrencyDeploy(s, row);
private static State addTestingCurrencies(State s) {
try {
@SuppressWarnings("unchecked")
AVector<AVector<ACell>> table = (AVector<AVector<ACell>>) Reader
.readResourceAsData("torus/genesis-currencies.cvx");
for (AVector<ACell> row : table) {
s = doCurrencyDeploy(s, row);
}
} catch (IOException e) {
throw new Error("Failre reading source data for currencies",e);
}
return s;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void explore (ACell a) {
public static void main(String[] args) {
Toolkit.init();
AKeyPair kp=AKeyPair.createSeeded(564646);
ACell state=Init.createBaseState(List.of(kp.getAccountKey()));
ACell state=Init.createState(List.of(kp.getAccountKey()));
new StateExplorer(state).run();
}
}

0 comments on commit c6448cf

Please sign in to comment.