Skip to content

Commit c6448cf

Browse files
committed
More CLI genesis preparation for Protonet
1 parent b0783cc commit c6448cf

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

convex-benchmarks/src/main/java/convex/benchmarks/LocalPeerBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class LocalPeerBenchmark {
4848
public static ArrayList<AccountKey> PEER_KEYS=(ArrayList<AccountKey>) Arrays.asList(KEYPAIRS).stream().map(kp->kp.getAccountKey()).collect(Collectors.toList());
4949

5050

51-
private static State GENESIS=Init.createBaseState(PEER_KEYS);
51+
private static State GENESIS=Init.createState(PEER_KEYS);
5252
private static Server SERVER;
5353
private static Address HERO;
5454
private static ConvexLocal PEER_CLIENT;

convex-cli/src/main/java/convex/cli/peer/PeerGenesis.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import convex.cli.ExitCodes;
88
import convex.core.State;
99
import convex.core.crypto.AKeyPair;
10+
import convex.core.data.AccountKey;
1011
import convex.core.data.Keyword;
1112
import convex.core.data.Keywords;
1213
import convex.core.init.Init;
@@ -17,6 +18,7 @@
1718
import picocli.CommandLine.Model.CommandSpec;
1819
import picocli.CommandLine.Option;
1920
import picocli.CommandLine.ParentCommand;
21+
import picocli.CommandLine.ScopeType;
2022
import picocli.CommandLine.Spec;
2123

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

3436
@Spec
3537
CommandSpec spec;
38+
39+
@Option(names = { "--governance-key" },
40+
defaultValue = "${env:CONVEX_GOVERNANCE_KEY}",
41+
scope = ScopeType.INHERIT,
42+
description = "Governance Key. Should be a valid account key. Genesis key will be used if not specified (unless security is strict).")
43+
protected String governanceKey;
3644

3745
@Override
3846
public void run() {
3947
storeMixin.loadKeyStore();
4048

4149
AKeyPair peerKey = ensurePeerKey();
4250
AKeyPair genesisKey=ensureControllerKey();
51+
52+
AccountKey govKey=AccountKey.parse(governanceKey);
53+
if (govKey==null) {
54+
paranoia("--gioverannce-key must be specified in strict security mode");
55+
if (governanceKey==null) {
56+
govKey=genesisKey.getAccountKey();
57+
} else {
58+
throw new CLIError(ExitCodes.DATAERR,"Unable to parse --governance-key argument. Should be a 32-byte hex key.");
59+
}
60+
}
4361

4462
EtchStore store=getEtchStore();
4563

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

67+
inform(2,"Testing genesis state peer initialisation");
4968
HashMap<Keyword,Object> config=new HashMap<>();
5069
config.put(Keywords.STORE, store);
5170
config.put(Keywords.STATE, genesisState);

convex-core/src/main/java/convex/core/init/Init.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private static State addStaticLibraries(State s) {
252252
}
253253

254254
public static State createState(List<AccountKey> genesisKeys) {
255-
try {
255+
256256
State s=createBaseState(genesisKeys);
257257
s = addStandardLibraries(s);
258258
s = addTestingCurrencies(s);
@@ -265,18 +265,20 @@ public static State createState(List<AccountKey> genesisKeys) {
265265
throw new Error("Bad total funds in init state amount: " + finalTotal);
266266

267267
return s;
268-
} catch (Exception e) {
269-
throw new RuntimeException("Unable to initialise core",e);
270-
}
268+
271269

272270
}
273271

274-
private static State addTestingCurrencies(State s) throws IOException {
275-
@SuppressWarnings("unchecked")
276-
AVector<AVector<ACell>> table = (AVector<AVector<ACell>>) Reader
277-
.readResourceAsData("torus/genesis-currencies.cvx");
278-
for (AVector<ACell> row : table) {
279-
s = doCurrencyDeploy(s, row);
272+
private static State addTestingCurrencies(State s) {
273+
try {
274+
@SuppressWarnings("unchecked")
275+
AVector<AVector<ACell>> table = (AVector<AVector<ACell>>) Reader
276+
.readResourceAsData("torus/genesis-currencies.cvx");
277+
for (AVector<ACell> row : table) {
278+
s = doCurrencyDeploy(s, row);
279+
}
280+
} catch (IOException e) {
281+
throw new Error("Failre reading source data for currencies",e);
280282
}
281283
return s;
282284
}

convex-gui/src/main/java/convex/gui/state/StateExplorer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static void explore (ACell a) {
5858
public static void main(String[] args) {
5959
Toolkit.init();
6060
AKeyPair kp=AKeyPair.createSeeded(564646);
61-
ACell state=Init.createBaseState(List.of(kp.getAccountKey()));
61+
ACell state=Init.createState(List.of(kp.getAccountKey()));
6262
new StateExplorer(state).run();
6363
}
6464
}

0 commit comments

Comments
 (0)