0

Upon the successful confirmation of a transaction submission, my app immediately queries the link to the transaction in the response. But I often receive a 404 error from Horizon. Sometimes I get a valid response.

I could only surmise that this inconsistent behavior is due to the fact that the transaction had not yet propagated Horizon when the queries that returned a 404 error were made. I'd like to know.

I have another transaction that has 4 operations in it, and I do not seem to get similar errors from that, perhaps due to the longer time that it takes to process the transaction(?).

I am using the Horizon testnet, Heroku, node.js, and axios to query.

2 Answers 2

2

Horizon ingests Stellar Core after the ledger is closed, so it takes some non-zero time to process all ledger transactions and write the parsed data into the db. When you receive the confirmation from the /submit endpoint, it's the confirmation that the transaction has been processed by Stellar Core, but it doesn't mean that Horizon will be able to ingest the data right away. There is always a lag, due to the very nature of its architecture. You may experience it or not depending on your network latency.

Another thing to consider is load balancing. API requests to SDF-maintained https://horizon.stellar.org are evenly distributed between several Horizon instances behind a load balancer, so you may experience a situation when one server has already processed a ledger, and the other lags behind, causing "disappearing" transaction or some other resource (operation, effect, account, etc.)

The simplest thing you can do with it (this also applies to most distributed systems as well) is to delay your second request for a few seconds, and implement a repeating strategy for the rare cases when Horizon ingestion lag exceeds your delay timeout.

0

Indeed my hypothesis is right. I got the fetch working by trying and trying to fetch until it succeeds. Oftentimes the second try is not necessary as the first already succeeded. But when a second try is performed, it always succeeds in my case. This is my code:

function tryFetch(url) {
  axios
    .get(url)
    .then(function(response) {
      //success
    })
    .catch(function(error) {
      console.log(error);
//try again
      setTimeout(function() {
        tryFetch(url);
      }, 1000);
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.