Fix gas limit issues introduced by upgrade to geth 1.7.0

* add configurable factor for adjusting gas estimates given by
  json-rpc's eth_estimateGas. This will adjust all gas estimates by
  multiplying json-rpc estimate with the factor.

* use fixed gas limit for deploying bounty contracts to avoid running
  out of gas with geth 1.7.0
This commit is contained in:
Teemu Patja 2017-09-22 16:36:03 +03:00
parent 97ca8a8690
commit 26d30ad91b
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
2 changed files with 41 additions and 9 deletions

View File

@ -11,6 +11,7 @@
(defn eth-rpc-url [] (env :eth-rpc-url "http://localhost:8545"))
(defn eth-account [] (:eth-account env))
(defn eth-password [] (:eth-password env))
(defn gas-estimate-factor [] (env :gas-estimate-factor 1.0))
(defn gas-price
[]
@ -39,12 +40,6 @@
(when-let [error (:error result)]
(log/error "Method: " method ", error: " error))))))
(defn estimate-gas
[from to value & [params]]
(eth-rpc "eth_estimateGas" [(merge params {:from from
:to to
:value value})]))
(defn hex->big-integer
[hex]
(new BigInteger (subs hex 2) 16))
@ -54,6 +49,39 @@
[n]
(str "0x" (.toString (BigInteger. (str n)) 16)))
(defn strip-decimal
[s]
(str/replace s #"\..*" ""))
(defn adjust-gas-estimate
"Multiply given estimate by factor"
[gas]
(let [factor (gas-estimate-factor)]
(if (= 1.0 factor)
gas
(let [adjust (fn [x] (+ x (* factor x)))]
(-> gas
hex->big-integer
adjust
strip-decimal
read-string
integer->hex)))))
(defn estimate-gas
[from to value & [params]]
(let [geth-estimate (eth-rpc
"eth_estimateGas" [(merge params {:from from
:to to
:value value})])
adjusted-gas (adjust-gas-estimate geth-estimate)]
(log/debug "estimated gas (geth):" geth-estimate)
(log/debug "bumped estimate:" adjusted-gas)
adjusted-gas))
(defn from-wei
[wei]
(/ wei 1000000000000000000))
@ -138,10 +166,13 @@
(eth-rpc "eth_call" [{:to contract :data data} "latest"])))
(defn execute
[from contract method-id & params]
[from contract method-id gas-limit & params]
(let [data (apply format-call-params method-id params)
value (format "0x%x" 0)]
(send-transaction from contract value {:data data})))
(send-transaction from contract value (merge
{:data data}
(when gas-limit
{:gas gas-limit})))))
(defn execute-using-addr
[from-addr from-passphrase contract method-id & params]
@ -159,7 +190,6 @@
(eth-rpc "personal_unlockAccount" [from-addr from-passphrase 30])
(let [data "0x"
value (integer->hex amount-wei)]
(println "value" value)
(send-transaction-using-from-account from-addr
to-addr
value

View File

@ -36,12 +36,14 @@
(eth/execute (eth/eth-account)
(factory-contract-addr)
(:create method-ids)
(eth/integer->hex 827000) ;; gas-limit
0x40
0x2
required
owner1
owner2))
(defn deploy-multisig
"Deploy a new multisig contract to the blockchain with commiteth bot
and given owner as owners."