Skip to content

Commit 91c48e4

Browse files
authored
Merge pull request #1299 from ainblockchain/release/v1.4.1
Release/v1.4.1
2 parents 7b41b72 + 68e60fc commit 91c48e4

File tree

18 files changed

+43
-2
lines changed

18 files changed

+43
-2
lines changed

blockchain-configs/afan-shard/node_params.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600,
3434
"EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 15000,
3535
"EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000,
36+
"EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH": 100,
3637
"EVENT_HANDLER_PORT": 5100,
3738
"EXPRESS_RATE_LIMIT_WINDOW_SECS": 60,
3839
"FREE_TX_POOL_SIZE_LIMIT_RATIO": 0.1,

blockchain-configs/base/node_params.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600,
3434
"EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000,
3535
"EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000,
36+
"EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH": 100,
3637
"EVENT_HANDLER_PORT": 5100,
3738
"EXPRESS_RATE_LIMIT_WINDOW_SECS": 60,
3839
"FREE_TX_POOL_SIZE_LIMIT_RATIO": 0.1,

blockchain-configs/he-shard/node_params.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600,
3434
"EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 15000,
3535
"EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000,
36+
"EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH": 100,
3637
"EVENT_HANDLER_PORT": 5100,
3738
"EXPRESS_RATE_LIMIT_WINDOW_SECS": 60,
3839
"FREE_TX_POOL_SIZE_LIMIT_RATIO": 0.1,

blockchain-configs/mainnet-prod/node_params.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600,
3333
"EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000,
3434
"EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000,
35+
"EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH": 100,
3536
"EVENT_HANDLER_PORT": 5100,
3637
"EXPRESS_RATE_LIMIT_WINDOW_SECS": 60,
3738
"FREE_TX_POOL_SIZE_LIMIT_RATIO": 0.1,

blockchain-configs/sim-shard/node_params.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600,
3434
"EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000,
3535
"EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000,
36+
"EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH": 100,
3637
"EVENT_HANDLER_PORT": 5100,
3738
"EXPRESS_RATE_LIMIT_WINDOW_SECS": 60,
3839
"FREE_TX_POOL_SIZE_LIMIT_RATIO": 0.1,

blockchain-configs/testnet-dev/node_params.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600,
3434
"EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000,
3535
"EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000,
36+
"EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH": 100,
3637
"EVENT_HANDLER_PORT": 5100,
3738
"EXPRESS_RATE_LIMIT_WINDOW_SECS": 60,
3839
"FREE_TX_POOL_SIZE_LIMIT_RATIO": 0.1,

blockchain-configs/testnet-exp/node_params.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600,
3434
"EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000,
3535
"EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000,
36+
"EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH": 100,
3637
"EVENT_HANDLER_PORT": 5100,
3738
"EXPRESS_RATE_LIMIT_WINDOW_SECS": 60,
3839
"FREE_TX_POOL_SIZE_LIMIT_RATIO": 0.1,

blockchain-configs/testnet-prod/node_params.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600,
3434
"EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000,
3535
"EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000,
36+
"EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH": 100,
3637
"EVENT_HANDLER_PORT": 5100,
3738
"EXPRESS_RATE_LIMIT_WINDOW_SECS": 60,
3839
"FREE_TX_POOL_SIZE_LIMIT_RATIO": 0.1,

blockchain-configs/testnet-sandbox/node_params.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600,
3434
"EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000,
3535
"EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000,
36+
"EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH": 100,
3637
"EVENT_HANDLER_PORT": 5100,
3738
"EXPRESS_RATE_LIMIT_WINDOW_SECS": 60,
3839
"FREE_TX_POOL_SIZE_LIMIT_RATIO": 0.1,

blockchain-configs/testnet-staging/node_params.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS": 3600,
3434
"EVENT_HANDLER_FILTER_DELETION_TIMEOUT_MS": 100000,
3535
"EVENT_HANDLER_HEARTBEAT_INTERVAL_MS": 15000,
36+
"EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH": 100,
3637
"EVENT_HANDLER_PORT": 5100,
3738
"EXPRESS_RATE_LIMIT_WINDOW_SECS": 60,
3839
"FREE_TX_POOL_SIZE_LIMIT_RATIO": 0.1,

client/protocol_versions.json

+3
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,8 @@
149149
},
150150
"1.4.0": {
151151
"min": "1.0.0"
152+
},
153+
"1.4.1": {
154+
"min": "1.0.0"
152155
}
153156
}

common/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ const BlockchainEventTypes = {
677677
};
678678

679679
const BlockchainEventMessageTypes = {
680+
SET_CUSTOM_CLIENT_ID: 'SET_CUSTOM_CLIENT_ID',
680681
REGISTER_FILTER: 'REGISTER_FILTER',
681682
DEREGISTER_FILTER: 'DEREGISTER_FILTER',
682683
EMIT_EVENT: 'EMIT_EVENT',

common/result-code.js

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ const EventHandlerErrorCode = {
226226
EVENT_FILTER_EXCEEDS_SIZE_LIMIT_PER_CHANNEL: 70016,
227227
FAILED_TO_REGISTER_FILTER: 70020,
228228
FAILED_TO_DEREGISTER_FILTER: 70030,
229+
INVALID_CUSTOM_CLIENT_ID: 70040,
229230
// BLOCK_FINALIZED (701XX)
230231
NEGATIVE_BLOCK_NUMBER: 70100,
231232
INVALID_BLOCK_NUMBER_TYPE: 70101,

event-handler/event-channel-manager.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
BlockchainEventTypes,
99
FilterDeletionReasons,
1010
} = require('../common/constants');
11+
const CommonUtil = require('../common/common-util');
1112
const EventHandlerError = require('./event-handler-error');
1213
const { EventHandlerErrorCode } = require('../common/result-code');
1314
const BlockchainEvent = require('./blockchain-event');
@@ -40,6 +41,7 @@ class EventChannelManager {
4041
return {
4142
maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS,
4243
numEventChannels: this.getNumEventChannels(),
44+
channelLifeTimeLimitSecs: NodeConfigs.EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS,
4345
channelIdleTimeLimitSecs: NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS,
4446
maxChannelLifeTimeMs: channelStats.maxLifeTimeMs,
4547
maxChannelIdleTimeMs: channelStats.maxIdleTimeMs,
@@ -157,6 +159,18 @@ class EventChannelManager {
157159
}
158160
}
159161

162+
handleSetCustomClientId(channel, messageData) {
163+
const LOG_HEADER = 'handleSetCustomClientId';
164+
const customClientId = messageData.customClientId;
165+
if (!CommonUtil.isString(customClientId)) {
166+
throw new EventHandlerError(EventHandlerErrorCode.INVALID_CUSTOM_CLIENT_ID,
167+
`Invalid custom client id: ${customClientId}`);
168+
}
169+
const normalized = customClientId.slice(0, NodeConfigs.EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH);
170+
logger.info(`[${LOG_HEADER}] Setting custom client id: ${normalized} for channel: ${channel.id}`);
171+
channel.setCustomClientId(normalized);
172+
}
173+
160174
handleRegisterFilterMessage(channel, messageData) {
161175
const LOG_HEADER = 'handleRegisterFilterMessage';
162176
const clientFilterId = messageData.id;
@@ -292,6 +306,9 @@ class EventChannelManager {
292306
// TODO(cshcomcom): Manage EVENT_PROTOCOL_VERSION.
293307
handleMessage(channel, messageType, messageData) {
294308
switch (messageType) {
309+
case BlockchainEventMessageTypes.SET_CUSTOM_CLIENT_ID:
310+
this.handleSetCustomClientId(channel, messageData);
311+
break;
295312
case BlockchainEventMessageTypes.REGISTER_FILTER:
296313
this.handleRegisterFilterMessage(channel, messageData);
297314
break;
@@ -300,7 +317,7 @@ class EventChannelManager {
300317
break;
301318
default:
302319
throw new EventHandlerError(EventHandlerErrorCode.INVALID_MESSAGE_TYPE,
303-
`Invalid message type (${messageType})`);
320+
`Invalid message type: ${messageType}`);
304321
}
305322
}
306323

event-handler/event-channel.js

+7
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ class EventChannel {
55
this.id = id;
66
this.webSocket = webSocket;
77
this.remoteUrl = buildRemoteUrlFromSocket(webSocket);
8+
this.customClientId = '';
89
this.eventFilterIds = new Set();
910
const curTimeMs = Date.now();
1011
this.creationTimeMs = curTimeMs;
1112
this.lastMessagingTimeMs = curTimeMs;
1213
}
1314

15+
setCustomClientId(customClientId) {
16+
this.customClientId = customClientId;
17+
}
18+
1419
setLastMessagingTimeMs(timeMs) {
1520
this.lastMessagingTimeMs = timeMs;
1621
}
@@ -43,7 +48,9 @@ class EventChannel {
4348
return {
4449
id: this.id,
4550
remoteUrl: this.remoteUrl,
51+
customClientId: this.customClientId,
4652
eventFilterIds: [...this.eventFilterIds],
53+
creationTimeMs: this.creationTimeMs,
4754
lastMessagingTimeMs: this.lastMessagingTimeMs,
4855
lifeTimeMs: this.getLifeTimeMs(),
4956
idleTimeMs: this.getIdleTimeMs(),

event-handler/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class EventHandler {
4848
channelStatus: {
4949
maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS,
5050
numEventChannels: 0,
51+
channelLifeTimeLimitSecs: NodeConfigs.EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS,
5152
channelIdleTimeLimitSecs: NodeConfigs.EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS,
5253
maxChannelLifeTimeMs: 0,
5354
maxChannelIdleTimeMs: 0,

package.json

+1-1
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.4.0",
4+
"version": "1.4.1",
55
"private": true,
66
"license": "MIT",
77
"author": "[email protected]",

test/unit/p2p.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ describe("P2p", () => {
235235
channelStatus: {
236236
maxNumEventChannels: 20,
237237
numEventChannels: 0,
238+
channelLifeTimeLimitSecs: 3600,
238239
channelIdleTimeLimitSecs: 600,
239240
maxChannelIdleTimeMs: 0,
240241
maxChannelLifeTimeMs: 0,

0 commit comments

Comments
 (0)