Skip to content

Commit 223777c

Browse files
authored
Merge pull request #1793 from tronprotocol/soliditynode_use_fullnode_databse
fix
2 parents f849724 + 3e70732 commit 223777c

File tree

6 files changed

+40
-17
lines changed

6 files changed

+40
-17
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ apply plugin: 'com.github.johnrengelman.shadow'
2323
apply plugin: "jacoco"
2424
apply plugin: 'maven-publish'
2525

26+
jar.enabled = false
27+
shadowJar.enabled = false
28+
2629
sourceCompatibility = 1.8
2730
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
2831
mainClassName = 'org.tron.program.FullNode'

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
import org.tron.core.exception.ValidateSignatureException;
112112
import org.tron.core.net.message.TransactionMessage;
113113
import org.tron.core.net.node.NodeImpl;
114+
import org.tron.core.net.peer.PeerConnection;
114115
import org.tron.protos.Contract.AssetIssueContract;
115116
import org.tron.protos.Contract.CreateSmartContract;
116117
import org.tron.protos.Contract.TransferContract;
@@ -145,6 +146,8 @@ public class Wallet {
145146
private static String addressPreFixString = Constant.ADD_PRE_FIX_STRING_TESTNET; //default testnet
146147
private static byte addressPreFixByte = Constant.ADD_PRE_FIX_BYTE_TESTNET;
147148

149+
private int minEffectiveConnection = Args.getInstance().getMinEffectiveConnection();
150+
148151
/**
149152
* Creates a new Wallet with a random ECKey.
150153
*/
@@ -399,22 +402,28 @@ public TransactionCapsule createTransactionCapsule(com.google.protobuf.Message m
399402
*/
400403
public GrpcAPI.Return broadcastTransaction(Transaction signaturedTransaction) {
401404
GrpcAPI.Return.Builder builder = GrpcAPI.Return.newBuilder();
402-
try {
403-
if (p2pNode.getActivePeer().isEmpty()) {
404-
logger.info("Broadcast transaction failed, no connection.");
405-
return builder.setResult(false).setCode(response_code.OTHER_ERROR)
406-
.setMessage(ByteString.copyFromUtf8("no connection"))
407-
.build();
408-
}
409-
if (!p2pNode.getActivePeer().stream()
410-
.filter(p -> !p.isNeedSyncFromUs() && !p.isNeedSyncFromPeer())
411-
.findFirst()
412-
.isPresent()) {
413-
logger.info("Broadcast transaction failed, no effective connection.");
414-
return builder.setResult(false).setCode(response_code.OTHER_ERROR)
415-
.setMessage(ByteString.copyFromUtf8("no effective connection"))
416-
.build();
405+
try{
406+
if (minEffectiveConnection != 0) {
407+
if (p2pNode.getActivePeer().isEmpty()) {
408+
logger.info("Broadcast transaction failed, no connection.");
409+
return builder.setResult(false).setCode(response_code.OTHER_ERROR)
410+
.setMessage(ByteString.copyFromUtf8("no connection"))
411+
.build();
412+
}
413+
414+
int count = (int) p2pNode.getActivePeer().stream()
415+
.filter(p -> !p.isNeedSyncFromUs() && !p.isNeedSyncFromPeer())
416+
.count();
417+
418+
if (count < minEffectiveConnection) {
419+
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)
422+
.setMessage(ByteString.copyFromUtf8(info))
423+
.build();
424+
}
417425
}
426+
418427
TransactionCapsule trx = new TransactionCapsule(signaturedTransaction);
419428
Message message = new TransactionMessage(signaturedTransaction);
420429

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ public class Args {
370370
@Setter
371371
private String trxReferenceBlock;
372372

373+
@Getter
374+
@Setter
375+
private int minEffectiveConnection;
376+
373377
public static void clearParam() {
374378
INSTANCE.outputDirectory = "output-directory";
375379
INSTANCE.help = false;
@@ -731,11 +735,16 @@ public static void setParam(final String[] args, final String confFileName) {
731735
INSTANCE.trxReferenceBlock = config.hasPath("trx.reference.block") ?
732736
config.getString("trx.reference.block") : "head";
733737

738+
INSTANCE.minEffectiveConnection = config.hasPath("node.rpc.minEffectiveConnection") ?
739+
config.getInt("node.rpc.minEffectiveConnection") : 1;
740+
734741
INSTANCE.vmTrace =
735742
config.hasPath("vm.vmTrace") ? config
736743
.getBoolean("vm.vmTrace") : false;
737744
initBackupProperty(config);
738745

746+
747+
739748
logConfig();
740749
}
741750

src/main/java/org/tron/program/SolidityNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class SolidityNode {
5959
public SolidityNode(Manager dbManager, Args cfgArgs) {
6060
this.dbManager = dbManager;
6161
this.cfgArgs = cfgArgs;
62+
resolveCompatibilityIssueIfUsingFullNodeDatabase();
6263
lastSolidityBlockNum = dbManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum();
6364
ID.set(lastSolidityBlockNum);
6465
databaseGrpcClient = new DatabaseGrpcClient(cfgArgs.getTrustNodeAddr());
@@ -323,7 +324,6 @@ public static void main(String[] args) throws InterruptedException {
323324
nodeManager.close();
324325

325326
SolidityNode node = new SolidityNode(appT.getDbManager(), cfgArgs);
326-
node.resolveCompatibilityIssueIfUsingFullNodeDatabase();
327327
node.start();
328328

329329
rpcApiService.blockUntilShutdown();

src/main/resources/config.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ node {
151151

152152
# The maximum size of header list allowed to be received, default 8192
153153
# maxHeaderListSize =
154+
155+
# Transactions can only be broadcast if the number of effective connections is reached.
156+
minEffectiveConnection = 1
154157
}
155158

156159
# Limits the maximum percentage (default 75%) of producing block interval

src/test/java/org/tron/core/net/node/StartFetchSyncBlockTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ public void run() {
243243
@AfterClass
244244
public static void destroy() {
245245
Args.clearParam();
246-
peerClient.close();
247246
handshakeHandlerTest.close();
248247
context.destroy();
249248
appT.shutdownServices();

0 commit comments

Comments
 (0)