indexer icon indicating copy to clipboard operation
indexer copied to clipboard

Add configuration for wait time after client error

Open jeapostrophe opened this issue 5 years ago • 6 comments

Right now, the indexer waits 5 seconds whenever it loses the connection to algod. I find that this happens a lot of my setup and drastically increases how long I need to wait to have queries answered. It would be nice to be able to configure this without modifying the source.

https://github.com/algorand/indexer/blob/44c0cf72872637f71fe344ed39aeb686c8d81f99/fetcher/fetcher.go#L144

(algorand edit) Scope

Since this ticket was created we've enhanced the config file support, and now have a good spot to put these sorts of configurations. We should go ahead and add a knob for the controlling this timeout.

jeapostrophe avatar Oct 01 '20 03:10 jeapostrophe

Information about 'now' should be gotten from algod, algorand-indexer is at best near-past. I'd expect indexer to usually be within a second or so of algod, but networking hiccups could delay that. Are algod and indexer on the same machine or at least in the same datacenter?

brianolson avatar Oct 01 '20 17:10 brianolson

The same machine (my laptop)

As far as I know, algod only gives me access to querying pending transactions, and only if I know their id, not looking up arbitrary information about transactions or querying... which is what the indexer is for. I'm looking at the API here --- https://developer.algorand.org/docs/reference/rest-apis/algod/v2/

jeapostrophe avatar Oct 01 '20 17:10 jeapostrophe

@jeapostrophe as @brianolson mentioned it's best to consider indexer as "near-past". What are you trying to do, and what are your applications requirements for "near-past"?

Is there an error in the indexer log about the connection issues?

Regarding your specific comment about pending transactions you can query a node for all pending transactions known by that node, or for information about pending/recently-confirmed transactions if you know the transaction ID: https://developer.algorand.org/docs/reference/rest-apis/algod/v2/#get-v2transactionspending https://developer.algorand.org/docs/reference/rest-apis/algod/v2/#get-v2transactionspendingtxid

winder avatar Oct 21 '20 15:10 winder

Thanks @winder.

I know that you can query pending transactions and that you can query transactions if you know their id; however, in my case "Bob"'s node doesn't know about "Alice"'s nodes pending transactions and doesn't know their transaction either.

My applications are primarily concerned with "now", but "near past" is good enough. The main issue is that we can't have our dApps rely on anything other than the Algorand network, so they can't rely on some external mechanism to communicate what the transaction ids are.

In Ethereum, normal nodes publish events from the running of contracts that you can watch to enable local agents to react to blockchain events. Basically, we're using the indexer in Algorand to recreate that by having the local agent repeatedly query the indexer for txns from a specific TEAL contract controlled account, then they look at the arguments to that transaction to read the event. (The TEAL contract checks that the arguments are valid and that it is a valid time for the event to fire.)

It would be just as good for me to be able to tell my local node, "Tell me when a transaction from address X comes by" and then I wouldn't need the indexer at all. (BTW, here I say "transaction" as a short-hand... I actually care about the entire transaction group.)

I'd be happy to talk live and give you a demo of how our system works.

jeapostrophe avatar Oct 21 '20 15:10 jeapostrophe

@jeapostrophe I wrote a Python framework for achieving event handling based on Algorand blocks. https://github.com/algobolson/algobot This was a quick hackathon project from almost a year ago and was based on the v1 sdk and it should be updated for the v2 sdk, but the basic concept is sound.

brianolson avatar Oct 21 '20 16:10 brianolson

Thanks @brianolson ; it looks to me that it directly reads the blocks in sequence looking for the events of interest, which would be /v2/blocks today. The api docs don't document the result of this (it just says object), but I guess it is this structure --- https://github.com/algorand/go-algorand/blob/e2865f404a9de7e07e562940e5ace1e991aaefd5/data/bookkeeping/block.go#L203 --- where all the action is https://github.com/algorand/go-algorand/blob/f17fe0584562bbda05f96280126ac8021a15e255/data/transactions/aggregates.go#L28 --- and https://github.com/algorand/go-algorand/blob/fe038ca47ad79835d0da7773fa77a1219fd9e71d/data/transactions/signedtxn.go#L42

I definitely could write code to use this and avoid the indexer. I think it would be better to implement an API call in algod that would do something like a really basic query over it. My use case is quite simple: I am looking for a transaction group from round A to round B where address X is a sender; since the sender is a TEAL contract I wrote, I know the layout of all of the other transactions in its group. I am willing to poll each round individually as well. (The reason I think it would be nicer to do this in algod is just because I expect this to be a pretty common pattern for dApps on Algorand, and I don't want to reimplement it for the JS backend, the C backend, the Rust backend, and so on.)

Thank you again! That's a nice hint.

(FWIW, my code today is here: https://github.com/reach-sh/reach-lang/blob/master/js/ts/ALGO.ts#L676 )

jeapostrophe avatar Oct 21 '20 17:10 jeapostrophe