Skip to content

Commit

Permalink
Merge pull request #195 from vision-consensus/feature/mainnet_1.3.0
Browse files Browse the repository at this point in the history
merge Feature/mainnet 1.3.0 to master
  • Loading branch information
darylccc authored Sep 19, 2023
2 parents 1277e31 + 1c76a42 commit 90d7afe
Show file tree
Hide file tree
Showing 26 changed files with 1,482 additions and 732 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ public void addTransaction(TransactionCapsule pendingTrx) {
getTransactions().add(pendingTrx);
}

public void addAllTransactions(List<TransactionCapsule> pendingTrxs) {
List<Transaction> list = pendingTrxs.stream().map(TransactionCapsule::getInstance).collect(
Collectors.toList());
this.block = this.block.toBuilder().addAllTransactions(list).build();
getTransactions().addAll(pendingTrxs);
}

public List<TransactionCapsule> getTransactions() {
return transactions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ public class TransactionCapsule implements ProtoCapsule<Transaction> {

private byte[] ethRlpData;

private Sha256Hash id;

private byte[] ownerAddress;

public byte[] getOwnerAddress() {
if (this.ownerAddress == null) {
this.ownerAddress = getOwner(this.transaction.getRawData().getContract(0));
}
return this.ownerAddress;
}

/**
* constructor TransactionCapsule.
*/
Expand Down Expand Up @@ -629,7 +640,8 @@ public void setReference(long blockNum, byte[] blockHash) {
.setRefBlockHash(ByteString.copyFrom(ByteArray.subArray(blockHash, 8, 16)))
.setRefBlockBytes(ByteString.copyFrom(ByteArray.subArray(refBlockNum, 6, 8)))
.build();
this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
// this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
setRawData(rawData);
}

public long getExpiration() {
Expand All @@ -642,26 +654,40 @@ public long getExpiration() {
public void setExpiration(long expiration) {
Transaction.raw rawData = this.transaction.getRawData().toBuilder().setExpiration(expiration)
.build();
this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
// this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
setRawData(rawData);
}

public void setTimestamp() {
Transaction.raw rawData = this.transaction.getRawData().toBuilder()
.setTimestamp(System.currentTimeMillis())
.build();
this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
// this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
setRawData(rawData);
}
public void setTimestamp(long timestamp) {
Transaction.raw rawData = this.transaction.getRawData().toBuilder()
.setTimestamp(timestamp)
.build();
this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
// this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
setRawData(rawData);
}

public long getTimestamp() {
return transaction.getRawData().getTimestamp();
}

public void setFeeLimit(long feeLimit) {
Transaction.raw rawData = this.transaction.getRawData().toBuilder()
.setFeeLimit(feeLimit)
.build();
setRawData(rawData);
}

public long getFeeLimit() {
return transaction.getRawData().getFeeLimit();
}

@Deprecated
public void createTransaction(com.google.protobuf.Message message, ContractType contractType) {
Transaction.raw.Builder transactionBuilder = Transaction.raw.newBuilder().addContract(
Expand All @@ -687,7 +713,7 @@ public void sign(byte[] privateKey) {
// String signature = cryptoEngine.signHash(getRawHash().getBytes());
// ByteString sig = ByteString.copyFrom(signature.getBytes());
ByteString sig = ByteString.copyFrom(cryptoEngine.Base64toBytes(cryptoEngine
.signHash(getRawHash().getBytes())));
.signHash(getTransactionId().getBytes())));
this.transaction = this.transaction.toBuilder().addSignature(sig).build();
}

Expand All @@ -711,7 +737,7 @@ public void addSign(byte[] privateKey, AccountStore accountStore)
.fromPrivate(privateKey, CommonParameter.getInstance().isECKeyCryptoEngine());
byte[] address = cryptoEngine.getAddress();
if (this.transaction.getSignatureCount() > 0) {
checkWeight(permission, this.transaction.getSignatureList(), this.getRawHash().getBytes(),
checkWeight(permission, this.transaction.getSignatureList(), this.getTransactionId().getBytes(),
approveList);
if (approveList.contains(ByteString.copyFrom(address))) {
throw new PermissionException(encode58Check(address) + " had signed!");
Expand All @@ -726,7 +752,7 @@ public void addSign(byte[] privateKey, AccountStore accountStore)
}
// String signature = cryptoEngine.signHash(getRawHash().getBytes());
ByteString sig = ByteString.copyFrom(cryptoEngine.Base64toBytes(cryptoEngine
.signHash(getRawHash().getBytes())));
.signHash(getTransactionId().getBytes())));
this.transaction = this.transaction.toBuilder().addSignature(sig).build();
}
private static void checkPermission(int permissionId, Permission permission, Transaction.Contract contract) throws PermissionException {
Expand Down Expand Up @@ -2020,8 +2046,15 @@ public synchronized UnfreezeBalanceContract rlpParseToUnfreezeBalanceContract()
build.setReceiverAddress(ByteString.copyFrom(ByteArray.fromHexString(receiverAddress)));
}

if (dataValue.length() >= VALUE_SIZE * 3){ // unfreezeBalance(uint256,address,uint256[])
if (dataValue.length() >= VALUE_SIZE * 3){ // unfreezeBalance(uint256,address,uint256[]) || unfreezeBalance(uint256,address,uint256[],uint256)
int stageIndex = VALUE_SIZE * 3;

int stageArrIndex = ByteUtil.byteArrayToInt(ByteArray.fromHexString(dataValue.substring(VALUE_SIZE * 2, VALUE_SIZE * 3))) * 2;
if (stageArrIndex == VALUE_SIZE * 4) {
build.setUnfreezeBalance(ByteUtil.byteArrayToLong(ByteArray.fromHexString(dataValue.substring(stageIndex, stageIndex + VALUE_SIZE))));
stageIndex += VALUE_SIZE;
}

int stageSize = ByteUtil.byteArrayToInt(ByteArray.fromHexString(dataValue.substring(stageIndex, stageIndex + VALUE_SIZE)));
int index = 1;
int startIndex, endIndex;
Expand Down Expand Up @@ -2238,7 +2271,7 @@ public boolean validatePubSignature(AccountStore accountStore,
throw new ValidateSignatureException("too many signatures");
}

byte[] hash = this.getRawHash().getBytes();
byte[] hash = this.getTransactionId().getBytes();

try {
if (!validateSignature(this.transaction, hash, accountStore, dynamicPropertiesStore)) {
Expand Down Expand Up @@ -2507,7 +2540,16 @@ private int validateAccountUpdateContractSignature(AccountStore accountStore, Dy
}

public Sha256Hash getTransactionId() {
return getRawHash();
if (this.id == null) {
this.id = getRawHash();
}
return this.id;
}

private void setRawData(Transaction.raw rawData) {
this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
// invalidate trxId
this.id = null;
}

public Sha256Hash getEthRlpDataHash(DynamicPropertiesStore dynamicPropertiesStore){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.vision.core.capsule;

import com.google.protobuf.InvalidProtocolBufferException;

import java.util.List;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.vision.core.exception.BadItemException;
Expand Down Expand Up @@ -29,7 +31,7 @@ public TransactionRetCapsule() {

public TransactionRetCapsule(byte[] data) throws BadItemException {
try {
this.transactionRet = transactionRet.parseFrom(data);
this.transactionRet = TransactionRet.parseFrom(data);
} catch (InvalidProtocolBufferException e) {
throw new BadItemException("TransactionInfoCapsule proto data parse exception");
}
Expand All @@ -39,6 +41,10 @@ public void addTransactionInfo(TransactionInfo result) {
this.transactionRet = this.transactionRet.toBuilder().addTransactioninfo(result).build();
}

public void addAllTransactionInfos(List<TransactionInfo> results) {
this.transactionRet = this.transactionRet.toBuilder().addAllTransactioninfo(results).build();
}

@Override
public byte[] getData() {
if (Objects.isNull(transactionRet)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,14 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
this.saveVPFreezeStageWeight("1,30,100;2,60,110;3,90,120;4,180,130;5,360,150");
}

try {
this.getAllowOptimizedReturnValueOfChainId();
} catch (IllegalArgumentException e) {
this.saveAllowOptimizedReturnValueOfChainId(
CommonParameter.getInstance().getAllowOptimizedReturnValueOfChainId()
);
}

}

public String intArrayToString(int[] a) {
Expand Down Expand Up @@ -3268,6 +3276,36 @@ public Long getSeparateProposalStringParameters() {
.orElse(0L);
}

public void saveAllowUnfreezeFragmentation(Long value) {
this.put(DynamicResourceProperties.ALLOW_UNFREEZE_FRAGMENTATION,
new BytesCapsule(ByteArray.fromLong(value)));
}

public boolean supportUnfreezeFragmentation() {
return getAllowUnfreezeFragmentation() == 1L;
}

public Long getAllowUnfreezeFragmentation() {
return Optional.ofNullable(getUnchecked(DynamicResourceProperties.ALLOW_UNFREEZE_FRAGMENTATION))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElse(0L);
}

public void saveAllowOptimizedReturnValueOfChainId(long value) {
this.put(DynamicResourceProperties.ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID,
new BytesCapsule(ByteArray.fromLong(value)));
}

public long getAllowOptimizedReturnValueOfChainId() {
String msg = "not found ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID";
return Optional.ofNullable(getUnchecked(DynamicResourceProperties.ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElseThrow(
() -> new IllegalArgumentException(msg));
}

public void burnSpreadAmount(long amount) {
if (amount <= 0) return;
long burn = getBurnSpreadAmount();
Expand Down Expand Up @@ -3397,6 +3435,8 @@ private static class DynamicResourceProperties {
private static final byte[] ALLOW_FREEZE_ACCOUNT = "ALLOW_FREEZE_ACCOUNT".getBytes();
private static final byte[] FREEZE_ACCOUNT_OWNER = "FREEZE_ACCOUNT_OWNER".getBytes();
private static final byte[] FREEZE_ACCOUNT_LIST = "FREEZE_ACCOUNT_LIST".getBytes();
public static final byte[] ALLOW_UNFREEZE_FRAGMENTATION = "ALLOW_UNFREEZE_FRAGMENTATION".getBytes();
private static final byte[] ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID = "ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID".getBytes();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class CommonParameter {
public boolean supportConstant = false;
@Getter
@Setter
@Parameter(names = {"--max-entropy-limit-for-constant"}, description = "Max entropy limit for "
+ "constant calling. (default: 100,000,000)")
public long maxEntropyLimitForConstant = 100_000_000L;
@Getter
@Setter
@Parameter(names = {"--debug"})
public boolean debug = false;
@Getter
Expand Down Expand Up @@ -260,6 +265,12 @@ public class CommonParameter {
public boolean walletExtensionApi;
@Getter
@Setter
public boolean estimateEntropy;
@Getter
@Setter
public int estimateEntropyMaxRetry;
@Getter
@Setter
public int backupPriority;
@Getter
@Setter
Expand Down Expand Up @@ -493,6 +504,10 @@ public class CommonParameter {
@Setter
public boolean jsonRpcFilterEnabled = true;

@Getter
@Setter
public long allowOptimizedReturnValueOfChainId = 0L;

private static double calcMaxTimeRatio() {
//return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1)));
return 5.0;
Expand Down
7 changes: 7 additions & 0 deletions common/src/main/java/org/vision/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ public class Constant {
public static final String LOCAL_WITNESS_ACCOUNT_ADDRESS = "localWitnessAccountAddress";
public static final String LOCAL_WITNESS_KEYSTORE = "localwitnesskeystore";
public static final String VM_SUPPORT_CONSTANT = "vm.supportConstant";
public static final String VM_MAX_ENTROPY_LIMIT_FOR_CONSTANT = "vm.maxEntropyLimitForConstant";
public static final String VM_MIN_TIME_RATIO = "vm.minTimeRatio";
public static final String VM_MAX_TIME_RATIO = "vm.maxTimeRatio";
public static final String VM_LONG_RUNNING_TIME = "vm.longRunningTime";
public static final String VM_ESTIMATE_ENTROPY = "vm.estimateEntropy";

public static final String VM_ESTIMATE_ENTROPY_MAX_RETRY = "vm.estimateEntropyMaxRetry";

public static final String ROCKSDB = "ROCKSDB";

Expand Down Expand Up @@ -269,6 +273,9 @@ public class Constant {

public static final String COMMITTEE_ALLOW_TRANSACTION_FEE_POOL = "committee.allowTransactionFeePool";
public static final String COMMITTEE_ALLOW_BLACK_HOLE_OPTIMIZATION = "committee.allowBlackHoleOptimization";
public static final String COMMITTEE_ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID =
"committee.allowOptimizedReturnValueOfChainId";

public static final String METRICS_STORAGE_ENABLE = "node.metrics.storageEnable";
public static final String METRICS_INFLUXDB_IP = "node.metrics.influxdb.ip";
public static final String METRICS_INFLUXDB_PORT = "node.metrics.influxdb.port";
Expand Down
8 changes: 6 additions & 2 deletions common/src/main/java/org/vision/core/config/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public class Parameter {
public enum ForkBlockVersionEnum {
ENTROPY_LIMIT(5, 0L, 0),
VERSION_1_0_0(20, 0L, 0),
VERSION_1_2_0(21, 1654444800000L, 80);//GMT 2022-06-06 00:00:00, 80 means 22 FV upgrade
VERSION_1_2_0(21, 1654444800000L, 80),//GMT 2022-06-06 00:00:00, 80 means 22 FV upgrade
VERSION_1_3_0(22, 1654444800000L, 80);//GMT 2022-06-06 00:00:00, 80 means 22 FV upgrade

@Getter
private int value;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class ChainConstant {
public static final int SINGLE_REPEAT = 1;
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
public static final int MAX_FROZEN_NUMBER = 1;
public static final int BLOCK_VERSION = 21;
public static final int BLOCK_VERSION = 22;
public static final long FROZEN_PERIOD = 86_400_000L;
public static final long VS_PRECISION = 1000_000L;
public static final long UN_FREEZE_FVGUARANTEE_LIMIT = 23L;
Expand Down Expand Up @@ -148,6 +149,9 @@ public class NativeTransactionContractAbi {
public static final String UnfreezeBalanceStage = "unfreezeBalance(uint256,address,uint256[])"; // b1c68f74 3ec3afdfe31282ab0b2c9362ef7c5c113743ee22ae0697d1207a7c06
public static final String UnfreezeBalanceStage_FunctionSelector = "b1c68f74";

public static final String UnfreezeBalanceStageFragment = "unfreezeBalance(uint256,address,uint256[],uint256)"; // 4d639a82 79345b705fc5a9552f378ef0de3ecdf6163cd6e999898381c0c39942
public static final String UnfreezeBalanceStageFragment_FunctionSelector = "4d639a82";

public static final String WithdrawBalance = "withdrawBalance(uint256)"; // da76d5cd be3baa4ef4f3adb20b7af22c89bcd5dc86bb34ab804e6d35b15874d4
public static final String WithdrawBalance_FunctionSelector = "da76d5cd";

Expand Down
Loading

0 comments on commit 90d7afe

Please sign in to comment.