Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

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

Merged
merged 10 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions resources/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,6 @@ AND i.contract_address IS 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 -------------------------------------------------------------------

-- :name save-pull-request! :! :n
Expand Down Expand Up @@ -249,7 +235,10 @@ WHERE pr_id = :pr_id;
-- :doc bounty issues where deploy contract has failed
SELECT
i.issue_id AS issue_id,
u.address AS owner_address
i.issue_number AS issue_number,
r.owner AS owner,
u.address AS owner_address,
r.repo AS repo
FROM issues i, users u, repositories r
WHERE
r.user_id = u.id
Expand Down
39 changes: 21 additions & 18 deletions src/clj/commiteth/bounties.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@
(let [labels (:labels issue)]
(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)
(let [resp (github/post-deploying-comment owner
repo
issue-number
transaction-hash)
_ (log/info "post-deploying-comment response:" resp)
comment-id (:id resp)]
(issues/update-comment-id issue-id comment-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]
(let [{issue-id :id
issue-number :number
Expand All @@ -29,24 +49,7 @@
owner :owner} (users/get-repo-owner repo-id)]
(log/debug "Adding bounty for issue " repo issue-number "owner address: " owner-address)
(if (= 1 created-issue)
(if (empty? owner-address)
(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))))
(deploy-contract owner owner-address repo issue-id issue-number)
(log/debug "Issue already exists in DB, ignoring"))))

(defn maybe-add-bounty-for-issue [repo repo-id issue]
Expand Down
6 changes: 0 additions & 6 deletions src/clj/commiteth/db/issues.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@
(jdbc/with-db-connection [con-db *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
[contract-address balance-eth]
(jdbc/with-db-connection [con-db *db*]
Expand Down
2 changes: 1 addition & 1 deletion src/clj/commiteth/github/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
(defn post-deploying-comment
[owner repo issue-number tx-id]
(let [comment (generate-deploying-comment owner repo issue-number tx-id)]
(log/debug "Posting comment to" (str owner "/" repo "/" issue-number) ":" comment)
(log/info "Posting comment to" (str owner "/" repo "/" issue-number) ":" comment)
(issues/create-comment owner repo issue-number comment (self-auth-params))))

(defn make-patch-request [end-point positional query]
Expand Down
34 changes: 8 additions & 26 deletions src/clj/commiteth/scheduler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -84,34 +84,17 @@
(log/info "Exit update-issue-contract-address"))


(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
"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."
[]
(p :deploy-pending-contracts
(doseq [{issue-id :issue_id
owner-address :owner_address} (db-bounties/pending-contracts)]
(p :deploy-pending-contracts
(doseq [{issue-id :issue_id
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)
(deploy-contract owner-address issue-id))))
(bounties/deploy-contract owner owner-address repo issue-id issue-number))))

(defn self-sign-bounty
"Walks through all issues eligible for bounty payout and signs corresponding transaction"
Expand Down Expand Up @@ -400,8 +383,7 @@
;; TODO: disabled for now. looks like it may cause extraneus
;; contract deployments and costs
(run-tasks
[;;redeploy-failed-contracts
deploy-pending-contracts
[deploy-pending-contracts
update-issue-contract-address
update-confirm-hash
update-payout-receipt
Expand Down