Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v1.3.1 #1279

Merged
merged 17 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": 3940700,
"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": 3938200,
"has_bandage": true
}
}
2 changes: 1 addition & 1 deletion client/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Middleware {
});
}

// TODO(platfowner): Use dynamic origin (see https://www.npmjs.com/package/cors).
// NOTE(platfowner): For performance reasons, we do not support dynamic origin (see https://www.npmjs.com/package/cors).
corsLimiter() {
return cors({ origin: NodeConfigs.CORS_WHITELIST === '*' ?
NodeConfigs.CORS_WHITELIST : CommonUtil.getRegexpList(NodeConfigs.CORS_WHITELIST) });
Expand Down
3 changes: 3 additions & 0 deletions client/protocol_versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,8 @@
},
"1.3.0": {
"min": "1.0.0"
},
"1.3.1": {
"min": "1.0.0"
}
}
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 }));
}
};
};
14 changes: 10 additions & 4 deletions p2p/p2p-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,18 @@ class P2pUtil {
}
}

static verifySignedMessage(message, address) {
static verifySignedMessage(message, address, chainId) {
const LOG_HEADER = 'verifySignedMessage';
if (!P2pUtil._isValidMessage(message)) {
return null;
return false;
} else {
const chainId = DB.getBlockchainParam('genesis/chain_id');
return ainUtil.ecVerifySig(JSON.stringify(message.data.body), message.data.signature, address, chainId);
const cId = chainId !== undefined ? chainId : DB.getBlockchainParam('genesis/chain_id');
try {
return ainUtil.ecVerifySig(JSON.stringify(message.data.body), message.data.signature, address, cId);
} catch (err) {
logger.error(`[${LOG_HEADER}] The message is not correctly signed. Discard the message!!`);
return false;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ain-blockchain",
"description": "AI Network Blockchain",
"version": "1.3.0",
"version": "1.3.1",
"private": true,
"license": "MIT",
"author": "[email protected]",
Expand Down
Loading
Loading