Skip to content

Commit 8723666

Browse files
authored
Merge pull request #1279 from ainblockchain/release/v1.3.1
Release/v1.3.1
2 parents a9bf234 + a0c8dbd commit 8723666

File tree

15 files changed

+423
-137
lines changed

15 files changed

+423
-137
lines changed

blockchain-configs/base/timer_flags.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,9 @@
5959
"allow_up_to_6_decimal_transfer_value_only": {
6060
"enabled_block": 2,
6161
"has_bandage": true
62+
},
63+
"update_tx_bytes_limit": {
64+
"enabled_block": 2,
65+
"has_bandage": true
6266
}
6367
}

blockchain-configs/mainnet-prod/timer_flags.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,9 @@
5858
"allow_up_to_6_decimal_transfer_value_only": {
5959
"enabled_block": 3064900,
6060
"has_bandage": true
61+
},
62+
"update_tx_bytes_limit": {
63+
"enabled_block": 3940700,
64+
"has_bandage": true
6165
}
6266
}

blockchain-configs/testnet-prod/timer_flags.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,9 @@
6262
"allow_up_to_6_decimal_transfer_value_only": {
6363
"enabled_block": 3062600,
6464
"has_bandage": true
65+
},
66+
"update_tx_bytes_limit": {
67+
"enabled_block": 3938200,
68+
"has_bandage": true
6569
}
6670
}

client/middleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Middleware {
3737
});
3838
}
3939

40-
// TODO(platfowner): Use dynamic origin (see https://www.npmjs.com/package/cors).
40+
// NOTE(platfowner): For performance reasons, we do not support dynamic origin (see https://www.npmjs.com/package/cors).
4141
corsLimiter() {
4242
return cors({ origin: NodeConfigs.CORS_WHITELIST === '*' ?
4343
NodeConfigs.CORS_WHITELIST : CommonUtil.getRegexpList(NodeConfigs.CORS_WHITELIST) });

client/protocol_versions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,8 @@
143143
},
144144
"1.3.0": {
145145
"min": "1.0.0"
146+
},
147+
"1.3.1": {
148+
"min": "1.0.0"
146149
}
147150
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
data: [
3+
{
4+
path: ['values', 'blockchain_params', 'resource', 'tx_bytes_limit'],
5+
value: 100000,
6+
prevValue: 10000
7+
}
8+
]
9+
};

json_rpc/transaction.js

Lines changed: 91 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,54 @@ const { JSON_RPC_METHODS } = require('./constants');
1313
function sendTransactionOnNode(node, p2pServer, args, done, isDryrun) {
1414
const beginTime = Date.now();
1515
const txBytesLimit = node.getBlockchainParam('resource/tx_bytes_limit');
16-
if (sizeof(args) > txBytesLimit) {
16+
if (!args.tx_body || !args.signature) {
17+
const latency = Date.now() - beginTime;
18+
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
19+
done(null, JsonRpcUtil.addProtocolVersion({
20+
result: null,
21+
code: JsonRpcApiResultCode.TX_MISSING_PROPERTIES,
22+
message: 'Missing properties.'
23+
}));
24+
return;
25+
}
26+
if (sizeof(args.tx_body) > txBytesLimit) {
1727
const latency = Date.now() - beginTime;
1828
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
1929
done(null, JsonRpcUtil.addProtocolVersion({
2030
result: null,
2131
code: JsonRpcApiResultCode.TX_EXCEEDS_SIZE_LIMIT,
2232
message: `Transaction size exceeds its limit: ${txBytesLimit} bytes.`
2333
}));
24-
} else if (!args.tx_body || !args.signature) {
34+
return;
35+
}
36+
const chainId = node.getBlockchainParam('genesis/chain_id');
37+
const createdTx = Transaction.create(args.tx_body, args.signature, chainId);
38+
if (!createdTx) {
2539
const latency = Date.now() - beginTime;
2640
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
2741
done(null, JsonRpcUtil.addProtocolVersion({
2842
result: null,
29-
code: JsonRpcApiResultCode.TX_MISSING_PROPERTIES,
30-
message: 'Missing properties.'
43+
code: JsonRpcApiResultCode.TX_INVALID_FORMAT,
44+
message: 'Invalid transaction format.'
3145
}));
32-
} else {
33-
const chainId = node.getBlockchainParam('genesis/chain_id');
34-
const createdTx = Transaction.create(args.tx_body, args.signature, chainId);
35-
if (!createdTx) {
36-
const latency = Date.now() - beginTime;
37-
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
38-
done(null, JsonRpcUtil.addProtocolVersion({
39-
result: null,
40-
code: JsonRpcApiResultCode.TX_INVALID_FORMAT,
41-
message: 'Invalid transaction format.'
42-
}));
43-
} else {
44-
if (!NodeConfigs.LIGHTWEIGHT &&
45-
NodeConfigs.ENABLE_EARLY_TX_SIG_VERIF &&
46-
!Transaction.verifyTransaction(createdTx, chainId)) {
47-
done(null, JsonRpcUtil.addProtocolVersion({
48-
result: null,
49-
code: JsonRpcApiResultCode.TX_INVALID_SIGNATURE,
50-
message: 'Invalid transaction signature.'
51-
}));
52-
} else {
53-
const result = p2pServer.executeAndBroadcastTransaction(createdTx, isDryrun);
54-
const latency = Date.now() - beginTime;
55-
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
56-
done(null, JsonRpcUtil.addProtocolVersion({ result }));
57-
}
58-
}
46+
return;
47+
}
48+
if (!NodeConfigs.LIGHTWEIGHT &&
49+
NodeConfigs.ENABLE_EARLY_TX_SIG_VERIF &&
50+
!Transaction.verifyTransaction(createdTx, chainId)) {
51+
const latency = Date.now() - beginTime;
52+
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
53+
done(null, JsonRpcUtil.addProtocolVersion({
54+
result: null,
55+
code: JsonRpcApiResultCode.TX_INVALID_SIGNATURE,
56+
message: 'Invalid transaction signature.'
57+
}));
58+
return;
5959
}
60+
const result = p2pServer.executeAndBroadcastTransaction(createdTx, isDryrun);
61+
const latency = Date.now() - beginTime;
62+
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
63+
done(null, JsonRpcUtil.addProtocolVersion({ result }));
6064
}
6165

6266
module.exports = function getTransactionApis(node, p2pServer) {
@@ -149,67 +153,70 @@ module.exports = function getTransactionApis(node, p2pServer) {
149153
code: JsonRpcApiResultCode.BATCH_INVALID_FORMAT,
150154
message: 'Invalid batch transaction format.'
151155
}));
152-
} else if (args.tx_list.length > batchTxListSizeLimit) {
156+
return;
157+
}
158+
if (args.tx_list.length > batchTxListSizeLimit) {
153159
const latency = Date.now() - beginTime;
154160
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
155161
done(null, JsonRpcUtil.addProtocolVersion({
156162
result: null,
157163
code: JsonRpcApiResultCode.BATCH_TX_LIST_EXCEEDS_SIZE_LIMIT,
158164
message: `Batch transaction list size exceeds its limit: ${batchTxListSizeLimit}.`
159165
}));
160-
} else {
161-
const txBytesLimit = node.getBlockchainParam('resource/tx_bytes_limit');
162-
const chainId = node.getBlockchainParam('genesis/chain_id');
163-
const txList = [];
164-
for (let i = 0; i < args.tx_list.length; i++) {
165-
const tx = args.tx_list[i];
166-
if (sizeof(tx) > txBytesLimit) {
167-
const latency = Date.now() - beginTime;
168-
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
169-
done(null, JsonRpcUtil.addProtocolVersion({
170-
result: null,
171-
code: JsonRpcApiResultCode.BATCH_TX_EXCEEDS_SIZE_LIMIT,
172-
message: `Transaction[${i}]'s size exceededs its limit: ${txBytesLimit} bytes.`
173-
}));
174-
return;
175-
} else if (!tx.tx_body || !tx.signature) {
176-
const latency = Date.now() - beginTime;
177-
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
178-
done(null, JsonRpcUtil.addProtocolVersion({
179-
result: null,
180-
code: JsonRpcApiResultCode.BATCH_TX_MISSING_PROPERTIES,
181-
message: `Missing properties of transaction[${i}].`
182-
}));
183-
return;
184-
}
185-
const createdTx = Transaction.create(tx.tx_body, tx.signature, chainId);
186-
if (!createdTx) {
187-
const latency = Date.now() - beginTime;
188-
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
189-
done(null, JsonRpcUtil.addProtocolVersion({
190-
result: null,
191-
code: JsonRpcApiResultCode.BATCH_TX_INVALID_FORMAT,
192-
message: `Invalid format of transaction[${i}].`
193-
}));
194-
return;
195-
}
196-
if (!NodeConfigs.LIGHTWEIGHT &&
197-
NodeConfigs.ENABLE_EARLY_TX_SIG_VERIF &&
198-
!Transaction.verifyTransaction(createdTx, chainId)) {
199-
done(null, JsonRpcUtil.addProtocolVersion({
200-
result: null,
201-
code: JsonRpcApiResultCode.BATCH_TX_INVALID_SIGNATURE,
202-
message: `Invalid signature of transaction[${i}].`
203-
}));
204-
return;
205-
}
206-
txList.push(createdTx);
166+
return;
167+
}
168+
const txBytesLimit = node.getBlockchainParam('resource/tx_bytes_limit');
169+
const chainId = node.getBlockchainParam('genesis/chain_id');
170+
const txList = [];
171+
for (let i = 0; i < args.tx_list.length; i++) {
172+
const tx = args.tx_list[i];
173+
if (!tx.tx_body || !tx.signature) {
174+
const latency = Date.now() - beginTime;
175+
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
176+
done(null, JsonRpcUtil.addProtocolVersion({
177+
result: null,
178+
code: JsonRpcApiResultCode.BATCH_TX_MISSING_PROPERTIES,
179+
message: `Missing properties of transaction[${i}].`
180+
}));
181+
return;
207182
}
208-
const result = p2pServer.executeAndBroadcastTransaction({ tx_list: txList });
209-
const latency = Date.now() - beginTime;
210-
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
211-
done(null, JsonRpcUtil.addProtocolVersion({ result }));
183+
if (sizeof(tx.tx_body) > txBytesLimit) {
184+
const latency = Date.now() - beginTime;
185+
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
186+
done(null, JsonRpcUtil.addProtocolVersion({
187+
result: null,
188+
code: JsonRpcApiResultCode.BATCH_TX_EXCEEDS_SIZE_LIMIT,
189+
message: `Transaction[${i}]'s size exceededs its limit: ${txBytesLimit} bytes.`
190+
}));
191+
return;
192+
}
193+
const createdTx = Transaction.create(tx.tx_body, tx.signature, chainId);
194+
if (!createdTx) {
195+
const latency = Date.now() - beginTime;
196+
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
197+
done(null, JsonRpcUtil.addProtocolVersion({
198+
result: null,
199+
code: JsonRpcApiResultCode.BATCH_TX_INVALID_FORMAT,
200+
message: `Invalid format of transaction[${i}].`
201+
}));
202+
return;
203+
}
204+
if (!NodeConfigs.LIGHTWEIGHT &&
205+
NodeConfigs.ENABLE_EARLY_TX_SIG_VERIF &&
206+
!Transaction.verifyTransaction(createdTx, chainId)) {
207+
done(null, JsonRpcUtil.addProtocolVersion({
208+
result: null,
209+
code: JsonRpcApiResultCode.BATCH_TX_INVALID_SIGNATURE,
210+
message: `Invalid signature of transaction[${i}].`
211+
}));
212+
return;
213+
}
214+
txList.push(createdTx);
212215
}
213-
},
216+
const result = p2pServer.executeAndBroadcastTransaction({ tx_list: txList });
217+
const latency = Date.now() - beginTime;
218+
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_SET, latency);
219+
done(null, JsonRpcUtil.addProtocolVersion({ result }));
220+
}
214221
};
215222
};

p2p/p2p-util.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,18 @@ class P2pUtil {
9292
}
9393
}
9494

95-
static verifySignedMessage(message, address) {
95+
static verifySignedMessage(message, address, chainId) {
96+
const LOG_HEADER = 'verifySignedMessage';
9697
if (!P2pUtil._isValidMessage(message)) {
97-
return null;
98+
return false;
9899
} else {
99-
const chainId = DB.getBlockchainParam('genesis/chain_id');
100-
return ainUtil.ecVerifySig(JSON.stringify(message.data.body), message.data.signature, address, chainId);
100+
const cId = chainId !== undefined ? chainId : DB.getBlockchainParam('genesis/chain_id');
101+
try {
102+
return ainUtil.ecVerifySig(JSON.stringify(message.data.body), message.data.signature, address, cId);
103+
} catch (err) {
104+
logger.error(`[${LOG_HEADER}] The message is not correctly signed. Discard the message!!`);
105+
return false;
106+
}
101107
}
102108
}
103109

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ain-blockchain",
33
"description": "AI Network Blockchain",
4-
"version": "1.3.0",
4+
"version": "1.3.1",
55
"private": true,
66
"license": "MIT",
77
"author": "[email protected]",

0 commit comments

Comments
 (0)