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

fix: removed ping method in WS server #2394

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ Unless you need to set a non-default value, it is recommended to only populate o
| `WS_MULTIPLE_ADDRESSES_ENABLED` | "false" | If enabled eth_subscribe will allow subscription to multiple contract address. |
| `WS_CACHE_TTL` | "20000" | The time to live for cached entries. |
| `WS_NEW_HEADS_ENABLED`. | "true" | Enables subscriptions for the latest blocks, `newHeads`. |
| `WS_PING_INTERVAL` | "1000" | Interval between ping messages. Set to `0` to disable pinger. |

## Sample for connecting to Hedera Environments

Expand Down
8 changes: 0 additions & 8 deletions packages/ws-server/src/webSocketServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ const mirrorNodeClient = relay.mirrorClient();
const limiter = new ConnectionLimiter(logger, register);
const wsMetricRegistry = new WsMetricRegistry(register);

const pingInterval = Number(process.env.WS_PING_INTERVAL || 1000);

const app = websockify(new Koa());
app.ws.use(async (ctx) => {
// Increment the total opened connections
Expand Down Expand Up @@ -243,12 +241,6 @@ app.ws.use(async (ctx) => {
// Update the connection duration histogram with the calculated duration
wsMetricRegistry.getHistogram('messageDuration').labels(method).observe(msgDurationInMiliSeconds);
});

if (pingInterval > 0) {
setInterval(async () => {
ctx.websocket.send(JSON.stringify(jsonResp(null, null, null)));
}, pingInterval);
}
});

const httpApp = new KoaJsonRpc(logger, register).getKoaApp();
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-server/tests/acceptance/estimateGas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('@release @web-socket-batch-1 eth_estimateGas', async function () {
expect(Number(estimatedGas)).to.be.greaterThan(currentPrice * (1 - gasPriceDeviation));
});

it('should return the code through a websocket', async () => {
it('@release should execute "eth_estimateGas" for contract call, using a standard websocket', async () => {
const tx = { to: basicContract.target, data: BASIC_CONTRACT_PING_CALL_DATA };
const response = await WsTestHelper.sendRequestToStandardWebSocket(METHOD_NAME, [tx]);
WsTestHelper.assertJsonRpcObject(response);
Expand Down
14 changes: 0 additions & 14 deletions packages/ws-server/tests/acceptance/subscribe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,6 @@ describe('@release @web-socket-batch-3 eth_subscribe', async function () {
expect(wsProvider.ready).to.eq(true);
});

it('@release receives ping messages', async function () {
expect(wsProvider).to.exist;
expect(wsProvider.ready).to.eq(true);

let pings = 0;
wsProvider.websocket.on('message', (message) => {
pings++;
});

await new Promise((resolve) => setTimeout(resolve, 2500));

expect(pings).to.greaterThanOrEqual(2);
});

it('@release Socket server responds to the eth_chainId event', async function () {
const response = await wsProvider.send('eth_chainId', []);
expect(response).to.eq(CHAIN_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ describe('@release @web-socket-batch-3 eth_subscribe newHeads', async function (

describe('Subscriptions for newHeads', async function () {
it('should subscribe to newHeads, include transactions true, and receive a valid JSON RPC response', (done) => {
process.env.WS_NEW_HEADS_ENABLED = 'true';
const webSocket = new WebSocket(WS_RELAY_URL);
const subscriptionId = 1;
Comment on lines 203 to 207
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We can extract the common setup logic in beforeEach:

  describe('Subscriptions for newHeads', async function () {
+   let webSocket: WebSocket;
+   const subscriptionId = 1;
+
+   beforeEach(() => {
+      process.env.WS_NEW_HEADS_ENABLED = 'true';
+.     webSocket = new WebSocket(WS_RELAY_URL);
+   });

    it('should subscribe to newHeads, include transactions true, and receive a valid JSON RPC response', (done) => {
-     process.env.WS_NEW_HEADS_ENABLED = 'true';
-     const webSocket = new WebSocket(WS_RELAY_URL);
-     const subscriptionId = 1;
      ...
    });
    
    it('should subscribe to newHeads, without the "include transactions", and receive a valid JSON RPC response', (done) => {
-     process.env.WS_NEW_HEADS_ENABLED = 'true';
-     const webSocket = new WebSocket(WS_RELAY_URL);
-     const subscriptionId = 1;
      ...
    });

    it('should subscribe to newHeads, with "include transactions false", and receive a valid JSON RPC response', (done) => {
-     process.env.WS_NEW_HEADS_ENABLED = 'true';
-     const webSocket = new WebSocket(WS_RELAY_URL);
-     const subscriptionId = 1;
      ...
    });

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion thanks a lot!

webSocket.on('open', function open() {
Expand Down Expand Up @@ -231,6 +232,7 @@ describe('@release @web-socket-batch-3 eth_subscribe newHeads', async function (
});

it('should subscribe to newHeads, without the "include transactions", and receive a valid JSON RPC response', (done) => {
process.env.WS_NEW_HEADS_ENABLED = 'true';
const webSocket = new WebSocket(WS_RELAY_URL);
const subscriptionId = 1;
webSocket.on('open', function open() {
Expand Down Expand Up @@ -260,6 +262,7 @@ describe('@release @web-socket-batch-3 eth_subscribe newHeads', async function (
});

it('should subscribe to newHeads, with "include transactions false", and receive a valid JSON RPC response', (done) => {
process.env.WS_NEW_HEADS_ENABLED = 'true';
const webSocket = new WebSocket(WS_RELAY_URL);
const subscriptionId = 1;
webSocket.on('open', function open() {
Expand Down
Loading