Skip to content

Commit 86e0d48

Browse files
author
renchenchang
committed
Merge branch 'develop' into multi_sign
2 parents d1e6d28 + 3f5eadd commit 86e0d48

36 files changed

Lines changed: 719 additions & 153 deletions

‎.travis.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ cache:
1515
script:
1616
- sh tron.sh
1717
- "./gradlew build"
18+
- "./gradlew jacocoTestReport"
1819
- bash deploy.sh
1920

21+
after_success:
22+
- "bash <(curl -s https://codecov.io/bash) -t 060bb400-c6fe-4d5f-a6c8-427105c746ac -s build/reports/jacoco/"
23+
2024
skip_build:
2125
- README.md:
2226
- LICENSE

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<img src="https://travis-ci.org/tronprotocol/java-tron.svg?branch=develop">
2121
</a>
2222

23+
<a href="https://codecov.io/gh/tronprotocol/java-tron">
24+
<img src="https://codecov.io/gh/tronprotocol/java-tron/branch/develop/graph/badge.svg" />
25+
</a>
26+
2327
<a href="https://github.com/tronprotocol/java-tron/issues">
2428
<img src="https://img.shields.io/github/issues/tronprotocol/java-tron.svg">
2529
</a>

‎build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ task stest(type: Test) {
288288

289289
jacocoTestReport {
290290
reports {
291-
xml.enabled false
291+
xml.enabled true
292292
csv.enabled false
293293
html.destination file("${buildDir}/jacocoHtml")
294294
}

‎src/main/java/org/tron/common/runtime/Runtime.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private void create()
339339
.getAccount(newSmartContract.getOriginAddress().toByteArray());
340340

341341
long MAX_CPU_TIME_OF_ONE_TX = deposit.getDbManager().getDynamicPropertiesStore()
342-
.getMaxCpuTimeOfOneTX() * 1000;
342+
.getMaxCpuTimeOfOneTx() * 1000;
343343

344344
long thisTxCPULimitInUs = (long) (MAX_CPU_TIME_OF_ONE_TX * getThisTxCPULimitInUsRatio());
345345

@@ -422,7 +422,7 @@ private void call()
422422
.getOriginAddress().toByteArray());
423423

424424
long MAX_CPU_TIME_OF_ONE_TX = deposit.getDbManager().getDynamicPropertiesStore()
425-
.getMaxCpuTimeOfOneTX() * 1000;
425+
.getMaxCpuTimeOfOneTx() * 1000;
426426
long thisTxCPULimitInUs =
427427
(long) (MAX_CPU_TIME_OF_ONE_TX * getThisTxCPULimitInUsRatio());
428428

‎src/main/java/org/tron/common/runtime/vm/program/InternalTransaction.java‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ public enum ExecutorType {
7373
*/
7474
public InternalTransaction(Transaction trx) {
7575
this.transaction = trx;
76-
this.protoEncoded = (new TransactionCapsule(trx)).getData();
76+
TransactionCapsule trxCap = new TransactionCapsule(trx);
77+
this.protoEncoded = trxCap.getData();
7778
this.nonce = 0;
79+
this.hash = trxCap.getTransactionId().getBytes();
7880
}
7981

8082
/**
@@ -92,6 +94,7 @@ public InternalTransaction(byte[] parentHash, int deep, int index,
9294
this.value = value;
9395
this.data = nullToEmpty(data);
9496
this.nonce = nonce;
97+
this.hash = getHash();
9598
}
9699

97100
public Transaction getTransaction() {
@@ -188,12 +191,17 @@ public byte[] getEncoded() {
188191
if (protoEncoded != null) {
189192
return protoEncoded.clone();
190193
}
194+
byte[] parentHashArray = parentHash.clone();
191195

196+
if (parentHashArray == null){
197+
parentHashArray = EMPTY_BYTE_ARRAY;
198+
}
192199
byte[] valueByte = Longs.toByteArray(this.value);
193-
byte[] raw = new byte[this.receiveAddress.length + this.data.length + valueByte.length];
194-
System.arraycopy(this.receiveAddress, 0, raw, 0, this.receiveAddress.length);
195-
System.arraycopy(this.data, 0, raw, this.receiveAddress.length, this.data.length);
196-
System.arraycopy(valueByte, 0, raw, this.receiveAddress.length + this.data.length,
200+
byte[] raw = new byte[parentHashArray.length + this.receiveAddress.length + this.data.length + valueByte.length];
201+
System.arraycopy(parentHashArray, 0, raw, 0, parentHashArray.length);
202+
System.arraycopy(this.receiveAddress, 0, raw, parentHashArray.length, this.receiveAddress.length);
203+
System.arraycopy(this.data, 0, raw, parentHashArray.length + this.receiveAddress.length, this.data.length);
204+
System.arraycopy(valueByte, 0, raw, parentHashArray.length + this.receiveAddress.length + this.data.length,
197205
valueByte.length);
198206
this.protoEncoded = raw;
199207
return protoEncoded.clone();

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

Lines changed: 92 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717
*/
1818

1919
package org.tron.core;
20-
20+
21+
import static org.tron.core.config.Parameter.DatabaseConstants.EXCHANGE_COUNT_LIMIT_MAX;
22+
import static org.tron.core.config.Parameter.DatabaseConstants.PROPOSAL_COUNT_LIMIT_MAX;
23+
24+
import com.google.common.collect.ContiguousSet;
25+
import com.google.common.collect.DiscreteDomain;
26+
import com.google.common.collect.ImmutableList;
27+
import com.google.common.collect.Range;
28+
import com.google.common.base.CaseFormat;
2129
import com.google.common.primitives.Longs;
2230
import com.google.protobuf.ByteString;
2331
import java.security.SignatureException;
@@ -591,90 +599,29 @@ public ExchangeList getExchangeList() {
591599

592600
public Protocol.ChainParameters getChainParameters() {
593601
Protocol.ChainParameters.Builder builder = Protocol.ChainParameters.newBuilder();
594-
DynamicPropertiesStore dynamicPropertiesStore = dbManager.getDynamicPropertiesStore();
595-
596-
Protocol.ChainParameters.ChainParameter.Builder builder1
597-
= Protocol.ChainParameters.ChainParameter.newBuilder();
598-
599-
builder.addChainParameter(builder1
600-
.setKey(ChainParameters.MAINTENANCE_TIME_INTERVAL.name())
601-
.setValue(
602-
dynamicPropertiesStore.getMaintenanceTimeInterval())
603-
.build());
604-
builder.addChainParameter(builder1
605-
.setKey(ChainParameters.ACCOUNT_UPGRADE_COST.name())
606-
.setValue(
607-
dynamicPropertiesStore.getAccountUpgradeCost())
608-
.build());
609-
builder.addChainParameter(builder1
610-
.setKey(ChainParameters.CREATE_ACCOUNT_FEE.name())
611-
.setValue(
612-
dynamicPropertiesStore.getCreateAccountFee())
613-
.build());
614-
builder.addChainParameter(builder1
615-
.setKey(ChainParameters.TRANSACTION_FEE.name())
616-
.setValue(
617-
dynamicPropertiesStore.getTransactionFee())
618-
.build());
619-
builder.addChainParameter(builder1
620-
.setKey(ChainParameters.ASSET_ISSUE_FEE.name())
621-
.setValue(
622-
dynamicPropertiesStore.getAssetIssueFee())
623-
.build());
624-
builder.addChainParameter(builder1
625-
.setKey(ChainParameters.WITNESS_PAY_PER_BLOCK.name())
626-
.setValue(
627-
dynamicPropertiesStore.getWitnessPayPerBlock())
628-
.build());
629-
builder.addChainParameter(builder1
630-
.setKey(ChainParameters.WITNESS_STANDBY_ALLOWANCE.name())
631-
.setValue(
632-
dynamicPropertiesStore.getWitnessStandbyAllowance())
633-
.build());
634-
builder.addChainParameter(builder1
635-
.setKey(ChainParameters.CREATE_NEW_ACCOUNT_FEE_IN_SYSTEM_CONTRACT.name())
636-
.setValue(
637-
dynamicPropertiesStore.getCreateNewAccountFeeInSystemContract())
638-
.build());
639-
builder.addChainParameter(builder1
640-
.setKey(ChainParameters.CREATE_NEW_ACCOUNT_BANDWIDTH_RATE.name())
641-
.setValue(
642-
dynamicPropertiesStore.getCreateNewAccountBandwidthRate())
643-
.build());
644-
645-
builder.addChainParameter(builder1
646-
.setKey(ChainParameters.ALLOW_CREATION_OF_CONTRACTS.name())
647-
.setValue(
648-
dynamicPropertiesStore.getAllowCreationOfContracts())
649-
.build());
650-
651-
builder.addChainParameter(builder1
652-
.setKey(ChainParameters.REMOVE_THE_POWER_OF_THE_GR.name())
653-
.setValue(
654-
dynamicPropertiesStore.getRemoveThePowerOfTheGr())
655-
.build());
656-
657-
builder.addChainParameter(builder1
658-
.setKey(ChainParameters.ENERGY_FEE.name())
659-
.setValue(
660-
dynamicPropertiesStore.getEnergyFee())
661-
.build());
662-
663-
builder.addChainParameter(builder1
664-
.setKey(ChainParameters.EXCHANGE_CREATE_FEE.name())
665-
.setValue(
666-
dynamicPropertiesStore.getExchangeCreateFee())
667-
.build());
668-
669-
builder.addChainParameter(builder1
670-
.setKey(ChainParameters.MAX_CPU_TIME_OF_ONE_TX.name())
671-
.setValue(
672-
dynamicPropertiesStore.getMaxCpuTimeOfOneTX())
673-
.build());
602+
603+
Arrays.stream(ChainParameters.values()).forEach(parameters -> {
604+
try {
605+
String methodName = Wallet.makeUpperCamelMethod(parameters.name());
606+
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
607+
.setKey(methodName)
608+
.setValue((Long) DynamicPropertiesStore.class.getDeclaredMethod(methodName)
609+
.invoke(dbManager.getDynamicPropertiesStore()))
610+
.build());
611+
} catch (Exception ex) {
612+
logger.error("get chainParameter error,", ex);
613+
}
614+
615+
});
674616

675617
return builder.build();
676618
}
677619

620+
public static String makeUpperCamelMethod(String originName) {
621+
return "get" + CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, originName)
622+
.replace("_", "");
623+
}
624+
678625
public AssetIssueList getAssetIssueList() {
679626
AssetIssueList.Builder builder = AssetIssueList.newBuilder();
680627
dbManager.getAssetIssueStore().getAllAssetIssues()
@@ -1051,4 +998,68 @@ private static boolean isConstant(SmartContract.ABI abi, byte[] selector) {
1051998
return false;
1052999
}
10531000

1001+
/*
1002+
input
1003+
offset:100,limit:10
1004+
return
1005+
id: 101~110
1006+
*/
1007+
public ProposalList getPaginatedProposalList(long offset, long limit) {
1008+
1009+
if (limit < 0 || offset < 0) {
1010+
return null;
1011+
}
1012+
1013+
long latestProposalNum = dbManager.getDynamicPropertiesStore().getLatestProposalNum();
1014+
if (latestProposalNum <= offset) {
1015+
return null;
1016+
}
1017+
limit = limit > PROPOSAL_COUNT_LIMIT_MAX ? PROPOSAL_COUNT_LIMIT_MAX : limit;
1018+
long end = offset + limit;
1019+
end = end > latestProposalNum ? latestProposalNum : end;
1020+
ProposalList.Builder builder = ProposalList.newBuilder();
1021+
1022+
ImmutableList<Long> rangeList = ContiguousSet
1023+
.create(Range.openClosed(offset, end), DiscreteDomain.longs()).asList();
1024+
rangeList.stream().map(ProposalCapsule::calculateDbKey).map(key -> {
1025+
try {
1026+
return dbManager.getProposalStore().get(key);
1027+
} catch (Exception ex) {
1028+
return null;
1029+
}
1030+
}).filter(Objects::nonNull)
1031+
.forEach(proposalCapsule -> builder.addProposals(proposalCapsule.getInstance()));
1032+
return builder.build();
1033+
}
1034+
1035+
public ExchangeList getPaginatedExchangeList(long offset, long limit) {
1036+
1037+
if (limit < 0 || offset < 0) {
1038+
return null;
1039+
}
1040+
1041+
long latestExchangeNum = dbManager.getDynamicPropertiesStore().getLatestExchangeNum();
1042+
if (latestExchangeNum <= offset) {
1043+
return null;
1044+
}
1045+
limit = limit > EXCHANGE_COUNT_LIMIT_MAX ? EXCHANGE_COUNT_LIMIT_MAX : limit;
1046+
long end = offset + limit;
1047+
end = end > latestExchangeNum ? latestExchangeNum : end;
1048+
1049+
ExchangeList.Builder builder = ExchangeList.newBuilder();
1050+
ImmutableList<Long> rangeList = ContiguousSet
1051+
.create(Range.openClosed(offset, end), DiscreteDomain.longs()).asList();
1052+
rangeList.stream().map(ExchangeCapsule::calculateDbKey).map(key -> {
1053+
try {
1054+
return dbManager.getExchangeStore().get(key);
1055+
} catch (Exception ex) {
1056+
return null;
1057+
}
1058+
}).filter(Objects::nonNull)
1059+
.forEach(exchangeCapsule -> builder.addExchanges(exchangeCapsule.getInstance()));
1060+
return builder.build();
1061+
1062+
}
1063+
1064+
10541065
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ interface NetConstants {
5454
interface DatabaseConstants {
5555
int TRANSACTIONS_COUNT_LIMIT_MAX = 1000;
5656
int ASSET_ISSUE_COUNT_LIMIT_MAX = 1000;
57+
int PROPOSAL_COUNT_LIMIT_MAX = 1000;
58+
int EXCHANGE_COUNT_LIMIT_MAX = 1000;
5759
}
5860

5961
enum ChainParameters {

‎src/main/java/org/tron/core/config/README.md‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,42 @@ node {
7878
}
7979
```
8080

81+
## backup
82+
You can custom backup options in the `node.backup` part of `config.conf`, which looks like:
83+
```
84+
node.backup {
85+
# my priority, each member should use different priority
86+
priority =
87+
# members should use same port
88+
port =
89+
# peer's ip list, can't contain mine
90+
members = []
91+
}
92+
```
93+
policy:
94+
1. the one which synchronized first will become master.
95+
2. if synchronization is completed at the same time, the one which with big priority will become master.
96+
97+
E.g. create backups for node A(192.168.0.100) and node B(192.168.0.100 ):
98+
node A's configuration:
99+
```
100+
node.backup {
101+
priority = 8
102+
port = 10001
103+
members = [
104+
"192.168.0.101"
105+
]
106+
}
107+
```
108+
node B's configuration:
109+
```
110+
node.backup {
111+
priority = 5
112+
port = 10001
113+
members = [
114+
"192.168.0.100"
115+
]
116+
}
117+
```
118+
81119
You may refer to the source code of `io.grpc.netty.NettyServerBuilder` class to see details or just make a decision according to the brief comments above.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
303303
}
304304

305305
try {
306-
this.getMaxCpuTimeOfOneTX();
306+
this.getMaxCpuTimeOfOneTx();
307307
} catch (IllegalArgumentException e) {
308-
this.saveMaxCpuTimeOfOneTX(50L);
308+
this.saveMaxCpuTimeOfOneTx(50L);
309309
}
310310

311311
try {
@@ -736,12 +736,12 @@ public long getEnergyFee() {
736736
() -> new IllegalArgumentException("not found ENERGY_FEE"));
737737
}
738738

739-
public void saveMaxCpuTimeOfOneTX(long time) {
739+
public void saveMaxCpuTimeOfOneTx(long time) {
740740
this.put(MAX_CPU_TIME_OF_ONE_TX,
741741
new BytesCapsule(ByteArray.fromLong(time)));
742742
}
743743

744-
public long getMaxCpuTimeOfOneTX() {
744+
public long getMaxCpuTimeOfOneTx() {
745745
return Optional.ofNullable(getUnchecked(MAX_CPU_TIME_OF_ONE_TX))
746746
.map(BytesCapsule::getData)
747747
.map(ByteArray::toLong)

‎src/main/java/org/tron/core/services/RpcApiService.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,24 @@ public void listProposals(EmptyMessage request,
13951395
responseObserver.onCompleted();
13961396
}
13971397

1398+
@Override
1399+
public void getPaginatedProposalList(PaginatedMessage request,
1400+
StreamObserver<ProposalList> responseObserver) {
1401+
responseObserver
1402+
.onNext(wallet.getPaginatedProposalList(request.getOffset(), request.getLimit()));
1403+
responseObserver.onCompleted();
1404+
1405+
}
1406+
1407+
@Override
1408+
public void getPaginatedExchangeList(PaginatedMessage request,
1409+
StreamObserver<ExchangeList> responseObserver) {
1410+
responseObserver
1411+
.onNext(wallet.getPaginatedExchangeList(request.getOffset(), request.getLimit()));
1412+
responseObserver.onCompleted();
1413+
1414+
}
1415+
13981416
@Override
13991417
public void listExchanges(EmptyMessage request,
14001418
StreamObserver<ExchangeList> responseObserver) {

0 commit comments

Comments
 (0)