From 063d0576e62e1141f18eb3584ccc550d54bf01b9 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 22 Feb 2024 23:04:37 +0800 Subject: [PATCH 1/2] fix: invoke worker in outside node process transaction Signed-off-by: Miles Zhang --- .../ckb_sync/new_node_data_processor.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index 1e7818e18..0741cad74 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -10,7 +10,7 @@ class NewNodeDataProcessor value :reorg_started_at, global: true attr_accessor :local_tip_block, :pending_raw_block, :ckb_txs, :target_block, :addrs_changes, :outputs, :inputs, :outputs_data, :udt_address_ids, :contained_address_ids, - :dao_address_ids, :contained_udt_ids, :cell_datas, :enable_cota + :dao_address_ids, :contained_udt_ids, :cell_datas, :enable_cota, :token_transfer_ckb_tx_ids def initialize(enable_cota = ENV["COTA_AGGREGATOR_URL"].present?) @enable_cota = enable_cota @@ -68,13 +68,14 @@ def process_block(node_block, refresh_balance: true) @dao_address_ids = dao_address_ids = [] @contained_udt_ids = contained_udt_ids = [] @contained_address_ids = contained_address_ids = [] + @token_transfer_ckb_tx_ids = token_transfer_ckb_tx_ids = Set.new benchmark :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 = benchmark :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 + tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_address_ids, addrs_changes, token_transfer_ckb_tx_ids # update explorer data benchmark :update_ckb_txs_rel_and_fee, ckb_txs, tags, input_capacities, output_capacities, udt_address_ids, @@ -94,6 +95,7 @@ def process_block(node_block, refresh_balance: true) generate_statistics_data(local_block) generate_deployed_cells_and_referring_cells(local_block) detect_cota_infos(local_block) + invoke_token_transfer_detect_worker(token_transfer_ckb_tx_ids) local_block.update_counter_for_ckb_node_version local_block @@ -131,6 +133,12 @@ def detect_cota_infos(local_block) FetchCotaWorker.perform_async(local_block.number) if enable_cota end + def invoke_token_transfer_detect_worker(token_transfer_ckb_tx_ids) + token_transfer_ckb_tx_ids.each do |tx_id| + TokenTransferDetectWorker.perform_async(tx_id) + end + end + def process_ckb_txs( node_block, ckb_txs, contained_address_ids, contained_udt_ids, dao_address_ids, tags, udt_address_ids @@ -808,7 +816,7 @@ def update_ckb_txs_rel_and_fee( def build_cells_and_locks!( local_block, node_block, ckb_txs, inputs, outputs, tags, udt_address_ids, - dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes + dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes, token_transfer_ckb_tx_ids ) cell_outputs_attributes = [] cell_inputs_attributes = [] @@ -818,7 +826,6 @@ def build_cells_and_locks!( lock_scripts_attributes, type_scripts_attributes = build_scripts(outputs) lock_script_ids = [] type_script_ids = [] - token_transfer_ckb_tx_ids = Set.new if lock_scripts_attributes.present? lock_scripts_attributes.map! do |attr| @@ -902,10 +909,6 @@ def build_cells_and_locks!( unique_by: %i[tx_hash cell_index]) end - token_transfer_ckb_tx_ids.each do |tx_id| - TokenTransferDetectWorker.perform_async(tx_id) - end - ScriptTransaction.create_from_scripts TypeScript.where(id: type_script_ids) ScriptTransaction.create_from_scripts LockScript.where(id: lock_script_ids) From 7dcaf232294f5fbcd3484f192fe44248169480a4 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Fri, 23 Feb 2024 11:26:54 +0800 Subject: [PATCH 2/2] Revert "Issue 548 3 (#1646)" This reverts commit 35dfa27dde48c60f39b1cbfa07026fae5801963b. --- app/workers/token_transfer_detect_worker.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/workers/token_transfer_detect_worker.rb b/app/workers/token_transfer_detect_worker.rb index da8aa94fe..026aba969 100644 --- a/app/workers/token_transfer_detect_worker.rb +++ b/app/workers/token_transfer_detect_worker.rb @@ -3,7 +3,6 @@ class TokenTransferDetectWorker def perform(tx_id) tx = CkbTransaction.includes(:cell_outputs, cell_inputs: :previous_cell_output).find tx_id - puts "==================#{tx.inspect}" return unless tx @lock = Redis::Lock.new("token_transfer_#{tx_id}", expiration: 180, timeout: 30) @@ -12,7 +11,6 @@ def perform(tx_id) source_collections = [] tx.cell_inputs.each do |input| - puts input.cell_type if input.cell_type.in?(%w(m_nft_token nrc_721_token spore_cell)) cell = input.previous_cell_output type_script = input.type_script @@ -22,9 +20,7 @@ def perform(tx_id) end tx.cell_outputs.each do |output| - puts output.cell_type if output.cell_type.in?(%w(m_nft_token nrc_721_token spore_cell)) - puts "========================#{output.id}" type_script = output.type_script item = find_or_create_item(output, type_script) attrs = {