mirror of
https://github.com/status-im/ethereumj-personal.git
synced 2025-02-27 03:00:28 +00:00
UncleBlocks bug - only headers should be parsed (not full blocks)
This commit is contained in:
parent
8cb39f2599
commit
87d07108e3
@ -49,7 +49,7 @@ public class Block {
|
||||
private List<Transaction> transactionsList = new CopyOnWriteArrayList<Transaction>();
|
||||
|
||||
/* Uncles */
|
||||
private List<Block> uncleList = new CopyOnWriteArrayList<Block>();
|
||||
private List<BlockHeader> uncleList = new CopyOnWriteArrayList<BlockHeader>();
|
||||
|
||||
/* Private */
|
||||
|
||||
@ -69,7 +69,7 @@ public class Block {
|
||||
public Block(byte[] parentHash, byte[] unclesHash, byte[] coinbase,
|
||||
byte[] difficulty, long number, long minGasPrice, long gasLimit,
|
||||
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,
|
||||
difficulty, number, minGasPrice, gasLimit, gasUsed,
|
||||
timestamp, extraData, nonce);
|
||||
@ -81,7 +81,7 @@ public class Block {
|
||||
this.uncleList = uncleList;
|
||||
if (this.uncleList == null){
|
||||
|
||||
this.uncleList = new CopyOnWriteArrayList<Block>();
|
||||
this.uncleList = new CopyOnWriteArrayList<BlockHeader>();
|
||||
}
|
||||
|
||||
this.parsed = true;
|
||||
@ -103,7 +103,9 @@ public class Block {
|
||||
// Parse Uncles
|
||||
RLPList uncleBlocks = (RLPList) block.get(2);
|
||||
for (RLPElement rawUncle : uncleBlocks) {
|
||||
Block blockData = new Block(rawUncle.getRLPData());
|
||||
|
||||
RLPList uncleHeader = (RLPList) rawUncle;
|
||||
BlockHeader blockData = new BlockHeader(uncleHeader);
|
||||
this.uncleList.add(blockData);
|
||||
}
|
||||
this.parsed = true;
|
||||
@ -207,7 +209,7 @@ public class Block {
|
||||
return txReceiptList;
|
||||
}
|
||||
|
||||
public List<Block> getUncleList() {
|
||||
public List<BlockHeader> getUncleList() {
|
||||
if (!parsed) parseRLP();
|
||||
return uncleList;
|
||||
}
|
||||
@ -219,9 +221,11 @@ public class Block {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
|
||||
toStringBuff.setLength(0);
|
||||
toStringBuff.append(Hex.toHexString(this.rlpEncoded)).append("\n");
|
||||
toStringBuff.append("BlockData [\n");
|
||||
toStringBuff.append(" hash=" + ByteUtil.toHexString(this.getHash())).append("\n");
|
||||
toStringBuff.append(header.toString());
|
||||
|
@ -202,7 +202,7 @@ public class Blockchain {
|
||||
repository.createAccount(block.getCoinbase());
|
||||
repository.addBalance(block.getCoinbase(), Block.BLOCK_REWARD);
|
||||
|
||||
for (Block uncle : block.getUncleList()) {
|
||||
for (BlockHeader uncle : block.getUncleList()) {
|
||||
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);
|
||||
// Last conflict on block 1501 -> worldstate 27920c6c7acd42c8a7ac8a835d4c0e0a45590deb094d6b72a8493fac5d7a3654
|
||||
// repository.close();
|
||||
// System.exit(-1); // Don't add block
|
||||
// System.exit(-1); // Don't add block
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -456,6 +456,8 @@ public class MessagesTest {
|
||||
@Test /* Block msg decode - found bug tool */
|
||||
public void test17() throws URISyntaxException, IOException {
|
||||
|
||||
// f8b3a014d130c317eb9440123b1db01bfb1f2e081d83200216bc032d7de2fc9ff3b46ba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794e559de5527492bcb42ec68d07df0742a98ec3f1ea063bb3d8f8428483b2dfd838bef3e7fba6df53fd088f176a4831065f36b93346a808372c7b0821e448609184e72a0008301e848808453c9b36980a078cc350ffafd409d918e0a015dcfa0bddeec4637fe266da36298577aa13173ad
|
||||
|
||||
URL rlpMsg_1 = ClassLoader
|
||||
.getSystemResource("rlp/rlp-msg-1.dmp");
|
||||
|
||||
@ -463,16 +465,22 @@ public class MessagesTest {
|
||||
byte[] strData = Files.readAllBytes(file.toPath());
|
||||
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);
|
||||
msg.getBlockDataList().get(0);
|
||||
Block block = msg.getBlockDataList().get(i);
|
||||
|
||||
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
Loading…
x
Reference in New Issue
Block a user