From 18c936be9dde7d3d3fbea6d5be4f6b3b64e056cf Mon Sep 17 00:00:00 2001 From: NanZhang Date: Thu, 23 Nov 2023 10:54:29 +0800 Subject: [PATCH 1/3] fix: handle deployed_type_script with matching code_hash (#1512) --- app/controllers/api/v2/scripts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v2/scripts_controller.rb b/app/controllers/api/v2/scripts_controller.rb index f3bdfdfb9..41347a4d9 100644 --- a/app/controllers/api/v2/scripts_controller.rb +++ b/app/controllers/api/v2/scripts_controller.rb @@ -40,7 +40,7 @@ def get_script_content deployed_cells = @contract.deployed_cell_outputs if deployed_cells.present? deployed_type_script = deployed_cells[0].type_script - if deployed_type_script.code_hash == Settings.type_id_code_hash + if deployed_type_script && deployed_type_script.code_hash == Settings.type_id_code_hash type_id = deployed_type_script.script_hash end end From 0669c1e328c7280d7efd8ae2b12a83350049bfc6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 24 Nov 2023 16:44:14 +0800 Subject: [PATCH 2/3] Merge released refs/heads/master into develop (#1506) feat: adjust halving miner reward (#1505) Signed-off-by: Miles Zhang Co-authored-by: Miles Zhang Co-authored-by: NanZhang --- app/utils/ckb_utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/utils/ckb_utils.rb b/app/utils/ckb_utils.rb index ca5196f56..dd5cd49f9 100644 --- a/app/utils/ckb_utils.rb +++ b/app/utils/ckb_utils.rb @@ -107,7 +107,7 @@ def self.base_reward(block_number, epoch_number) end def self.epoch_reward_with_halving(epoch_number) - Settings.default_epoch_reward.to_i >> epoch_number / HALVING_EPOCH + Settings.default_epoch_reward.to_i >> epoch_number / HALVING_EPOCH end def self.primary_reward(block_number, block_economic_state) From 162a8bf0907c0fa698bfee59c0dcf24f5b5eb41b Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Fri, 24 Nov 2023 17:11:15 +0800 Subject: [PATCH 3/3] Issue 490 (#1515) * feat: update pending tx to commited, not add new commited tx Signed-off-by: Miles Zhang * feat: remove clean pending tx code Signed-off-by: Miles Zhang --------- Signed-off-by: Miles Zhang --- app/jobs/import_block_job.rb | 1 + app/jobs/revert_block_job.rb | 2 -- app/models/ckb_sync/new_node_data_processor.rb | 11 +++++++---- app/workers/clean_up_worker.rb | 2 +- app/workers/pool_transaction_check_worker.rb | 6 ------ 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/jobs/import_block_job.rb b/app/jobs/import_block_job.rb index d39e9cd0f..58bd09cda 100644 --- a/app/jobs/import_block_job.rb +++ b/app/jobs/import_block_job.rb @@ -1,3 +1,4 @@ +# No used class ImportBlockJob < ApplicationJob def perform(block_hash) if block_hash.is_a?(Integer) diff --git a/app/jobs/revert_block_job.rb b/app/jobs/revert_block_job.rb index 49ac115c7..cfabb33e0 100644 --- a/app/jobs/revert_block_job.rb +++ b/app/jobs/revert_block_job.rb @@ -11,8 +11,6 @@ def perform(local_tip_block = nil) end ApplicationRecord.transaction do - CkbTransaction.tx_pending. - where(tx_hash: CkbUtils.hexes_to_bins(local_tip_block.ckb_transactions.pluck(:tx_hash))).update_all(tx_status: "pending") benchmark :revert_dao_contract_related_operations, local_tip_block benchmark :revert_mining_info, local_tip_block diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index b355a297b..736d3c68e 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -77,7 +77,8 @@ def process_block(node_block, refresh_balance: true) @contained_udt_ids = contained_udt_ids = [] @contained_address_ids = contained_address_ids = [] - process_ckb_txs(node_block, ckb_txs, contained_address_ids, contained_udt_ids, dao_address_ids, tags, udt_address_ids) + process_ckb_txs(node_block, ckb_txs, contained_address_ids, contained_udt_ids, dao_address_ids, tags, + udt_address_ids) addrs_changes = Hash.new { |hash, key| hash[key] = {} } input_capacities, output_capacities = build_cells_and_locks!(local_block, node_block, ckb_txs, inputs, outputs, tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_address_ids, addrs_changes) @@ -136,7 +137,10 @@ def generate_statistics_data(local_block) GenerateStatisticsDataWorker.perform_async(local_block.id) end - def process_ckb_txs(node_block, ckb_txs, contained_address_ids, contained_udt_ids, dao_address_ids, tags, udt_address_ids) + def process_ckb_txs( + node_block, ckb_txs, contained_address_ids, contained_udt_ids, dao_address_ids, tags, +udt_address_ids + ) tx_index = 0 ckb_txs.each do |cbk_tx| cbk_tx["tx_hash"][0] = "0" @@ -1182,7 +1186,6 @@ def cell_input_attributes(input, ckb_transaction_id, local_block_id, prev_output def build_ckb_transactions!(node_block, local_block, inputs, outputs, outputs_data) cycles = CkbSync::Api.instance.get_block_cycles node_block.header.hash - txs = nil ckb_transactions_attributes = [] tx_index = 0 hashes = [] @@ -1209,7 +1212,7 @@ def build_ckb_transactions!(node_block, local_block, inputs, outputs, outputs_da # locate correct record according to tx_hash binary_hashes = CkbUtils.hexes_to_bins(hashes) pending_txs = CkbTransaction.where(tx_hash: binary_hashes, tx_status: :pending).pluck(:tx_hash, :created_at) - CkbTransaction.where(tx_hash: hashes).update_all tx_status: "committed" + CkbTransaction.where(tx_hash: binary_hashes).update_all tx_status: "committed" txs = CkbTransaction.upsert_all(ckb_transactions_attributes, unique_by: [:tx_status, :tx_hash], returning: %w(id tx_hash block_timestamp created_at)) diff --git a/app/workers/clean_up_worker.rb b/app/workers/clean_up_worker.rb index 0f3afb2a7..187fbd992 100644 --- a/app/workers/clean_up_worker.rb +++ b/app/workers/clean_up_worker.rb @@ -3,7 +3,7 @@ class CleanUpWorker def perform TokenCollection.remove_corrupted - CkbTransaction.tx_pending.where("created_at < ?", 2.weeks.ago).destroy_all + CkbTransaction.tx_pending.where("created_at < ?", 1.day.ago).destroy_all CkbTransaction.tx_rejected.where("created_at < ?", 3.months.ago).destroy_all end end diff --git a/app/workers/pool_transaction_check_worker.rb b/app/workers/pool_transaction_check_worker.rb index d5445503e..12d2a2a09 100644 --- a/app/workers/pool_transaction_check_worker.rb +++ b/app/workers/pool_transaction_check_worker.rb @@ -14,12 +14,6 @@ def perform includes(:cell_dependencies, cell_inputs: :previous_cell_output). order(id: :asc).limit(150) pending_transactions.each do |tx| - # FIXME: remove this code - if CkbTransaction.tx_committed.exists?(tx_hash: tx.tx_hash) - tx.destroy! - next - end - is_rejected = false rejected_transaction = nil # check if any input is used by other transactions