mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-25 07:16:46 +01:00
Mohamed Sohail
b9d3c219c8
NOTE: This needs the db to be nuked if you are running a test cluster * updated gas refilling logic to reflect EthFaucet contract * fully dependant on on-chain contract to refill and unlock gas * minor fixes to nonce bootstrapper Ideal Values: INITIAL GIFT = 0.015 THRESHOLD = 0.01 TIME = 12 * 60 * 60 # Sample for 30 txs EXTREME LOW = 0.00675 LOW GAS USAGE = 0.00694605 RISING = 0.0135 HIGH = 0.027
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package task
|
|
|
|
import (
|
|
"math/big"
|
|
"time"
|
|
|
|
"github.com/bsm/redislock"
|
|
)
|
|
|
|
const (
|
|
gasLimit = 250000
|
|
|
|
lockPrefix = "lock:"
|
|
lockRetryDelay = 25 * time.Millisecond
|
|
lockTimeout = 1 * time.Second
|
|
)
|
|
|
|
var (
|
|
// 20 gwei = max gas price we are willing to pay
|
|
// 250k = max gas limit
|
|
// minGasBalanceRequired is optimistic that the immidiate next transfer request will be successful
|
|
// but the subsequent one could fail (though low probability), therefore we can trigger a gas lock.
|
|
// Therefore our system wide threshold is 0.01 CELO or 10000000000000000 gas units
|
|
minGasBalanceRequired = big.NewInt(20000000000 * 250000 * 2)
|
|
)
|
|
|
|
// lockRetry will at most try to obtain the lock 20 times within ~0.5s.
|
|
// it is expected to prevent immidiate requeue of the task at the expense of more redis calls.
|
|
func lockRetry() redislock.RetryStrategy {
|
|
return redislock.LimitRetry(
|
|
redislock.LinearBackoff(lockRetryDelay),
|
|
20,
|
|
)
|
|
}
|
|
|
|
// balanceCheck compares the network balance with the system set min as threshold to execute a transfer.
|
|
func balanceCheck(networkBalance big.Int) bool {
|
|
return minGasBalanceRequired.Cmp(&networkBalance) < 0
|
|
}
|