Skip to content

Commit

Permalink
feat: limit pending tx query (#2027)
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid authored Jul 5, 2024
1 parent 2713bcc commit 0fffb95
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 5 additions & 4 deletions app/workers/pool_transaction_check_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ class PoolTransactionCheckWorker

def perform
pending_transactions = CkbTransaction.tx_pending.where("created_at < ?",
2.minutes.ago)
2.minutes.ago).limit(100)
pending_transactions.each do |tx|
response_string = CkbSync::Api.instance.directly_single_call_rpc method: "get_transaction",
params: [tx.tx_hash]
reason = response_string["result"]["tx_status"]
if reason["status"] == "committed" && CkbTransaction.where(tx_hash: tx.tx_hash, tx_status: :committed).exists?
tx.destroy
end

if reason["status"] == "rejected"
ApplicationRecord.transaction do
Expand All @@ -27,6 +24,10 @@ def perform
tx.create_reject_reason!(message: "unknown")
end
end

if reason["status"] == "committed" && CkbTransaction.where(tx_hash: tx.tx_hash).count == 2 && CkbTransaction.where(tx_hash: tx.tx_hash, tx_status: :committed).exists?
tx.destroy
end
end
end
end
4 changes: 0 additions & 4 deletions lib/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ def call_worker(clz)
call_worker PoolTransactionCheckWorker
end

s.every "1h", overlap: false do
call_worker CleanUpWorker
end

s.interval "10s", overlap: false do
puts "reset transactions_count_per_minute, average_block_time, transaction_fee_rates"
StatisticInfo.default.reset! :transactions_count_per_minute,
Expand Down

0 comments on commit 0fffb95

Please sign in to comment.