Skip to content

Commit

Permalink
Merge pull request #140 from eosnetworkfoundation/yarkin/ws_batch_has…
Browse files Browse the repository at this point in the history
…h_check

Extra checks for block hash when batch requesting block and logs.
  • Loading branch information
arhag authored Dec 8, 2023
2 parents 8c8f62e + d8e2a14 commit ff5e012
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions peripherals/eos-evm-ws-proxy/block-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ class BlockMonitor extends EventEmitter {
const block = results.data[0].result;
const logs = results.data[1].result;

if (!block || !block["hash"]) {
throw new Error("missing hash in response for getBlock request of the [getBlock, GetPastLogs] batch request");
}
if (!Array.isArray(logs)) {
throw new Error("invalid logs in response for GetPastLogs request of the [getBlock, GetPastLogs] batch request");
}
for (const logEntry of logs) {
if (!logEntry["blockHash"]) {
throw new Error("missing blockHash in response for GetPastLogs request of the [getBlock, GetPastLogs] batch request");
}
else if (logEntry["blockHash"] !== block["hash"]) {
throw new Error("mismatched hashes in response of [getBlock, GetPastLogs] batch request");
}
}

block.logs = logs;
//console.log("RPC batch result:" + JSON.stringify(block));
return block;
Expand Down

0 comments on commit ff5e012

Please sign in to comment.