Skip to content

Commit c5e62ed

Browse files
committed
Merge branch 'develop' of https://github.com/tronprotocol/java-tron into sync_restruct
2 parents 8f5c7ee + ac50c5a commit c5e62ed

133 files changed

Lines changed: 6035 additions & 787 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎build.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ dependencies {
169169
compile 'org.eclipse.jetty:jetty-server:9.4.11.v20180605'
170170
compile 'org.eclipse.jetty:jetty-servlet:9.4.11.v20180605'
171171
compile 'com.alibaba:fastjson:1.2.47'
172+
compile group: 'org.apache.httpcomponents', name:'httpasyncclient', version:'4.1.1'
172173
// end http
173174

174175
compile "io.vavr:vavr:0.9.2"

‎src/main/java/org/tron/core/Wallet.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public TransactionCapsule createTransactionCapsule(com.google.protobuf.Message m
399399
}
400400
trx.setReference(blockId.getNum(), blockId.getBytes());
401401
long expiration =
402-
dbManager.getHeadBlockTimeStamp() + Constant.TRANSACTION_DEFAULT_EXPIRATION_TIME;
402+
dbManager.getHeadBlockTimeStamp() + Args.getInstance().getTrxExpirationTimeInMilliseconds();
403403
trx.setExpiration(expiration);
404404
trx.setTimestamp();
405405
} catch (Exception e) {
@@ -881,6 +881,16 @@ public Protocol.ChainParameters getChainParameters() {
881881
.setValue(dbManager.getDynamicPropertiesStore().getTotalEnergyAverageUsage())
882882
.build());
883883

884+
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
885+
.setKey("getUpdateAccountPermissionFee")
886+
.setValue(dbManager.getDynamicPropertiesStore().getUpdateAccountPermissionFee())
887+
.build());
888+
889+
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
890+
.setKey("getMultiSignFee")
891+
.setValue(dbManager.getDynamicPropertiesStore().getMultiSignFee())
892+
.build());
893+
884894
return builder.build();
885895
}
886896

‎src/main/java/org/tron/core/actuator/AccountPermissionUpdateActuator.java‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.tron.core.capsule.TransactionResultCapsule;
1414
import org.tron.core.db.AccountStore;
1515
import org.tron.core.db.Manager;
16+
import org.tron.core.exception.BalanceInsufficientException;
1617
import org.tron.core.exception.ContractExeException;
1718
import org.tron.core.exception.ContractValidateException;
1819
import org.tron.protos.Contract.AccountPermissionUpdateContract;
@@ -35,19 +36,29 @@ public boolean execute(TransactionResultCapsule result) throws ContractExeExcept
3536
final AccountPermissionUpdateContract accountPermissionUpdateContract;
3637
try {
3738
accountPermissionUpdateContract = contract.unpack(AccountPermissionUpdateContract.class);
39+
40+
byte[] ownerAddress = accountPermissionUpdateContract.getOwnerAddress().toByteArray();
41+
AccountStore accountStore = dbManager.getAccountStore();
42+
AccountCapsule account = accountStore.get(ownerAddress);
43+
account.updatePermissions(accountPermissionUpdateContract.getOwner(),
44+
accountPermissionUpdateContract.getWitness(),
45+
accountPermissionUpdateContract.getActivesList());
46+
accountStore.put(ownerAddress, account);
47+
48+
dbManager.adjustBalance(ownerAddress, -fee);
49+
dbManager.adjustBalance(dbManager.getAccountStore().getBlackhole().createDbKey(), fee);
50+
51+
result.setStatus(fee, code.SUCESS);
52+
} catch (BalanceInsufficientException e) {
53+
logger.debug(e.getMessage(), e);
54+
result.setStatus(fee, code.FAILED);
55+
throw new ContractExeException(e.getMessage());
3856
} catch (InvalidProtocolBufferException e) {
3957
logger.debug(e.getMessage(), e);
4058
result.setStatus(fee, code.FAILED);
4159
throw new ContractExeException(e.getMessage());
4260
}
43-
byte[] ownerAddress = accountPermissionUpdateContract.getOwnerAddress().toByteArray();
44-
AccountStore accountStore = dbManager.getAccountStore();
45-
AccountCapsule account = accountStore.get(ownerAddress);
46-
account.updatePermissions(accountPermissionUpdateContract.getOwner(),
47-
accountPermissionUpdateContract.getWitness(),
48-
accountPermissionUpdateContract.getActivesList());
49-
accountStore.put(ownerAddress, account);
50-
result.setStatus(fee, code.SUCESS);
61+
5162
return true;
5263
}
5364

@@ -216,6 +227,6 @@ public ByteString getOwnerAddress() throws InvalidProtocolBufferException {
216227

217228
@Override
218229
public long calcFee() {
219-
return 0;
230+
return dbManager.getDynamicPropertiesStore().getUpdateAccountPermissionFee();
220231
}
221232
}

‎src/main/java/org/tron/core/actuator/ProposalCreateActuator.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,26 @@ private void validateValue(Map.Entry<Long, Long> entry) throws ContractValidateE
267267
}
268268
break;
269269
}
270+
case (22): {
271+
if (!dbManager.getForkController().pass(ForkBlockVersionEnum.VERSION_3_5)) {
272+
throw new ContractValidateException("Bad chain parameter id: UPDATE_ACCOUNT_PERMISSION_FEE");
273+
}
274+
if (entry.getValue() < 0 || entry.getValue() > 100_000_000_000L) {
275+
throw new ContractValidateException(
276+
"Bad chain parameter value,valid range is [0,100_000_000_000L]");
277+
}
278+
break;
279+
}
280+
case (23): {
281+
if (!dbManager.getForkController().pass(ForkBlockVersionEnum.VERSION_3_5)) {
282+
throw new ContractValidateException("Bad chain parameter id: MULTI_SIGN_FEE");
283+
}
284+
if (entry.getValue() < 0 || entry.getValue() > 100_000_000_000L) {
285+
throw new ContractValidateException(
286+
"Bad chain parameter value,valid range is [0,100_000_000_000L]");
287+
}
288+
break;
289+
}
270290
default:
271291
break;
272292
}

‎src/main/java/org/tron/core/capsule/ReceiptCapsule.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.tron.core.capsule;
22

3-
import org.tron.common.runtime.RuntimeImpl;
3+
import lombok.Getter;
4+
import lombok.Setter;
45
import org.tron.common.runtime.config.VMConfig;
56
import org.tron.common.utils.Sha256Hash;
67
import org.tron.common.utils.StringUtil;
78
import org.tron.core.Constant;
8-
import org.tron.core.config.Parameter.ForkBlockVersionConsts;
99
import org.tron.core.db.EnergyProcessor;
1010
import org.tron.core.db.Manager;
1111
import org.tron.core.exception.BalanceInsufficientException;
@@ -15,6 +15,9 @@
1515
public class ReceiptCapsule {
1616

1717
private ResourceReceipt receipt;
18+
@Getter
19+
@Setter
20+
private long multiSignFee;
1821

1922
private Sha256Hash receiptAddress;
2023

@@ -48,6 +51,10 @@ public void setNetFee(long netFee) {
4851
this.receipt = this.receipt.toBuilder().setNetFee(netFee).build();
4952
}
5053

54+
public void addNetFee(long netFee) {
55+
this.receipt = this.receipt.toBuilder().setNetFee(getNetFee() + netFee).build();
56+
}
57+
5158
public long getEnergyUsage() {
5259
return this.receipt.getEnergyUsage();
5360
}

‎src/main/java/org/tron/core/capsule/TransactionInfoCapsule.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ public static TransactionInfoCapsule buildInstance(TransactionCapsule trxCap, Bl
157157
builder.setId(ByteString.copyFrom(trxCap.getTransactionId().getBytes()));
158158
ProgramResult programResult = trace.getRuntimeResult();
159159
long fee =
160-
programResult.getRet().getFee() + traceReceipt.getEnergyFee() + traceReceipt.getNetFee();
160+
programResult.getRet().getFee() + traceReceipt.getEnergyFee()
161+
+ traceReceipt.getNetFee() + traceReceipt.getMultiSignFee();
161162
ByteString contractResult = ByteString.copyFrom(programResult.getHReturn());
162163
ByteString ContractAddress = ByteString.copyFrom(programResult.getContractAddress());
163164

‎src/main/java/org/tron/core/config/Parameter.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ enum ChainParameters {
9595
TOTAL_CURRENT_ENERGY_LIMIT, // 50,000,000,000, 19
9696
ALLOW_MULTI_SIGN, // 1, 20
9797
ALLOW_ADAPTIVE_ENERGY, // 1, 21
98+
UPDATE_ACCOUNT_PERMISSION_FEE, // 100, 22
99+
MULTI_SIGN_FEE, // 1, 23
98100
// ONE_DAY_NET_LIMIT,
99101
// MAX_FROZEN_TIME,
100102
// MIN_FROZEN_TIME,

‎src/main/java/org/tron/core/config/args/Args.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ public class Args {
415415
@Getter
416416
private FilterQuery eventFilter;
417417

418+
@Getter
419+
@Setter
420+
private long trxExpirationTimeInMilliseconds; // (ms)
421+
418422
public static void clearParam() {
419423
INSTANCE.outputDirectory = "output-directory";
420424
INSTANCE.help = false;
@@ -485,6 +489,7 @@ public static void clearParam() {
485489
INSTANCE.maxTimeRatio = 5.0;
486490
INSTANCE.longRunningTime = 10;
487491
INSTANCE.allowMultiSign = 0;
492+
INSTANCE.trxExpirationTimeInMilliseconds = 0;
488493
}
489494

490495
/**
@@ -823,6 +828,10 @@ public static void setParam(final String[] args, final String confFileName) {
823828
INSTANCE.trxReferenceBlock = config.hasPath("trx.reference.block") ?
824829
config.getString("trx.reference.block") : "head";
825830

831+
INSTANCE.trxExpirationTimeInMilliseconds =
832+
config.hasPath("trx.expiration.timeInMilliseconds") && config.getLong("trx.expiration.timeInMilliseconds") > 0 ?
833+
config.getLong("trx.expiration.timeInMilliseconds") : Constant.TRANSACTION_DEFAULT_EXPIRATION_TIME;
834+
826835
INSTANCE.minEffectiveConnection = config.hasPath("node.rpc.minEffectiveConnection") ?
827836
config.getInt("node.rpc.minEffectiveConnection") : 1;
828837

‎src/main/java/org/tron/core/db/DynamicPropertiesStore.java‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ private static class DynamicResourceProperties {
100100

101101
private static final byte[] ASSET_ISSUE_FEE = "ASSET_ISSUE_FEE".getBytes();
102102

103+
private static final byte[] UPDATE_ACCOUNT_PERMISSION_FEE = "UPDATE_ACCOUNT_PERMISSION_FEE"
104+
.getBytes();
105+
106+
private static final byte[] MULTI_SIGN_FEE = "MULTI_SIGN_FEE"
107+
.getBytes();
108+
109+
103110
private static final byte[] EXCHANGE_CREATE_FEE = "EXCHANGE_CREATE_FEE".getBytes();
104111

105112
private static final byte[] EXCHANGE_BALANCE_LIMIT = "EXCHANGE_BALANCE_LIMIT".getBytes();
@@ -397,6 +404,20 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
397404
this.saveAssetIssueFee(1024000000L);
398405
}
399406

407+
try {
408+
this.getUpdateAccountPermissionFee();
409+
} catch (IllegalArgumentException e) {
410+
this.saveUpdateAccountPermissionFee(100000000L);
411+
}
412+
413+
try {
414+
this.getMultiSignFee();
415+
} catch (IllegalArgumentException e) {
416+
this.saveMultiSignFee(1000000L);
417+
}
418+
419+
420+
400421
try {
401422
this.getExchangeCreateFee();
402423
} catch (IllegalArgumentException e) {
@@ -1029,6 +1050,17 @@ public void saveAssetIssueFee(long fee) {
10291050
new BytesCapsule(ByteArray.fromLong(fee)));
10301051
}
10311052

1053+
public void saveUpdateAccountPermissionFee(long fee) {
1054+
this.put(UPDATE_ACCOUNT_PERMISSION_FEE,
1055+
new BytesCapsule(ByteArray.fromLong(fee)));
1056+
}
1057+
1058+
public void saveMultiSignFee(long fee) {
1059+
this.put(MULTI_SIGN_FEE,
1060+
new BytesCapsule(ByteArray.fromLong(fee)));
1061+
}
1062+
1063+
10321064
public long getAssetIssueFee() {
10331065
return Optional.ofNullable(getUnchecked(ASSET_ISSUE_FEE))
10341066
.map(BytesCapsule::getData)
@@ -1037,6 +1069,24 @@ public long getAssetIssueFee() {
10371069
() -> new IllegalArgumentException("not found ASSET_ISSUE_FEE"));
10381070
}
10391071

1072+
public long getUpdateAccountPermissionFee() {
1073+
return Optional.ofNullable(getUnchecked(UPDATE_ACCOUNT_PERMISSION_FEE))
1074+
.map(BytesCapsule::getData)
1075+
.map(ByteArray::toLong)
1076+
.orElseThrow(
1077+
() -> new IllegalArgumentException("not found UPDATE_ACCOUNT_PERMISSION_FEE"));
1078+
}
1079+
1080+
public long getMultiSignFee() {
1081+
return Optional.ofNullable(getUnchecked(MULTI_SIGN_FEE))
1082+
.map(BytesCapsule::getData)
1083+
.map(ByteArray::toLong)
1084+
.orElseThrow(
1085+
() -> new IllegalArgumentException("not found MULTI_SIGN_FEE"));
1086+
}
1087+
1088+
1089+
10401090
public void saveExchangeCreateFee(long fee) {
10411091
this.put(EXCHANGE_CREATE_FEE,
10421092
new BytesCapsule(ByteArray.fromLong(fee)));

‎src/main/java/org/tron/core/db/Manager.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,27 @@ public boolean pushTransaction(final TransactionCapsule trx)
763763
return true;
764764
}
765765

766+
public void consumeMultiSignFee(TransactionCapsule trx, TransactionTrace trace)
767+
throws AccountResourceInsufficientException {
768+
if (trx.getInstance().getSignatureCount() > 1) {
769+
long fee = getDynamicPropertiesStore().getMultiSignFee();
770+
771+
List<Contract> contracts = trx.getInstance().getRawData().getContractList();
772+
for (Contract contract : contracts) {
773+
byte[] address = TransactionCapsule.getOwner(contract);
774+
AccountCapsule accountCapsule = getAccountStore().get(address);
775+
try {
776+
adjustBalance(accountCapsule, -fee);
777+
adjustBalance(this.getAccountStore().getBlackhole().createDbKey(), +fee);
778+
} catch (BalanceInsufficientException e) {
779+
throw new AccountResourceInsufficientException(
780+
"Account Insufficient balance[" + fee + "] to MultiSign");
781+
}
782+
}
783+
784+
trace.getReceipt().setMultiSignFee(fee);
785+
}
786+
}
766787

767788
public void consumeBandwidth(TransactionCapsule trx, TransactionTrace trace)
768789
throws ContractValidateException, AccountResourceInsufficientException, TooBigTransactionResultException {
@@ -1189,6 +1210,7 @@ public boolean processTransaction(final TransactionCapsule trxCap, BlockCapsule
11891210
trxCap.setTrxTrace(trace);
11901211

11911212
consumeBandwidth(trxCap, trace);
1213+
consumeMultiSignFee(trxCap, trace);
11921214

11931215
VMConfig.initVmHardFork();
11941216
VMConfig.initAllowMultiSign(dynamicPropertiesStore.getAllowMultiSign());

0 commit comments

Comments
 (0)