coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.61k stars 1.32k forks source link

Anchor Events are sometimes missed by the event listener? #3203

Closed floscar12 closed 1 month ago

floscar12 commented 1 month ago

My Anchor/Solana program emits certain events for certain actions initiated by my users client side. My web app requires the server to be listening to these events and processing them (NodeJS).

Per documentation, I subscribe to events on my program like so:

const subscriptionId = program.addEventListener("TransferEvent", (event) => {
  // Handle event...
});

Around 3/4 of the time most events are received by my server, but there are instances when some events straight up dont get caught by my event listener. I am using a paid Helius RPC on mainnet so I cannot imagine this is a rate limiting issue, and events that happen after the ghost event sometimes get caught, so its not like the connection was dropped.

What could be happening? Is listening to events on a server to perform important business information bad architectural design in general? Or is it a conventional approach that shouldn't be having issues like this?

Note that sometimes this will happen on the devnet as well.

acheroncrypto commented 1 month ago

This is because the default events use program logs which can be unreliable. See https://github.com/coral-xyz/anchor/issues/2408 for an explanation and check out emit_cpi to not miss events.