oasislabs / oasis-gateway

⛩ Developer mediated access to the Oasis Platform
Apache License 2.0
23 stars 8 forks source link

Fix RetryWithConfig behavior #228

Closed ennsharma closed 4 years ago

ennsharma commented 4 years ago

This solves RetryWithConfig issues in both the Random: true and Random: false cases.

When Random: false, the function sets the timeout to be the current timeout modulo the max timeout rather than the minimum of the two. This causes cyclic timeout patterns such as:

1000000 3000000 7000000 9000000 1000000 3000000 7000000 9000000

The real problem arises with Random: true, which happens with the PooledClient used to communicate with the web3 gateway. Entropy is introduced by multiplying by a random value in [0, 1), which disproportionately causes the timeout to never really grow and in fact shrink past it's base timeout. I changed this to select a random value from [0.5, 1.5) when the max timeout hasn't been hit and [1, 2) in the case when it has, and this gave rise to nicer (empirically observed) patterns. E.g:

1000000 2209321 6365094 14377142 16868231 11565193 13009119 18136400 13806572 14688899