-
Notifications
You must be signed in to change notification settings - Fork 118
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
zkApp.fetchEvents() throws Gateway Time-out error on devnet #1777
Comments
The issue seems to be related to the argument The updated example: import { NameContractV2 } from "minanft";
import { PublicKey, Mina, fetchEvents, Field, UInt32 } from "o1js";
const contractAddress =
"B62qs2NthDuxAT94tTFg6MtuaP1gaBxTZyNv9D3uQiQciy1VsaimNFT";
describe("Should get events", () => {
it(`should get events`, async () => {
const networkInstance = Mina.Network({
mina: "https://api.minascan.io/node/devnet/v1/graphql",
archive: "https://api.minascan.io/archive/devnet/v1/graphql",
});
Mina.setActiveInstance(networkInstance);
const address = PublicKey.fromBase58(contractAddress);
const zkApp = new NameContractV2(address);
console.log("Fetching events for", address.toBase58());
try {
const events1 = await fetchEvents({ publicKey: contractAddress });
console.log("Events1:", events1?.length);
const events2 = await Mina.fetchEvents(address, Field(1));
console.log("Events2:", events2?.length);
const events3 = await Mina.fetchEvents(address, Field(1), {
from: UInt32.from(0),
});
console.log("Events3:", events3?.length);
const events4 = await zkApp.fetchEvents();
console.log("Events4:", events2?.length);
} catch (e) {
console.error("Error fetching events", e);
}
});
}); The log:
|
It can be related to #1426 |
I've found a workaround using the method described in #1775 const events4 = await zkApp.fetchEvents(); with const events4 = await zkApp.fetchEvents(UInt32.from(321138)); makes this code work |
@dfstio, can you share your project config for running this test? I ran
If you could share your ts config and package json, or just link me to the repo so I can play around, I'd appreciate it! |
I am able to run the file by converting it from a test to a simple script, but I am getting a different error before I reach the timeout:
Of course, I've kept the line: |
Ok, I am able to reproduce this issue by removing the minanft library dependency. I tried normalizing all o1js versions to 1.4.0, but I continued to have issues from multiple versions of the library. Simplified reproduction script: import { PublicKey, Mina, fetchEvents, SmartContract, state, Field, State } from "o1js";
class NFTContractV2 extends SmartContract {
@state(Field) name = State<Field>();
}
const contractAddress =
"B62qs2NthDuxAT94tTFg6MtuaP1gaBxTZyNv9D3uQiQciy1VsaimNFT";
const Devnet1 = {
mina: ["https://api.minascan.io/node/devnet/v1/graphql"],
archive: ["https://api.minascan.io/archive/devnet/v1/graphql"],
};
const networkInstance = Mina.Network({
mina: "https://api.minascan.io/node/devnet/v1/graphql",
archive: "https://api.minascan.io/archive/devnet/v1/graphql",
});
Mina.setActiveInstance(networkInstance);
const address = PublicKey.fromBase58(contractAddress);
const zkApp = new NFTContractV2(address);
console.log("Fetching events for", address.toBase58());
try {
const events1 = await fetchEvents({ publicKey: contractAddress });
console.log("Events1:", events1?.length);
const events2 = await zkApp.fetchEvents();
console.log("Events2:", events2?.length);
} catch (e) {
console.error("Error fetching events", e);
} |
Digging deeper into the implementation, this seems to be a difference in default parameters between fetch.fetchEvents and zkapp.fetchEvents, where the latter adds extra parameters. The difference in final graphQL query looks like this:
|
I will open a quick PR to make the default behavior the same, and raise this issue further with our node team to understand why the difference between nothing and |
minanft is a library and you can use yarn to install it and run the tests: |
I'm having this issue now on mainnet, too, with the MinaNFT contract. I've just checked again and have received the message This problem arises with time, as soon as you have more than 300 events. The workaround I use now is to use pagination: const MAX_BLOCKS = 10000;
const currentBlock = Number((await fetchLastBlock()).blockchainLength);
const firstBlock: number = chain === "mainnet" ? 365480 : 321138;
const events: any[] = [];
let from = firstBlock;
let to =
firstBlock + MAX_BLOCKS > currentBlock
? currentBlock
: firstBlock + MAX_BLOCKS;
while (from < currentBlock) {
console.log("Fetching events from", from, "to", to);
const fetchedEvents = await zkApp.fetchEvents(
UInt32.from(from),
UInt32.from(to)
);
if (fetchedEvents === undefined) {
console.error("Events fetch error");
return;
}
events.push(...fetchedEvents);
from = to + 1;
to = from + MAX_BLOCKS > currentBlock ? currentBlock : from + MAX_BLOCKS;
} Vote to reopen this issue |
On mainnet, both zkApp.fetchEvents() and fetchEvents({ publicKey: contractAddress }) work.
On devnet, fetchEvents({ publicKey: contractAddress }) work, while zkApp.fetchEvents() throws Gateway Time-out error.
The code to reproduce:
The log:
The text was updated successfully, but these errors were encountered: