diff --git a/ethereumj-core/src/main/java/org/ethereum/config/blockchain/HomesteadDAOConfig.java b/ethereumj-core/src/main/java/org/ethereum/config/blockchain/HomesteadDAOConfig.java index ae6fd8a21d..3257196ab7 100644 --- a/ethereumj-core/src/main/java/org/ethereum/config/blockchain/HomesteadDAOConfig.java +++ b/ethereumj-core/src/main/java/org/ethereum/config/blockchain/HomesteadDAOConfig.java @@ -20,7 +20,7 @@ */ public class HomesteadDAOConfig extends HomesteadConfig { - public static final long DAO_RESCUE_BLOCK = 1_800_000; + public static final long DAO_RESCUE_BLOCK = 1_787_300; public static final long DAO_RESCUE_GAS_LIMIT_TRIGGER = 4_000_000; public static final byte[] DAO_CODE_HASH = Hex.decode("6a5d24750f78441e56fec050dc52fe8e911976485b7472faac7464a176a67caa"); public static final byte[][] WHITELISTED_RECIPIENTS = new byte[][] { @@ -87,7 +87,10 @@ public String validateTransactionChanges(BlockStore blockStore, Block curBlock, if (shouldRescueDAO(blockStore, curBlock)) { Set changedAddresses = repositoryTrack.getFullAddressSet(); for (ByteArrayWrapper address : changedAddresses) { - AccountState accountState = repositoryTrack.getOriginRepository().getAccountState(address.getData()); + AccountState accountState = repositoryTrack.getAccountState(address.getData()); + if (accountState == null) { + return null; + } byte[] codeHash = accountState.getCodeHash(); if (codeHash != null && FastByteComparisons.compareTo(daoCodeHash, 0, 32, codeHash, 0, 32) == 0) { BigInteger newBalance = repositoryTrack.getBalance(address.getData()); diff --git a/ethereumj-core/src/test/java/org/ethereum/core/DAORescueTest.java b/ethereumj-core/src/test/java/org/ethereum/core/DAORescueTest.java index 143a89dcc5..5bdd54d2a2 100644 --- a/ethereumj-core/src/test/java/org/ethereum/core/DAORescueTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/core/DAORescueTest.java @@ -7,6 +7,7 @@ import org.ethereum.config.blockchain.HomesteadDAOConfig; import org.ethereum.config.net.AbstractNetConfig; import org.ethereum.config.net.MainNetConfig; +import org.ethereum.crypto.ECKey; import org.ethereum.util.blockchain.SolidityContract; import org.ethereum.util.blockchain.StandaloneBlockchain; import org.ethereum.vm.program.Program; @@ -46,6 +47,11 @@ public BigInteger getMINIMUM_DIFFICULTY() { "function saveDao(address daoAddr) {" + " TestDAO(daoAddr).withdraw();" + "}" + + "}" + + "contract Suicide {" + + "function selfDestroy() {" + + " suicide(msg.sender);" + + "}" + "}"; @BeforeClass @@ -126,6 +132,24 @@ public void testForkAgreed() { Assert.assertEquals(BigInteger.valueOf(balance), bc.getBlockchain().getRepository().getBalance(dao.getAddress())); } + + ECKey rndReceiver = new ECKey(); + bc.sendEther(rndReceiver.getAddress(), BigInteger.valueOf(10000)); + bc.createBlock(); + Assert.assertEquals(BigInteger.valueOf(10000), + bc.getBlockchain().getRepository().getBalance(rndReceiver.getAddress())); + + SolidityContract suicide = bc.submitNewContract(daoEmulator, "Suicide"); + bc.createBlock(); + bc.sendEther(suicide.getAddress(), BigInteger.valueOf(10000)); + bc.createBlock(); + Assert.assertEquals(BigInteger.valueOf(10000), + bc.getBlockchain().getRepository().getBalance(suicide.getAddress())); + suicide.callFunction("selfDestroy"); + bc.createBlock(); + Assert.assertEquals(BigInteger.ZERO, + bc.getBlockchain().getRepository().getBalance(suicide.getAddress())); + } @Test