From f171259ed40a77d63c7c12bb5f998c391306cd94 Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Wed, 31 May 2017 09:32:46 +0300 Subject: [PATCH] Recover from bot account ETH balance running out Recover from situation where Commit ETH bot account's ETH balance runs out and gets replenished by re-deploying contracts that were not actually written to the blockchain. Fixes: #58 --- resources/sql/queries.sql | 3 ++- src/clj/commiteth/scheduler.clj | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 0b5709b..ac95044 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -165,7 +165,8 @@ WHERE issue_id = :issue_id; -- :doc retrieves pending transaction ids SELECT issue_id, - transaction_hash + transaction_hash, + owner_address FROM issues WHERE contract_address IS NULL AND issues.transaction_hash IS NOT NULL; diff --git a/src/clj/commiteth/scheduler.clj b/src/clj/commiteth/scheduler.clj index 3fbfb4b..175dafa 100644 --- a/src/clj/commiteth/scheduler.clj +++ b/src/clj/commiteth/scheduler.clj @@ -45,18 +45,33 @@ balance-str)))))) +(defn deploy-contract [owner-address issue-id] + (let [transaction-hash (eth/deploy-contract owner-address)] + (if (nil? transaction-hash) + (log/error "Failed to deploy contract to" owner-address) + (log/info "Contract deployed, transaction-hash:" + transaction-hash )) + (issues/update-transaction-hash issue-id transaction-hash))) + + +(defn redeploy-failed-contracts + "If the bot account runs out of gas, we end up with transaction-id in db, but with nothing written to blockchain. In this case we should try to re-deploy the contract." + [] + (doseq [{issue-id :issue_id + transaction-hash :transaction_hash + owner-address :owner_address} (issues/list-pending-deployments)] + (when (nil? (eth/get-transaction-receipt transaction-hash)) + (log/info "Detected nil transaction receipt for pending contract deployment for issue" issue-id ", re-deploying contract") + (deploy-contract owner-address issue-id)))) + + (defn deploy-pending-contracts "Under high-concurrency circumstances or in case geth is in defunct state, a bounty contract may not deploy successfully when the bounty label is addded to an issue. This function deploys such contracts." [] (doseq [{issue-id :issue_id owner-address :owner_address} (db-bounties/pending-contracts)] (log/debug "Trying to re-deploy failed bounty contract deployment, issue-id:" issue-id) - (let [transaction-hash (eth/deploy-contract owner-address)] - (if (nil? transaction-hash) - (log/error "Failed to deploy contract to" owner-address) - (log/info "Contract deployed, transaction-hash:" - transaction-hash )) - (issues/update-transaction-hash issue-id transaction-hash)))) + (deploy-contract owner-address issue-id))) (defn self-sign-bounty "Walks through all issues eligible for bounty payout and signs corresponding transaction" @@ -169,6 +184,7 @@ (defn run-periodic-tasks [time] (do (log/debug "run-periodic-tasks" time) + (redeploy-failed-contracts) (deploy-pending-contracts) (update-issue-contract-address) (update-confirm-hash)