Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 4de63de

Browse files
committed
Merge branch 'develop'
2 parents 1884df3 + 237259b commit 4de63de

File tree

13 files changed

+735
-28
lines changed

13 files changed

+735
-28
lines changed

ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,9 @@ public synchronized BlockSummary add(Repository repo, final Block block) {
562562
public synchronized BlockSummary addImpl(Repository repo, final Block block) {
563563

564564
if (exitOn < block.getNumber()) {
565-
System.out.print("Exiting after block.number: " + bestBlock.getNumber());
565+
String msg = String.format("Exiting after block.number: %d", bestBlock.getNumber());
566+
logger.info(msg);
567+
System.out.println(msg);
566568
dbFlushManager.flushSync();
567569
System.exit(-1);
568570
}

ethereumj-core/src/main/java/org/ethereum/core/Transaction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public byte[] getEncodedRaw() {
473473
return rlpRaw;
474474
}
475475

476-
public byte[] getEncoded() {
476+
public synchronized byte[] getEncoded() {
477477

478478
if (rlpEncoded != null) return rlpEncoded;
479479

ethereumj-core/src/main/java/org/ethereum/net/rlpx/discover/NodeManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public ScheduledExecutorService getPongTimer() {
117117
return pongTimer;
118118
}
119119

120-
void setBootNodes(List<Node> bootNodes) {
120+
public void setBootNodes(List<Node> bootNodes) {
121121
this.bootNodes = bootNodes;
122122
}
123123

ethereumj-core/src/main/java/org/ethereum/util/blockchain/StandaloneBlockchain.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.ethereum.config.blockchain.DaoNoHFConfig;
2626
import org.ethereum.config.blockchain.FrontierConfig;
2727
import org.ethereum.config.blockchain.HomesteadConfig;
28+
import org.ethereum.config.blockchain.PetersburgConfig;
2829
import org.ethereum.core.*;
2930
import org.ethereum.core.genesis.GenesisLoader;
3031
import org.ethereum.crypto.ECKey;
@@ -765,8 +766,8 @@ public synchronized void updateBatch(Map<byte[], byte[]> rows) {
765766
}
766767

767768
// Override blockchain net config for fast mining
768-
public static ByzantiumConfig getEasyMiningConfig() {
769-
return new ByzantiumConfig(new DaoNoHFConfig(new HomesteadConfig(new HomesteadConfig.HomesteadConstants() {
769+
public static PetersburgConfig getEasyMiningConfig() {
770+
return new PetersburgConfig(new DaoNoHFConfig(new HomesteadConfig(new HomesteadConfig.HomesteadConstants() {
770771
@Override
771772
public BigInteger getMINIMUM_DIFFICULTY() {
772773
return BigInteger.ONE;

ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -549,23 +549,24 @@ private void createContractImpl(DataWord value, byte[] programCode, byte[] newAd
549549
}
550550

551551
// 4. CREATE THE CONTRACT OUT OF RETURN
552-
byte[] code = result.getHReturn();
553-
554-
long storageCost = getLength(code) * getBlockchainConfig().getGasCost().getCREATE_DATA();
555-
long afterSpend = programInvoke.getGas().longValue() - storageCost - result.getGasUsed();
556-
if (afterSpend < 0) {
557-
if (!blockchainConfig.getConstants().createEmptyContractOnOOG()) {
558-
result.setException(Program.Exception.notEnoughSpendingGas("No gas to return just created contract",
552+
if (!result.isRevert() && result.getException() == null) {
553+
byte[] code = result.getHReturn();
554+
long storageCost = getLength(code) * getBlockchainConfig().getGasCost().getCREATE_DATA();
555+
long afterSpend = programInvoke.getGas().longValue() - result.getGasUsed() - storageCost;
556+
if (afterSpend < 0) {
557+
if (!blockchainConfig.getConstants().createEmptyContractOnOOG()) {
558+
result.setException(Program.Exception.notEnoughSpendingGas("No gas to return just created contract",
559+
storageCost, this));
560+
} else {
561+
track.saveCode(newAddress, EMPTY_BYTE_ARRAY);
562+
}
563+
} else if (getLength(code) > blockchainConfig.getConstants().getMAX_CONTRACT_SZIE()) {
564+
result.setException(Program.Exception.notEnoughSpendingGas("Contract size too large: " + getLength(result.getHReturn()),
559565
storageCost, this));
560566
} else {
561-
track.saveCode(newAddress, EMPTY_BYTE_ARRAY);
567+
result.spendGas(storageCost);
568+
track.saveCode(newAddress, code);
562569
}
563-
} else if (getLength(code) > blockchainConfig.getConstants().getMAX_CONTRACT_SZIE()) {
564-
result.setException(Program.Exception.notEnoughSpendingGas("Contract size too large: " + getLength(result.getHReturn()),
565-
storageCost, this));
566-
} else if (!result.isRevert()){
567-
result.spendGas(storageCost);
568-
track.saveCode(newAddress, code);
569570
}
570571

571572
getResult().merge(result);

ethereumj-core/src/main/resources/ethereumj.conf

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,25 @@ peer.discovery = {
2222
"52.74.57.123:30303",
2323

2424
# Parity discovery nodes
25+
"193.70.55.37:30303",
26+
"144.217.139.5:30303",
27+
"139.99.51.203:30303",
28+
"139.99.160.213:30303",
29+
"163.172.131.191:30303",
30+
"212.47.247.103:30303",
31+
"163.172.157.114:30303"
32+
"138.201.223.35:30303",
33+
"138.201.144.135:30303",
34+
"51.15.42.252:30303",
35+
"163.172.171.38:30303"
2536
"163.172.187.252:30303",
26-
"163.172.157.114:30303",
2737
"136.243.154.244:30303",
2838
"88.212.206.70:30303",
2939
"37.128.191.230:30303",
3040
"46.20.235.22:30303",
3141
"216.158.85.185:30303",
32-
"212.47.247.103:30303",
33-
"138.201.144.135:30303",
34-
"45.55.33.62:30303",
35-
"188.166.255.12:30303",
36-
"159.203.210.80:30303",
37-
"51.15.42.252:30303",
38-
"163.172.171.38:30303"
42+
"52.79.241.155:30303",
43+
"52.78.149.82:30303",
3944
]
4045

4146
# external IP/hostname which is reported as our host during discovery
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
versionNumber='1.11.0'
1+
versionNumber='1.12.0'
22
// Remove org.ethereum.db.migrate.MigrateHeaderSourceTotalDiff with databaseVersion > 6
33
databaseVersion=6
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.ethereum.core;
2+
3+
import org.ethereum.core.genesis.GenesisJson;
4+
import org.ethereum.core.genesis.GenesisLoader;
5+
import org.junit.Test;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import java.io.InputStream;
10+
import java.math.BigInteger;
11+
12+
import static org.junit.Assert.*;
13+
14+
/**
15+
* @author alexbraz
16+
* @since 29/03/2019
17+
*/
18+
public class ChainTest {
19+
20+
private static final Logger logger = LoggerFactory.getLogger("test");
21+
22+
Block genesis = GenesisLoader.loadGenesis(getClass().getResourceAsStream("/genesis/olympic.json"));
23+
GenesisJson genesisJson = GenesisLoader.loadGenesisJson((InputStream) getClass().getResourceAsStream("/genesis/olympic.json"));
24+
25+
@Test
26+
public void testContainsBlock() {
27+
Chain c = new Chain();
28+
c.add(genesis);
29+
assertEquals(genesis, c.getLast());
30+
}
31+
32+
@Test
33+
public void testBlockHashNotNull() {
34+
Chain c = new Chain();
35+
c.add(genesis);
36+
assertNotNull(c.getLast().getHash());
37+
}
38+
39+
@Test
40+
public void testDifficultyGenesisCorrectLoadedAndConverted() {
41+
Chain c = new Chain();
42+
c.add(genesis);
43+
assertEquals(new BigInteger(genesisJson.getDifficulty().replace("0x", ""), 16).intValue(), c.getLast().getDifficultyBI().intValue());
44+
}
45+
46+
@Test
47+
public void testParentOnTheChain() {
48+
Chain c = new Chain();
49+
c.add(genesis);
50+
Block block = new Block(genesis.getHeader(), genesis.getTransactionsList(), null);
51+
assertFalse(c.isParentOnTheChain(block));
52+
}
53+
54+
@Test
55+
public void testParentOnTheChain2() {
56+
Chain c = new Chain();
57+
c.add(genesis);
58+
assertFalse(c.isParentOnTheChain(genesis));
59+
}
60+
61+
62+
63+
64+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.ethereum.core;
2+
3+
import org.junit.Test;
4+
5+
import java.math.BigInteger;
6+
7+
import static org.junit.Assert.*;
8+
9+
/**
10+
* @author alexbraz
11+
* @since 29/03/2019
12+
*/
13+
public class PremineRawTest {
14+
15+
@Test
16+
public void testPremineRawNotNull() {
17+
18+
byte[] addr = "0xcf0f482f2c1ef1f221f09e3cf14122fce0424f94".getBytes();
19+
PremineRaw pr = new PremineRaw(addr, BigInteger.ONE, Denomination.ETHER);
20+
21+
assertTrue(pr.getDenomination() == Denomination.ETHER);
22+
assertEquals(pr.value, BigInteger.ONE);
23+
assertNotNull(pr.getAddr());
24+
}
25+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.ethereum.datasource;
2+
3+
import org.junit.Test;
4+
5+
import java.math.BigInteger;
6+
7+
import static org.junit.Assert.assertEquals;
8+
import static org.junit.Assert.assertTrue;
9+
import static org.mockito.Mockito.mock;
10+
11+
/**
12+
* @author alexbraz
13+
* @since 29/03/2019
14+
*/
15+
public class BatchSourceWriterTest {
16+
17+
@Test
18+
public void testFlush() {
19+
BatchSource batchSource = mock(BatchSource.class);
20+
BatchSourceWriter<String, BigInteger> bsw = new BatchSourceWriter(batchSource);
21+
bsw.put("KEY", BigInteger.ONE);
22+
assertTrue(bsw.flushImpl());
23+
}
24+
25+
@Test
26+
public void testValues() {
27+
BatchSource batchSource = mock(BatchSource.class);
28+
BatchSourceWriter<String, BigInteger> bsw = new BatchSourceWriter(batchSource);
29+
bsw.put("ONE", BigInteger.ONE);
30+
bsw.put("TEN", BigInteger.TEN);
31+
bsw.put("ZERO", BigInteger.ZERO);
32+
33+
bsw.buf.forEach((K, v) -> {
34+
assertEquals(v, bsw.buf.get(K));
35+
});
36+
37+
}
38+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package org.ethereum.datasource;
2+
3+
import org.ethereum.core.Block;
4+
import org.ethereum.core.Genesis;
5+
import org.ethereum.datasource.inmem.HashMapDB;
6+
import org.ethereum.db.IndexedBlockStore;
7+
import org.ethereum.db.TransactionStore;
8+
import org.ethereum.listener.BlockReplay;
9+
import org.ethereum.listener.EthereumListener;
10+
import org.junit.Before;
11+
import org.junit.Test;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
14+
import org.spongycastle.util.encoders.Hex;
15+
16+
import java.io.File;
17+
import java.io.IOException;
18+
import java.math.BigInteger;
19+
import java.net.URISyntaxException;
20+
import java.net.URL;
21+
import java.nio.charset.StandardCharsets;
22+
import java.nio.file.Files;
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
26+
import static java.math.BigInteger.ZERO;
27+
import static org.mockito.ArgumentMatchers.any;
28+
import static org.mockito.Mockito.*;
29+
30+
/**
31+
* @author alexbraz
32+
* @since 29/03/2019
33+
*/
34+
public class BlockReplayTest {
35+
private static final Logger logger = LoggerFactory.getLogger("test");
36+
37+
38+
BlockReplay replay;
39+
EthereumListener listener;
40+
private List<Block> blocks = new ArrayList<>();
41+
private BigInteger totDifficulty = ZERO;
42+
Block genesis = Genesis.getInstance();
43+
44+
@Before
45+
public void setup() throws URISyntaxException, IOException {
46+
URL scenario1 = ClassLoader
47+
.getSystemResource("blockstore/load.dmp");
48+
49+
File file = new File(scenario1.toURI());
50+
List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
51+
52+
IndexedBlockStore indexedBlockStore = indexedBlockStore = new IndexedBlockStore();
53+
indexedBlockStore.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
54+
55+
TransactionStore txStore = new TransactionStore(new HashMapDB<>());
56+
57+
listener = mock(EthereumListener.class);
58+
59+
replay = new BlockReplay(indexedBlockStore, txStore, listener, 0L);
60+
for (String blockRLP : strData) {
61+
62+
Block block = new Block(
63+
Hex.decode(blockRLP));
64+
65+
if (block.getNumber() % 1000 == 0)
66+
logger.info("adding block.hash: [{}] block.number: [{}]",
67+
block.getShortHash(),
68+
block.getNumber());
69+
70+
blocks.add(block);
71+
totDifficulty = totDifficulty.add(block.getDifficultyBI());
72+
indexedBlockStore.saveBlock(block, totDifficulty, true);
73+
}
74+
75+
}
76+
77+
@Test
78+
public void testReplayBlock() {
79+
IndexedBlockStore i = mock(IndexedBlockStore.class);
80+
when(i.getChainBlockByNumber(anyLong())).thenReturn(genesis);
81+
TransactionStore txStore = new TransactionStore(new HashMapDB<>());
82+
replay = new BlockReplay(i, txStore, listener, 0L);
83+
replay.replay();
84+
85+
verify(listener, times(1)).onBlock(any());
86+
}
87+
88+
@Test
89+
public void testListenerNoConnection() {
90+
replay.onNoConnections();
91+
verify(listener, times(1)).onNoConnections();
92+
93+
replay.onSyncDone(null);
94+
verify(listener, times(1)).onSyncDone(any());
95+
96+
replay.onNodeDiscovered(any());
97+
verify(listener, times(1)).onNodeDiscovered(any());
98+
99+
replay.onEthStatusUpdated(any(), any());
100+
verify(listener, times(1)).onEthStatusUpdated(any(), any());
101+
102+
replay.onHandShakePeer(any(), any());
103+
verify(listener, times(1)).onHandShakePeer(any(), any());
104+
105+
replay.onPeerAddedToSyncPool(any());
106+
verify(listener, times(1)).onPeerAddedToSyncPool(any());
107+
108+
replay.onPeerDisconnect(anyString(), anyLong());
109+
verify(listener, times(1)).onPeerDisconnect(anyString(), anyLong());
110+
111+
replay.onPendingStateChanged(any());
112+
verify(listener, times(1)).onPendingStateChanged(any());
113+
114+
replay.onPendingTransactionUpdate(any(), any(), any());
115+
verify(listener, times(1)).onPendingTransactionUpdate(any(), any(), any());
116+
117+
replay.onRecvMessage(any(), any());
118+
verify(listener, times(1)).onRecvMessage(any(), any());
119+
120+
replay.onTransactionExecuted(any());
121+
verify(listener, times(1)).onTransactionExecuted(any());
122+
123+
replay.onSendMessage(any(), any());
124+
verify(listener, times(1)).onSendMessage(any(), any());
125+
126+
replay.onVMTraceCreated(anyString(), anyString());
127+
verify(listener, times(1)).onVMTraceCreated(anyString(), anyString());
128+
129+
}
130+
131+
132+
133+
}

0 commit comments

Comments
 (0)