Skip to content

Commit

Permalink
Merge pull request #710 from aionnetwork/AIP_forkproperties
Browse files Browse the repository at this point in the history
AIP forkproperties
  • Loading branch information
AionJayT authored Nov 23, 2018
2 parents 6178ceb + 1774aa7 commit 0394a42
Show file tree
Hide file tree
Showing 27 changed files with 731 additions and 103 deletions.
14 changes: 10 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# aion
/config/
/database/
/keystore/
/pack/
/reports/
/cache/
/ssl_keystore/
/log/
/rt/
/web3/
/zmq_keystore/
Expand Down Expand Up @@ -61,3 +57,13 @@ tmp/

# gradle
.gradle/**

# network data
/mainnet/
/conquest/
/mastery/
/custom/

# openjdk artifacts
openjdk*.tar.gz
openjfx*.zip
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions config/custom/fork.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fork0.3.2=0
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions config/mainnet/fork.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fork0.3.2=1902000
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions config/mastery/fork.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fork0.3.2=1132000
File renamed without changes.
63 changes: 41 additions & 22 deletions modAionImpl/src/org/aion/zero/impl/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.aion.base.util.Hex;
import org.aion.crypto.ECKey;
import org.aion.crypto.ECKeyFac;
Expand Down Expand Up @@ -170,6 +174,15 @@ public ReturnType call(final String[] args, Cfg cfg) {
cfg.setReadConfigFiles(configFile, cfg.getExecGenesisFile());
}

// reading from correct fork file
File forkFile = cfg.getExecForkFile();
if (forkFile == null || !forkFile.exists()) {
forkFile = cfg.getInitialForkFile();
}

if (forkFile != null && forkFile.exists()) {
cfg.setForkProperties(cfg.getNetwork(), forkFile);
}
// true means the UUID must be set
boolean overwrite = cfg.fromXML(configFile);

Expand Down Expand Up @@ -226,7 +239,7 @@ public ReturnType call(final String[] args, Cfg cfg) {
}

// make directories for kernel execution
makeDirs(configFile, cfg);
makeDirs(configFile, forkFile, cfg);

if (overwrite) {
// only updating the file in case the user id was not set
Expand Down Expand Up @@ -535,10 +548,11 @@ private void printInvalidNetwork() {
* Creates the directories for persistence of the kernel data. Copies the config and genesis
* files from the initial path for the execution directory.
*
* @param forkFile
* @param cfg the configuration for the runtime kernel environment
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
private void makeDirs(File startConfigFile, Cfg cfg) {
private void makeDirs(File startConfigFile, File forkFile, Cfg cfg) {
File file = cfg.getExecDir();
if (!file.exists()) {
file.mkdirs();
Expand All @@ -564,6 +578,13 @@ private void makeDirs(File startConfigFile, Cfg cfg) {
}
}

// copy fork file
initial = forkFile;
target = cfg.getExecForkFile();
if (!initial.equals(target)) {
copyRecursively(initial, target);
}

// create target log directory
file = cfg.getLogDir();
if (!file.exists()) {
Expand Down Expand Up @@ -759,9 +780,10 @@ private void checkArguments(Arguments options) {
if (skippedTasks.isEmpty()) {
return;
}
String errorMessage = String.format(
"Given arguments require incompatible tasks. Skipped arguments: %s.",
String.join(", ", skippedTasks));
String errorMessage =
String.format(
"Given arguments require incompatible tasks. Skipped arguments: %s.",
String.join(", ", skippedTasks));
System.out.println(errorMessage);
}

Expand Down Expand Up @@ -838,56 +860,53 @@ Set<String> getSkippedTasks(Arguments options, TaskPriority breakingTaskPriority
skippedTasks.add("--config");
}
}
if (breakingTaskPriority.compareTo(TaskPriority.INFO) < 0
&& options.isInfo()) {
if (breakingTaskPriority.compareTo(TaskPriority.INFO) < 0 && options.isInfo()) {
skippedTasks.add("--info");
}
if (breakingTaskPriority.compareTo(TaskPriority.CREATE_ACCOUNT) < 0
&& options.isCreateAccount()) {
&& options.isCreateAccount()) {
skippedTasks.add("--account create");
}
if (breakingTaskPriority.compareTo(TaskPriority.LIST_ACCOUNTS) < 0
&& options.isListAccounts()) {
&& options.isListAccounts()) {
skippedTasks.add("--account list");
}
if (breakingTaskPriority.compareTo(TaskPriority.EXPORT_ACCOUNT) < 0
&& options.getExportAccount() != null) {
&& options.getExportAccount() != null) {
skippedTasks.add("--account export");
}
if (breakingTaskPriority.compareTo(TaskPriority.IMPORT_ACCOUNT) < 0
&& options.getImportAccount() != null) {
&& options.getImportAccount() != null) {
skippedTasks.add("--account import");
}
if (breakingTaskPriority.compareTo(TaskPriority.SSL) < 0
&& options.getSsl() != null) {
if (breakingTaskPriority.compareTo(TaskPriority.SSL) < 0 && options.getSsl() != null) {
skippedTasks.add("-s create");
}
if (breakingTaskPriority.compareTo(TaskPriority.PRUNE_BLOCKS) < 0
&& options.isRebuildBlockInfo()) {
&& options.isRebuildBlockInfo()) {
skippedTasks.add("--prune-blocks");
}
if (breakingTaskPriority.compareTo(TaskPriority.REVERT) < 0
&& options.getRevertToBlock() != null) {
&& options.getRevertToBlock() != null) {
skippedTasks.add("--revert");
}
if (breakingTaskPriority.compareTo(TaskPriority.PRUNE_STATE) < 0
&& options.getPruneStateOption() != null) {
&& options.getPruneStateOption() != null) {
skippedTasks.add("--state");
}
if (breakingTaskPriority.compareTo(TaskPriority.DUMP_STATE_SIZE) < 0
&& options.getDumpStateSizeCount() != null) {
&& options.getDumpStateSizeCount() != null) {
skippedTasks.add("--dump-state-size");
}
if (breakingTaskPriority.compareTo(TaskPriority.DUMP_STATE) < 0
&& options.getDumpStateCount() != null) {
&& options.getDumpStateCount() != null) {
skippedTasks.add("--dump-state");
}
if (breakingTaskPriority.compareTo(TaskPriority.DUMP_BLOCKS) < 0
&& options.getDumpBlocksCount() != null) {
&& options.getDumpBlocksCount() != null) {
skippedTasks.add("--dump-blocks");
}
if (breakingTaskPriority.compareTo(TaskPriority.DB_COMPACT) < 0
&& options.isDbCompact()) {
if (breakingTaskPriority.compareTo(TaskPriority.DB_COMPACT) < 0 && options.isDbCompact()) {
skippedTasks.add("--db-compact");
}
return skippedTasks;
Expand Down
55 changes: 55 additions & 0 deletions modAionImpl/src/org/aion/zero/impl/config/CfgAion.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
Expand All @@ -39,6 +40,7 @@
import org.aion.mcf.config.Cfg;
import org.aion.mcf.config.CfgApi;
import org.aion.mcf.config.CfgDb;
import org.aion.mcf.config.CfgFork;
import org.aion.mcf.config.CfgGui;
import org.aion.mcf.config.CfgLog;
import org.aion.mcf.config.CfgNet;
Expand All @@ -63,6 +65,7 @@ public final class CfgAion extends Cfg {
public CfgAion() {
this.mode = "aion";
this.id = UUID.randomUUID().toString();
this.keystorePath = null;
this.net = new CfgNet();
this.consensus = new CfgConsensusPow();
this.sync = new CfgSync();
Expand All @@ -72,6 +75,7 @@ public CfgAion() {
this.tx = new CfgTx();
this.reports = new CfgReports();
this.gui = new CfgGui();
this.fork = new CfgFork();
initializeConfiguration();
}

Expand Down Expand Up @@ -136,6 +140,43 @@ private void closeFileInputStream(final FileInputStream fis) {
}
}

// /** @implNote the default fork settings is looking for the fork config of the mainnet. */
// public void setForkProperties() {
// setForkProperties("mainnet", null);
// }

public void setForkProperties(String networkName, File forkFile) {
Properties properties = new Properties();

// old kernel doesn't support the fork feature.
if (networkName == null || networkName.equals("config")) {
return;
}

try (FileInputStream fis =
(forkFile == null)
? new FileInputStream(
System.getProperty("user.dir")
+ "/"
+ networkName
+ "/config"
+ CfgFork.FORK_PROPERTIES_PATH)
: new FileInputStream(forkFile)) {

properties.load(fis);
this.getFork().setProperties(properties);
} catch (Exception e) {
System.out.println(
"<error on-parsing-fork-properties msg="
+ e.getLocalizedMessage()
+ ">, no protocol been updated.");
}
}

// public void setForkProperties(String networkName) {
// setForkProperties(networkName, null);
// }

public void dbFromXML() {
File cfgFile = getInitialConfigFile();
XMLInputFactory input = XMLInputFactory.newInstance();
Expand Down Expand Up @@ -267,6 +308,13 @@ public boolean fromXML(File cfgFile) {
this.setLogDir(log);
}

if (keystorePath != null) {
File ks = new File(keystorePath);
if (ks.isAbsolute()) {
this.setKeystoreDir(ks);
}
}

return shouldWriteBackToFile;
}

Expand Down Expand Up @@ -347,6 +395,13 @@ public void toXML(final String[] args, File file) {
sw.writeCharacters(this.getId());
sw.writeEndElement();

if (keystorePath != null) {
sw.writeCharacters("\r\n\t");
sw.writeStartElement("keystore");
sw.writeCharacters(keystorePath);
sw.writeEndElement();
}

sw.writeCharacters(this.getApi().toXML());
sw.writeCharacters(this.getNet().toXML());
sw.writeCharacters(this.getSync().toXML());
Expand Down
Loading

0 comments on commit 0394a42

Please sign in to comment.