Merge branch 'develop' into throw-if-no-gas

This commit is contained in:
Tetiana Churikova 2018-03-22 17:26:04 +02:00 committed by GitHub
commit df823722fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 66 deletions

View File

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

View File

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

View File

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

View File

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

View File

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