Skip to content

Commit

Permalink
Merge pull request #1278 from ainblockchain/bugfix/platfowner/bugfix
Browse files Browse the repository at this point in the history
Increase tx_bytes_limit to 100k bytes from 10k bytes
  • Loading branch information
platfowner authored Jul 1, 2024
2 parents 94e21f3 + 022ae8a commit fed1f3c
Show file tree
Hide file tree
Showing 6 changed files with 367 additions and 111 deletions.
4 changes: 4 additions & 0 deletions blockchain-configs/base/timer_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@
"allow_up_to_6_decimal_transfer_value_only": {
"enabled_block": 2,
"has_bandage": true
},
"update_tx_bytes_limit": {
"enabled_block": 2,
"has_bandage": true
}
}
4 changes: 4 additions & 0 deletions blockchain-configs/mainnet-prod/timer_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,9 @@
"allow_up_to_6_decimal_transfer_value_only": {
"enabled_block": 3064900,
"has_bandage": true
},
"update_tx_bytes_limit": {
"enabled_block": null,
"has_bandage": true
}
}
4 changes: 4 additions & 0 deletions blockchain-configs/testnet-prod/timer_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@
"allow_up_to_6_decimal_transfer_value_only": {
"enabled_block": 3062600,
"has_bandage": true
},
"update_tx_bytes_limit": {
"enabled_block": null,
"has_bandage": true
}
}
9 changes: 9 additions & 0 deletions db/bandage-files/update_tx_bytes_limit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
data: [
{
path: ['values', 'blockchain_params', 'resource', 'tx_bytes_limit'],
value: 100000,
prevValue: 10000
}
]
};
175 changes: 91 additions & 84 deletions json_rpc/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,54 @@ const { JSON_RPC_METHODS } = require('./constants');
function sendTransactionOnNode(node, p2pServer, args, done, isDryrun) {
const beginTime = Date.now();
const txBytesLimit = node.getBlockchainParam('resource/tx_bytes_limit');
if (sizeof(args) > txBytesLimit) {
if (!args.tx_body || !args.signature) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.TX_MISSING_PROPERTIES,
message: 'Missing properties.'
}));
return;
}
if (sizeof(args.tx_body) > txBytesLimit) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.TX_EXCEEDS_SIZE_LIMIT,
message: `Transaction size exceeds its limit: ${txBytesLimit} bytes.`
}));
} else if (!args.tx_body || !args.signature) {
return;
}
const chainId = node.getBlockchainParam('genesis/chain_id');
const createdTx = Transaction.create(args.tx_body, args.signature, chainId);
if (!createdTx) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.TX_MISSING_PROPERTIES,
message: 'Missing properties.'
code: JsonRpcApiResultCode.TX_INVALID_FORMAT,
message: 'Invalid transaction format.'
}));
} else {
const chainId = node.getBlockchainParam('genesis/chain_id');
const createdTx = Transaction.create(args.tx_body, args.signature, chainId);
if (!createdTx) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.TX_INVALID_FORMAT,
message: 'Invalid transaction format.'
}));
} else {
if (!NodeConfigs.LIGHTWEIGHT &&
NodeConfigs.ENABLE_EARLY_TX_SIG_VERIF &&
!Transaction.verifyTransaction(createdTx, chainId)) {
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.TX_INVALID_SIGNATURE,
message: 'Invalid transaction signature.'
}));
} else {
const result = p2pServer.executeAndBroadcastTransaction(createdTx, isDryrun);
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({ result }));
}
}
return;
}
if (!NodeConfigs.LIGHTWEIGHT &&
NodeConfigs.ENABLE_EARLY_TX_SIG_VERIF &&
!Transaction.verifyTransaction(createdTx, chainId)) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.TX_INVALID_SIGNATURE,
message: 'Invalid transaction signature.'
}));
return;
}
const result = p2pServer.executeAndBroadcastTransaction(createdTx, isDryrun);
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({ result }));
}

module.exports = function getTransactionApis(node, p2pServer) {
Expand Down Expand Up @@ -149,67 +153,70 @@ module.exports = function getTransactionApis(node, p2pServer) {
code: JsonRpcApiResultCode.BATCH_INVALID_FORMAT,
message: 'Invalid batch transaction format.'
}));
} else if (args.tx_list.length > batchTxListSizeLimit) {
return;
}
if (args.tx_list.length > batchTxListSizeLimit) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.BATCH_TX_LIST_EXCEEDS_SIZE_LIMIT,
message: `Batch transaction list size exceeds its limit: ${batchTxListSizeLimit}.`
}));
} else {
const txBytesLimit = node.getBlockchainParam('resource/tx_bytes_limit');
const chainId = node.getBlockchainParam('genesis/chain_id');
const txList = [];
for (let i = 0; i < args.tx_list.length; i++) {
const tx = args.tx_list[i];
if (sizeof(tx) > txBytesLimit) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.BATCH_TX_EXCEEDS_SIZE_LIMIT,
message: `Transaction[${i}]'s size exceededs its limit: ${txBytesLimit} bytes.`
}));
return;
} else if (!tx.tx_body || !tx.signature) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.BATCH_TX_MISSING_PROPERTIES,
message: `Missing properties of transaction[${i}].`
}));
return;
}
const createdTx = Transaction.create(tx.tx_body, tx.signature, chainId);
if (!createdTx) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.BATCH_TX_INVALID_FORMAT,
message: `Invalid format of transaction[${i}].`
}));
return;
}
if (!NodeConfigs.LIGHTWEIGHT &&
NodeConfigs.ENABLE_EARLY_TX_SIG_VERIF &&
!Transaction.verifyTransaction(createdTx, chainId)) {
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.BATCH_TX_INVALID_SIGNATURE,
message: `Invalid signature of transaction[${i}].`
}));
return;
}
txList.push(createdTx);
return;
}
const txBytesLimit = node.getBlockchainParam('resource/tx_bytes_limit');
const chainId = node.getBlockchainParam('genesis/chain_id');
const txList = [];
for (let i = 0; i < args.tx_list.length; i++) {
const tx = args.tx_list[i];
if (!tx.tx_body || !tx.signature) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.BATCH_TX_MISSING_PROPERTIES,
message: `Missing properties of transaction[${i}].`
}));
return;
}
const result = p2pServer.executeAndBroadcastTransaction({ tx_list: txList });
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({ result }));
if (sizeof(tx.tx_body) > txBytesLimit) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.BATCH_TX_EXCEEDS_SIZE_LIMIT,
message: `Transaction[${i}]'s size exceededs its limit: ${txBytesLimit} bytes.`
}));
return;
}
const createdTx = Transaction.create(tx.tx_body, tx.signature, chainId);
if (!createdTx) {
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.BATCH_TX_INVALID_FORMAT,
message: `Invalid format of transaction[${i}].`
}));
return;
}
if (!NodeConfigs.LIGHTWEIGHT &&
NodeConfigs.ENABLE_EARLY_TX_SIG_VERIF &&
!Transaction.verifyTransaction(createdTx, chainId)) {
done(null, JsonRpcUtil.addProtocolVersion({
result: null,
code: JsonRpcApiResultCode.BATCH_TX_INVALID_SIGNATURE,
message: `Invalid signature of transaction[${i}].`
}));
return;
}
txList.push(createdTx);
}
},
const result = p2pServer.executeAndBroadcastTransaction({ tx_list: txList });
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
done(null, JsonRpcUtil.addProtocolVersion({ result }));
}
};
};
Loading

0 comments on commit fed1f3c

Please sign in to comment.