-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Casper FFG test net compatibility #1015
base: develop
Are you sure you want to change the base?
Changes from 34 commits
4f7b653
7d62991
c34ea0f
0902660
ebe5fb0
d736638
3f1b724
726f4f7
e2e3fd6
71dde8d
a50d280
6b0f381
4369d4f
a556ecc
492468e
4818249
5287b22
b47e24c
068152a
3a88e8b
11fa1a7
dbdbc28
a87b98f
26f5c6e
770b377
23e894c
d5c2650
f932df1
beccdb9
abc8906
6d23835
5c8634d
920747f
0fb3a63
dbc1dcf
97dba27
b83b9cb
281c60c
ce4bdf8
f101e4b
dc652a3
c06a3b5
313223b
16e4515
2b1db0f
56f7d04
73fddc3
43b3f96
1f0e5dc
0423bbf
8ec6864
845c0bf
c72cb9d
2117fdc
3a3e536
13fda70
0cc765d
3f39e57
bc829f6
d7703cb
2517cc0
cce4815
5e13b15
9840b71
d0cea52
ad92db0
33e6721
feb3f91
84a3254
6760e96
179888a
e835c4a
316c43d
29614b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) [2016] [ <ether.camp> ] | ||
* This file is part of the ethereumJ library. | ||
* | ||
* The ethereumJ library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The ethereumJ library 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.ethereum.casper; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.ethereum.casper.config.CasperConfig; | ||
import org.ethereum.cli.CLIInterface; | ||
import org.ethereum.config.SystemProperties; | ||
import org.ethereum.facade.Ethereum; | ||
import org.ethereum.facade.EthereumFactory; | ||
import org.ethereum.mine.Ethash; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
|
||
public class Start { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger("general"); | ||
|
||
public static void main(String args[]) throws IOException, URISyntaxException { | ||
logger.info("EthereumJ Casper edition"); | ||
CLIInterface.call(args); | ||
|
||
final SystemProperties config = SystemProperties.getDefault(); | ||
final boolean actionBlocksLoader = !config.blocksLoader().equals(""); | ||
final boolean actionGenerateDag = !StringUtils.isEmpty(System.getProperty("ethash.blockNumber")); | ||
|
||
if (actionBlocksLoader || actionGenerateDag) { | ||
config.setSyncEnabled(false); | ||
config.setDiscoveryEnabled(false); | ||
} | ||
|
||
if (actionGenerateDag) { | ||
new Ethash(config, Long.parseLong(System.getProperty("ethash.blockNumber"))).getFullDataset(); | ||
// DAG file has been created, lets exit | ||
System.exit(0); | ||
} else { | ||
Ethereum ethereum = EthereumFactory.createEthereum(new Class[] {CasperConfig.class}); | ||
|
||
if (actionBlocksLoader) { | ||
ethereum.getBlockLoader().loadBlocks(); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright (c) [2016] [ <ether.camp> ] | ||
* This file is part of the ethereumJ library. | ||
* | ||
* The ethereumJ library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The ethereumJ library 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.ethereum.casper.config; | ||
|
||
import org.ethereum.casper.core.CasperPendingStateImpl; | ||
import org.ethereum.casper.manager.CasperWorldManager; | ||
import org.ethereum.casper.mine.CasperBlockMiner; | ||
import org.ethereum.config.CommonConfig; | ||
import org.ethereum.config.SystemProperties; | ||
import org.ethereum.core.Block; | ||
import org.ethereum.core.Blockchain; | ||
import org.ethereum.core.PendingState; | ||
import org.ethereum.core.Repository; | ||
import org.ethereum.core.Transaction; | ||
import org.ethereum.core.TransactionExecutor; | ||
import org.ethereum.core.TransactionExecutorFactory; | ||
import org.ethereum.casper.core.CasperBlockchain; | ||
import org.ethereum.casper.core.CasperTransactionExecutor; | ||
import org.ethereum.db.BlockStore; | ||
import org.ethereum.listener.CompositeEthereumListener; | ||
import org.ethereum.listener.EthereumListener; | ||
import org.ethereum.manager.WorldManager; | ||
import org.ethereum.mine.BlockMiner; | ||
import org.ethereum.vm.program.invoke.ProgramInvokeFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
public class CasperBeanConfig extends CommonConfig { | ||
|
||
@Override | ||
@Bean | ||
public Blockchain blockchain() { | ||
return new CasperBlockchain(systemProperties()); | ||
} | ||
|
||
@Override | ||
@Bean | ||
public TransactionExecutorFactory transactionExecutorFactory() { | ||
return new CasperTransactionExecutorFactory(); | ||
} | ||
|
||
class CasperTransactionExecutorFactory implements TransactionExecutorFactory { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better keep an implementation in the same package where interface is placed in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? We have implementation for different purpose. Interface is universal and used as interface. |
||
|
||
@Override | ||
public TransactionExecutor createTransactionExecutor(Transaction tx, byte[] coinbase, Repository track, | ||
BlockStore blockStore, ProgramInvokeFactory programInvokeFactory, | ||
Block currentBlock) { | ||
return new CasperTransactionExecutor(tx, coinbase, track, blockStore, programInvokeFactory, currentBlock); | ||
} | ||
|
||
@Override | ||
public TransactionExecutor createTransactionExecutor(Transaction tx, byte[] coinbase, Repository track, | ||
BlockStore blockStore, ProgramInvokeFactory programInvokeFactory, | ||
Block currentBlock, EthereumListener listener, long gasUsedInTheBlock) { | ||
return new CasperTransactionExecutor(tx, coinbase, track, blockStore, programInvokeFactory, currentBlock, | ||
listener, gasUsedInTheBlock); | ||
} | ||
} | ||
|
||
@Bean | ||
@Override | ||
public WorldManager worldManager() { | ||
return new CasperWorldManager(systemProperties(), repository(), blockchain()); | ||
} | ||
|
||
@Bean | ||
@Override | ||
public PendingState pendingState() { | ||
return new CasperPendingStateImpl(ethereumListener); | ||
} | ||
|
||
@Bean | ||
@Override | ||
public BlockMiner blockMiner() { | ||
return new CasperBlockMiner(systemProperties(), (CompositeEthereumListener) ethereumListener, | ||
blockchain(), pendingState()); | ||
} | ||
|
||
@Bean | ||
@Override | ||
public SystemProperties systemProperties() { | ||
return CasperProperties.getDefault(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) [2016] [ <ether.camp> ] | ||
* This file is part of the ethereumJ library. | ||
* | ||
* The ethereumJ library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The ethereumJ library 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.ethereum.casper.config; | ||
|
||
import org.ethereum.config.CommonConfig; | ||
import org.ethereum.config.DefaultConfig; | ||
import org.ethereum.config.NoAutoscan; | ||
import org.ethereum.config.SystemProperties; | ||
import org.ethereum.datasource.Source; | ||
import org.ethereum.db.BlockStore; | ||
import org.ethereum.db.IndexedBlockStore; | ||
import org.ethereum.db.PruneManager; | ||
import org.ethereum.db.TransactionStore; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.FilterType; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Configuration | ||
@ComponentScan( | ||
basePackages = "org.ethereum", | ||
excludeFilters = {@ComponentScan.Filter(NoAutoscan.class), | ||
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = {CommonConfig.class, DefaultConfig.class})}, | ||
includeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = {CasperBeanConfig.class})} | ||
) | ||
@Import(CasperBeanConfig.class) | ||
public class CasperConfig { | ||
private static Logger logger = LoggerFactory.getLogger("general"); | ||
|
||
@Autowired | ||
ApplicationContext appCtx; | ||
|
||
@Autowired | ||
CasperBeanConfig beanConfig; | ||
|
||
@Autowired | ||
SystemProperties config; | ||
|
||
public CasperConfig() { | ||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> logger.error("Uncaught exception", e)); | ||
} | ||
|
||
@Bean | ||
public BlockStore blockStore(){ | ||
beanConfig.fastSyncCleanUp(); | ||
IndexedBlockStore indexedBlockStore = new IndexedBlockStore(); | ||
Source<byte[], byte[]> block = beanConfig.cachedDbSource("block"); | ||
Source<byte[], byte[]> index = beanConfig.cachedDbSource("index"); | ||
indexedBlockStore.init(index, block); | ||
|
||
return indexedBlockStore; | ||
} | ||
|
||
@Bean | ||
public TransactionStore transactionStore() { | ||
beanConfig.fastSyncCleanUp(); | ||
return new TransactionStore(beanConfig.cachedDbSource("transactions")); | ||
} | ||
|
||
@Bean | ||
public PruneManager pruneManager() { | ||
if (config.databasePruneDepth() >= 0) { | ||
return new PruneManager((IndexedBlockStore) blockStore(), beanConfig.stateSource().getJournalSource(), | ||
config.databasePruneDepth()); | ||
} else { | ||
return new PruneManager(null, null, -1); // dummy | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.ethereum.casper.config; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.ethereum.casper.config.net.CasperTestNetConfig; | ||
import org.ethereum.config.BlockchainNetConfig; | ||
import org.ethereum.config.SystemProperties; | ||
import org.ethereum.core.genesis.GenesisConfig; | ||
import org.ethereum.util.ByteUtil; | ||
import org.ethereum.validator.BlockCustomHashRule; | ||
import org.ethereum.validator.BlockHeaderValidator; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.ethereum.casper.config.net.CasperTestNetConfig.EPOCH_LENGTH; | ||
|
||
public class CasperProperties extends SystemProperties { | ||
|
||
private static CasperProperties CONFIG; | ||
|
||
private byte[] casperAddress = null; | ||
|
||
public static SystemProperties getDefault() { | ||
if (CONFIG == null) { | ||
CONFIG = new CasperProperties(); | ||
} | ||
return CONFIG; | ||
} | ||
|
||
public byte[] getCasperAddress() { | ||
return casperAddress; | ||
} | ||
|
||
public void setCasperAddress(byte[] casperAddress) { | ||
this.casperAddress = casperAddress; | ||
} | ||
|
||
public int getCasperEpochLength() { | ||
return EPOCH_LENGTH; | ||
} | ||
|
||
public byte[] getCasperValidatorPrivateKey() { | ||
String key = config.getString("casper.validator.privateKey"); | ||
if (key == null) return null; | ||
return ByteUtil.hexStringToBytes(key); | ||
} | ||
|
||
public long getCasperValidatorDeposit() { | ||
return config.getLong("casper.validator.deposit"); | ||
} | ||
|
||
public Boolean getCasperValidatorEnabled() { | ||
return config.getBoolean("casper.validator.enabled"); | ||
} | ||
|
||
public String getCasperAbi() { | ||
final String abiLocation = config.getString("casper.contractAbi"); | ||
return readFile(abiLocation); | ||
} | ||
|
||
public String getCasperBin() { | ||
final String binLocation = config.getString("casper.contractBin"); | ||
return readFile(binLocation); | ||
} | ||
|
||
private static String readFile(final String location) { | ||
try { | ||
InputStream is = SystemProperties.class.getResourceAsStream(location); | ||
|
||
if (is != null) { | ||
return readStream(is); | ||
} else { | ||
logger.error("File not found `{}`", location); | ||
throw new RuntimeException(String.format("File not found `%s`", location)); | ||
} | ||
} catch (Exception ex) { | ||
String errorMsg = String.format("Error while reading file from %s", location); | ||
logger.error(errorMsg, ex); | ||
throw new RuntimeException(errorMsg, ex); | ||
} | ||
} | ||
|
||
private static String readStream(InputStream input) throws IOException { | ||
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) { | ||
return buffer.lines().collect(Collectors.joining("\n")); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will
@Import(DefaultConfig.class)
work here instead of inheritance? If yes then it might also keep us from addingCasperConfig
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, will check. Expecting two beans of the same type by intuition.