[Fix #339] Update GitHub comment in deploy-pending-contracts scheduler

thread;
refactor contract deployment code to a separate fn;
remove unused code
This commit is contained in:
Vitaliy Vlasov 2018-03-01 17:52:17 +02:00
parent a4e901cb43
commit ebec83c704
No known key found for this signature in database
GPG Key ID: A7D57C347F2B2964
4 changed files with 30 additions and 63 deletions

View File

@ -196,20 +196,6 @@ AND i.contract_address IS NULL
AND i.transaction_hash IS NOT NULL; AND i.transaction_hash IS NOT NULL;
-- :name list-failed-deployments :? :*
-- :doc retrieves failed contract deployments
SELECT
i.issue_id as issue_id,
i.transaction_hash as transaction_hash,
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.contract_address IS NULL
AND i.transaction_hash IS NOT NULL
AND i.updated < now() at time zone 'UTC' - interval '1 hour';
-- Pull Requests ------------------------------------------------------------------- -- Pull Requests -------------------------------------------------------------------
-- :name save-pull-request! :! :n -- :name save-pull-request! :! :n
@ -252,7 +238,10 @@ WHERE pr_id = :pr_id;
-- :doc bounty issues where deploy contract has failed -- :doc bounty issues where deploy contract has failed
SELECT SELECT
i.issue_id AS issue_id, i.issue_id AS issue_id,
u.address AS owner_address i.issue_number AS issue_number,
u.login AS owner,
u.address AS owner_address,
r.repo AS repo
FROM issues i, users u, repositories r FROM issues i, users u, repositories r
WHERE WHERE
r.user_id = u.id r.user_id = u.id

View File

@ -20,6 +20,25 @@
(let [labels (:labels issue)] (let [labels (:labels issue)]
(some #(= label-name (:name %)) labels))) (some #(= label-name (:name %)) labels)))
(defn deploy-contract [owner owner-address repo issue-id issue-number]
(if (empty? owner-address)
(log/error "Unable to deploy bounty contract because"
"repo owner has no Ethereum addres")
(do
(log/info "deploying contract to " owner-address)
(if-let [transaction-hash (multisig/deploy-multisig owner-address)]
(do
(log/info "Contract deployed, transaction-hash:"
transaction-hash)
(->> (github/post-deploying-comment owner
repo
issue-number
transaction-hash)
:id
(issues/update-comment-id issue-id))
(issues/update-transaction-hash issue-id transaction-hash))
(log/error "Failed to deploy contract to" owner-address)))))
(defn add-bounty-for-issue [repo repo-id issue] (defn add-bounty-for-issue [repo repo-id issue]
(let [{issue-id :id (let [{issue-id :id
issue-number :number issue-number :number
@ -29,24 +48,7 @@
owner :owner} (users/get-repo-owner repo-id)] owner :owner} (users/get-repo-owner repo-id)]
(log/debug "Adding bounty for issue " repo issue-number "owner address: " owner-address) (log/debug "Adding bounty for issue " repo issue-number "owner address: " owner-address)
(if (= 1 created-issue) (if (= 1 created-issue)
(if (empty? owner-address) (deploy-contract owner owner-address repo issue-id issue-number)
(log/error "Unable to deploy bounty contract because"
"repo owner has no Ethereum addres")
(do
(log/debug "deploying contract to " owner-address)
(let [transaction-hash (multisig/deploy-multisig owner-address)]
(if (nil? transaction-hash)
(log/error "Failed to deploy contract to" owner-address)
(do
(log/info "Contract deployed, transaction-hash:"
transaction-hash)
(->> (github/post-deploying-comment owner
repo
issue-number
transaction-hash)
:id
(issues/update-comment-id issue-id))))
(issues/update-transaction-hash issue-id transaction-hash))))
(log/debug "Issue already exists in DB, ignoring")))) (log/debug "Issue already exists in DB, ignoring"))))
(defn maybe-add-bounty-for-issue [repo repo-id issue] (defn maybe-add-bounty-for-issue [repo repo-id issue]

View File

@ -63,12 +63,6 @@
(jdbc/with-db-connection [con-db *db*] (jdbc/with-db-connection [con-db *db*]
(db/list-pending-deployments con-db))) (db/list-pending-deployments con-db)))
(defn list-failed-deployments
[]
(jdbc/with-db-connection [con-db *db*]
(db/list-failed-deployments con-db)))
(defn update-eth-balance (defn update-eth-balance
[contract-address balance-eth] [contract-address balance-eth]
(jdbc/with-db-connection [con-db *db*] (jdbc/with-db-connection [con-db *db*]

View File

@ -54,33 +54,16 @@
(log/error "Failed to find contract address in tx logs"))))) (log/error "Failed to find contract address in tx logs")))))
(defn deploy-contract [owner-address issue-id]
(let [transaction-hash (multisig/deploy-multisig 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-failed-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 (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." "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 (doseq [{issue-id :issue_id
owner-address :owner_address} (db-bounties/pending-contracts)] issue-number :issue_number
owner :owner
owner-address :owner_address
repo :repo} (db-bounties/pending-contracts)]
(log/debug "Trying to re-deploy failed bounty contract deployment, issue-id:" issue-id) (log/debug "Trying to re-deploy failed bounty contract deployment, issue-id:" issue-id)
(deploy-contract owner-address issue-id))) (bounties/deploy-contract owner owner-address repo issue-id issue-number)))
(defn self-sign-bounty (defn self-sign-bounty
"Walks through all issues eligible for bounty payout and signs corresponding transaction" "Walks through all issues eligible for bounty payout and signs corresponding transaction"
@ -327,8 +310,7 @@
;; TODO: disabled for now. looks like it may cause extraneus ;; TODO: disabled for now. looks like it may cause extraneus
;; contract deployments and costs ;; contract deployments and costs
(run-tasks (run-tasks
[;;redeploy-failed-contracts [deploy-pending-contracts
deploy-pending-contracts
update-issue-contract-address update-issue-contract-address
update-confirm-hash update-confirm-hash
update-payout-receipt update-payout-receipt