UncleBlocks bug - only headers should be parsed (not full blocks)

This commit is contained in:
romanman 2014-08-15 00:01:44 +03:00
parent 8cb39f2599
commit 87d07108e3
4 changed files with 25 additions and 13 deletions

View File

@ -49,7 +49,7 @@ public class Block {
private List<Transaction> transactionsList = new CopyOnWriteArrayList<Transaction>(); private List<Transaction> transactionsList = new CopyOnWriteArrayList<Transaction>();
/* Uncles */ /* Uncles */
private List<Block> uncleList = new CopyOnWriteArrayList<Block>(); private List<BlockHeader> uncleList = new CopyOnWriteArrayList<BlockHeader>();
/* Private */ /* Private */
@ -69,7 +69,7 @@ public class Block {
public Block(byte[] parentHash, byte[] unclesHash, byte[] coinbase, public Block(byte[] parentHash, byte[] unclesHash, byte[] coinbase,
byte[] difficulty, long number, long minGasPrice, long gasLimit, byte[] difficulty, long number, long minGasPrice, long gasLimit,
long gasUsed, long timestamp, byte[] extraData, byte[] nonce, long gasUsed, long timestamp, byte[] extraData, byte[] nonce,
List<Transaction> transactionsList, List<Block> uncleList) { List<Transaction> transactionsList, List<BlockHeader> uncleList) {
this.header = new BlockHeader(parentHash, unclesHash, coinbase, this.header = new BlockHeader(parentHash, unclesHash, coinbase,
difficulty, number, minGasPrice, gasLimit, gasUsed, difficulty, number, minGasPrice, gasLimit, gasUsed,
timestamp, extraData, nonce); timestamp, extraData, nonce);
@ -81,7 +81,7 @@ public class Block {
this.uncleList = uncleList; this.uncleList = uncleList;
if (this.uncleList == null){ if (this.uncleList == null){
this.uncleList = new CopyOnWriteArrayList<Block>(); this.uncleList = new CopyOnWriteArrayList<BlockHeader>();
} }
this.parsed = true; this.parsed = true;
@ -103,7 +103,9 @@ public class Block {
// Parse Uncles // Parse Uncles
RLPList uncleBlocks = (RLPList) block.get(2); RLPList uncleBlocks = (RLPList) block.get(2);
for (RLPElement rawUncle : uncleBlocks) { for (RLPElement rawUncle : uncleBlocks) {
Block blockData = new Block(rawUncle.getRLPData());
RLPList uncleHeader = (RLPList) rawUncle;
BlockHeader blockData = new BlockHeader(uncleHeader);
this.uncleList.add(blockData); this.uncleList.add(blockData);
} }
this.parsed = true; this.parsed = true;
@ -207,7 +209,7 @@ public class Block {
return txReceiptList; return txReceiptList;
} }
public List<Block> getUncleList() { public List<BlockHeader> getUncleList() {
if (!parsed) parseRLP(); if (!parsed) parseRLP();
return uncleList; return uncleList;
} }
@ -219,9 +221,11 @@ public class Block {
@Override @Override
public String toString() { public String toString() {
if (!parsed) parseRLP(); if (!parsed) parseRLP();
toStringBuff.setLength(0); toStringBuff.setLength(0);
toStringBuff.append(Hex.toHexString(this.rlpEncoded)).append("\n");
toStringBuff.append("BlockData [\n"); toStringBuff.append("BlockData [\n");
toStringBuff.append(" hash=" + ByteUtil.toHexString(this.getHash())).append("\n"); toStringBuff.append(" hash=" + ByteUtil.toHexString(this.getHash())).append("\n");
toStringBuff.append(header.toString()); toStringBuff.append(header.toString());

View File

@ -202,7 +202,7 @@ public class Blockchain {
repository.createAccount(block.getCoinbase()); repository.createAccount(block.getCoinbase());
repository.addBalance(block.getCoinbase(), Block.BLOCK_REWARD); repository.addBalance(block.getCoinbase(), Block.BLOCK_REWARD);
for (Block uncle : block.getUncleList()) { for (BlockHeader uncle : block.getUncleList()) {
repository.addBalance(uncle.getCoinbase(), Block.UNCLE_REWARD); repository.addBalance(uncle.getCoinbase(), Block.UNCLE_REWARD);
} }
} }
@ -217,7 +217,7 @@ public class Blockchain {
logger.error("ERROR: STATE CONFLICT! block: {} worldstate {} mismatch", block.getNumber(), worldStateRootHash); logger.error("ERROR: STATE CONFLICT! block: {} worldstate {} mismatch", block.getNumber(), worldStateRootHash);
// Last conflict on block 1501 -> worldstate 27920c6c7acd42c8a7ac8a835d4c0e0a45590deb094d6b72a8493fac5d7a3654 // Last conflict on block 1501 -> worldstate 27920c6c7acd42c8a7ac8a835d4c0e0a45590deb094d6b72a8493fac5d7a3654
// repository.close(); // repository.close();
// System.exit(-1); // Don't add block // System.exit(-1); // Don't add block
} }
} }

View File

@ -456,6 +456,8 @@ public class MessagesTest {
@Test /* Block msg decode - found bug tool */ @Test /* Block msg decode - found bug tool */
public void test17() throws URISyntaxException, IOException { public void test17() throws URISyntaxException, IOException {
// f8b3a014d130c317eb9440123b1db01bfb1f2e081d83200216bc032d7de2fc9ff3b46ba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794e559de5527492bcb42ec68d07df0742a98ec3f1ea063bb3d8f8428483b2dfd838bef3e7fba6df53fd088f176a4831065f36b93346a808372c7b0821e448609184e72a0008301e848808453c9b36980a078cc350ffafd409d918e0a015dcfa0bddeec4637fe266da36298577aa13173ad
URL rlpMsg_1 = ClassLoader URL rlpMsg_1 = ClassLoader
.getSystemResource("rlp/rlp-msg-1.dmp"); .getSystemResource("rlp/rlp-msg-1.dmp");
@ -463,16 +465,22 @@ public class MessagesTest {
byte[] strData = Files.readAllBytes(file.toPath()); byte[] strData = Files.readAllBytes(file.toPath());
byte[] data = Hex.decode(new String(strData)); byte[] data = Hex.decode(new String(strData));
RLPList rlpList = RLP.decode2(data); BlocksMessage msg = new BlocksMessage(data);
int size = msg.getBlockDataList().size();
for (int i = 0; i < size; ++i){
BlocksMessage msg = new BlocksMessage(rlpList); Block block = msg.getBlockDataList().get(i);
msg.getBlockDataList().get(0);
int unclesSize = block.getUncleList().size();
for (int j = 0; j < unclesSize; ++j){
System.out.println(msg); System.out.println("*** uncle: " + Hex.toHexString( block.getUncleList().get(j).getCoinbase() ));
}
System.out.println(block);
System.out.println("===============================");
}
} }
} }

File diff suppressed because one or more lines are too long