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

GraphQL returns incorrect block height for block queries when there are over 100 blocks #128

Closed
DanMacDonald opened this issue Jul 21, 2022 · 2 comments · Fixed by #130
Closed
Assignees
Labels
bug Something isn't working

Comments

@DanMacDonald
Copy link

DanMacDonald commented Jul 21, 2022

import Arweave from "arweave";

const arweave = Arweave.init({
	host: "127.0.0.1",
	port: 1984,
	protocol: "http",
});

(async () => {
	// Query the blockheight via GQL
	let currentBlockHeight = await getArweaveBlockheight();
	console.log(`initial blockHeight: ${currentBlockHeight}`);

	// Mint 110 blocks
	for (let i = 0; i < 110; i++) {
		await arweave.api.get(`mine`);
	}

	// Query the blockheight via GQL again
	currentBlockHeight = await getArweaveBlockheight();
	console.error(`queried blockHeight: ${currentBlockHeight}`);
	
	// Now check the blockheight via the info endpoint
	const response = await arweave.api.get("");
	console.log(`actual blockHeight: ${response.data.height}`);
	console.log("done");
})();

async function getArweaveBlockheight(): Promise<number> {
	const queryObject = { query: `query{ blocks(sort: HEIGHT_DESC, first:100 ){ edges{ node{ height } } } }` }
	const result = await arweave.api.post(`/graphql`, queryObject)
	const edge = result.data.data.blocks.edges[0];
	if (edge) {
		const arweaveBlockHeight = edge.node.height;
		return arweaveBlockHeight;
	}
	return -1;
}

running this test with a fresh instance of arlocal produces the following output...
image

Expected result

A block height GQL query returns the same height as the info endpoint when there are more than 100 blocks.

@fuadop fuadop self-assigned this Jul 21, 2022
@fuadop fuadop added the bug Something isn't working label Jul 21, 2022
@fuadop
Copy link
Contributor

fuadop commented Jul 21, 2022

Thanks for the bug report @DanMacDonald. It has been fixed on the latest version (1.1.52) 🎉 . Please update your arlocal and verify this fix works.

@DanMacDonald
Copy link
Author

Love it @fuadop 🥳 Keep kicking 🍑!

Tested locally and now I'm seeing the expected blockHeight 🙌

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

Successfully merging a pull request may close this issue.

2 participants