Open shrnkld opened 3 years ago
Info for testing:
Creates an order with no remainder: (5 x 0.02):
dxMakePartialOrder "SYS" "0.1" "SYSCOIN_ADDRESS" "BLOCK" "0.01" "BLOCK_ADDRESS" "0.02" true false true
Creates an order with a remainder: (5 x 0.02 + 0.005):
dxMakePartialOrder "SYS" "0.105" "SYSCOIN_ADDRESS" "BLOCK" "0.01" "BLOCK_ADDRESS" "0.02" true false true
0.02 - split utxo (Note: the resulting utxo seen in the wallet will be slightly larger, because it also accounts for the tx fee, e.g 0.0204 in the case of SYS) 0.005 - remainder
Some test cases: (create orders from a set of utxo with the follow properties)
Latest test builds: https://gitlab.com/blocknetdx/blocknet/-/pipelines/345361961
It is essentially caused by the CAmount to double conversion, which can lead to slight rounding errors. During the order creation process, the client will sign a message (which also includes the amount) to prove ownership. This is being signed:
std::string UtxoEntry::toString() const
{
std::ostringstream o;
o << txId << ":" << vout << ":" << amount << ":" << address;
return o.str();
}
https://github.com/blocknetdx/blocknet/blob/master/src/xbridge/xbridgewalletconnector.cpp#L28 (note the usage of type double for amount)
Now when the exchange (snode) tries to verify the signed message, it will come up with a slightly different amount and therefore different message. Consequently, the exchange believes the signature is invalid. That is what caused the problem.
Solution: - Long-term: Get rid of the double, replace it with CAmount, which is essentially an integer (this might happen anyway with the 18 decimal thing?) - there is a reason bitcoin is doing the math in int - Short-term: Reload amount values before signing in a similar fashion as the exchange does (both client and exchange should end up with the same amount)
New builds: https://gitlab.com/blocknetdx/blocknet/-/pipelines/345361961
The PR now contains fixes for 5 things:
Invalid amount Issue still persists when using a combination of Block core and XLite for other assets due to the fix/patch use of gettxout
to update the amounts.
In most cases the utxo being updated will still have 0 confirmations because we just created the transaction. This isn't really an issue as long as the core wallet is run locally, the wallet will still recognise it as a "wallet transaction" and as such return the information. This doesn't appear to be the case when using xlite.
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:
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:
dxmakepartialorder
is calledthe maximum number of utxos on the order was exceeded (UTXOs empty):
insufficient funds on partial order:
the maximum number of utxos on the order was exceeded: