Transaction structure adapt for 0.7.8 and several bug fix

* it's possible now to have full block chain sync with 0.7.8 peer
This commit is contained in:
romanman 2014-11-03 10:59:17 -05:00
parent 60eb716383
commit 1a01f17f4c
6 changed files with 22 additions and 90 deletions

View File

@ -26,7 +26,7 @@
<property name="artifact.groupId" value="org.ethereum"/>
<property name="artifact.id" value="ethereumj"/>
<property name="artifact.version" value="0.7.2"/>
<property name="artifact.version" value="0.7.8"/>
<property name="artifact.path" value="" />
<property name="artifact.snapshot" value="snapshot" />

View File

@ -92,8 +92,8 @@ public class Block {
this.header = new BlockHeader(header);
// Parse Transactions
RLPList txReceipts = (RLPList) block.get(1);
this.parseTxs(this.header.getTxTrieRoot(), txReceipts);
RLPList txTransactions = (RLPList) block.get(1);
this.parseTxs(this.header.getTxTrieRoot(), txTransactions);
// Parse Uncles
RLPList uncleBlocks = (RLPList) block.get(2);
@ -272,43 +272,14 @@ public class Block {
return toStringBuff.toString();
}
public String toStylishString(){
if (!parsed) parseRLP();
toStringBuff.setLength(0);
toStringBuff.append("<font color=\"${header_color}\"> BlockData </font> [");
toStringBuff.append("<font color=\"${attribute_color}\">hash</font>=" +
ByteUtil.toHexString(this.getHash())).append("<br/>");
toStringBuff.append(header.toStylishString());
for (TransactionReceipt tx : getTxReceiptList()) {
toStringBuff.append("<br/>");
toStringBuff.append(tx.toStylishString());
toStringBuff.append("<br/>");
}
toStringBuff.append("]");
return toStringBuff.toString();
}
private void parseTxs(byte[] expectedRoot, RLPList txReceipts) {
private void parseTxs(byte[] expectedRoot, RLPList txTransactions) {
this.txsState = new TrieImpl(null);
for (int i = 0; i < txReceipts.size(); i++) {
RLPElement rlpTxReceipt = txReceipts.get(i);
RLPElement txData = ((RLPList)rlpTxReceipt).get(0);
// YP 4.3.1
RLPElement pstTxState = ((RLPList)rlpTxReceipt).get(1);
RLPElement cummGas = ((RLPList)rlpTxReceipt).get(2);
Transaction tx = new Transaction(txData.getRLPData());
this.transactionsList.add(tx);
TransactionReceipt txReceipt =
new TransactionReceipt(tx, pstTxState.getRLPData(), cummGas.getRLPData());
this.addTxReceipt(i, txReceipt);
for (int i = 0; i < txTransactions.size(); i++) {
RLPElement transactionRaw = txTransactions.get(i);
this.transactionsList.add(new Transaction(transactionRaw.getRLPData()));
this.txsState.update(RLP.encodeInt(i) , transactionRaw.getRLPData());
}
String calculatedRoot = Hex.toHexString(txsState.getRootHash());
@ -316,23 +287,7 @@ public class Block {
logger.error("Added tx receipts don't match the given txsStateRoot");
}
private void addTxReceipt(int counter, TransactionReceipt txReceipt) {
this.txReceiptList.add(txReceipt);
this.txsState.update(RLP.encodeInt(counter), txReceipt.getEncoded());
/* Figure out type of tx
* 1. Contract creation
* - perform code
* - create state object
* - add contract body to DB,
* 2. Contract call
* - perform code
* - update state object
* 3. Account to account -
* - update state object
*/
}
/**
* This mechanism enforces a homeostasis in terms of the time between blocks;
* a smaller period between the last two blocks results in an increase in the

View File

@ -5,6 +5,7 @@ import java.math.BigInteger;
import static org.ethereum.util.ByteUtil.*;
import org.ethereum.crypto.HashUtil;
import org.ethereum.crypto.SHA3Helper;
import org.ethereum.manager.WorldManager;
import org.ethereum.util.*;
import org.spongycastle.util.Arrays;
@ -69,6 +70,7 @@ public class BlockHeader {
private byte[] nonce;
public BlockHeader(RLPList rlpHeader) {
this.parentHash = ((RLPItem) rlpHeader.get(0)).getRLPData();
this.unclesHash = ((RLPItem) rlpHeader.get(1)).getRLPData();
this.coinbase = ((RLPItem) rlpHeader.get(2)).getRLPData();
@ -99,6 +101,7 @@ public class BlockHeader {
this.extraData = ((RLPItem) rlpHeader.get(13)).getRLPData();
this.nonce = ((RLPItem) rlpHeader.get(14)).getRLPData();
}
public BlockHeader(byte[] parentHash, byte[] unclesHash, byte[] coinbase,
@ -287,17 +290,11 @@ public class BlockHeader {
byte[] stateRoot = RLP.encodeElement(this.stateRoot);
if (this.txTrieRoot == null)
this.txTrieRoot = ByteUtil.EMTPY_TRIE_HASH;
byte[] txTrieRoot = RLP.encodeElement(this.txTrieRoot);
if (this.recieptTrieRoot == null)
this.recieptTrieRoot = ByteUtil.EMTPY_TRIE_HASH;
byte[] recieptTrieRoot = RLP.encodeElement(this.txTrieRoot);
if (txTrieRoot == null) this.txTrieRoot = ByteUtil.EMTPY_TRIE_HASH;
byte[] txTrieRoot = RLP.encodeElement(this.txTrieRoot);
if (recieptTrieRoot == null) this.recieptTrieRoot = ByteUtil.EMTPY_TRIE_HASH;
byte[] recieptTrieRoot = RLP.encodeElement(this.recieptTrieRoot);
byte[] logsBloom = RLP.encodeElement(this.logsBloom);
byte[] difficulty = RLP.encodeElement(this.difficulty);

View File

@ -213,21 +213,6 @@ public class Transaction {
"]";
}
public String toStylishString() {
if (!parsed) rlpParse();
return " <font color=\"${sub_header_color}\"> TransactionData </font>[" + "<font color=\"${attribute_color}\"> hash</font>=" + ByteUtil.toHexString(hash) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> nonce</font>=" + ByteUtil.toHexString(nonce) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> gasPrice</font>=" + ByteUtil.toHexString(gasPrice) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> gas</font>=" + ByteUtil.toHexString(gasLimit) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> receiveAddress</font>=" + ByteUtil.toHexString(receiveAddress) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> value</font>=" + ByteUtil.toHexString(value) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> data</font>=" + ByteUtil.toHexString(data) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> signatureV</font>=" + signature.v + "<br/>" +
"-> , <font color=\"${attribute_color}\"> signatureR</font>=" + ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.r)) + "<br/>" +
"-> , <font color=\"${attribute_color}\"> signatureS</font>=" + ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.s)) + "<br/>" +
" ]";
}
/**
* For signatures you have to keep also
* RLP of the transaction without any signature data

View File

@ -8,6 +8,10 @@ import org.spongycastle.util.encoders.Hex;
* comprising the transaction, together with the post-transaction state,
* and the cumulative gas used in the block containing the transaction receipt
* as of immediately after the transaction has happened,
*
* ** not todo: the transaction receipt was removed from the game but don't remove it
* as it will be used in the very near future.
*
*/
public class TransactionReceipt {
@ -54,13 +58,4 @@ public class TransactionReceipt {
']';
}
public String toStylishString() {
return "<font color=\"${sub_header_color}\"> TransactionReceipt</font>[" +
"<br/> " + transaction.toStylishString() +
"<br/> , <font color=\"${attribute_color}\">postTxState</font>=" + Hex.toHexString(postTxState) +
"<br/> , <font color=\"${attribute_color}\">cumulativeGas</font>=" + Hex.toHexString(cumulativeGas) +
']';
}
}

View File

@ -4,7 +4,7 @@
<groupId>org.ethereum</groupId>
<artifactId>ethereumj-studio</artifactId>
<packaging>jar</packaging>
<version>0.6.1</version>
<version>0.7.8</version>
<name>EthereumJ Studio</name>
<url>http://www.ethereumj.org</url>
@ -71,7 +71,7 @@
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj</artifactId>
<version>0.7.2.20141031.1029</version>
<version>0.7.8.20141103.1055</version>
</dependency>