Skip to content

Commit

Permalink
merge freeze_account
Browse files Browse the repository at this point in the history
  • Loading branch information
darylccc committed Aug 4, 2023
1 parent 5823791 commit 59bc6a5
Show file tree
Hide file tree
Showing 25 changed files with 114 additions and 851 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,6 @@ 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,17 +113,6 @@ 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 @@ -640,8 +629,7 @@ 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();
setRawData(rawData);
this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
}

public long getExpiration() {
Expand All @@ -654,40 +642,26 @@ 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();
setRawData(rawData);
this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
}

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

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 @@ -713,7 +687,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(getTransactionId().getBytes())));
.signHash(getRawHash().getBytes())));
this.transaction = this.transaction.toBuilder().addSignature(sig).build();
}

Expand All @@ -737,7 +711,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.getTransactionId().getBytes(),
checkWeight(permission, this.transaction.getSignatureList(), this.getRawHash().getBytes(),
approveList);
if (approveList.contains(ByteString.copyFrom(address))) {
throw new PermissionException(encode58Check(address) + " had signed!");
Expand All @@ -752,7 +726,7 @@ public void addSign(byte[] privateKey, AccountStore accountStore)
}
// String signature = cryptoEngine.signHash(getRawHash().getBytes());
ByteString sig = ByteString.copyFrom(cryptoEngine.Base64toBytes(cryptoEngine
.signHash(getTransactionId().getBytes())));
.signHash(getRawHash().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 @@ -2264,7 +2238,7 @@ public boolean validatePubSignature(AccountStore accountStore,
throw new ValidateSignatureException("too many signatures");
}

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

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

public Sha256Hash getTransactionId() {
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;
return getRawHash();
}

public Sha256Hash getEthRlpDataHash(DynamicPropertiesStore dynamicPropertiesStore){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
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 @@ -31,7 +29,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 @@ -41,10 +39,6 @@ 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,14 +905,6 @@ 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 @@ -3276,36 +3268,6 @@ 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 @@ -3435,8 +3397,6 @@ 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,11 +46,6 @@ 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 @@ -265,12 +260,6 @@ 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 @@ -504,10 +493,6 @@ 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: 0 additions & 7 deletions common/src/main/java/org/vision/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,9 @@ 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 @@ -273,9 +269,6 @@ 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
5 changes: 2 additions & 3 deletions common/src/main/java/org/vision/core/config/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ 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_3_0(22, 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

@Getter
private int value;
Expand Down Expand Up @@ -55,7 +54,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 = 22;
public static final int BLOCK_VERSION = 21;
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
Loading

0 comments on commit 59bc6a5

Please sign in to comment.