Merge remote-tracking branch 'origin/master'

This commit is contained in:
Roman Mandeleil 2015-01-22 12:49:45 +02:00
commit c87a5c3cb6
4 changed files with 89 additions and 131 deletions

View File

@ -19,7 +19,7 @@ To see ethereum-studio in action, watch this [video](https://youtu.be/D5ok7jh7AO
The Ethereum protocol is under heavy development, thus so is this implementation. See the [todo list](TODO.md), GitHub [Issues](https://github.com/ethereum/ethereumj/issues) and [milestone schedule](https://github.com/ethereum/ethereumj/milestones). Issues are prioritized using [waffle](http://waffle.io/ethereum/ethereumj).
# Contact
Chat with us via [Gitter](https://gitter.im/ethereum/ethereumj) or [#ethereumj](webchat.freenode.net/?channels=ethereumj) on Freenode.
Chat with us via [Gitter](https://gitter.im/ethereum/ethereumj) or [#ethereumj](https://webchat.freenode.net/?channels=ethereumj) on Freenode.
# Building from source

View File

@ -23,47 +23,46 @@ public class SystemProperties {
private static Logger logger = LoggerFactory.getLogger("general");
private static int DEFAULT_TX_APPROVE_TIMEOUT = 10;
private static String DEFAULT_DISCOVERY_PEER_LIST = "poc-7.ethdev.com:30303";
private static String DEFAULT_ACTIVE_PEER_IP = "poc-7.ethdev.com";
private static int DEFAULT_ACTIVE_PORT = 30303;
private static String DEFAULT_SAMPLES_DIR = "samples";
private static String DEFAULT_COINBASE_SECRET = "monkey";
private static int DEFAULT_ACTIVE_PEER_CHANNEL_TIMEOUT = 5;
private static Boolean DEFAULT_DB_RESET = false;
private static Boolean DEFAULT_DUMP_FULL = false;
private static Boolean DEFAULT_RECORD_BLOCKS = false;
private static String DEFAULT_DUMP_DIR = "dmp";
private static String DEFAULT_DUMP_STYLE = "standard+";
private static Integer DEFAULT_VMTRACE_BLOCK = 0;
private static String DEFAULT_DATABASE_DIR = System.getProperty("user.dir");
private static Boolean DEFAULT_DUMP_CLEAN_ON_RESTART = true;
private static Boolean DEFAULT_PLAY_VM = true;
private static Boolean DEFAULT_BLOCKCHAIN_ONLY = false;
private static int DEFAULT_TRACE_STARTBLOCK = -1;
private static int DEFAULT_MAX_HASHES_ASK = -1; // unlimited
private static int DEFAULT_MAX_BLOCKS_ASK = 10;
private static int DEFAULT_MAX_BLOCKS_QUEUED = 300;
private static String DEFAULT_PROJECT_VERSION = "";
private static String DEFAULT_HELLO_PHRASE = "Dev";
private static Boolean DEFAULT_VM_TRACE = false;
private static String DEFAULT_VM_TRACE_DIR = "dmp";
private static int DEFAULT_PEER_LISTEN_PORT = 30303;
private static String DEFAULT_KEY_VALUE_DATA_SOURCE = "leveldb";
private final static int DEFAULT_TX_APPROVE_TIMEOUT = 10;
private final static String DEFAULT_DISCOVERY_PEER_LIST = "poc-7.ethdev.com:30303";
private final static String DEFAULT_ACTIVE_PEER_IP = "poc-7.ethdev.com";
private final static int DEFAULT_ACTIVE_PORT = 30303;
private final static String DEFAULT_SAMPLES_DIR = "samples";
private final static String DEFAULT_COINBASE_SECRET = "monkey";
private final static int DEFAULT_ACTIVE_PEER_CHANNEL_TIMEOUT = 5;
private final static Boolean DEFAULT_DB_RESET = false;
private final static Boolean DEFAULT_DUMP_FULL = false;
private final static Boolean DEFAULT_RECORD_BLOCKS = false;
private final static String DEFAULT_DUMP_DIR = "dmp";
private final static String DEFAULT_DUMP_STYLE = "standard+";
private final static Integer DEFAULT_VMTRACE_BLOCK = 0;
private final static String DEFAULT_DATABASE_DIR = System.getProperty("user.dir");
private final static Boolean DEFAULT_DUMP_CLEAN_ON_RESTART = true;
private final static Boolean DEFAULT_PLAY_VM = true;
private final static Boolean DEFAULT_BLOCKCHAIN_ONLY = false;
private final static int DEFAULT_TRACE_STARTBLOCK = -1;
private final static int DEFAULT_MAX_HASHES_ASK = -1; // unlimited
private final static int DEFAULT_MAX_BLOCKS_ASK = 10;
private final static int DEFAULT_MAX_BLOCKS_QUEUED = 300;
private final static String DEFAULT_PROJECT_VERSION = "";
private final static String DEFAULT_HELLO_PHRASE = "Dev";
private final static Boolean DEFAULT_VM_TRACE = false;
private final static String DEFAULT_VM_TRACE_DIR = "dmp";
private final static int DEFAULT_PEER_LISTEN_PORT = 30303;
private final static String DEFAULT_KEY_VALUE_DATA_SOURCE = "leveldb";
/* Testing */
private static Boolean DEFAULT_VMTEST_LOAD_LOCAL = false;
private final static Boolean DEFAULT_VMTEST_LOAD_LOCAL = false;
private static List<String> DEFAULT_PROTOCOL_LIST = Arrays.asList("eth", "shh");
private final static String DEFAULT_PROTOCOL_LIST = "eth,shh";
public static SystemProperties CONFIG = new SystemProperties();
private Properties prop = new Properties();
private InputStream input = null;
private final Properties prop = new Properties();
public SystemProperties() {
InputStream input = null;
try {
String userDir = System.getProperty("user.dir");
String fileName = userDir + "/config/system.properties";
@ -84,7 +83,7 @@ public class SystemProperties {
// load a properties file from class path, inside static method
prop.load(input);
overideCLIParams();
overrideCLIParams();
} catch (IOException ex) {
logger.error(ex.getMessage(), ex);
@ -99,41 +98,35 @@ public class SystemProperties {
}
}
private void overideCLIParams() {
private void overrideCLIParams() {
String value = System.getProperty("keyvalue.datasource");
if (value != null){
if (value != null) {
prop.setProperty("keyvalue.datasource", value);
}
}
public boolean peerDiscovery() {
if (prop.isEmpty()) return true;
return Boolean.parseBoolean(prop.getProperty("peer.discovery"));
return Boolean.parseBoolean(prop.getProperty("peer.discovery", "true"));
}
public int peerDiscoveryWorkers() {
if (prop.isEmpty()) return 2;
return Integer.parseInt(prop.getProperty("peer.discovery.workers"));
return Integer.parseInt(prop.getProperty("peer.discovery.workers", "2"));
}
public int peerConnectionTimeout() {
if (prop.isEmpty()) return 10000;
return Integer.parseInt(prop.getProperty("peer.connection.timeout")) * 1000;
return Integer.parseInt(prop.getProperty("peer.connection.timeout", "10")) * 1000;
}
public int transactionApproveTimeout() {
if (prop.isEmpty()) return DEFAULT_TX_APPROVE_TIMEOUT;
return Integer.parseInt(prop.getProperty("transaction.approve.timeout"));
return Integer.parseInt(prop.getProperty("transaction.approve.timeout", String.valueOf("DEFAULT_TX_APPROVE_TIMEOUT")));
}
public String peerDiscoveryIPList() {
if (prop.isEmpty()) return DEFAULT_DISCOVERY_PEER_LIST;
return prop.getProperty("peer.discovery.ip.list");
return prop.getProperty("peer.discovery.ip.list", DEFAULT_DISCOVERY_PEER_LIST);
}
public boolean databaseReset() {
if (prop.isEmpty()) return DEFAULT_DB_RESET;
return Boolean.parseBoolean(prop.getProperty("database.reset"));
return Boolean.parseBoolean(prop.getProperty("database.reset", String.valueOf(DEFAULT_DB_RESET)));
}
public void setDatabaseReset(Boolean reset) {
@ -141,17 +134,15 @@ public class SystemProperties {
}
public String activePeerIP() {
if (prop.isEmpty()) return DEFAULT_ACTIVE_PEER_IP;
return prop.getProperty("peer.active.ip");
return prop.getProperty("peer.active.ip", DEFAULT_ACTIVE_PEER_IP);
}
public void setActivePeerIP(String host) {
prop.setProperty("peer.active.ip", host.toString());
prop.setProperty("peer.active.ip", host);
}
public int activePeerPort() {
if (prop.isEmpty()) return DEFAULT_ACTIVE_PORT;
return Integer.parseInt(prop.getProperty("peer.active.port"));
return Integer.parseInt(prop.getProperty("peer.active.port", String.valueOf(DEFAULT_ACTIVE_PORT)));
}
public void setActivePeerPort(Integer port) {
@ -159,54 +150,43 @@ public class SystemProperties {
}
public String samplesDir() {
if (prop.isEmpty()) return DEFAULT_SAMPLES_DIR;
return prop.getProperty("samples.dir");
return prop.getProperty("samples.dir", DEFAULT_SAMPLES_DIR);
}
public String coinbaseSecret() {
if (prop.isEmpty()) return DEFAULT_COINBASE_SECRET;
return prop.getProperty("coinbase.secret");
return prop.getProperty("coinbase.secret", DEFAULT_COINBASE_SECRET);
}
public Integer peerChannelReadTimeout() {
if (prop.isEmpty()) return DEFAULT_ACTIVE_PEER_CHANNEL_TIMEOUT;
return Integer.parseInt(prop.getProperty("peer.channel.read.timeout"));
return Integer.parseInt(prop.getProperty("peer.channel.read.timeout", String.valueOf(DEFAULT_ACTIVE_PEER_CHANNEL_TIMEOUT)));
}
public Integer traceStartBlock() {
if (prop.isEmpty()) return DEFAULT_TRACE_STARTBLOCK;
return Integer.parseInt(prop.getProperty("trace.startblock"));
return Integer.parseInt(prop.getProperty("trace.startblock", String.valueOf(DEFAULT_TRACE_STARTBLOCK)));
}
public Boolean recordBlocks() {
if (prop.isEmpty()) return DEFAULT_RECORD_BLOCKS;
return Boolean.parseBoolean(prop.getProperty("record.blocks"));
return Boolean.parseBoolean(prop.getProperty("record.blocks", String.valueOf(DEFAULT_RECORD_BLOCKS)));
}
public Boolean dumpFull() {
if (prop.isEmpty()) return DEFAULT_DUMP_FULL;
return Boolean.parseBoolean(prop.getProperty("dump.full"));
return Boolean.parseBoolean(prop.getProperty("dump.full", String.valueOf(DEFAULT_DUMP_FULL)));
}
public String dumpDir() {
if (prop.isEmpty()) return DEFAULT_DUMP_DIR;
return prop.getProperty("dump.dir");
return prop.getProperty("dump.dir", DEFAULT_DUMP_DIR);
}
public String dumpStyle() {
if (prop.isEmpty()) return DEFAULT_DUMP_STYLE;
return prop.getProperty("dump.style");
return prop.getProperty("dump.style", DEFAULT_DUMP_STYLE);
}
public Integer dumpBlock() {
if (prop.isEmpty()) return DEFAULT_VMTRACE_BLOCK;
return Integer.parseInt(prop.getProperty("dump.block"));
return Integer.parseInt(prop.getProperty("dump.block", String.valueOf(DEFAULT_VMTRACE_BLOCK)));
}
public String databaseDir() {
if (prop.isEmpty()) return DEFAULT_DATABASE_DIR;
return prop.getProperty("database.dir");
return prop.getProperty("database.dir", DEFAULT_DATABASE_DIR);
}
public void setDataBaseDir(String dataBaseDir) {
@ -214,43 +194,35 @@ public class SystemProperties {
}
public Boolean dumpCleanOnRestart() {
if (prop.isEmpty()) return DEFAULT_DUMP_CLEAN_ON_RESTART;
return Boolean.parseBoolean(prop.getProperty("dump.clean.on.restart"));
return Boolean.parseBoolean(prop.getProperty("dump.clean.on.restart", String.valueOf(DEFAULT_DUMP_CLEAN_ON_RESTART)));
}
public Boolean playVM() {
if (prop.isEmpty()) return DEFAULT_PLAY_VM;
return Boolean.parseBoolean(prop.getProperty("play.vm"));
return Boolean.parseBoolean(prop.getProperty("play.vm", String.valueOf(DEFAULT_PLAY_VM)));
}
public Boolean blockChainOnly() {
if (prop.isEmpty()) return DEFAULT_BLOCKCHAIN_ONLY;
return Boolean.parseBoolean(prop.getProperty("blockchain.only"));
return Boolean.parseBoolean(prop.getProperty("blockchain.only", String.valueOf(DEFAULT_BLOCKCHAIN_ONLY)));
}
public Integer maxHashesAsk() {
if (prop.isEmpty()) return DEFAULT_MAX_HASHES_ASK;
return Integer.parseInt(prop.getProperty("max.hashes.ask"));
return Integer.parseInt(prop.getProperty("max.hashes.ask", String.valueOf(DEFAULT_MAX_HASHES_ASK)));
}
public Integer maxBlocksAsk() {
if (prop.isEmpty()) return DEFAULT_MAX_BLOCKS_ASK;
return Integer.parseInt(prop.getProperty("max.blocks.ask"));
return Integer.parseInt(prop.getProperty("max.blocks.ask", String.valueOf(DEFAULT_MAX_BLOCKS_ASK)));
}
public Integer maxBlocksQueued() {
if (prop.isEmpty()) return DEFAULT_MAX_BLOCKS_QUEUED;
return Integer.parseInt(prop.getProperty("max.blocks.queued"));
return Integer.parseInt(prop.getProperty("max.blocks.queued", String.valueOf(DEFAULT_MAX_BLOCKS_QUEUED)));
}
public String projectVersion() {
if (prop.isEmpty()) return DEFAULT_PROJECT_VERSION;
return prop.getProperty("project.version");
return prop.getProperty("project.version", DEFAULT_PROJECT_VERSION);
}
public String helloPhrase() {
if (prop.isEmpty()) return DEFAULT_HELLO_PHRASE;
return prop.getProperty("hello.phrase");
return prop.getProperty("hello.phrase", DEFAULT_HELLO_PHRASE);
}
public String rootHashStart() {
@ -262,30 +234,25 @@ public class SystemProperties {
}
public List<String> peerCapabilities() {
if (prop.isEmpty()) return DEFAULT_PROTOCOL_LIST;
String capabilitiesList = prop.getProperty("peer.capabilities");
String capabilitiesList = prop.getProperty("peer.capabilities", DEFAULT_PROTOCOL_LIST);
return Arrays.asList(capabilitiesList.split(","));
}
public boolean vmTrace() {
if (prop.isEmpty()) return DEFAULT_VM_TRACE;
return Boolean.parseBoolean(prop.getProperty("vm.structured.trace"));
return Boolean.parseBoolean(prop.getProperty("vm.structured.trace", String.valueOf(DEFAULT_VM_TRACE)));
}
public String vmTraceDir() {
if (prop.isEmpty()) return DEFAULT_VM_TRACE_DIR;
return prop.getProperty("vm.structured.dir");
return prop.getProperty("vm.structured.dir", DEFAULT_VM_TRACE_DIR);
}
public int listenPort() {
if (prop.isEmpty()) return DEFAULT_PEER_LISTEN_PORT;
return Integer.parseInt(prop.getProperty("peer.listen.port"));
return Integer.parseInt(prop.getProperty("peer.listen.port", String.valueOf(DEFAULT_PEER_LISTEN_PORT)));
}
public String getKeyValueDataSource() {
if (prop.isEmpty()) return DEFAULT_KEY_VALUE_DATA_SOURCE;
return prop.getProperty("keyvalue.datasource");
return prop.getProperty("keyvalue.datasource", DEFAULT_KEY_VALUE_DATA_SOURCE);
}
public void setListenPort(Integer port) {
@ -308,8 +275,7 @@ public class SystemProperties {
*
*/
public boolean vmTestLoadLocal() {
if (prop.isEmpty() || !prop.containsKey("GitHubTests.VMTest.loadLocal")) return DEFAULT_VMTEST_LOAD_LOCAL;
return Boolean.parseBoolean(prop.getProperty("GitHubTests.VMTest.loadLocal"));
return Boolean.parseBoolean(prop.getProperty("GitHubTests.VMTest.loadLocal", String.valueOf(DEFAULT_VMTEST_LOAD_LOCAL)));
}
public static void main(String args[]) {

View File

@ -66,7 +66,7 @@ import static org.ethereum.core.Denomination.SZABO;
public class BlockchainImpl implements Blockchain {
/* A scalar value equal to the minimum limit of gas expenditure per block */
private static long MIN_GAS_LIMIT = 125000L;
private static final long MIN_GAS_LIMIT = 125000L;
private static final Logger logger = LoggerFactory.getLogger("blockchain");
private static final Logger stateLogger = LoggerFactory.getLogger("state");
@ -138,7 +138,6 @@ public class BlockchainImpl implements Blockchain {
return blockStore.getListOfHashesStartFrom(hash, qty);
}
public void tryToConnect(Block block) {
recordBlock(block);
@ -217,7 +216,7 @@ public class BlockchainImpl implements Blockchain {
AdvancedDeviceUtils.adjustDetailedTracing(block.getNumber());
}
this.processBlock(block);
processBlock(block);
stateLogger.info("applied reward for block: [{}] \n state: [{}]",
block.getNumber(),
Hex.toHexString(repository.getRoot()));
@ -258,26 +257,19 @@ public class BlockchainImpl implements Blockchain {
public long calcGasLimit(BlockHeader header) {
if (header.isGenesis())
return Genesis.GAS_LIMIT;
else {
Block parent = getParent(header);
return Math.max(MIN_GAS_LIMIT, (parent.getGasLimit() * (1024 - 1) + (parent.getGasUsed() * 6 / 5)) / 1024);
}
}
public boolean isValid(BlockHeader header) {
boolean isValid = false;
// verify difficulty meets requirements
isValid = header.getDifficulty() == header.calcDifficulty();
// verify gasLimit meets requirements
isValid = isValid && header.getGasLimit() == calcGasLimit(header);
// verify timestamp meets requirements
isValid = isValid && header.getTimestamp() > getParent(header).getTimestamp();
// verify extraData doesn't exceed 1024 bytes
isValid = isValid && header.getExtraData() == null || header.getExtraData().length <= 1024;
return isValid;
}
return header.getDifficulty() == header.calcDifficulty() // difficulty meets requirements
&& header.getGasLimit() == calcGasLimit(header) // gasLimit meets requirements
&& header.getTimestamp() > getParent(header).getTimestamp() // timestamp meets requirements
&& (header.getExtraData() == null || header.getExtraData().length <= 1024); // extraData doesn't exceed 1024 bytes
}
/**
* This mechanism enforces a homeostasis in terms of the time between blocks;
@ -318,11 +310,11 @@ public class BlockchainImpl implements Blockchain {
if (!block.isGenesis()) {
if (!CONFIG.blockChainOnly()) {
wallet.addTransactions(block.getTransactionsList());
receipts = this.applyBlock(block);
receipts = applyBlock(block);
wallet.processBlock(block);
}
}
this.storeBlock(block, receipts);
storeBlock(block, receipts);
} else {
logger.warn("Invalid block with nr: {}", block.getNumber());
}
@ -332,7 +324,7 @@ public class BlockchainImpl implements Blockchain {
int i = 1;
long totalGasUsed = 0;
List<TransactionReceipt> reciepts = new ArrayList<>();
List<TransactionReceipt> receipts = new ArrayList<>();
for (Transaction tx : block.getTransactionsList()) {
stateLogger.info("apply block: [{}] tx: [{}] ", block.getNumber(), i);
@ -361,18 +353,18 @@ public class BlockchainImpl implements Blockchain {
if (block.getNumber() >= CONFIG.traceStartBlock())
repository.dumpState(block, totalGasUsed, i++, tx.getHash());
reciepts.add(receipt);
receipts.add(receipt);
}
this.addReward(block);
this.updateTotalDifficulty(block);
addReward(block);
updateTotalDifficulty(block);
track.commit();
if (block.getNumber() >= CONFIG.traceStartBlock())
repository.dumpState(block, totalGasUsed, 0, null);
return reciepts;
return receipts;
}
/**
@ -417,7 +409,7 @@ public class BlockchainImpl implements Blockchain {
}
blockStore.saveBlock(block, receipts);
this.setBestBlock(block);
setBestBlock(block);
if (logger.isDebugEnabled())
logger.debug("block added to the blockChain: index: [{}]", block.getNumber());
@ -475,7 +467,7 @@ public class BlockchainImpl implements Blockchain {
@Override
public void updateTotalDifficulty(Block block) {
this.totalDifficulty = totalDifficulty.add(block.getCumulativeDifficulty());
totalDifficulty = totalDifficulty.add(block.getCumulativeDifficulty());
}
@Override
@ -526,7 +518,6 @@ public class BlockchainImpl implements Blockchain {
}
public void setRepository(Repository repository) {
this.repository = repository;
}

View File

@ -80,6 +80,7 @@ public class Wallet {
public void addNewAccount() {
Account account = new Account();
account.init();
String address = Hex.toHexString(account.getEcKey().getAddress());
rows.put(address, account);
for (WalletListener listener : listeners)