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 14 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
38 changes: 38 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 Down Expand Up @@ -72,6 +74,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 +139,41 @@ private void closeFileInputStream(final FileInputStream fis) {
}
}

public void setForkProperties() {
AionJayT marked this conversation as resolved.
Show resolved Hide resolved
setForkProperties("mainnet");
}

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

// old kernel doesn't support the fork feature.
if (networkName.equals("config")) {
AionJayT marked this conversation as resolved.
Show resolved Hide resolved
return;
}

FileInputStream fis = null;
try {
AionJayT marked this conversation as resolved.
Show resolved Hide resolved
fis =
new FileInputStream(
System.getProperty("user.dir")
+ "/"
+ networkName
+ "/config"
+ CfgFork.FORK_PROPERTIES_PATH);
properties.load(fis);

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

} finally {
closeFileInputStream(fis);
}
}

public void dbFromXML() {
File cfgFile = getInitialConfigFile();
XMLInputFactory input = XMLInputFactory.newInstance();
Expand Down
16 changes: 13 additions & 3 deletions modAionImpl/test/org/aion/zero/impl/cli/CliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import static org.aion.zero.impl.cli.Cli.ReturnType.EXIT;
import static org.aion.zero.impl.cli.Cli.ReturnType.RUN;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doReturn;
Expand Down Expand Up @@ -85,6 +84,7 @@ public class CliTest {

private static final String configFileName = "config.xml";
private static final String genesisFileName = "genesis.json";
private static final String forkFileName = "fork.properties";

private static final String dataDirectory = "datadir";
private static final String alternativeDirectory = "random";
Expand All @@ -102,6 +102,11 @@ public class CliTest {
private static final File mainnetGenesis = new File(MAIN_CONFIG_PATH, genesisFileName);
private static final File testnetGenesis = new File(TEST_CONFIG_PATH, genesisFileName);

private static final File fork = new File(TEST_RESOURCE_DIR, forkFileName);
private static final File oldFork = new File(CONFIG_PATH, forkFileName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a test for behavior with old kernels config using the variable above

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disable to support the old config compatibility for the fork. And will put it in the release note.

private static final File mainnetFork = new File(MAIN_CONFIG_PATH, forkFileName);
private static final File testnetFork = new File(TEST_CONFIG_PATH, forkFileName);

/** @implNote set this to true to enable printing */
private static final boolean verbose = false;

Expand All @@ -117,6 +122,7 @@ public void setup() {
}
Cli.copyRecursively(config, mainnetConfig);
Cli.copyRecursively(genesis, mainnetGenesis);
Cli.copyRecursively(fork, mainnetFork);
}

if (BASE_PATH.contains(module) && !testnetConfig.exists()) {
Expand All @@ -126,6 +132,7 @@ public void setup() {
}
Cli.copyRecursively(config, mainnetConfig);
Cli.copyRecursively(genesis, testnetGenesis);
Cli.copyRecursively(fork, testnetFork);
}

cfg.resetInternal();
Expand Down Expand Up @@ -1158,7 +1165,10 @@ private Object parametersForArgumentCheck() {
skippedTasks.add("--db-compact");
parameters.add(new Object[] {input, TaskPriority.REVERT, skippedTasks});

input = new String[] {"--state", "FULL", "--db-compact", "--dump-state-size", "--dump-state"};
input =
new String[] {
"--state", "FULL", "--db-compact", "--dump-state-size", "--dump-state"
};
skippedTasks = new HashSet<String>();
skippedTasks.add("--db-compact");
skippedTasks.add("--dump-state-size");
Expand Down Expand Up @@ -1186,7 +1196,7 @@ private Object parametersForArgumentCheck() {
@Test
@Parameters(method = "parametersForArgumentCheck")
public void testCheckArguments(
String[] input, TaskPriority expectedPriority, Set<String> expectedTasks) {
String[] input, TaskPriority expectedPriority, Set<String> expectedTasks) {
Arguments options = new Arguments();
CommandLine parser = new CommandLine(options);
parser.parse(input);
Expand Down
1 change: 1 addition & 0 deletions modBoot/resource/custom/fork.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fork0.3.2=1132000
1 change: 1 addition & 0 deletions modBoot/resource/mainnet/fork.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fork0.3.2=1902000
1 change: 1 addition & 0 deletions modBoot/resource/mastery/fork.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fork0.3.2=1132000
13 changes: 13 additions & 0 deletions modBoot/src/org/aion/Aion.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.TimeZone;
Expand Down Expand Up @@ -98,11 +99,23 @@ public static void main(String args[]) {

CfgAion cfg = CfgAion.inst();


ReturnType ret = new Cli().call(args, cfg);
if (ret != ReturnType.RUN) {
exit(ret.getValue());
}

Properties p = cfg.getFork().getProperties();
p.forEach(
(k, v) -> {
System.out.println(
"<Protocol name: "
+ k.toString()
+ " block#: "
+ v.toString()
+ " updated!");
});

// Check ZMQ server secure connect settings, generate keypair when the settings enabled and
// can't find the keypair.
if (cfg.getApi().getZmq().getActive()
Expand Down
1 change: 0 additions & 1 deletion modGui/test/org/aion/gui/model/ConfigManipulatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class ConfigManipulatorTest {
@Before
public void before() {
jmxCaller = mock(ConfigManipulator.JmxCaller.class);
;
fileLoaderSaver = mock(ConfigManipulator.FileLoaderSaver.class);
cfg = new CfgAion();
kernelLauncher = mock(KernelLauncher.class);
Expand Down
20 changes: 20 additions & 0 deletions modMcf/src/org/aion/mcf/config/Cfg.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.io.IOException;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.aion.mcf.types.AbstractBlock;
Expand Down Expand Up @@ -53,6 +54,8 @@ public abstract class Cfg {

protected CfgGui gui;

protected CfgFork fork;

public void setId(final String _id) {
this.id = _id;
}
Expand Down Expand Up @@ -117,6 +120,10 @@ public CfgGui getGui() {
return this.gui;
}

public CfgFork getFork() {
return this.fork;
}

public String[] getNodes() {
return this.net.getNodes();
}
Expand All @@ -136,6 +143,7 @@ public void setConsensus(CfgConsensus _consensus) {
private final String configFileName = "config.xml";
private final String genesisFileName = "genesis.json";
private final String keystoreDirName = "keystore";
private final String forkFileName = "fork.properties";

// base path
private final File INITIAL_PATH = new File(System.getProperty("user.dir"));
Expand All @@ -147,6 +155,8 @@ public void setConsensus(CfgConsensus _consensus) {
// base configuration: old kernel OR using network config
private File baseConfigFile = null;
private File baseGenesisFile = null;
private File baseForkFile = null;


// can be absolute in config file OR depend on execution path
private File logDir = null;
Expand All @@ -164,13 +174,15 @@ public void setConsensus(CfgConsensus _consensus) {
private File execConfigDir = null;
private File execConfigFile = null;
private File execGenesisFile = null;
private File execForkFile = null;

/** Resets internal data containing network and path. */
@VisibleForTesting
public void resetInternal() {
networkConfigDir = null;
baseConfigFile = null;
baseGenesisFile = null;
baseForkFile = null;
logDir = null;
databaseDir = null;
absoluteLogDir = false;
Expand All @@ -181,6 +193,7 @@ public void resetInternal() {
execConfigDir = null;
execConfigFile = null;
execGenesisFile = null;
execForkFile = null;
}

/**
Expand Down Expand Up @@ -214,6 +227,7 @@ private void updateNetworkExecPaths() {
networkConfigDir = new File(CONFIG_DIR, network);
baseConfigFile = new File(networkConfigDir, configFileName);
baseGenesisFile = new File(networkConfigDir, genesisFileName);
baseForkFile = new File(networkConfigDir, forkFileName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fork files need to be initialized for the case where the config files reside directly in the config folder as used by old kernels (implemented in else clause at line 210 above). I propose that we assume that anyone using the old config location takes the time to copy the fork.properties file.


if (dataDir == null) {
dataDir = INITIAL_PATH;
Expand All @@ -222,8 +236,10 @@ private void updateNetworkExecPaths() {
execConfigDir = new File(execDir, configDirName);
execConfigFile = new File(execConfigDir, configFileName);
execGenesisFile = new File(execConfigDir, genesisFileName);
execForkFile = new File(execConfigDir, forkFileName);

updateStoragePaths();
setForkProperties(network);
}

/** Updates the path to the log, database directories. */
Expand Down Expand Up @@ -428,6 +444,10 @@ public static void skipElement(final XMLStreamReader sr) throws XMLStreamExcepti

public abstract void toXML(final String[] args, File file);

public abstract void setForkProperties();

public abstract void setForkProperties(String network);

public abstract void setGenesis();

public abstract AbstractBlock<?, ?> getGenesis();
Expand Down
42 changes: 42 additions & 0 deletions modMcf/src/org/aion/mcf/config/CfgFork.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2017-2018 Aion foundation.
*
* This file is part of the aion network project.
*
* The aion network project is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or any later version.
*
* The aion network project is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the aion network project source files.
* If not, see <https://www.gnu.org/licenses/>.
*
* Contributors:
* Aion foundation.
*/
package org.aion.mcf.config;

import java.util.Properties;

public class CfgFork {

public CfgFork() {}

public static final String FORK_PROPERTIES_PATH = "/fork.properties";

private static Properties forkProperties = new Properties();

public void setProperties(Properties properties) {
forkProperties = properties;
}

public Properties getProperties() {
return forkProperties;
}
}
80 changes: 80 additions & 0 deletions modMcf/test/org/aion/mcf/config/CfgForkTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2017-2018 Aion foundation.
*
* This file is part of the aion network project.
*
* The aion network project is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or any later version.
*
* The aion network project is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the aion network project source files.
* If not, see <https://www.gnu.org/licenses/>.
*
* Contributors:
* Aion foundation.
*/
package org.aion.mcf.config;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNull;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.aion.zero.impl.config.CfgAion;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class CfgForkTest {

private CfgAion cfg;
private File forkFile;

@Before
public void setup() throws IOException {
new File(System.getProperty("user.dir") + "/mainnet/config").mkdirs();
forkFile =
new File(
System.getProperty("user.dir")
+ "/mainnet/config"
+ CfgFork.FORK_PROPERTIES_PATH);
forkFile.createNewFile();

// Open given file in append mode.
BufferedWriter out = new BufferedWriter(
new FileWriter(forkFile, true));
out.write("fork0.3.2=2000000");
out.close();

cfg = CfgAion.inst();
}

@After
public void teardown() {
forkFile.delete();
AionJayT marked this conversation as resolved.
Show resolved Hide resolved
forkFile.getParentFile().delete();
forkFile.getParentFile().getParentFile().delete();
}

@Test
public void getForkPropertyTest() {

String forkProperty = cfg.getFork().getProperties().getProperty("fork0.3.2");
assertEquals("2000000", forkProperty);
}

@Test
public void getForkPropertyTest2() {
String forkProperty = cfg.getFork().getProperties().getProperty("fork0.3.1");
assertNull(forkProperty);
}
}
Loading