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

Hashes from newHeads and eth_getBlockByNumber are different #3050

Closed
KirillPamPam opened this issue Oct 28, 2024 · 2 comments
Closed

Hashes from newHeads and eth_getBlockByNumber are different #3050

KirillPamPam opened this issue Oct 28, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@KirillPamPam
Copy link

Describe the Bug
We noticed the differences in the hashes between the blocks via the newHeads subscription and blocks via eth_getBlockByNumber at the same height. The blocks via eth_getBlockByNumber are equals to the ones in https://explorer.zetachain.com/ but the newHeads blocks seem to be forked.

To Reproduce
There is the script to reproduce this bug.

const wsUrl = "your_ws_url";
const rpcUrl = "your_http_url";
const WebSocket = require('ws');

function wsNewHeads(wsUrl, cb) {
    const ws = new WebSocket(wsUrl);
    ws.onopen = () => {
        console.log("ws connected");
        ws.send(JSON.stringify({
            jsonrpc: "2.0",
            method: "eth_subscribe",
            params: ["newHeads"],
            id: 1
        }));
    };
    ws.onclose = () => {
        console.log("ws closed");
    };
    let isFirst = true;
    ws.onmessage = (event) => {
        if (isFirst) {
            isFirst = false;
            return;
        }
        const data = JSON.parse(event.data);
        cb(data);
    };
}

async function rpcGetBlock(rpcUrl, blockNum) {
    const response = await fetch(rpcUrl, {
        method: "POST",
        headers: {
            "Content-Type": "application/json"
        },
        body: JSON.stringify({
            jsonrpc: "2.0",
            method: "eth_getBlockByNumber",
            params: [blockNum, false],
            id: 1
        })
    });
    return await response.json();
}

async function main() {
    wsNewHeads(wsUrl, async (data) => {
        const block = await rpcGetBlock(rpcUrl, data.params.result.number);
        console.log(data.params.result)
        console.log(block)
    });
}

main();

Expected Behavior
The hashes from the newHeads sub and eth_getBlockByNumber must be equal to each other.

Screenshots

Environment (please complete the following information):

  • OS
  • Version used - zetacored/20.0.5/linux-amd64/go1.22.5
@KirillPamPam KirillPamPam added the bug Something isn't working label Oct 28, 2024
@skosito skosito self-assigned this Oct 28, 2024
@skosito
Copy link
Contributor

skosito commented Oct 28, 2024

fixed with #3047

Thanks @KirillPamPam for reporting!

@skosito skosito closed this as completed Oct 28, 2024
@KirillPamPam
Copy link
Author

@skosito Awesome! Will it be included in the next release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants