Inconsistent value in utils.ZERO_BN causes "size too small" error
creatzor opened this issue · comments
Background:
Installed in project via yarn @blockworks-foundation/mango-client
Version: 3.2.16
Problem: Orders placed to BTC SPOT intermittently fail with "size too small"
Diagnosis:
The value of utils.ZERO_BN is randomly inconsistent at
Line 1617 in 36065ee
Additional Information:
I place a log in that function for utils.ZERO_BN and noticed it's value was not 0 when placing my order. After manually changing the base quantity comparison to a consistent value of BN(0), my orders stopped failing.
if (maxBaseQuantity.lte(new BN(0))) {
throw new Error('size too small');
}
It's possible that the value is being changed in-place somewhere in the library. The behavior is not consistent, so reproduction is difficult, but it's happening.
I believe ZERO_BN is changed in the line below.
Line 86 in 625c336
We should be using a clone of ZERO_BN instead of changing it directly via s.iadd. iadd is an inplace method. This could be happening in many places if thats the case
const zero = new BN(0);
console.log('zero 1', zero.toNumber());
const a = zero;
console.log('a 1', a.toNumber());
a.iadd(new BN(323));
console.log('zero 2', zero.toNumber());
console.log('a 2', a.toNumber());
Notice the value of zero
is 323 after the iadd instruction.
Hey @creatzor can you try the above PR and see if that one solves he issues you are seeing?
Yep that PR fixes the "size too small" issue @mschneider thanks!