Skip to content

Commit

Permalink
Merge branch 'test/4.2_case' of https://github.com/tronprotocol/java-…
Browse files Browse the repository at this point in the history
…tron into test/4.2_case
  • Loading branch information
MiraculousWang committed Apr 23, 2021
2 parents e7b89c0 + 037f254 commit 5ca0f26
Show file tree
Hide file tree
Showing 12 changed files with 3 additions and 111 deletions.
12 changes: 0 additions & 12 deletions actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,6 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case ALLOW_RECEIPTS_MERKLE_ROOT: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_2)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_RECEIPTS_MERKLE_ROOT]");
}
if (value != 1) {
throw new ContractValidateException(
"This value[ALLOW_RECEIPTS_MERKLE_ROOT] is only allowed to be 1");
}
break;
}
case ALLOW_NEW_RESOURCE_MODEL: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_2)) {
throw new ContractValidateException(
Expand Down Expand Up @@ -541,7 +530,6 @@ public enum ProposalType { // current value, value range
MAX_FEE_LIMIT(47), // [0, 10_000_000_000]
ALLOW_TRANSACTION_FEE_POOL(48), // 0, 1
ALLOW_BLACKHOLE_OPTIMIZATION(49),// 0,1
ALLOW_RECEIPTS_MERKLE_ROOT(50),// 0,1
ALLOW_NEW_RESOURCE_MODEL(51),// 0,1
ALLOW_TVM_FREEZE(52); // 0, 1

Expand Down
30 changes: 0 additions & 30 deletions chainbase/src/main/java/org/tron/core/capsule/BlockCapsule.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,30 +224,6 @@ public void setMerkleRoot() {
this.block.getBlockHeader().toBuilder().setRawData(blockHeaderRaw)).build();
}

public Sha256Hash calcReceiptsRoot() {
List<Transaction> transactionsList = this.block.getTransactionsList();

if (CollectionUtils.isEmpty(transactionsList)) {
return Sha256Hash.ZERO_HASH;
}

ArrayList<Sha256Hash> ids = transactionsList.stream()
.map(TransactionCapsule::new)
.map(TransactionCapsule::getReceiptsMerkleHash)
.collect(Collectors.toCollection(ArrayList::new));

return MerkleTree.getInstance().createTree(ids).getRoot().getHash();
}

public void setReceiptsRoot() {
BlockHeader.raw blockHeaderRaw =
this.block.getBlockHeader().getRawData().toBuilder()
.setReceiptsRoot(calcReceiptsRoot().getByteString()).build();

this.block = this.block.toBuilder().setBlockHeader(
this.block.getBlockHeader().toBuilder().setRawData(blockHeaderRaw)).build();
}

public void setAccountStateRoot(byte[] root) {
BlockHeader.raw blockHeaderRaw =
this.block.getBlockHeader().getRawData().toBuilder()
Expand All @@ -270,11 +246,6 @@ public void setWitness(String witness) {
public Sha256Hash getMerkleRoot() {
return Sha256Hash.wrap(this.block.getBlockHeader().getRawData().getTxTrieRoot());
}
public Sha256Hash getReceiptsRoot() {
if (this.block.getBlockHeader().getRawData().getReceiptsRoot().isEmpty())
return Sha256Hash.ZERO_HASH;
return Sha256Hash.wrap(this.block.getBlockHeader().getRawData().getReceiptsRoot());
}

public Sha256Hash getAccountRoot() {
if (this.block.getBlockHeader().getRawData().getAccountStateRoot() != null
Expand Down Expand Up @@ -338,7 +309,6 @@ public String toString() {
toStringBuff.append("account root=").append(getAccountRoot()).append("\n");
if (!getTransactions().isEmpty()) {
toStringBuff.append("merkle root=").append(getMerkleRoot()).append("\n");
toStringBuff.append("receipt root=").append(getReceiptsRoot()).append("\n");
toStringBuff.append("txs size=").append(getTransactions().size()).append("\n");
} else {
toStringBuff.append("txs are empty\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,15 +524,6 @@ public Sha256Hash getMerkleHash() {
transBytes);
}

public Sha256Hash getReceiptsMerkleHash() {
if (this.transaction.getRetCount() <= 0) {
return Sha256Hash.ZERO_HASH;
}
byte[] transBytes = this.transaction.getRet(0).toByteArray();
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
transBytes);
}

private Sha256Hash getRawHash() {
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
this.transaction.getRawData().toByteArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
private static final byte[] MAX_FEE_LIMIT = "MAX_FEE_LIMIT".getBytes();
private static final byte[] BURN_TRX_AMOUNT = "BURN_TRX_AMOUNT".getBytes();
private static final byte[] ALLOW_BLACKHOLE_OPTIMIZATION = "ALLOW_BLACKHOLE_OPTIMIZATION".getBytes();
private static final byte[] ALLOW_RECEIPTS_MERKLE_ROOT = "ALLOW_RECEIPTS_MERKLE_ROOT".getBytes();
private static final byte[] ALLOW_NEW_RESOURCE_MODEL = "ALLOW_NEW_RESOURCE_MODEL".getBytes();
private static final byte[] ALLOW_TVM_FREEZE = "ALLOW_TVM_FREEZE".getBytes();

Expand Down Expand Up @@ -745,13 +744,6 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
this.saveAllowNewResourceModel(CommonParameter.getInstance().getAllowNewResourceModel());
}


try {
this.getAllowReceiptsMerkleRoot();
} catch (IllegalArgumentException e) {
this.saveAllowReceiptsMerkleRoot(CommonParameter.getInstance().getAllowReceiptsMerkleRoot());
}

try {
this.getAllowTvmFreeze();
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -2233,23 +2225,6 @@ public long getAllowNewResourceModel() {
() -> new IllegalArgumentException("not found ALLOW_NEW_RESOURCE_MODEL"));
}

public void saveAllowReceiptsMerkleRoot(long value) {
this.put(ALLOW_RECEIPTS_MERKLE_ROOT, new BytesCapsule(ByteArray.fromLong(value)));
}

public long getAllowReceiptsMerkleRoot() {
return Optional.ofNullable(getUnchecked(ALLOW_RECEIPTS_MERKLE_ROOT))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElseThrow(
() -> new IllegalArgumentException("not found ALLOW_RECEIPTS_MERKLE_ROOT")
);
}

public boolean allowReceiptsMerkleRoot() {
return getAllowReceiptsMerkleRoot() == 1L;
}

public void saveAllowTvmFreeze(long allowTvmFreeze) {
this.put(DynamicPropertiesStore.ALLOW_TVM_FREEZE,
new BytesCapsule(ByteArray.fromLong(allowTvmFreeze)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,6 @@ public class CommonParameter {
@Setter
public long allowNewResourceModel;

@Getter
@Setter
public long allowReceiptsMerkleRoot;

// @Getter
// @Setter
// public long allowShieldedTransaction; //committee parameter
Expand Down
5 changes: 0 additions & 5 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1002,11 +1002,6 @@ public Protocol.ChainParameters getChainParameters() {
.setKey("getAllowNewResourceModel")
.setValue(dbManager.getDynamicPropertiesStore().getAllowNewResourceModel())
.build());

builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
.setKey("getAllowReceiptsMerkleRoot")
.setValue(dbManager.getDynamicPropertiesStore().getAllowReceiptsMerkleRoot())
.build());

builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
.setKey("getAllowTvmFreeze")
Expand Down
4 changes: 0 additions & 4 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,6 @@ public static void setParam(final String[] args, final String confFileName) {
config.hasPath(Constant.COMMITTEE_ALLOW_NEW_RESOURCE_MODEL) ? config
.getInt(Constant.COMMITTEE_ALLOW_NEW_RESOURCE_MODEL) : 0;

PARAMETER.allowReceiptsMerkleRoot =
config.hasPath(Constant.COMMITTEE_ALLOW_RECEIPTS_MERKLE_ROOT) ? config
.getInt(Constant.COMMITTEE_ALLOW_RECEIPTS_MERKLE_ROOT) : 0;

PARAMETER.allowTvmIstanbul =
config.hasPath(Constant.COMMITTEE_ALLOW_TVM_ISTANBUL) ? config
.getInt(Constant.COMMITTEE_ALLOW_TVM_ISTANBUL) : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
manager.getDynamicPropertiesStore().saveAllowBlackHoleOptimization(entry.getValue());
break;
}
case ALLOW_RECEIPTS_MERKLE_ROOT: {
manager.getDynamicPropertiesStore().saveAllowReceiptsMerkleRoot(entry.getValue());
break;
}
case ALLOW_NEW_RESOURCE_MODEL: {
manager.getDynamicPropertiesStore().saveAllowNewResourceModel(entry.getValue());
break;
Expand Down
14 changes: 0 additions & 14 deletions framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -946,17 +946,6 @@ public synchronized void pushBlock(final BlockCapsule block)
+ block.getMerkleRoot());
throw new BadBlockException("The merkle hash is not validated");
}
if (getDynamicPropertiesStore().allowReceiptsMerkleRoot()
&& !block.calcReceiptsRoot().equals(block.getReceiptsRoot())) {
logger.warn(
"The receipts merkle root doesn't match, Calc result is "
+ block.calcMerkleRoot()
+ " , the headers is "
+ block.getMerkleRoot());
throw new BadBlockException("The receipt merkle hash is not validated");
}


consensus.receiveBlock(block);
}

Expand Down Expand Up @@ -1317,9 +1306,6 @@ public synchronized BlockCapsule generateBlock(Miner miner, long blockTime, long
pendingTransactions.size(), rePushTransactions.size(), postponedTrxCount);

blockCapsule.setMerkleRoot();
if (getDynamicPropertiesStore().allowReceiptsMerkleRoot()) {
blockCapsule.setReceiptsRoot();
}
blockCapsule.sign(miner.getPrivateKey());

return blockCapsule;
Expand Down
4 changes: 2 additions & 2 deletions framework/src/main/java/org/tron/program/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class Version {

public static final String VERSION_NAME = "GreatVoyage-v4.1.1-2046-gc465c9ee4";
public static final String VERSION_CODE = "15262";
public static final String VERSION_NAME = "GreatVoyage-v4.1.2-43-gdceccc5dc";
public static final String VERSION_CODE = "15309";
private static final String VERSION = "4.2.0";

public static String getVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void test03GetBurnTrx() {
/**
* constructor.
*/
@Test(enabled = true, description = "Get receipt root by http")
@Test(enabled = false, description = "Get receipt root by http")
public void test04GetReceiptRootByHttp() {
response = HttpMethed.getBlockByNum(httpnode,sendcoinBlockNumber);
responseContent = HttpMethed.parseResponseContent(response);
Expand Down
1 change: 0 additions & 1 deletion protocol/src/main/protos/core/Tron.proto
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ message BlockHeader {
bytes witness_address = 9;
int32 version = 10;
bytes accountStateRoot = 11;
bytes receiptsRoot = 12;
}
raw raw_data = 1;
bytes witness_signature = 2;
Expand Down

0 comments on commit 5ca0f26

Please sign in to comment.