Skip to content

Commit 5aa4f24

Browse files
authored
Merge pull request #615 from tronprotocol/transaction_bytes
check transaction size before broadcast
2 parents 33f7add + 727fd17 commit 5aa4f24

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@ public class Constant {
4141
public static final String ADD_PRE_FIX_STRING_TESTNET = "a0";
4242
public static final int ADDRESS_SIZE = 42;
4343
public static final int BASE58CHECK_ADDRESS_SIZE = 35;
44+
45+
// config for transaction
46+
public static final long TRANSACTION_MAX_BYTE_SIZE = 500 * 1024;
4447
}

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@
4343
import org.tron.core.capsule.WitnessCapsule;
4444
import org.tron.core.db.AccountStore;
4545
import org.tron.core.db.Manager;
46-
import org.tron.core.exception.ContractExeException;
47-
import org.tron.core.exception.ContractValidateException;
48-
import org.tron.core.exception.DupTransactionException;
49-
import org.tron.core.exception.StoreException;
50-
import org.tron.core.exception.TaposException;
51-
import org.tron.core.exception.ValidateBandwidthException;
52-
import org.tron.core.exception.ValidateSignatureException;
46+
import org.tron.core.exception.*;
5347
import org.tron.core.net.message.TransactionMessage;
5448
import org.tron.core.net.node.NodeImpl;
5549
import org.tron.protos.Contract.AccountCreateContract;
@@ -209,6 +203,9 @@ public boolean broadcastTransaction(Transaction signaturedTransaction) {
209203
TransactionCapsule trx = new TransactionCapsule(signaturedTransaction);
210204
try {
211205
Message message = new TransactionMessage(signaturedTransaction);
206+
if (message.getData().length > Constant.TRANSACTION_MAX_BYTE_SIZE) {
207+
throw new TooBigTransactionException("too big transaction, the size is " + message.getData().length + " bytes");
208+
}
212209
dbManager.pushTransactions(trx);
213210
p2pNode.broadcast(message);
214211
return true;
@@ -223,8 +220,10 @@ public boolean broadcastTransaction(Transaction signaturedTransaction) {
223220
} catch (DupTransactionException e) {
224221
logger.error("dup trans", e);
225222
} catch (TaposException e) {
226-
logger.error("tapos error", e);
227-
}catch (Exception e){
223+
logger.debug("tapos error", e);
224+
} catch (TooBigTransactionException e) {
225+
logger.debug("transaction error", e);
226+
} catch (Exception e){
228227
logger.error("exception caught", e);
229228
}
230229
return false;
@@ -344,12 +343,12 @@ public Block getBlockById(ByteString BlockId) {
344343
if (Objects.isNull(BlockId)) {
345344
return null;
346345
}
347-
Block blocke = null;
346+
Block block = null;
348347
try {
349-
blocke = dbManager.getBlockStore().get(BlockId.toByteArray()).getInstance();
348+
block = dbManager.getBlockStore().get(BlockId.toByteArray()).getInstance();
350349
} catch (StoreException e) {
351350
}
352-
return blocke;
351+
return block;
353352
}
354353

355354
public BlockList getBlocksByLimitNext(long number, long limit) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.tron.core.exception;
2+
3+
public class TooBigTransactionException extends TronException {
4+
5+
public TooBigTransactionException() { super(); }
6+
7+
public TooBigTransactionException(String message) { super(message); }
8+
}

0 commit comments

Comments
 (0)