If they use transaction/wallet listener, how do they detect deposit transactions when their services are not running, do they fetch blocks at every height to scan for deposits to avoid any missing? Thanks,
There are several ways to accomplish this. First as chytrik stated above, not running your own node is dangerous, but in my opinion only if you plan on submitting transactions. When it comes to watching wallets, there are 2 ways.
- Active scanning. This method involves asking nodes/services what transactions exist for a particular address.
- Passive triggering. This is usually accomplished by asking a third party to inform you that a deposit has been detected.
In the case of 1, it can be costly to scan every address ever used especially when creating a new address for each transaction or scaling to a large user or wallet count.
In the case of 2, relying only on a third party can be tricky.
The most cost effective way to handle this is to do both. Use a third party for primary notifications. If you expect a transaction during a window of say 10 minutes, you can have your system process the request once the third party triggers, and you can perform a "manual check" from the node directly by asking for all transactions and parsing the results looking for the expected transaction. This will give you the fastest response and the lowest delay. You could even only make the node request once at the end of 10 minutes as a fall back "final check" before invalidating the transaction (common with bitcoin payment services).
If you're doing something longer term, then you can once again rely on a third party to trigger an immediate update. As a fall back scan once an hour/day/week depending on what the use case is. If it's an end user application allow them to trigger the scan (of course within reason so you don't get DoS'd by your own clients clicking 'rescan').
This is the entire "trust but verify". No third party will have your keys. If you're an exchange you'll likely be scanning, but for a better user experience depending on the size of your customer base, scanning millions of wallets every 5 seconds just isn't feasible. You can also use multiple third parties as well. For an exchange these services won't be that expensive.
If intent on being the third party in these examples, then parse every block that arrives from the blockchain. Do what you need to do when you detect a deposit on one of your addresses.
Note: I formed this as a "large scale" response to the concept of exchanges. There are other things that can be done at small scale eg: a personal wallet and setting a node to watch an address.
They're running full-node implementation.
how do they detect deposit transactions when their services are not running?
It's blockchain, all data available for anyone, they able to fetch data from blockchain anytime.
do they fetch blocks at every height to scan for deposits to avoid any missing?
There is a couple ways to get address deposits:
- You can check the balance of particular address every N seconds.
- You can parse a block and check if there are transactions related to particular address.