blocknetdx / blocknet

Official Blocknet cryptocurrency wallet
https://www.blocknet.org
MIT License
214 stars 95 forks source link

Add reporting to xbridge logs to capture Invalid amount error #560

Open shrnkld opened 2 years ago

shrnkld commented 2 years ago

Scenario: There is an intermittent bug with xbridge order posting that results in an 'invalid amount' error (see screenshot attached)

We need to find the route of this issue but the logs don't provide enough info to track it down. Currently we don't have the exact steps to reproduce but the following process can result in the error:

Steps to reproduce:

  1. start and unlock blocknet core wallet2. start and unlock LTC local wallet3. start block DX4. place a partial order via console or cli calling dxmakepartialorder) for eg: dxMakePartialOrder LTC 0.010853 LNu2ja6eLrttWj4VwpABFAB4dBVeJBjSAB BLOCK 1 BVADycgu66et8PANEwLNY1uCHbBZFuC8Wp 0.001085 true

Error result: error 1026 - invalid amount

Important note: this error is intermittent as you can see from the screenshots attached. Sometimes the same order works and others it fails.

To do: 1. Investigate what causes xbridge to return the ‘invalid amount' error when dxmakepartialorder is called

We need to add further logging to xbridge if this cannot be determined from the current code:

2. each UTXOs details should be available in the log

the maximum number of utxos on the order was exceeded (UTXOs empty) =

if (utxos.empty()) {...
    xbridge::LogOrderMsg(log_obj, "failed to create order, the maximum number of utxos on the order was exceeded", __FUNCTION__);
                    return xbridge::Error::UTXOS_EMPTY;
                }

Insufficient funds on partial order =

xbridge::LogOrderMsg(log_obj, "failed to create order, insufficient funds on partial order", __FUNCTION__);
                    return xbridge::Error::INSUFFICIENT_FUNDS_PARTIAL_ORDER;

the maximum number of utxos on the order was exceeded =

if (ptr->usedCoins.size() > xBridgePartialOrderMaxUtxos) {...
  xbridge::LogOrderMsg(log_obj, "failed to create order, the maximum number of utxos on the order was exceeded", __FUNCTION__);
                    return xbridge::Error::EXCEEDED_MAX_UTXOS;

3. add the above new errors in blocknet/src/xbridge/util/xbridgeerror.cpp

case Error::UTXOS_EMPTY:
            return "Failed to create order, the maximum number of utxos on the order was exceeded " + argument;
case Error::INSUFFICIENT_FUNDS_PARTIAL_ORDER:
            return "failed to create order, insufficient funds on partial order " + argument;
case Error::EXCEEDED_MAX_UTXOS:
            return "failed to create order, the maximum number of utxos on the order was exceeded " + argument;

Ref: https://api.blocknet.co/#error-codes

Dev update after investigating issue: https://docs.google.com/document/d/1-cviFKPSC8wMJRNEP6cnoFkbVIEDXK3bxf99pBbCjbc/edit