Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIP forkproperties #710

Merged
merged 28 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
99de446
add CfgFork
beidouz Nov 16, 2018
7ed73f0
add fork cases to getPrecompiledContract
beidouz Nov 16, 2018
fc6fc9e
fix failing tests in modPrecompiled after adding fork-properties
beidouz Nov 16, 2018
0dc8939
fix failing tests in modPrecompiled after adding fork-properties
beidouz Nov 16, 2018
17dd8b1
Merge branch 'AIP_forkproperties' of https://github.com/aionnetwork/a…
aionjay Nov 20, 2018
74aded9
revise cfgFork class
aionjay Nov 20, 2018
d4e0ad1
revise cgfFork implement
aionjay Nov 20, 2018
1747549
revise fork implementation
aionjay Nov 20, 2018
41da690
revise testcase
aionjay Nov 20, 2018
fe2780b
revise testcase
aionjay Nov 20, 2018
36a39c7
update forkNumber
aionjay Nov 20, 2018
756b0c0
print fork info
aionjay Nov 20, 2018
caae18e
Merge branch 'AIP_redo' into AIP_forkproperties
aionjay Nov 20, 2018
e0e7adf
fix pack
aionjay Nov 20, 2018
1fec69e
fix fork default settings logic in Cli and CfgAion
aionjay Nov 21, 2018
9f7348d
refactor fork properties settings by review comments
aionjay Nov 21, 2018
02f917a
1.) revise fork logic in cfgAion and test case 2.) refactoring the Co…
aionjay Nov 21, 2018
8d49e96
fix fork setting overwrite issue
aionjay Nov 21, 2018
a752293
set default fork# to 0 in the custom network
aionjay Nov 21, 2018
a89e939
introduced migration of old kernel configuration
AlexandraRoatis Nov 21, 2018
21a51b1
setting the keystore path from the config file
AlexandraRoatis Nov 21, 2018
454f0db
Update the gitignore to exlucde network data folders
iamyulong Nov 22, 2018
3dbe09c
Move the modBoot/resource to config
iamyulong Nov 22, 2018
19e5f8a
set the absolute path for db and log to be written back to file
AlexandraRoatis Nov 22, 2018
7497336
updated unit tests for migration of old kernel config
AlexandraRoatis Nov 22, 2018
2a19f3e
minor spacking adjustment
AlexandraRoatis Nov 22, 2018
4b8f728
Merge pull request #718 from aionnetwork/AIP_config_migration
AionJayT Nov 22, 2018
1774aa7
Merge pull request #719 from aionnetwork/yulong
AionJayT Nov 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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