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

Update postBlock and postTransactionsAnnouncement channel communication to hex - Closes #6254 #6255

Merged
merged 1 commit into from Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions framework/src/constants.ts
Expand Up @@ -35,3 +35,7 @@ export const APP_EVENT_CHAIN_FORK = 'app:chain:fork';
export const APP_EVENT_CHAIN_VALIDATORS_CHANGE = 'app:chain:validators:change';
export const APP_EVENT_BLOCK_NEW = 'app:block:new';
export const APP_EVENT_BLOCK_DELETE = 'app:block:delete';

export const EVENT_POST_BLOCK = 'postBlock';
export const EVENT_POST_TRANSACTION_ANNOUNCEMENT = 'postTransactionsAnnouncement';
export const EVENT_POST_NODE_INFO = 'postNodeInfo';
17 changes: 12 additions & 5 deletions framework/src/node/network/network.ts
Expand Up @@ -18,7 +18,13 @@ import { KVStore, NotFoundError } from '@liskhq/lisk-db';
import { EventEmitter } from 'events';
import * as liskP2P from '@liskhq/lisk-p2p';

import { APP_EVENT_NETWORK_READY, APP_EVENT_NETWORK_EVENT } from '../../constants';
import {
APP_EVENT_NETWORK_READY,
APP_EVENT_NETWORK_EVENT,
EVENT_POST_BLOCK,
EVENT_POST_NODE_INFO,
EVENT_POST_TRANSACTION_ANNOUNCEMENT,
} from '../../constants';
import { InMemoryChannel } from '../../controller/channels';
import { lookupPeersIPs } from './utils';
import { Logger } from '../../logger';
Expand Down Expand Up @@ -50,7 +56,11 @@ const DB_KEY_NETWORK_NODE_SECRET = 'network:nodeSecret';
const DB_KEY_NETWORK_TRIED_PEERS_LIST = 'network:triedPeersList';
const DEFAULT_PEER_SAVE_INTERVAL = 10 * 60 * 1000; // 10min in ms

const REMOTE_EVENTS_WHITE_LIST = ['postTransactionsAnnouncement', 'postBlock', 'postNodeInfo'];
const REMOTE_EVENTS_WHITE_LIST = [
EVENT_POST_BLOCK,
EVENT_POST_NODE_INFO,
EVENT_POST_TRANSACTION_ANNOUNCEMENT,
];

interface NodeInfoOptions {
[key: string]: unknown;
Expand Down Expand Up @@ -373,9 +383,6 @@ export class Network {
'EVENT_MESSAGE_RECEIVED: Received inbound message',
);
this.events.emit(APP_EVENT_NETWORK_EVENT, packet);
const data =
packet.data && Buffer.isBuffer(packet.data) ? packet.data.toString('hex') : packet.data;
this._channel.publish(APP_EVENT_NETWORK_EVENT, { ...packet, data });
},
);

Expand Down
17 changes: 16 additions & 1 deletion framework/src/node/transport/transport.ts
Expand Up @@ -43,7 +43,12 @@ import { Broadcaster } from './broadcaster';
import { InMemoryChannel } from '../../controller/channels';
import { Network } from '../network';
import { ApplyPenaltyError } from '../../errors';
import { APP_EVENT_TRANSACTION_NEW } from '../../constants';
import {
APP_EVENT_TRANSACTION_NEW,
APP_EVENT_NETWORK_EVENT,
EVENT_POST_BLOCK,
EVENT_POST_TRANSACTION_ANNOUNCEMENT,
} from '../../constants';

const DEFAULT_RATE_RESET_TIME = 10000;
const DEFAULT_RATE_LIMIT_FREQUENCY = 3;
Expand Down Expand Up @@ -274,6 +279,10 @@ export class Transport {
}

const { block: blockBytes } = decodedData;
this._channel.publish(APP_EVENT_NETWORK_EVENT, {
event: EVENT_POST_BLOCK,
data: { block: blockBytes.toString('hex') },
});

let block: Block;
try {
Expand Down Expand Up @@ -440,6 +449,12 @@ export class Transport {

const { transactionIds } = decodedData as EventPostTransactionsAnnouncementData;

const encodedIds = transactionIds.map(id => id.toString('hex'));
this._channel.publish(APP_EVENT_NETWORK_EVENT, {
event: EVENT_POST_TRANSACTION_ANNOUNCEMENT,
data: { transactionIds: encodedIds },
});

const unknownTransactionIDs = await this._obtainUnknownTransactionIDs(transactionIds);
if (unknownTransactionIDs.length > 0) {
const transactionIdsBuffer = codec.encode(transactionIdsSchema, {
Expand Down