From a533f8e11136d0a0539f148e09bd2ba5723e598d Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Wed, 20 Nov 2024 18:09:12 +0900 Subject: [PATCH 1/3] fix: revert is too slowly (#2292) Signed-off-by: Miles Zhang --- app/models/block.rb | 10 +++++----- app/models/ckb_transaction.rb | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/block.rb b/app/models/block.rb index 18c15c114..ef5f1d435 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -81,7 +81,7 @@ def self.query_transaction_fee_rate(date_string) def self.fetch_transaction_fee_rate_from_cache(date_string) Rails.cache.fetch("transaction_fee_rate_#{date_string}", expires_in: 10.minutes) do - self.query_transaction_fee_rate date_string + query_transaction_fee_rate date_string end end @@ -227,7 +227,7 @@ def block_index_in_epoch end def fraction_epoch - OpenStruct.new(number: epoch, index: block_index_in_epoch, length: length) + OpenStruct.new(number: epoch, index: block_index_in_epoch, length:) end def self.find_block!(query_key) @@ -261,7 +261,7 @@ def self.largest_in_epoch(epoch_number) if b&.block_size { number: b.number, - bytes: b.block_size + bytes: b.block_size, } end end @@ -310,7 +310,7 @@ def self.update_block_median_timestamp(block_number) end def update_counter_for_ckb_node_version - witness = self.cellbase.witnesses[0].data + witness = cellbase.witnesses[0].data return if witness.blank? matched = [witness.gsub("0x", "")].pack("H*").match(/\d\.\d+\.\d/) @@ -325,7 +325,7 @@ def update_counter_for_ckb_node_version # update the current block's ckb_node_version self.ckb_node_version = matched[0] - self.save! + save! end # NOTICE: this method would do a fresh calculate for all the block's ckb_node_version, it will: diff --git a/app/models/ckb_transaction.rb b/app/models/ckb_transaction.rb index a91735da9..cf3f04bdf 100644 --- a/app/models/ckb_transaction.rb +++ b/app/models/ckb_transaction.rb @@ -25,12 +25,12 @@ class CkbTransaction < ApplicationRecord has_many :inputs, class_name: "CellOutput", inverse_of: "consumed_by", foreign_key: "consumed_by_id" has_many :outputs, class_name: "CellOutput" has_many :dao_events # , dependent: :delete_all - has_many :script_transactions, dependent: :delete_all - has_many :scripts, through: :script_transactions + # has_many :script_transactions, dependent: :delete_all + # has_many :scripts, through: :script_transactions has_many :referring_cells, dependent: :delete_all has_many :token_transfers, foreign_key: :transaction_id, dependent: :delete_all, inverse_of: :ckb_transaction - has_many :cell_dependencies, dependent: :delete_all + # has_many :cell_dependencies, dependent: :delete_all has_many :header_dependencies, dependent: :delete_all has_many :witnesses, dependent: :delete_all From daf47aabcaadea27c8ce7345ee5fb5e4d6316689 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Wed, 20 Nov 2024 18:23:01 +0900 Subject: [PATCH 2/3] fix: directly delete all tx (#2294) Signed-off-by: Miles Zhang --- app/models/block.rb | 2 +- app/models/ckb_transaction.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/block.rb b/app/models/block.rb index ef5f1d435..394507622 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -284,7 +284,7 @@ def cache_keys def invalid! uncle_blocks.delete_all # delete_address_txs_cache - ckb_transactions.destroy_all + ckb_transactions.delete_all ForkedBlock.create(attributes) destroy end diff --git a/app/models/ckb_transaction.rb b/app/models/ckb_transaction.rb index cf3f04bdf..5434b8bf9 100644 --- a/app/models/ckb_transaction.rb +++ b/app/models/ckb_transaction.rb @@ -30,7 +30,7 @@ class CkbTransaction < ApplicationRecord has_many :referring_cells, dependent: :delete_all has_many :token_transfers, foreign_key: :transaction_id, dependent: :delete_all, inverse_of: :ckb_transaction - # has_many :cell_dependencies, dependent: :delete_all + has_many :cell_dependencies, dependent: :delete_all has_many :header_dependencies, dependent: :delete_all has_many :witnesses, dependent: :delete_all From 681b2da7a0de194cf4a4251eb2d4ba29277967f0 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Wed, 20 Nov 2024 20:23:39 +0900 Subject: [PATCH 3/3] fix: delete_all cell_output when rollback (#2296) Signed-off-by: Miles Zhang --- app/models/block.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/block.rb b/app/models/block.rb index 394507622..2cfddbebc 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -285,6 +285,7 @@ def invalid! uncle_blocks.delete_all # delete_address_txs_cache ckb_transactions.delete_all + CellOutput.where(block_id: id).delete_all ForkedBlock.create(attributes) destroy end