Avoid unneeded watch transactions
Store tx id for watch smart contract call while it is pending to avoid sending unneeded transactions.
This commit is contained in:
parent
62b4394c14
commit
a9e178a2f1
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE "public"."issues"
|
||||||
|
ADD COLUMN "watch_hash" character varying(128);
|
|
@ -339,6 +339,21 @@ UPDATE issues
|
||||||
SET winner_login = :winner_login
|
SET winner_login = :winner_login
|
||||||
WHERE issue_id = :issue_id;
|
WHERE issue_id = :issue_id;
|
||||||
|
|
||||||
|
-- :name update-watch-hash :! :n
|
||||||
|
-- :doc updates issue with watch transaction hash
|
||||||
|
UPDATE issues
|
||||||
|
SET watch_hash = :watch_hash
|
||||||
|
WHERE issue_id = :issue_id;
|
||||||
|
|
||||||
|
-- :name pending-watch-calls :? :*
|
||||||
|
-- :doc issues with a pending watch transaction
|
||||||
|
SELECT
|
||||||
|
issue_id,
|
||||||
|
watch_hash
|
||||||
|
FROM issues
|
||||||
|
WHERE watch_hash IS NOT NULL;
|
||||||
|
|
||||||
|
|
||||||
-- :name update-payout-hash :! :n
|
-- :name update-payout-hash :! :n
|
||||||
-- :doc updates issue with payout transaction hash
|
-- :doc updates issue with payout transaction hash
|
||||||
UPDATE issues
|
UPDATE issues
|
||||||
|
@ -492,7 +507,8 @@ SELECT
|
||||||
i.issue_id AS issue_id,
|
i.issue_id AS issue_id,
|
||||||
i.balance_eth AS balance_eth,
|
i.balance_eth AS balance_eth,
|
||||||
i.tokens AS tokens,
|
i.tokens AS tokens,
|
||||||
i.value_usd AS value_usd
|
i.value_usd AS value_usd,
|
||||||
|
i.watch_hash AS watch_hash
|
||||||
FROM issues i, repositories r
|
FROM issues i, repositories r
|
||||||
WHERE r.repo_id = i.repo_id
|
WHERE r.repo_id = i.repo_id
|
||||||
AND contract_address IS NOT NULL
|
AND contract_address IS NOT NULL
|
||||||
|
|
|
@ -55,6 +55,16 @@
|
||||||
(jdbc/with-db-connection [con-db *db*]
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
(db/update-winner-login con-db {:issue_id issue-id :winner_login login})))
|
(db/update-winner-login con-db {:issue_id issue-id :winner_login login})))
|
||||||
|
|
||||||
|
(defn update-watch-hash
|
||||||
|
[issue-id watch-hash]
|
||||||
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
|
(db/update-watch-hash con-db {:issue_id issue-id :watch_hash watch-hash})))
|
||||||
|
|
||||||
|
(defn pending-watch-calls
|
||||||
|
[]
|
||||||
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
|
(db/pending-watch-calls con-db)))
|
||||||
|
|
||||||
(defn update-payout-hash
|
(defn update-payout-hash
|
||||||
[issue-id payout-hash]
|
[issue-id payout-hash]
|
||||||
(jdbc/with-db-connection [con-db *db*]
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
|
|
|
@ -129,6 +129,16 @@
|
||||||
(db-bounties/update-confirm-hash issue-id confirm-hash)))))
|
(db-bounties/update-confirm-hash issue-id confirm-hash)))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn update-watch-hash
|
||||||
|
"Sets watch-hash to NULL for bounties where watch tx has been mined. Used to avoid unneeded watch transactions in update-bounty-token-balances"
|
||||||
|
[]
|
||||||
|
(doseq [{issue-id :issue_id
|
||||||
|
watch-hash :watch_hash} (db-bounties/pending-watch-calls)]
|
||||||
|
(log/info "pending watch call" watch-hash)
|
||||||
|
(when-let [receipt (eth/get-transaction-receipt watch-hash)]
|
||||||
|
(db-bounties/update-watch-hash issue-id nil))))
|
||||||
|
|
||||||
|
|
||||||
(defn older-than-3h?
|
(defn older-than-3h?
|
||||||
[timestamp]
|
[timestamp]
|
||||||
(let [now (t/now)
|
(let [now (t/now)
|
||||||
|
@ -198,23 +208,27 @@
|
||||||
|
|
||||||
(defn update-bounty-token-balances
|
(defn update-bounty-token-balances
|
||||||
"Helper function for updating internal ERC20 token balances to token multisig contract. Will be called periodically for all open bounty contracts."
|
"Helper function for updating internal ERC20 token balances to token multisig contract. Will be called periodically for all open bounty contracts."
|
||||||
[bounty-addr]
|
[issue-id bounty-addr watch-hash]
|
||||||
(doseq [[tla token-data] (token-data/as-map)]
|
(doseq [[tla token-data] (token-data/as-map)]
|
||||||
(let [balance (multisig/token-balance bounty-addr tla)]
|
(let [balance (multisig/token-balance bounty-addr tla)]
|
||||||
(when (> balance 0)
|
(when (> balance 0)
|
||||||
(do
|
(do
|
||||||
(log/debug "bounty at" bounty-addr "has" balance "of token" tla)
|
(log/debug "bounty at" bounty-addr "has" balance "of token" tla)
|
||||||
(let [internal-balance (multisig/token-balance-in-bounty bounty-addr tla)]
|
(let [internal-balance (multisig/token-balance-in-bounty bounty-addr tla)]
|
||||||
(when (not= balance internal-balance)
|
(when (and (nil? watch-hash)
|
||||||
|
(not= balance internal-balance))
|
||||||
(log/info "balances not in sync, calling watch")
|
(log/info "balances not in sync, calling watch")
|
||||||
(multisig/watch-token bounty-addr tla))))))))
|
(let [hash (multisig/watch-token bounty-addr tla)]
|
||||||
|
(db-bounties/update-watch-hash issue-id hash)))))))))
|
||||||
|
|
||||||
(defn update-contract-internal-balances
|
(defn update-contract-internal-balances
|
||||||
"It is required in our current smart contract to manually update it's internal balance when some tokens have been added."
|
"It is required in our current smart contract to manually update it's internal balance when some tokens have been added."
|
||||||
[]
|
[]
|
||||||
(doseq [{bounty-address :contract_address}
|
(doseq [{issue-id :issue_id
|
||||||
|
bounty-address :contract_address
|
||||||
|
watch-hash :watch_hash}
|
||||||
(db-bounties/open-bounty-contracts)]
|
(db-bounties/open-bounty-contracts)]
|
||||||
(update-bounty-token-balances bounty-address)))
|
(update-bounty-token-balances issue-id bounty-address watch-hash)))
|
||||||
|
|
||||||
|
|
||||||
(defn get-bounty-funds
|
(defn get-bounty-funds
|
||||||
|
@ -313,6 +327,7 @@
|
||||||
update-issue-contract-address
|
update-issue-contract-address
|
||||||
update-confirm-hash
|
update-confirm-hash
|
||||||
update-payout-receipt
|
update-payout-receipt
|
||||||
|
update-watch-hash
|
||||||
self-sign-bounty
|
self-sign-bounty
|
||||||
update-contract-internal-balances
|
update-contract-internal-balances
|
||||||
update-balances])
|
update-balances])
|
||||||
|
|
Loading…
Reference in New Issue