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

Casper FFG test net compatibility #1015

Open
wants to merge 74 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
4f7b653
Merge branch 'develop' into research/casper
zilm13 Jan 22, 2018
7d62991
Merge branch 'develop' into research/casper
zilm13 Jan 31, 2018
c34ea0f
Casper init commit. Passive sync is ok, mining is ok, validator in de…
zilm13 Feb 22, 2018
0902660
Merge branch 'develop' into research/casper
zilm13 Feb 22, 2018
ebe5fb0
TransactionExecutor split to standard implementation and Casper version
zilm13 Feb 22, 2018
d736638
Fixing Spring circular references
zilm13 Feb 23, 2018
3f1b724
Fixing miner rejects casper votes
zilm13 Feb 23, 2018
726f4f7
Fixed Ethereum Harmony build dependency failing
zilm13 Feb 23, 2018
e2e3fd6
Init Casper with passed params instead of hexcode
zilm13 Feb 26, 2018
71dde8d
Added Casper Epoch test + minor fixes
zilm13 Feb 27, 2018
a50d280
Quick fix casper votes are dropped
zilm13 Feb 28, 2018
6b0f381
Fixed sync not done after miner start
zilm13 Feb 28, 2018
4369d4f
Added simple casper validator test, fixed voting in casper validator …
zilm13 Mar 1, 2018
a556ecc
Added logging of my validator stats
zilm13 Mar 1, 2018
492468e
Added validator logout test
zilm13 Mar 2, 2018
4818249
Fixed processed txs removal
zilm13 Mar 2, 2018
5287b22
Fixed basis test was started, but shouldn't
zilm13 Mar 2, 2018
b47e24c
Refactored null sender txs signing
zilm13 Mar 2, 2018
068152a
Started to detaching Casper in separate package: Config moved
zilm13 Mar 2, 2018
3a88e8b
Moved Blockchain and validators out of consensus strategy
zilm13 Mar 2, 2018
11fa1a7
Fixed frame encoding for chunked frames
zilm13 Mar 5, 2018
dbdbc28
Fxied type size counting
zilm13 Mar 5, 2018
a87b98f
Fixed dirty read coded size adjust
zilm13 Mar 5, 2018
26f5c6e
Fixed incorrect Transactions creation (with lead zeros)
zilm13 Mar 6, 2018
770b377
Fixed wrong place of chunked frame size adjust
zilm13 Mar 6, 2018
23e894c
Fixed tests
zilm13 Mar 6, 2018
d5c2650
Add publishing to jfrog
zilm13 Mar 6, 2018
f932df1
Trying another naming for publishing
zilm13 Mar 6, 2018
beccdb9
TransactionExecutor creation moved to CommonConfig. CasperBlockchain …
zilm13 Mar 7, 2018
abc8906
Net config moved to casper package
zilm13 Mar 7, 2018
6d23835
Moved switching to short sync on manual miner start to Harmony
zilm13 Mar 7, 2018
5c8634d
Completely removed ConsensusStrategy abstraction
zilm13 Mar 8, 2018
920747f
More cleanup to enclose casper in separate package
zilm13 Mar 8, 2018
0fb3a63
Temp patch for p2pv4 framing compatibility with p2pv5 snappy
zilm13 Mar 8, 2018
dbc1dcf
Validator start logging added
zilm13 Mar 9, 2018
97dba27
Fixed: casper votes should come after regular txs in mined block + va…
zilm13 Mar 9, 2018
b83b9cb
Fixing ethereumj w. ethereumj p2p
zilm13 Mar 10, 2018
281c60c
Moved dummy contracts to Casper genesis
zilm13 Mar 11, 2018
ce4bdf8
Cleanup of default config
zilm13 Mar 11, 2018
f101e4b
Correct constructor for creating RepositoryRoot without autowiring added
zilm13 Mar 11, 2018
dc652a3
Logic of casper validator start moved to casper validator
zilm13 Mar 11, 2018
c06a3b5
Casper vote checking moved to CasperFacade
zilm13 Mar 11, 2018
313223b
Fixed block was not always thrown away with new block mined when mini…
zilm13 Mar 12, 2018
16e4515
Removed state init abstraction
zilm13 Mar 12, 2018
2b1db0f
Added validators for transaction and transaction receipt in PendingState
zilm13 Mar 12, 2018
56f7d04
Revert "Added validators for transaction and transaction receipt in P…
zilm13 Mar 13, 2018
73fddc3
Decreased validator gas limit to make it easy passing in block with a…
zilm13 Mar 13, 2018
43b3f96
Fixed failure when no validator options configured
zilm13 Mar 13, 2018
1f0e5dc
Fixed: unsuccessful txs with 0 gas used were included in mined blocks
zilm13 Mar 13, 2018
0423bbf
Fixed wrong init in CasperValidatorService
zilm13 Mar 13, 2018
8ec6864
Make casper epoch switch free
zilm13 Mar 14, 2018
845c0bf
Revert "Make casper epoch switch free"
zilm13 Mar 14, 2018
c72cb9d
Don't subtract fee from null sender on succesful casper vote. Instead…
zilm13 Mar 14, 2018
2117fdc
Fixed makeInitTxs
zilm13 Mar 14, 2018
3a3e536
Logging of casper address added
zilm13 Mar 14, 2018
13fda70
Trying to fix github tests with delay after failed request
zilm13 Mar 14, 2018
0cc765d
Revert "Don't subtract fee from null sender on succesful casper vote.…
zilm13 Mar 14, 2018
3f39e57
Removed TransactionExecutorFactory
zilm13 Mar 14, 2018
bc829f6
Storing finalized checkpoints in separate source
zilm13 Mar 14, 2018
d7703cb
Fixed Casper test (finalizedBlocks storage was not set)
zilm13 Mar 18, 2018
2517cc0
Merge branch 'develop' into research/casper
zilm13 Mar 20, 2018
cce4815
Revert "Revert "Make casper epoch switch free""
zilm13 Mar 20, 2018
5e13b15
Revert "Revert "Don't subtract fee from null sender on succesful casp…
zilm13 Mar 20, 2018
9840b71
Testing that no gas was used for casper service txs and bad casper vo…
zilm13 Mar 20, 2018
d0cea52
Merge branch 'develop' into research/casper
zilm13 Mar 21, 2018
ad92db0
Merge branch 'develop' into research/casper
zilm13 Mar 21, 2018
33e6721
Merge branch 'develop' into research/casper
zilm13 Mar 22, 2018
feb3f91
CasperFacade: use apache.commons Pair instead of javafx.util Pair
mkalinin Apr 8, 2018
84a3254
Added transaction executor note for casper service txs
zilm13 Apr 9, 2018
6760e96
Bump Casper contract to commit #251a1a349fddd90b40febf9781ffc92e8c6a4a0e
zilm13 Apr 9, 2018
179888a
Temporary EIP-86 partial implementation
zilm13 Apr 10, 2018
e835c4a
Fixing Circle CI for Casper branch
zilm13 Apr 11, 2018
316c43d
Refactored tx validation
zilm13 Apr 11, 2018
29614b4
Testing chainId compatibility
zilm13 Apr 11, 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
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ subprojects {

group = 'org.ethereum'

version = config.versionNumber + ("master" == gitCurBranch() ? "-RELEASE" : "-SNAPSHOT")
version = config.versionNumber + ("master" == gitCurBranch() ? "-RELEASE" :
"research/casper" == gitCurBranch() ? "-casper-SNAPSHOT" : "-SNAPSHOT")

println("Building version: " + version + " (from branch " + gitCurBranch() + ")")

Expand Down
9 changes: 8 additions & 1 deletion ethereumj-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ task runTest (type: JavaExec) {
jvmArgs = applicationDefaultJvmArgs + '-Dethereumj.conf.res=test.conf'
}

task runCasper (type: JavaExec) {
main = 'org.ethereum.casper.Start'
classpath = sourceSets.main.runtimeClasspath
jvmArgs = applicationDefaultJvmArgs + '-Dethereumj.conf.res=casper.conf'
}

/**
* This is TCK test command line option,
* to run the test:
Expand Down Expand Up @@ -217,7 +223,8 @@ artifactoryPublish.onlyIf {
project.version.endsWith('-SNAPSHOT') &&
(branchName.startsWith('master') ||
branchName.startsWith('develop') ||
branchName.startsWith('stage'))
branchName.startsWith('stage') ||
branchName.startsWith('research/casper'))
}

bintray {
Expand Down
62 changes: 62 additions & 0 deletions ethereumj-core/src/main/java/org/ethereum/casper/Start.java
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 {
Copy link
Contributor

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 adding CasperConfig.

Copy link
Collaborator Author

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.


@Override
@Bean
public Blockchain blockchain() {
return new CasperBlockchain(systemProperties());
}

@Override
@Bean
public TransactionExecutorFactory transactionExecutorFactory() {
return new CasperTransactionExecutorFactory();
}

class CasperTransactionExecutorFactory implements TransactionExecutorFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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"));
}
}
}
Loading