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 3 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
19 changes: 19 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,22 @@ private void closeFileInputStream(final FileInputStream fis) {
}
}

public void setForkProperties() {
AionJayT marked this conversation as resolved.
Show resolved Hide resolved
Properties properties = new Properties();
FileInputStream fis = null;
try {
AionJayT marked this conversation as resolved.
Show resolved Hide resolved
fis = new FileInputStream(getBasePath() + CfgFork.FORK_PROPERTIES_PATH);
properties.load(fis);
} catch (IOException e) {
System.out.println(
"<error on-parsing-fork-properties msg=" + e.getLocalizedMessage() + ">");
System.exit(1);
} finally {
closeFileInputStream(fis);
}
this.getFork().setProperties(properties);
}

public void dbFromXML() {
File cfgFile = getInitialConfigFile();
XMLInputFactory input = XMLInputFactory.newInstance();
Expand Down
8 changes: 8 additions & 0 deletions modAionImpl/test/org/aion/zero/impl/cli/CliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 +103,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 +123,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 +133,7 @@ public void setup() {
}
Cli.copyRecursively(config, mainnetConfig);
Cli.copyRecursively(genesis, testnetGenesis);
Cli.copyRecursively(fork, testnetFork);
}

cfg.resetInternal();
Expand Down
1 change: 1 addition & 0 deletions modBoot/resource/mainnet/fork.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fork1=2000000
1 change: 1 addition & 0 deletions modBoot/resource/mastery/fork.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fork1=2000000
9 changes: 9 additions & 0 deletions modMcf/src/org/aion/mcf/config/Cfg.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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 +119,10 @@ public CfgGui getGui() {
return this.gui;
}

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

public String[] getNodes() {
return this.net.getNodes();
}
Expand Down Expand Up @@ -201,6 +207,7 @@ protected void initializeConfiguration() {
execGenesisFile = baseGenesisFile;
updateStoragePaths();
}
setForkProperties();
}

/**
Expand Down Expand Up @@ -428,6 +435,8 @@ 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 setGenesis();

public abstract AbstractBlock<?, ?> getGenesis();
Expand Down
41 changes: 41 additions & 0 deletions modMcf/src/org/aion/mcf/config/CfgFork.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 static final String FORK_PROPERTIES_PATH = "/fork.properties";

private static Properties forkProperties;

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

public String getForkPropertyByNumber(final int forkNum) {
if (forkProperties == null) return null;
return forkProperties.getProperty("fork" + String.valueOf(forkNum));
}
}
39 changes: 39 additions & 0 deletions modMcf/test/org/aion/mcf/config/CfgForkTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 org.aion.zero.impl.config.CfgAion;
import org.junit.Test;

public class CfgForkTest {

@Test
public void getForkPropertyTest() {
CfgAion cfg = CfgAion.inst();
cfg.setForkProperties();
String forkProperty = cfg.getFork().getForkPropertyByNumber(1);
assertEquals("2000000", forkProperty);
}
}
77 changes: 54 additions & 23 deletions modPrecompiled/src/org/aion/precompiled/ContractFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.aion.base.db.IRepositoryCache;
import org.aion.base.type.Address;
import org.aion.base.vm.IDataWord;
import org.aion.mcf.config.CfgFork;
import org.aion.mcf.core.AccountState;
import org.aion.mcf.db.IBlockStoreBase;
import org.aion.precompiled.contracts.ATB.TokenBridgeContract;
Expand Down Expand Up @@ -78,30 +79,60 @@ public IPrecompiledContract getPrecompiledContract(
ExecutionContext context,
IRepositoryCache<AccountState, IDataWord, IBlockStoreBase<?, ?>> track) {

switch (context.address().toString()) {
case ADDR_TOKEN_BRIDGE:
TokenBridgeContract contract =
new TokenBridgeContract(
context,
track,
Address.wrap(ADDR_TOKEN_BRIDGE_INITIAL_OWNER),
Address.wrap(ADDR_TOKEN_BRIDGE));

if (!context.origin().equals(Address.wrap(ADDR_TOKEN_BRIDGE_INITIAL_OWNER))
&& !contract.isInitialized()) {
CfgFork cfg = new CfgFork();
String forkProperty = cfg.getForkPropertyByNumber(1);
boolean firstFork =
(forkProperty != null) && (context.blockNumber() > Long.valueOf(forkProperty));

if (firstFork) {
switch (context.address().toString()) {
case ADDR_TOKEN_BRIDGE:
TokenBridgeContract contract =
new TokenBridgeContract(
context,
track,
Address.wrap(ADDR_TOKEN_BRIDGE_INITIAL_OWNER),
Address.wrap(ADDR_TOKEN_BRIDGE));

if (!context.origin().equals(Address.wrap(ADDR_TOKEN_BRIDGE_INITIAL_OWNER))
&& !contract.isInitialized()) {
return null;
}

return contract;
case ADDR_ED_VERIFY:
return PC_ED_VERIFY;
case ADDR_BLAKE2B_HASH:
return PC_BLAKE2B_HASH;
case ADDR_TX_HASH:
return new TXHashContract(context);
case ADDR_TOTAL_CURRENCY:
default:
return null;
}

return contract;
case ADDR_ED_VERIFY:
return PC_ED_VERIFY;
case ADDR_BLAKE2B_HASH:
return PC_BLAKE2B_HASH;
case ADDR_TX_HASH:
return new TXHashContract(context);
case ADDR_TOTAL_CURRENCY:
default:
return null;
}
} else {
switch (context.address().toString()) {
case ADDR_TOTAL_CURRENCY:
// return new TotalCurrencyContract(track, context.sender(),
// Address.wrap(OWNER));
return null;
AionJayT marked this conversation as resolved.
Show resolved Hide resolved
case ADDR_TOKEN_BRIDGE:
TokenBridgeContract contract =
new TokenBridgeContract(
context,
track,
Address.wrap(ADDR_TOKEN_BRIDGE_INITIAL_OWNER),
Address.wrap(ADDR_TOKEN_BRIDGE));

if (!context.origin().equals(Address.wrap(ADDR_TOKEN_BRIDGE_INITIAL_OWNER))
&& !contract.isInitialized()) {
return null;
}

return contract;
AionJayT marked this conversation as resolved.
Show resolved Hide resolved
default:
return null;
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions modPrecompiled/test/org/aion/precompiled/BenchmarkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.aion.mcf.vm.types.DataWord;
import org.aion.vm.ExecutionContext;
import org.aion.vm.IPrecompiledContract;
import org.aion.zero.impl.config.CfgAion;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -48,12 +49,12 @@ public class BenchmarkTest {
@Before
public void setup() {
cf = new ContractFactory();

CfgAion.inst().setForkProperties();
txHash = RandomUtils.nextBytes(32);
origin = Address.wrap(RandomUtils.nextBytes(32));
caller = origin;
blockCoinbase = Address.wrap(RandomUtils.nextBytes(32));
blockNumber = 1;
blockNumber = 2000001;
blockTimestamp = System.currentTimeMillis() / 1000;
blockNrgLimit = 5000000;
blockDifficulty = new DataWord(0x100000000L);
Expand Down
4 changes: 3 additions & 1 deletion modPrecompiled/test/org/aion/precompiled/TXHashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.aion.vm.ExecutionContext;
import org.aion.vm.ExecutionResult;
import org.aion.vm.IPrecompiledContract;
import org.aion.zero.impl.config.CfgAion;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -44,10 +45,11 @@ public class TXHashTest {

@Before
public void setUp() {
CfgAion.inst().setForkProperties();
ExecutionContext ctx = new ExecutionContext(txHash,
ContractFactory.getTxHashContractAddress(), null, null, null,
0L, null, null, 0, 0, 0, null,
0L, 0L, 0L,
2000001L, 0L, 0L,
null);

tXHashContract = new ContractFactory().getPrecompiledContract(ctx, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.aion.vm.ExecutionContext;
import org.aion.vm.ExecutionResult;
import org.aion.vm.IPrecompiledContract;
import org.aion.zero.impl.config.CfgAion;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -49,7 +50,7 @@ public class EDVerifyContractTest {
private Address caller = origin;

private Address blockCoinbase = Address.wrap(RandomUtils.nextBytes(32));
private long blockNumber = 1;
private long blockNumber = 2000001;
private long blockTimestamp = System.currentTimeMillis() / 1000;
private long blockNrgLimit = 5000000;
private DataWord blockDifficulty = new DataWord(0x100000000L);
Expand All @@ -69,6 +70,7 @@ public void setup() {
nrgLimit = 20000;
callValue = DataWord.ZERO;
callData = new byte[0];
CfgAion.inst().setForkProperties();
}

@Test
Expand Down