|
111 | 111 | import org.tron.core.exception.ValidateSignatureException; |
112 | 112 | import org.tron.core.net.message.TransactionMessage; |
113 | 113 | import org.tron.core.net.node.NodeImpl; |
| 114 | +import org.tron.core.net.peer.PeerConnection; |
114 | 115 | import org.tron.protos.Contract.AssetIssueContract; |
115 | 116 | import org.tron.protos.Contract.CreateSmartContract; |
116 | 117 | import org.tron.protos.Contract.TransferContract; |
@@ -145,6 +146,8 @@ public class Wallet { |
145 | 146 | private static String addressPreFixString = Constant.ADD_PRE_FIX_STRING_TESTNET; //default testnet |
146 | 147 | private static byte addressPreFixByte = Constant.ADD_PRE_FIX_BYTE_TESTNET; |
147 | 148 |
|
| 149 | + private int minEffectiveConnection = Args.getInstance().getMinEffectiveConnection(); |
| 150 | + |
148 | 151 | /** |
149 | 152 | * Creates a new Wallet with a random ECKey. |
150 | 153 | */ |
@@ -399,22 +402,28 @@ public TransactionCapsule createTransactionCapsule(com.google.protobuf.Message m |
399 | 402 | */ |
400 | 403 | public GrpcAPI.Return broadcastTransaction(Transaction signaturedTransaction) { |
401 | 404 | 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 | + } |
417 | 425 | } |
| 426 | + |
418 | 427 | TransactionCapsule trx = new TransactionCapsule(signaturedTransaction); |
419 | 428 | Message message = new TransactionMessage(signaturedTransaction); |
420 | 429 |
|
|
0 commit comments