diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 1421ced..2335e72 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -196,20 +196,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 @@ -252,7 +238,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, + u.login AS owner, + u.address AS owner_address, + r.repo AS repo FROM issues i, users u, repositories r WHERE r.user_id = u.id diff --git a/src/clj/commiteth/bounties.clj b/src/clj/commiteth/bounties.clj index 19d995b..aa2e04c 100644 --- a/src/clj/commiteth/bounties.clj +++ b/src/clj/commiteth/bounties.clj @@ -20,6 +20,25 @@ (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) + (->> (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] (let [{issue-id :id issue-number :number @@ -29,24 +48,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] diff --git a/src/clj/commiteth/db/issues.clj b/src/clj/commiteth/db/issues.clj index 834684f..37db8d1 100644 --- a/src/clj/commiteth/db/issues.clj +++ b/src/clj/commiteth/db/issues.clj @@ -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*] diff --git a/src/clj/commiteth/scheduler.clj b/src/clj/commiteth/scheduler.clj index 0c35df3..f1535c7 100644 --- a/src/clj/commiteth/scheduler.clj +++ b/src/clj/commiteth/scheduler.clj @@ -54,33 +54,16 @@ (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 "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)] + 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" @@ -327,8 +310,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