Page 1 of 2

How to deal with tefMAX_LEDGER error?

PostPosted: Fri Mar 04, 2016 5:41 pm
by vunguyen
I'm using ripple-lib for JS to write an app. I create an order to trade USD for XRP but when I submit the signed transaction, the result is {resultCode: "tefMAX_LEDGER", resultMessage: "Ledger sequence too high."}

I don't understand what it is though I googled but no information seems relate to this error. Please help me understand the error and what should I do to place an order.

Thank you!

Re: How to deal with tefMAX_LEDGER error?

PostPosted: Fri Mar 04, 2016 5:53 pm
by twarden
vunguyen wrote:I'm using ripple-lib for JS to write an app. I create an order to trade USD for XRP but when I submit the signed transaction, the result is {resultCode: "tefMAX_LEDGER", resultMessage: "Ledger sequence too high."}

I don't understand what it is though I googled but no information seems relate to this error. Please help me understand the error and what should I do to place an order.

Thank you!


If you can provide the transaction json it will make it easier for someone to assist you with troubleshooting this issue. I believe that the cause of this is is perhaps your account's sequence may have incremented before you submitted your transaction.

Re: How to deal with tefMAX_LEDGER error?

PostPosted: Fri Mar 04, 2016 10:22 pm
by JoelKatz
vunguyen wrote:I'm using ripple-lib for JS to write an app. I create an order to trade USD for XRP but when I submit the signed transaction, the result is {resultCode: "tefMAX_LEDGER", resultMessage: "Ledger sequence too high."}

I don't understand what it is though I googled but no information seems relate to this error. Please help me understand the error and what should I do to place an order.


As a general rule, you should mostly ignore the results of transaction submission. What you care about is whether the transaction itself succeeded or failed, not what happened some particular time you submitted it. But if this happens the first time you submit a transaction, that suggests you put the wrong value in its "LastLedgerSequence" field.

It is very important to understand that "tefMAX_LEDGER" is a submission error that tells what happened when you submitted a transaction. It is not a status for the transaction itself. If, for example, you submit a transaction that has already succeeded, that submission will always fail. One way it can fail is with "tefMAX_LEDGER". (It can also fail with "tefALREADY" or "tefPAST_SEQ".)

Once a transaction is validly signed, it could potentially execute at any time. Until it succeeds, it remains a potentially valid transaction. So, for example, say I sign a transaction with too low a fee and the network doesn't process it. Someone could store that transaction and resubmit it a week later when the required fee is lower. I wouldn't get any final result for potentially a very long time.

To avoid this problem, a transaction can include a maximum ledger sequence number. After that ledger sequence passes, the transaction is no longer valid. If I set a maximum ledger sequence that's, say, 4 greater than the current sequence, if my transaction doesn't succeed in about 20 seconds or so, it never will.

The "tefMAX_LEDGER" error means that a transaction had such a limit and was submitted after that limit passed. It may also have been submitted before that limit passed, and that submission may or may not have succeeded.

There are a few ways this error can occur. If it occurs the first time you submit a transaction, you are probably setting "LastLedgerSequence" too low. It should be at least two greater than the sequence number of the current ledger when you submit it.

If you set the fee too low (use at least 1500 drops), this will also eventually occur. Eventually the ledger will exceed the limit in the transaction, and so this will happen.

So what you should do on "tefMAX_LEDGER" is:

1) Check the sequence number of the last valid ledger.
2) Check if the transaction succeeded. If so, stop, the transaction succeeded.
3) If the sequence you noted in step one was less than the LastLedgerSequence in the transaction, wait for the last valid ledger to advance and then go back to step 1.
4) The transaction failed. Consider re-signing a new version of it. Maybe increase the fee when you do so.

Re: How to deal with tefMAX_LEDGER error?

PostPosted: Sat Mar 05, 2016 4:18 pm
by vunguyen
Thank you so much for the answers. I'm quite new with the Ripple network so I may miss something in my code. Could you please have a look into my code? I'm afraid my order setting is wrong but I'm not sure where it is.

Code: Select all
var order = {
                  direction: "sell",
                  quantity: {
                     currency: "USD",
                     counterparty: trustAddress,   
                     value: amount.toString()
                  },
                  totalPrice: {
                     currency: "XRP",
                     value: amountXRP.toString()
                  },   
                  passive: false,
                  fillOrKill: true
               };

               return api.prepareOrder(ghAddress, order, instructions).then(function(prepared) {
                  console.log('Order transaction prepared...');
                  var _api$sign = api.sign(prepared.txJSON, secret);
                  var signedTransaction = _api$sign.signedTransaction;
                  
                  console.log('Order transaction signed...');
                  api.submit(signedTransaction).then(function(result) {
                     if (result.resultCode === 'tefMAX_LEDGER') {
                        // Catch the tefMAX_LEDGER here
                     } else {
                        callback(null, result);
                     }                        
                  });
               });


- I see the value of "prepared" is:

Code: Select all
{
    instructions: {
        fee: "0.012"
        maxLedgerVersion: 19433172
        sequence: 27
    },
    txJSON: "{"TransactionType":"OfferCreate","Account":"rBXVDxEUFwS7gXPwjTLqt9ok3fv41FKoxm","TakerGets":{"currency":"USD","issuer":"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B","value":"1"},"TakerPays":"128700000","Flags":2148270080,"LastLedgerSequence":19433172,"Fee":"12000","Sequence":27}"
}

Re: How to deal with tefMAX_LEDGER error?

PostPosted: Sun Mar 06, 2016 1:45 am
by JoelKatz
I don't see anything obviously wrong with, assuming the value for LastLedgerSequence is a few ledgers greater than the current ledger sequence at the time you issues the transaction.

Re: How to deal with tefMAX_LEDGER error?

PostPosted: Tue Mar 08, 2016 2:13 am
by vunguyen
Thank you JoelKatz.
I resolved the issue, I've just increased the maxLedgerVersionOffset to a higer value, e.g. 50. 8-)

Re: How to deal with tefMAX_LEDGER error?

PostPosted: Tue Mar 08, 2016 6:55 am
by JoelKatz
vunguyen wrote:Thank you JoelKatz.
I resolved the issue, I've just increased the maxLedgerVersionOffset to a higer value, e.g. 50. 8-)

What was it before? That seems extremely high.

The downside of setting this value too high is that it can take a very long time before a transaction fails. With a setting of 50, it can take around 200 seconds. There really should never be any reason to go over 6 or so. You can always sign a new transaction if the previous one definitively fails.

Re: How to deal with tefMAX_LEDGER error?

PostPosted: Tue Mar 08, 2016 7:34 am
by vunguyen
It was 5 before that. I used 50 just for testing, and as your suggestion I will try a smaller one.

Thank you!

Re: How to deal with tefMAX_LEDGER error?

PostPosted: Sun May 07, 2017 10:11 am
by jn_r
I am getting a lot of tefMAX_LEDGER lately, especially when it is busy.
Would it help if I would use my own rippled? Currently making use of 'wss://s1.ripple.com'..

Re: How to deal with tefMAX_LEDGER error?

PostPosted: Sun May 07, 2017 2:37 pm
by jn_r
Ok, so I tested this with a local rippled and it makes a huge difference! no tefMAX_LEDGER anymore...(up till now)
So for the tip, if you experience lots of tefMAX_LEDGER error and the likes, try running a personal rippled :)

edit: It might have to with the several calls I make (via the rippleApi) to rippled before deciding that I want to make a transaction. They all add up to the time it takes to finally make a transaction (one of the first steps is to determine the ledgerSequence). If I make the transaction then apparently so much time has past by that we are beyond maxledger supplied (where I use current + 3).