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+
}

0 commit comments

Comments
 (0)