From f0f7bf9c7dddd78b0997fa19dea31a12d462a8f2 Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Sun, 12 Mar 2017 19:50:05 +0200 Subject: [PATCH] Scheduled task for re-deploying failed bounty contracts * as a secondary pre-caution, look for bounty issues where the deploy contract transaction has failed and re-deploy the contract (Fixes #32) --- resources/sql/queries.sql | 14 ++++++++++++++ src/clj/commiteth/db/bounties.clj | 5 +++++ src/clj/commiteth/scheduler.clj | 15 +++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 07e261d..8367f65 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -206,6 +206,20 @@ SET -- Bounties ------------------------------------------------------------------------ + +-- :name pending-contracts :? :* +-- :doc bounty issues where deploy contract has failed +SELECT + i.issue_id AS issue_id, + u.address AS owner_address +FROM issues i, users u, repositories r +WHERE +r.user_id = u.id +AND i.repo_id = r.repo_id +AND i.transaction_hash IS NULL +AND i.contract_address IS NULL; + + -- :name pending-bounties-list :? :* -- :doc lists all recently closed issues awaiting to be signed SELECT diff --git a/src/clj/commiteth/db/bounties.clj b/src/clj/commiteth/db/bounties.clj index c857cbb..91c1c2c 100644 --- a/src/clj/commiteth/db/bounties.clj +++ b/src/clj/commiteth/db/bounties.clj @@ -5,6 +5,11 @@ +(defn pending-contracts + [] + (jdbc/with-db-connection [con-db *db*] + (db/pending-contracts con-db))) + (defn list-owner-bounties [owner] (jdbc/with-db-connection [con-db *db*] diff --git a/src/clj/commiteth/scheduler.clj b/src/clj/commiteth/scheduler.clj index 58e8db4..d74805a 100644 --- a/src/clj/commiteth/scheduler.clj +++ b/src/clj/commiteth/scheduler.clj @@ -43,6 +43,20 @@ balance balance-str)))))) + +(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)))) + (defn self-sign-bounty "Walks through all issues eligible for bounty payout and signs corresponding transaction" [] @@ -130,6 +144,7 @@ (defn run-periodic-tasks [time] (do (log/debug "run-periodic-tasks" time) + (deploy-pending-contracts) (update-issue-contract-address) (update-confirm-hash) (update-payout-receipt)