Skip to content

Commit

Permalink
Add Protonet warning before running stress test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 25, 2024
1 parent 0123dab commit df7145e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 8 additions & 0 deletions convex-core/src/main/java/convex/core/Networks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package convex.core;

import convex.core.data.Hash;

public class Networks {

public static final Hash PRONONET_GENESIS=Hash.parse("0xb0e44f2a645abfa539f5b96b7a0eabb0f902866feaff0f7c12d1213e02333f13");
}
8 changes: 8 additions & 0 deletions convex-core/src/main/java/convex/core/cvm/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -677,4 +677,12 @@ public boolean isReadyToPublish() {
if (ps.getBalance()<CPoSConstants.MINIMUM_EFFECTIVE_STAKE) return false;
return true;
}

/**
* Gets the genesis state hash for this peer
* @return
*/
public Hash getGenesisHash() {
return getGenesisState().getHash();
}
}
11 changes: 10 additions & 1 deletion convex-gui/src/main/java/convex/gui/server/StressPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JSplitPane;
Expand All @@ -30,6 +31,7 @@
import org.slf4j.LoggerFactory;

import convex.api.Convex;
import convex.core.Networks;
import convex.core.Result;
import convex.core.crypto.AKeyPair;
import convex.core.cvm.transactions.ATransaction;
Expand All @@ -38,6 +40,7 @@
import convex.core.cvm.transactions.Transfer;
import convex.core.data.ACell;
import convex.core.data.AVector;
import convex.core.data.Hash;
import convex.core.cvm.Address;
import convex.core.data.Strings;
import convex.core.lang.Reader;
Expand Down Expand Up @@ -83,6 +86,12 @@ public StressPanel(Convex peerView) {
btnRun = new JButton("Run Test");
actionPanel.add(btnRun);
btnRun.addActionListener(e -> {
Hash network=peerView.getLocalServer().getPeer().getGenesisHash();
if (network.equals(Networks.PRONONET_GENESIS)) {
int confirm=JOptionPane.showConfirmDialog(this, "This is the live network. Running a stress test is likley to be expensive! Are you really sure you want to do this?", "Run test on Live network?", JOptionPane.WARNING_MESSAGE);
if (confirm!=JOptionPane.OK_OPTION) return;
}

btnRun.setEnabled(false);
Address address=peerConvex.getAddress();
AKeyPair kp=peerConvex.getKeyPair();
Expand Down Expand Up @@ -238,7 +247,7 @@ protected String doStressRun() throws Exception {

// Generate client accounts
StringBuilder cmdsb=new StringBuilder();
cmdsb.append("(let [f (fn [k] (let [a (create-account k)] (transfer a 1000000000) a))] ");
cmdsb.append("(let [f (fn [k] (let [a (deploy `(do (set-key ~k) (set-controller #13))] (transfer a 1000000000) a))] ");
cmdsb.append(" (mapv f [");
for (int i=0; i<clientCount; i++) {
AKeyPair kp=AKeyPair.generate();
Expand Down

0 comments on commit df7145e

Please sign in to comment.