Skip to content

Commit 246ba16

Browse files
committed
2 parents 9480d63 + bd770bd commit 246ba16

File tree

77 files changed

+2460
-1306
lines changed

Some content is hidden

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

77 files changed

+2460
-1306
lines changed

deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ change_branch_CMD="sed -i '1c branch_name_in_CI=$TRAVIS_BRANCH' /data/workspace/
3636
echo "$TRAVIS_BRANCH"
3737

3838
if [[ "$TRAVIS_BRANCH" = "develop" || "$TRAVIS_BRANCH" = "master" || "$TRAVIS_BRANCH" = "Odyssey_v3.2.1" ]];then
39+
3940
echo "init env"
4041
ssh java-tron@$stest_server -p 22008 $change_branch_CMD
4142
ssh java-tron@$stest_server -p 22008 sh /data/workspace/docker_workspace/do_stest.sh >$stestlogname 2>&1

gradlew

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,4 @@ if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169169
cd "$(dirname "$0")"
170170
fi
171171

172-
exec "$JAVACMD" "$@"
172+
exec "$JAVACMD" "$@" --no-daemon

src/main/java/org/tron/common/utils/ForkController.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.apache.commons.lang3.StringUtils;
1818
import org.tron.core.Wallet;
1919
import org.tron.core.capsule.BlockCapsule;
20+
import org.tron.core.config.Parameter;
2021
import org.tron.core.config.Parameter.ForkBlockVersionConsts;
2122
import org.tron.core.db.Manager;
2223

@@ -41,6 +42,10 @@ public void init(Manager manager) {
4142
}
4243

4344
public synchronized boolean pass(int version) {
45+
if (!check(version)) {
46+
return false;
47+
}
48+
4449
if (passSet.contains(version)) {
4550
return true;
4651
}
@@ -53,6 +58,15 @@ public synchronized boolean pass(int version) {
5358
return pass;
5459
}
5560

61+
private boolean check(int version) {
62+
if (version != ForkBlockVersionConsts.ENERGY_LIMIT) {
63+
return true;
64+
}
65+
66+
long blockNum = manager.getDynamicPropertiesStore().getLatestBlockHeaderNumber();
67+
return blockNum >= 4727890L;
68+
}
69+
5670
private boolean check(byte[] stats) {
5771
if (stats == null || stats.length == 0) {
5872
return false;

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,14 @@ public TransactionCapsule createTransactionCapsule(com.google.protobuf.Message m
402402
*/
403403
public GrpcAPI.Return broadcastTransaction(Transaction signaturedTransaction) {
404404
GrpcAPI.Return.Builder builder = GrpcAPI.Return.newBuilder();
405+
TransactionCapsule trx = new TransactionCapsule(signaturedTransaction);
406+
Message message = new TransactionMessage(signaturedTransaction);
407+
405408
try{
406409
if (minEffectiveConnection != 0) {
407410
if (p2pNode.getActivePeer().isEmpty()) {
408-
logger.info("Broadcast transaction failed, no connection.");
409-
return builder.setResult(false).setCode(response_code.OTHER_ERROR)
411+
logger.warn("Broadcast transaction {} failed, no connection.", trx.getTransactionId());
412+
return builder.setResult(false).setCode(response_code.NO_CONNECTION)
410413
.setMessage(ByteString.copyFromUtf8("no connection"))
411414
.build();
412415
}
@@ -417,31 +420,25 @@ public GrpcAPI.Return broadcastTransaction(Transaction signaturedTransaction) {
417420

418421
if (count < minEffectiveConnection) {
419422
String info = "effective connection:" + count + " lt minEffectiveConnection:" + minEffectiveConnection;
420-
logger.info("Broadcast transaction failed, {}", info);
421-
return builder.setResult(false).setCode(response_code.OTHER_ERROR)
423+
logger.warn("Broadcast transaction {} failed, {}.", trx.getTransactionId(), info);
424+
return builder.setResult(false).setCode(response_code.NOT_ENOUGH_EFFECTIVE_CONNECTION)
422425
.setMessage(ByteString.copyFromUtf8(info))
423426
.build();
424427
}
425428
}
426429

427-
TransactionCapsule trx = new TransactionCapsule(signaturedTransaction);
428-
Message message = new TransactionMessage(signaturedTransaction);
429-
430430
if (dbManager.isTooManyPending()) {
431-
logger.debug(
432-
"Manager is busy, pending transaction count:{}, discard the new coming transaction",
433-
(dbManager.getPendingTransactions().size() + PendingManager.getTmpTransactions()
434-
.size()));
431+
logger.warn("Broadcast transaction {} failed, too many pending.", trx.getTransactionId());
435432
return builder.setResult(false).setCode(response_code.SERVER_BUSY).build();
436433
}
437434

438435
if (dbManager.isGeneratingBlock()) {
439-
logger.debug("Manager is generating block, discard the new coming transaction");
436+
logger.warn("Broadcast transaction {} failed, is generating block.", trx.getTransactionId());
440437
return builder.setResult(false).setCode(response_code.SERVER_BUSY).build();
441438
}
442439

443440
if (dbManager.getTransactionIdCache().getIfPresent(trx.getTransactionId()) != null) {
444-
logger.debug("This transaction has been processed, discard the transaction");
441+
logger.warn("Broadcast transaction {} failed, is already exist.", trx.getTransactionId());
445442
return builder.setResult(false).setCode(response_code.DUP_TRANSACTION_ERROR).build();
446443
} else {
447444
dbManager.getTransactionIdCache().put(trx.getTransactionId(), true);
@@ -451,50 +448,50 @@ public GrpcAPI.Return broadcastTransaction(Transaction signaturedTransaction) {
451448
}
452449
dbManager.pushTransaction(trx);
453450
p2pNode.broadcast(message);
454-
451+
logger.info("Broadcast transaction {} successfully.", trx.getTransactionId());
455452
return builder.setResult(true).setCode(response_code.SUCCESS).build();
456453
} catch (ValidateSignatureException e) {
457-
logger.info(e.getMessage());
454+
logger.error("Broadcast transaction {} failed, {}.", trx.getTransactionId(), e.getMessage());
458455
return builder.setResult(false).setCode(response_code.SIGERROR)
459456
.setMessage(ByteString.copyFromUtf8("validate signature error"))
460457
.build();
461458
} catch (ContractValidateException e) {
462-
logger.info(e.getMessage());
459+
logger.error("Broadcast transaction {} failed, {}.", trx.getTransactionId(), e.getMessage());
463460
return builder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR)
464461
.setMessage(ByteString.copyFromUtf8("contract validate error : " + e.getMessage()))
465462
.build();
466463
} catch (ContractExeException e) {
467-
logger.info(e.getMessage());
464+
logger.error("Broadcast transaction {} failed, {}.", trx.getTransactionId(), e.getMessage());
468465
return builder.setResult(false).setCode(response_code.CONTRACT_EXE_ERROR)
469466
.setMessage(ByteString.copyFromUtf8("contract execute error : " + e.getMessage()))
470467
.build();
471468
} catch (AccountResourceInsufficientException e) {
472-
logger.info(e.getMessage());
469+
logger.error("Broadcast transaction {} failed, {}.", trx.getTransactionId(), e.getMessage());
473470
return builder.setResult(false).setCode(response_code.BANDWITH_ERROR)
474471
.setMessage(ByteString.copyFromUtf8("AccountResourceInsufficient error"))
475472
.build();
476473
} catch (DupTransactionException e) {
477-
logger.info("dup trans" + e.getMessage());
474+
logger.error("Broadcast transaction {} failed, {}.", trx.getTransactionId(), e.getMessage());
478475
return builder.setResult(false).setCode(response_code.DUP_TRANSACTION_ERROR)
479476
.setMessage(ByteString.copyFromUtf8("dup transaction"))
480477
.build();
481478
} catch (TaposException e) {
482-
logger.info("tapos error" + e.getMessage());
479+
logger.error("Broadcast transaction {} failed, {}.", trx.getTransactionId(), e.getMessage());
483480
return builder.setResult(false).setCode(response_code.TAPOS_ERROR)
484481
.setMessage(ByteString.copyFromUtf8("Tapos check error"))
485482
.build();
486483
} catch (TooBigTransactionException e) {
487-
logger.info("transaction error" + e.getMessage());
484+
logger.error("Broadcast transaction {} failed, {}.", trx.getTransactionId(), e.getMessage());
488485
return builder.setResult(false).setCode(response_code.TOO_BIG_TRANSACTION_ERROR)
489486
.setMessage(ByteString.copyFromUtf8("transaction size is too big"))
490487
.build();
491488
} catch (TransactionExpirationException e) {
492-
logger.info("transaction expired" + e.getMessage());
489+
logger.error("Broadcast transaction {} failed, {}.", trx.getTransactionId(), e.getMessage());
493490
return builder.setResult(false).setCode(response_code.TRANSACTION_EXPIRATION_ERROR)
494491
.setMessage(ByteString.copyFromUtf8("transaction expired"))
495492
.build();
496493
} catch (Exception e) {
497-
logger.info("exception caught" + e.getMessage());
494+
logger.error("Broadcast transaction {} failed, {}.", trx.getTransactionId(), e.getMessage());
498495
return builder.setResult(false).setCode(response_code.OTHER_ERROR)
499496
.setMessage(ByteString.copyFromUtf8("other error : " + e.getMessage()))
500497
.build();

src/main/java/org/tron/core/capsule/TransactionCapsule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public class TransactionCapsule implements ProtoCapsule<Transaction> {
8888
@Setter
8989
private boolean isVerified = false;
9090

91+
@Setter
92+
@Getter
93+
private long blockNum = -1;
94+
9195
@Getter
9296
@Setter
9397
private TransactionTrace trxTrace;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.tron.common.runtime.vm.LogInfo;
1111
import org.tron.common.runtime.vm.program.InternalTransaction;
1212
import org.tron.common.runtime.vm.program.ProgramResult;
13+
import org.tron.core.config.args.Args;
1314
import org.tron.core.db.TransactionTrace;
1415
import org.tron.core.exception.BadItemException;
1516
import org.tron.protos.Protocol;
@@ -187,7 +188,7 @@ public static TransactionInfoCapsule buildInstance(TransactionCapsule trxCap, Bl
187188

188189
builder.setReceipt(traceReceipt.getReceipt());
189190

190-
if (null != programResult.getInternalTransactions()) {
191+
if (Args.getInstance().isSaveInternalTx() && null != programResult.getInternalTransactions()) {
191192
for (InternalTransaction internalTransaction : programResult
192193
.getInternalTransactions()) {
193194
Protocol.InternalTransaction.Builder internalTrxBuilder = Protocol.InternalTransaction

src/main/java/org/tron/core/config/DefaultConfig.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.apache.commons.lang3.BooleanUtils;
44
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
6-
import org.springframework.beans.factory.annotation.Autowire;
76
import org.springframework.beans.factory.annotation.Autowired;
87
import org.springframework.context.ApplicationContext;
98
import org.springframework.context.annotation.Bean;
@@ -54,7 +53,7 @@ public RevokingDatabase revokingDatabase() {
5453
}
5554
}
5655

57-
// @Bean
56+
@Bean
5857
public RpcApiServiceOnSolidity getRpcApiServiceOnSolidity() {
5958
boolean isSolidityNode = Args.getInstance().isSolidityNode();
6059
int dbVersion = Args.getInstance().getStorage().getDbVersion();
@@ -65,7 +64,7 @@ public RpcApiServiceOnSolidity getRpcApiServiceOnSolidity() {
6564
return null;
6665
}
6766

68-
// @Bean
67+
@Bean
6968
public HttpApiOnSolidityService getHttpApiOnSolidityService() {
7069
boolean isSolidityNode = Args.getInstance().isSolidityNode();
7170
int dbVersion = Args.getInstance().getStorage().getDbVersion();

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,18 @@ public class Args {
108108
@Parameter(names = {"--storage-db-version"}, description = "Storage db version.(1 or 2)")
109109
private String storageDbVersion = "";
110110

111+
@Parameter(names = {"--storage-db-synchronous"}, description = "Storage db is synchronous or not.(true or flase)")
112+
private String storageDbSynchronous = "";
113+
111114
@Parameter(names = {"--storage-index-directory"}, description = "Storage index directory")
112115
private String storageIndexDirectory = "";
113116

114117
@Parameter(names = {"--storage-index-switch"}, description = "Storage index switch.(on or off)")
115118
private String storageIndexSwitch = "";
116119

120+
@Parameter(names = {"--storage-transactionHistory-switch"}, description = "Storage transaction history switch.(on or off)")
121+
private String storageTransactionHistoreSwitch = "";
122+
117123
@Getter
118124
private Storage storage;
119125

@@ -197,6 +203,10 @@ public class Args {
197203
// @Getter
198204
// @Setter
199205
// private long syncNodeCount;
206+
@Getter
207+
@Setter
208+
@Parameter(names = {"--save-internaltx"})
209+
private boolean saveInternalTx;
200210

201211
@Getter
202212
@Setter
@@ -525,6 +535,11 @@ public static void setParam(final String[] args, final String confFileName) {
525535
.map(Integer::valueOf)
526536
.orElse(Storage.getDbVersionFromConfig(config)));
527537

538+
INSTANCE.storage.setDbSync(Optional.ofNullable(INSTANCE.storageDbSynchronous)
539+
.filter(StringUtils::isNotEmpty)
540+
.map(Boolean::valueOf)
541+
.orElse(Storage.getDbVersionSyncFromConfig(config)));
542+
528543
INSTANCE.storage.setDbDirectory(Optional.ofNullable(INSTANCE.storageDbDirectory)
529544
.filter(StringUtils::isNotEmpty)
530545
.orElse(Storage.getDbDirectoryFromConfig(config)));
@@ -537,6 +552,11 @@ public static void setParam(final String[] args, final String confFileName) {
537552
.filter(StringUtils::isNotEmpty)
538553
.orElse(Storage.getIndexSwitchFromConfig(config)));
539554

555+
INSTANCE.storage.setTransactionHistoreSwitch(Optional.ofNullable(INSTANCE.storageTransactionHistoreSwitch)
556+
.filter(StringUtils::isNotEmpty)
557+
.orElse(Storage.getTransactionHistoreSwitchFromConfig(config)));
558+
559+
540560
INSTANCE.storage.setPropertyMapFromConfig(config);
541561

542562
INSTANCE.seedNode = new SeedNode();
@@ -741,6 +761,10 @@ public static void setParam(final String[] args, final String confFileName) {
741761
INSTANCE.vmTrace =
742762
config.hasPath("vm.vmTrace") ? config
743763
.getBoolean("vm.vmTrace") : false;
764+
765+
INSTANCE.saveInternalTx =
766+
config.hasPath("vm.saveInternalTx") && config.getBoolean("vm.saveInternalTx");
767+
744768
initBackupProperty(config);
745769

746770

src/main/java/org/tron/core/config/args/Storage.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ public class Storage {
4242
*/
4343
private static final String DB_DIRECTORY_CONFIG_KEY = "storage.db.directory";
4444
private static final String DB_VERSION_CONFIG_KEY = "storage.db.version";
45+
private static final String DB_SYNC_CONFIG_KEY = "storage.db.sync";
4546
private static final String INDEX_DIRECTORY_CONFIG_KEY = "storage.index.directory";
4647
private static final String INDEX_SWITCH_CONFIG_KEY = "storage.index.switch";
48+
private static final String TRANSACTIONHISTORY_SWITCH_CONFIG_KEY = "storage.transHistory.switch";
4749
private static final String PROPERTIES_CONFIG_KEY = "storage.properties";
50+
private static final String DEFAULT_TRANSACTIONHISTORY_SWITCH = "on";
4851

4952
private static final String NAME_CONFIG_KEY = "name";
5053
private static final String PATH_CONFIG_KEY = "path";
@@ -61,6 +64,7 @@ public class Storage {
6164
* Default values of directory
6265
*/
6366
private static final int DEFAULT_DB_VERSION = 2;
67+
private static final boolean DEFAULT_DB_SYNC = false;
6468
private static final String DEFAULT_DB_DIRECTORY = "database";
6569
private static final String DEFAULT_INDEX_DIRECTORY = "index";
6670
private static final String DEFAULT_INDEX_SWTICH = "on";
@@ -91,6 +95,10 @@ public class Storage {
9195
@Setter
9296
private int dbVersion;
9397

98+
@Getter
99+
@Setter
100+
private boolean dbSync;
101+
94102
/**
95103
* Index storage directory: /path/to/{indexDirectory}
96104
*/
@@ -102,6 +110,10 @@ public class Storage {
102110
@Setter
103111
private String indexSwitch;
104112

113+
@Getter
114+
@Setter
115+
private String transactionHistoreSwitch;
116+
105117
/**
106118
* Other custom database configurations
107119
*/
@@ -123,6 +135,11 @@ public static int getDbVersionFromConfig(final Config config) {
123135
config.getInt(DB_VERSION_CONFIG_KEY) : DEFAULT_DB_VERSION;
124136
}
125137

138+
public static Boolean getDbVersionSyncFromConfig(final Config config) {
139+
return config.hasPath(DB_SYNC_CONFIG_KEY) ?
140+
config.getBoolean(DB_SYNC_CONFIG_KEY) : DEFAULT_DB_SYNC;
141+
}
142+
126143
public static String getDbDirectoryFromConfig(final Config config) {
127144
return config.hasPath(DB_DIRECTORY_CONFIG_KEY) ?
128145
config.getString(DB_DIRECTORY_CONFIG_KEY) : DEFAULT_DB_DIRECTORY;
@@ -139,6 +156,11 @@ public static String getIndexSwitchFromConfig(final Config config) {
139156
config.getString(INDEX_SWITCH_CONFIG_KEY) : DEFAULT_INDEX_SWTICH;
140157
}
141158

159+
public static String getTransactionHistoreSwitchFromConfig(final Config config) {
160+
return config.hasPath(TRANSACTIONHISTORY_SWITCH_CONFIG_KEY)?
161+
config.getString(TRANSACTIONHISTORY_SWITCH_CONFIG_KEY) : DEFAULT_TRANSACTIONHISTORY_SWITCH;
162+
}
163+
142164
/**
143165
* Set propertyMap of Storage object from Config
144166
*

src/main/java/org/tron/core/db/AbstractRevokingStore.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public abstract class AbstractRevokingStore implements RevokingDatabase {
4141
private boolean disabled = true;
4242
private int activeDialog = 0;
4343
private AtomicInteger maxSize = new AtomicInteger(DEFAULT_STACK_MAX_SIZE);
44-
private WriteOptions writeOptions = new WriteOptions().sync(true);
44+
private WriteOptions writeOptions = new WriteOptions()
45+
.sync(Args.getInstance().getStorage().isDbSync());
4546
private List<LevelDbDataSourceImpl> dbs = new ArrayList<>();
4647

4748
@Override
@@ -69,6 +70,11 @@ public synchronized ISession buildSession(boolean forceEnable) {
6970
return new Dialog(this, disableOnExit);
7071
}
7172

73+
@Override
74+
public void setMode(boolean mode) {
75+
76+
}
77+
7278
@Override
7379
public synchronized void check() {
7480
LevelDbDataSourceImpl check =
@@ -84,13 +90,18 @@ public synchronized void check() {
8490
byte[] key = e.getKey();
8591
byte[] value = e.getValue();
8692
String db = simpleDecode(key);
93+
if (dbMap.get(db) == null) {
94+
continue;
95+
}
8796
byte[] realKey = Arrays.copyOfRange(key, db.getBytes().length + 4, key.length);
8897

8998
byte[] realValue = value.length == 1 ? null : Arrays.copyOfRange(value, 1, value.length);
9099
if (realValue != null) {
91-
dbMap.get(db).putData(realKey, realValue, new WriteOptions().sync(true));
100+
dbMap.get(db).putData(realKey, realValue, new WriteOptions()
101+
.sync(Args.getInstance().getStorage().isDbSync()));
92102
} else {
93-
dbMap.get(db).deleteData(realKey, new WriteOptions().sync(true));
103+
dbMap.get(db).deleteData(realKey, new WriteOptions()
104+
.sync(Args.getInstance().getStorage().isDbSync()));
94105
}
95106
}
96107
}

0 commit comments

Comments
 (0)