Skip to content

Commit

Permalink
Merge branch 'develop' into research/sharding
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalinin committed Aug 30, 2018
2 parents 25b1b6c + 5474319 commit 2e07679
Show file tree
Hide file tree
Showing 65 changed files with 4,533 additions and 3,534 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,16 @@ String validateTransactionChanges(BlockStore blockStore, Block curBlock, Transac
* Replaces the intermediate state root field of the receipt with the status
*/
boolean eip658();

/**
* EIP145: https://eips.ethereum.org/EIPS/eip-145
* Bitwise shifting instructions in EVM
*/
boolean eip145();

/**
* EIP1052: https://eips.ethereum.org/EIPS/eip-1052
* EXTCODEHASH opcode
*/
boolean eip1052();
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ protected RocksDbDataSource rocksDbDataSource() {
}

public void fastSyncCleanUp() {
if (!systemProperties().isSyncEnabled()) return;
byte[] fastsyncStageBytes = blockchainDB().get(FastSyncManager.FASTSYNC_DB_KEY_SYNC_STAGE);
if (fastsyncStageBytes == null) return; // no uncompleted fast sync
if (!systemProperties().blocksLoader().isEmpty()) return; // blocks loader enabled
Expand Down Expand Up @@ -256,9 +257,9 @@ public Source<byte[], ProgramPrecompile> precompileSource() {
return new SourceCodec<byte[], ProgramPrecompile, byte[], byte[]>(source,
new Serializer<byte[], byte[]>() {
public byte[] serialize(byte[] object) {
DataWord ret = new DataWord(object);
ret.add(new DataWord(1));
return ret.getLast20Bytes();
DataWord ret = DataWord.of(object);
DataWord addResult = ret.add(DataWord.ONE);
return addResult.getLast20Bytes();
}
public byte[] deserialize(byte[] stream) {
throw new RuntimeException("Shouldn't be called");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public DataWord getCallGas(OpCode op, DataWord requestedGas, DataWord availableG
if (requestedGas.compareTo(availableGas) > 0) {
throw Program.Exception.notEnoughOpGas(op, requestedGas, availableGas);
}
return requestedGas.clone();
return requestedGas;
}

@Override
Expand Down Expand Up @@ -193,6 +193,16 @@ public boolean eip658() {
return false;
}

@Override
public boolean eip1052() {
return false;
}

@Override
public boolean eip145() {
return false;
}

@Override
public String toString() {
return getClass().getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.config.blockchain;

import org.ethereum.config.BlockchainConfig;

/**
* EIPs included in the Constantinople Hard Fork:
* <ul>
* <li>145 - Bitwise shifting instructions in EVM</li>
* <li>1014 - Skinny CREATE2</li>
* <li>1052 - EXTCODEHASH opcode</li>
* <li>1087 - Net gas metering for SSTORE operations</li>
* </ul>
*/
public class ConstantinopleConfig extends ByzantiumConfig {

public ConstantinopleConfig(BlockchainConfig parent) {
super(parent);
}

@Override
public boolean eip1052() {
return true;
}

@Override
public boolean eip145() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,14 @@ public boolean eip214() {
public boolean eip658() {
return false;
}

@Override
public boolean eip145() {
return false;
}

@Override
public boolean eip1052() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public static TransactionTouchedStorage decodeTouchedStorage(RLPElement encoded)
for (RLPElement entry : (RLPList) encoded) {
RLPList asList = (RLPList) entry;

DataWord key = new DataWord(asList.get(0).getRLPData());
DataWord value = new DataWord(asList.get(1).getRLPData());
DataWord key = DataWord.of(asList.get(0).getRLPData());
DataWord value = DataWord.of(asList.get(1).getRLPData());
byte[] changedBytes = asList.get(2).getRLPData();
boolean changed = isNotEmpty(changedBytes) && RLP.decodeInt(changedBytes, 0) == 1;

Expand Down Expand Up @@ -184,8 +184,8 @@ private static byte[] encodeStorageDiff(Map<DataWord, DataWord> storageDiff) {
private static Map<DataWord, DataWord> decodeStorageDiff(RLPList storageDiff) {
Map<DataWord, DataWord> result = new HashMap<>();
for (RLPElement entry : storageDiff) {
DataWord key = new DataWord(((RLPList) entry).get(0).getRLPData());
DataWord value = new DataWord(((RLPList) entry).get(1).getRLPData());
DataWord key = DataWord.of(((RLPList) entry).get(0).getRLPData());
DataWord value = DataWord.of(((RLPList) entry).get(1).getRLPData());
result.put(key, value);
}
return result;
Expand Down Expand Up @@ -222,7 +222,7 @@ private static byte[] encodeDeletedAccounts(List<DataWord> deletedAccounts) {
private static List<DataWord> decodeDeletedAccounts(RLPList deletedAccounts) {
List<DataWord> result = new ArrayList<>();
for (RLPElement deletedAccount : deletedAccounts) {
result.add(new DataWord(deletedAccount.getRLPData()));
result.add(DataWord.of(deletedAccount.getRLPData()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void call() {
if (!readyToExecute) return;

byte[] targetAddress = tx.getReceiveAddress();
precompiledContract = PrecompiledContracts.getContractForAddress(new DataWord(targetAddress), blockchainConfig);
precompiledContract = PrecompiledContracts.getContractForAddress(DataWord.of(targetAddress), blockchainConfig);

if (precompiledContract != null) {
long requiredGas = precompiledContract.getGasForData(tx.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
import static org.ethereum.crypto.HashUtil.sha3;

/**
* Composes keys for contract storage nodes. <br/><br/>
* Composes keys for contract storage nodes.
*
* <b>Input:</b> 32-bytes node key, 20-bytes contract address <br/>
* <b>Output:</b> 32-bytes composed key <i>[first 16-bytes of node key : first 16-bytes of address hash]</i> <br/><br/>
* <p>
* <b>Input:</b> 32-bytes node key, 20-bytes contract address
* <br/>
* <b>Output:</b> 32-bytes composed key <i>[first 16-bytes of node key : first 16-bytes of address hash]</i>
*
* Example: <br/>
* Contract address hash <i>a9539c810cc2e8fa20785bdd78ec36ccb25e1b5be78dbadf6c4e817c6d170bbb</i> <br/>
* Key of one of the storage nodes <i>bbbbbb5be78dbadf6c4e817c6d170bbb47e9916f8f6cc4607c5f3819ce98497b</i> <br/>
* Composed key will be <i>a9539c810cc2e8fa20785bdd78ec36ccbbbbbb5be78dbadf6c4e817c6d170bbb</i> <br/><br/>
* <p>
* Example: <br/>
* Contract address hash <i>a9539c810cc2e8fa20785bdd78ec36ccb25e1b5be78dbadf6c4e817c6d170bbb</i> <br/>
* Key of one of the storage nodes <i>bbbbbb5be78dbadf6c4e817c6d170bbb47e9916f8f6cc4607c5f3819ce98497b</i> <br/>
* Composed key will be <i>bbbbbb5be78dbadf6c4e817c6d170bbba9539c810cc2e8fa20785bdd78ec36cc</i>
*
* This mechanism is a part of flat storage source which is free from reference counting
* <p>
* This mechanism is a part of flat storage source which is free from reference counting
*
* @see CommonConfig#trieNodeSource()
* @see RepositoryRoot#RepositoryRoot(Source, byte[])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public byte[] serialize(DataWord object) {

@Override
public DataWord deserialize(byte[] stream) {
return new DataWord(stream);
return DataWord.of(stream);
}
};

Expand All @@ -86,7 +86,7 @@ public byte[] serialize(DataWord object) {
public DataWord deserialize(byte[] stream) {
if (stream == null || stream.length == 0) return null;
byte[] dataDecoded = RLP.decode2(stream).get(0).getRLPData();
return new DataWord(dataDecoded);
return DataWord.of(dataDecoded);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public synchronized void saveCode(byte[] addr, byte[] code) {
@Override
public synchronized byte[] getCode(byte[] addr) {
byte[] codeHash = getCodeHash(addr);
return FastByteComparisons.equal(codeHash, HashUtil.EMPTY_DATA_HASH) ?
return codeHash == null || FastByteComparisons.equal(codeHash, HashUtil.EMPTY_DATA_HASH) ?
ByteUtil.EMPTY_BYTE_ARRAY : codeCache.get(codeKey(codeHash, addr));
}

Expand All @@ -147,7 +147,7 @@ private byte[] codeKey(byte[] codeHash, byte[] addr) {
@Override
public byte[] getCodeHash(byte[] addr) {
AccountState accountState = getAccountState(addr);
return accountState != null ? accountState.getCodeHash() : HashUtil.EMPTY_DATA_HASH;
return accountState != null ? accountState.getCodeHash() : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public boolean matchesExactly(LogInfo logInfo) {
boolean orMatches = false;
DataWord logTopic = logTopics.get(i);
for (byte[] orTopic : orTopics) {
if (new DataWord(orTopic).equals(logTopic)) {
if (DataWord.of(orTopic).equals(logTopic)) {
orMatches = true;
break;
}
Expand Down
8 changes: 7 additions & 1 deletion ethereumj-core/src/main/java/org/ethereum/net/rlpx/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public Node(byte[] id, String host, int port) {
this.port = port;
}

/**
* Instantiates node from RLP list containing node data.
* @throws IllegalArgumentException if node id is not a valid EC point.
*/
public Node(RLPList nodeRLP) {
byte[] hostB = nodeRLP.get(0).getRLPData();
byte[] portB = nodeRLP.get(1).getRLPData();
Expand All @@ -100,7 +104,9 @@ public Node(RLPList nodeRLP) {

this.host = bytesToIp(hostB);
this.port = port;
this.id = idB;

// a tricky way to check whether given data is a valid EC point or not
this.id = ECKey.fromNodeId(idB).getNodeId();
}

public Node(byte[] rlp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception {

@Override
public void channelRead0(ChannelHandlerContext ctx, DiscoveryEvent event) throws Exception {
nodeManager.handleInbound(event);
try {
nodeManager.handleInbound(event);
} catch (Throwable t) {
logger.info("Failed to process incoming message: {}, caused by: {}", event.getMessage(), t.toString());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public enum State {
boolean waitForPong = false;
long pingSent;
int pingTrials = 3;
boolean waitForNeighbors = false;
NodeHandler replaceCandidate;

public NodeHandler(Node node, NodeManager nodeManager) {
Expand Down Expand Up @@ -240,9 +241,12 @@ void handlePong(PongMessage msg) {
void handleNeighbours(NeighborsMessage msg) {
logMessage(msg, true);
// logMessage(" ===> [NEIGHBOURS] " + this + ", Count: " + msg.getNodes().size());
getNodeStatistics().discoverInNeighbours.add();
for (Node n : msg.getNodes()) {
nodeManager.getNodeHandler(n);
if (waitForNeighbors) {
waitForNeighbors = false;
getNodeStatistics().discoverInNeighbours.add();
for (Node n : msg.getNodes()) {
nodeManager.getNodeHandler(n);
}
}
}

Expand Down Expand Up @@ -322,6 +326,7 @@ void sendFindNode(byte[] target) {
// logMessage("<=== [FIND_NODE] " + this);
Message findNode = FindNodeMessage.create(target, nodeManager.key);
logMessage(findNode, false);
waitForNeighbors = true;
sendMessage(findNode);
getNodeStatistics().discoverOutFind.add();
}
Expand All @@ -333,7 +338,7 @@ private void sendMessage(Message msg) {
@Override
public String toString() {
return "NodeHandler[state: " + state + ", node: " + node.getHost() + ":" + node.getPort() + ", id="
+ (node.getId().length > 0 ? Hex.toHexString(node.getId(), 0, 4) : "empty") + "]";
+ (node.getId().length >= 4 ? Hex.toHexString(node.getId(), 0, 4) : "empty") + "]";
}


Expand Down
9 changes: 3 additions & 6 deletions ethereumj-core/src/main/java/org/ethereum/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import javax.swing.*;

public class Utils {
private static final DataWord DIVISOR = new DataWord(64);
private static final DataWord DIVISOR = DataWord.of(64);

private static SecureRandom random = new SecureRandom();

Expand Down Expand Up @@ -230,11 +230,8 @@ public static List<ByteArrayWrapper> dumpKeys(DbSource<byte[]> ds) {
}

public static DataWord allButOne64th(DataWord dw) {
DataWord ret = dw.clone();
DataWord d = dw.clone();
d.div(DIVISOR);
ret.sub(d);
return ret;
DataWord divResult = dw.div(DIVISOR);
return dw.sub(divResult);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,12 @@ public SolidityStorageImpl(byte[] contractAddr) {

@Override
public byte[] getStorageSlot(long slot) {
return getStorageSlot(new DataWord(slot).getData());
return getStorageSlot(DataWord.of(slot).getData());
}

@Override
public byte[] getStorageSlot(byte[] slot) {
DataWord ret = getBlockchain().getRepository().getContractDetails(contractAddr).get(new DataWord(slot));
DataWord ret = getBlockchain().getRepository().getContractDetails(contractAddr).get(DataWord.of(slot));
return ret.getData();
}
}
Expand Down
Loading

0 comments on commit 2e07679

Please sign in to comment.