diff --git a/app/controllers/api/v2/fiber/graph_nodes_controller.rb b/app/controllers/api/v2/fiber/graph_nodes_controller.rb index 2c175c037..482500488 100644 --- a/app/controllers/api/v2/fiber/graph_nodes_controller.rb +++ b/app/controllers/api/v2/fiber/graph_nodes_controller.rb @@ -7,7 +7,7 @@ def index @page_size = params.fetch(:page_size, FiberGraphNode.default_per_page) @nodes = if params[:q].present? - FiberGraphNode.where("alias = :q or peer_id = :q or node_id = :q", q: params[:q]).page(@page).per(@page_size) + FiberGraphNode.where("node_name = :q or peer_id = :q or node_id = :q", q: params[:q]).page(@page).per(@page_size) else FiberGraphNode.all.page(@page).per(@page_size) end diff --git a/app/models/block.rb b/app/models/block.rb index 7f22d905a..bc0afc959 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -285,10 +285,15 @@ def invalid! uncle_blocks.delete_all # delete_address_txs_cache ckb_transaction_ids = ckb_transactions.pluck(:id) + tx_hashes = ckb_transactions.pluck(:tx_hash) CellOutput.where(ckb_transaction_id: ckb_transaction_ids).delete_all CellInput.where(ckb_transaction_id: ckb_transaction_ids).delete_all AccountBook.where(ckb_transaction_id: ckb_transaction_ids).delete_all CellDependency.where(ckb_transaction_id: ckb_transaction_ids).delete_all + cell_deps = CellDepsOutPoint.where(tx_hash: tx_hashes).select(:tx_hash, :cell_index) + cell_deps.each do |cell_dep| + Rails.cache.delete(["cell_output", cell_dep.tx_hash, cell_dep.cell_index]) + end HeaderDependency.where(ckb_transaction_id: ckb_transaction_ids).delete_all TokenTransfer.where(transaction_id: ckb_transaction_ids).delete_all Witness.where(ckb_transaction_id: ckb_transaction_ids).delete_all diff --git a/app/models/daily_statistic.rb b/app/models/daily_statistic.rb index 63b8ca5bf..b19e14a35 100644 --- a/app/models/daily_statistic.rb +++ b/app/models/daily_statistic.rb @@ -1,5 +1,5 @@ # TODO -# remove dao_depositors_count daily_dao_withdraw nodes_distribution nodes_count average_block_time columns +# remove daily_dao_withdraw nodes_distribution nodes_count average_block_time columns class DailyStatistic < ApplicationRecord include AttrLogics @@ -216,6 +216,10 @@ def liquidity select(:address_id)).distinct.count(:address_id) end + define_logic :dao_depositors_count do + DaoEvent.depositor.created_before(ended_at).distinct.count(:address_id) + end + define_logic :circulation_ratio do total_dao_deposit.to_i / circulating_supply end @@ -512,7 +516,7 @@ def yesterday_daily_statistic if to_be_counted_date.beginning_of_day.to_i == Time.at(GENESIS_TIMESTAMP / 1000).in_time_zone.beginning_of_day.to_i \ || aggron_first_day? \ || yesterday_statistic.blank? - OpenStruct.new(addresses_count: 0, total_dao_deposit: 0, + OpenStruct.new(addresses_count: 0, total_dao_deposit: 0, dao_depositors_count: 0, unclaimed_compensation: 0, claimed_compensation: 0, average_deposit_time: 0, mining_reward: 0, deposit_compensation: 0, treasury_amount: 0, total_depositors_count: 0, diff --git a/app/models/fiber_graph_node.rb b/app/models/fiber_graph_node.rb index 4b39f8496..22a15fc72 100644 --- a/app/models/fiber_graph_node.rb +++ b/app/models/fiber_graph_node.rb @@ -34,7 +34,7 @@ def open_channels_count # Table name: fiber_graph_nodes # # id :bigint not null, primary key -# alias :string +# node_name :string # node_id :string # addresses :string default([]), is an Array # timestamp :bigint diff --git a/app/models/suggest_query.rb b/app/models/suggest_query.rb index b004e963f..34a66da25 100644 --- a/app/models/suggest_query.rb +++ b/app/models/suggest_query.rb @@ -163,7 +163,7 @@ def find_fiber_graph_nodes else query_key end - fiber_graph_nodes = FiberGraphNode.where("alias = :query_key or peer_id = :query_key or node_id = :query_key", query_key: normalized_key) + fiber_graph_nodes = FiberGraphNode.where("node_name = :query_key or peer_id = :query_key or node_id = :query_key", query_key: normalized_key) FiberGraphNodeSerializer.new(fiber_graph_nodes) if fiber_graph_nodes.present? end end diff --git a/app/serializers/fiber_graph_node_serializer.rb b/app/serializers/fiber_graph_node_serializer.rb index a191d52ee..c7edc1191 100644 --- a/app/serializers/fiber_graph_node_serializer.rb +++ b/app/serializers/fiber_graph_node_serializer.rb @@ -1,6 +1,6 @@ class FiberGraphNodeSerializer include FastJsonapi::ObjectSerializer - attributes :id, :alias, :node_id, :peer_id, :addresses, :timestamp, :chain_hash, + attributes :id, :node_name, :node_id, :peer_id, :addresses, :timestamp, :chain_hash, :auto_accept_min_ckb_funding_amount end diff --git a/app/services/charts/daily_statistic_generator.rb b/app/services/charts/daily_statistic_generator.rb index 5f45cfd92..80b7ac6e3 100644 --- a/app/services/charts/daily_statistic_generator.rb +++ b/app/services/charts/daily_statistic_generator.rb @@ -30,7 +30,7 @@ def updated_attrs daily_dao_depositors_count total_depositors_count unclaimed_compensation claimed_compensation deposit_compensation daily_dao_deposit total_dao_deposit circulating_supply circulation_ratio } others = %i{ - block_timestamp transactions_count addresses_count + dao_depositors_count block_timestamp transactions_count addresses_count average_deposit_time mining_reward knowledge_size treasury_amount estimated_apc live_cells_count dead_cells_count avg_hash_rate avg_difficulty uncle_rate address_balance_distribution diff --git a/app/views/api/v2/fiber/graph_nodes/index.jbuilder b/app/views/api/v2/fiber/graph_nodes/index.jbuilder index a0140cad1..4cb173f8f 100644 --- a/app/views/api/v2/fiber/graph_nodes/index.jbuilder +++ b/app/views/api/v2/fiber/graph_nodes/index.jbuilder @@ -1,6 +1,6 @@ json.data do json.fiber_graph_nodes @nodes do |node| - json.(node, :alias, :node_id, :addresses, :peer_id, :timestamp, :chain_hash, :connected_node_ids, :open_channels_count) + json.(node, :node_name, :node_id, :addresses, :peer_id, :timestamp, :chain_hash, :connected_node_ids, :open_channels_count) json.timestamp node.timestamp.to_s json.auto_accept_min_ckb_funding_amount node.auto_accept_min_ckb_funding_amount.to_s json.total_capacity node.total_capacity.to_s diff --git a/app/views/api/v2/fiber/graph_nodes/show.jbuilder b/app/views/api/v2/fiber/graph_nodes/show.jbuilder index f097b4fa4..58457ac65 100644 --- a/app/views/api/v2/fiber/graph_nodes/show.jbuilder +++ b/app/views/api/v2/fiber/graph_nodes/show.jbuilder @@ -1,5 +1,5 @@ json.data do - json.(@node, :alias, :node_id, :addresses, :peer_id, :timestamp, :chain_hash, :connected_node_ids) + json.(@node, :node_name, :node_id, :addresses, :peer_id, :timestamp, :chain_hash, :connected_node_ids) json.timestamp @node.timestamp.to_s json.auto_accept_min_ckb_funding_amount @node.auto_accept_min_ckb_funding_amount.to_s json.total_capacity @node.total_capacity.to_s diff --git a/app/workers/fiber_graph_detect_worker.rb b/app/workers/fiber_graph_detect_worker.rb index fb31e8c3b..a3855f309 100644 --- a/app/workers/fiber_graph_detect_worker.rb +++ b/app/workers/fiber_graph_detect_worker.rb @@ -14,7 +14,6 @@ def perform FiberGraphNode.where.not(node_id: @graph_node_ids).destroy_all # purge outdated graph channels FiberGraphChannel.where.not(channel_outpoint: @graph_channel_outpoints).destroy_all - # check channel is closed FiberGraphChannel.open_channels.each do |channel| funding_cell = channel.funding_cell @@ -62,7 +61,7 @@ def fetch_channels(last_cursor) def upsert_node_with_cfg_info(node) node_attributes = { - alias: node["alias"], + node_name: node["node_name"], node_id: node["node_id"], addresses: node["addresses"], timestamp: node["timestamp"].to_i(16), diff --git a/db/migrate/20250108053433_rename_alias_to_node_name.rb b/db/migrate/20250108053433_rename_alias_to_node_name.rb new file mode 100644 index 000000000..2e9d10225 --- /dev/null +++ b/db/migrate/20250108053433_rename_alias_to_node_name.rb @@ -0,0 +1,5 @@ +class RenameAliasToNodeName < ActiveRecord::Migration[7.0] + def change + rename_column :fiber_graph_nodes, :alias, :node_name + end +end diff --git a/db/structure.sql b/db/structure.sql index c762c3a7f..368eb8864 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1797,7 +1797,7 @@ ALTER SEQUENCE public.fiber_graph_channels_id_seq OWNED BY public.fiber_graph_ch CREATE TABLE public.fiber_graph_nodes ( id bigint NOT NULL, - alias character varying, + node_name character varying, node_id character varying, addresses character varying[] DEFAULT '{}'::character varying[], "timestamp" bigint, @@ -6317,6 +6317,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20241223060331'), ('20241225045757'), ('20241231022644'), -('20250103072945'); +('20250103072945'), +('20250108053433');