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)
This commit is contained in:
Teemu Patja 2017-03-12 19:50:05 +02:00
parent b788f91149
commit f0f7bf9c7d
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
3 changed files with 34 additions and 0 deletions

View File

@ -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

View File

@ -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*]

View File

@ -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)