From 41f88176aa99447076a510436f996a7de83a0ee3 Mon Sep 17 00:00:00 2001 From: Rabbit Date: Fri, 3 Jan 2025 16:57:40 +0800 Subject: [PATCH 1/3] feat: update fiber graph channels columns (#2386) --- app/models/bitcoin_statistic.rb | 2 +- app/models/fiber_graph_channel.rb | 33 +++++++++---------- .../v2/fiber/graph_channels/index.jbuilder | 9 +++-- .../api/v2/fiber/graph_nodes/show.jbuilder | 9 +++-- app/workers/fiber_graph_detect_worker.rb | 9 +++-- ...50103072945_update_fiber_graph_channels.rb | 14 ++++++++ db/structure.sql | 16 ++++----- 7 files changed, 51 insertions(+), 41 deletions(-) create mode 100644 db/migrate/20250103072945_update_fiber_graph_channels.rb diff --git a/app/models/bitcoin_statistic.rb b/app/models/bitcoin_statistic.rb index 49bae6460..04ecc40a6 100644 --- a/app/models/bitcoin_statistic.rb +++ b/app/models/bitcoin_statistic.rb @@ -34,5 +34,5 @@ def self.refresh # # Indexes # -# index_bitcoin_statistics_on_timestamp (timestamp) UNIQUE +# index_bitcoin_statistics_on_timestamp (timestamp) # diff --git a/app/models/fiber_graph_channel.rb b/app/models/fiber_graph_channel.rb index 42e03ee64..ca2ac583e 100644 --- a/app/models/fiber_graph_channel.rb +++ b/app/models/fiber_graph_channel.rb @@ -51,23 +51,22 @@ def funding_cell # # Table name: fiber_graph_channels # -# id :bigint not null, primary key -# channel_outpoint :string -# funding_tx_block_number :bigint -# funding_tx_index :integer -# node1 :string -# node2 :string -# last_updated_timestamp :bigint -# created_timestamp :bigint -# node1_to_node2_fee_rate :decimal(30, ) default(0) -# node2_to_node1_fee_rate :decimal(30, ) default(0) -# capacity :decimal(64, 2) default(0.0) -# chain_hash :string -# created_at :datetime not null -# updated_at :datetime not null -# udt_id :bigint -# open_transaction_id :bigint -# closed_transaction_id :bigint +# id :bigint not null, primary key +# channel_outpoint :string +# node1 :string +# node2 :string +# created_timestamp :bigint +# capacity :decimal(64, 2) default(0.0) +# chain_hash :string +# created_at :datetime not null +# updated_at :datetime not null +# udt_id :bigint +# open_transaction_id :bigint +# closed_transaction_id :bigint +# last_updated_timestamp_of_node1 :bigint +# last_updated_timestamp_of_node2 :bigint +# fee_rate_of_node1 :decimal(30, ) default(0) +# fee_rate_of_node2 :decimal(30, ) default(0) # # Indexes # diff --git a/app/views/api/v2/fiber/graph_channels/index.jbuilder b/app/views/api/v2/fiber/graph_channels/index.jbuilder index a53cbb927..063aa2491 100644 --- a/app/views/api/v2/fiber/graph_channels/index.jbuilder +++ b/app/views/api/v2/fiber/graph_channels/index.jbuilder @@ -1,12 +1,11 @@ json.data do json.fiber_graph_channels @channels do |channel| json.(channel, :channel_outpoint, :node1, :node2, :chain_hash, :open_transaction_info, :closed_transaction_info) - json.funding_tx_block_number channel.funding_tx_block_number.to_s - json.funding_tx_index channel.funding_tx_index.to_s - json.last_updated_timestamp channel.last_updated_timestamp.to_s + json.last_updated_timestamp_of_node1 channel.last_updated_timestamp_of_node1.to_s + json.last_updated_timestamp_of_node2 channel.last_updated_timestamp_of_node2.to_s json.created_timestamp channel.created_timestamp.to_s - json.node1_to_node2_fee_rate channel.node1_to_node2_fee_rate.to_s - json.node2_to_node1_fee_rate channel.node2_to_node1_fee_rate.to_s + json.fee_rate_of_node1 channel.fee_rate_of_node1.to_s + json.fee_rate_of_node2 channel.fee_rate_of_node2.to_s json.capacity channel.capacity.to_s json.udt_cfg_info channel.udt_info end diff --git a/app/views/api/v2/fiber/graph_nodes/show.jbuilder b/app/views/api/v2/fiber/graph_nodes/show.jbuilder index 2cc5aeb58..f097b4fa4 100644 --- a/app/views/api/v2/fiber/graph_nodes/show.jbuilder +++ b/app/views/api/v2/fiber/graph_nodes/show.jbuilder @@ -7,12 +7,11 @@ json.data do json.fiber_graph_channels @graph_channels do |channel| json.(channel, :channel_outpoint, :node1, :node2, :chain_hash, :open_transaction_info, :closed_transaction_info, :udt_info) - json.funding_tx_block_number channel.funding_tx_block_number.to_s - json.funding_tx_index channel.funding_tx_index.to_s - json.last_updated_timestamp channel.last_updated_timestamp.to_s + json.last_updated_timestamp_of_node1 channel.last_updated_timestamp_of_node1.to_s + json.last_updated_timestamp_of_node2 channel.last_updated_timestamp_of_node2.to_s + json.fee_rate_of_node1 channel.fee_rate_of_node1.to_s + json.fee_rate_of_node2 channel.fee_rate_of_node2.to_s json.created_timestamp channel.created_timestamp.to_s - json.node1_to_node2_fee_rate channel.node1_to_node2_fee_rate.to_s - json.node2_to_node1_fee_rate channel.node2_to_node1_fee_rate.to_s json.capacity channel.capacity.to_s end end diff --git a/app/workers/fiber_graph_detect_worker.rb b/app/workers/fiber_graph_detect_worker.rb index a39d9fd7f..fb31e8c3b 100644 --- a/app/workers/fiber_graph_detect_worker.rb +++ b/app/workers/fiber_graph_detect_worker.rb @@ -100,14 +100,13 @@ def build_channel_attributes(channel) { channel_outpoint:, - funding_tx_block_number: channel["funding_tx_block_number"].to_i(16), - funding_tx_index: channel["funding_tx_index"].to_i(16), node1: channel["node1"], node2: channel["node2"], - last_updated_timestamp: channel["last_updated_timestamp"].to_i(16), created_timestamp: channel["created_timestamp"], - node1_to_node2_fee_rate: channel["node1_to_node2_fee_rate"].to_i(16), - node2_to_node1_fee_rate: channel["node2_to_node1_fee_rate"].to_i(16), + last_updated_timestamp_of_node1: channel["last_updated_timestamp_of_node1"].to_i(16), + last_updated_timestamp_of_node2: channel["last_updated_timestamp_of_node2"].to_i(16), + fee_rate_of_node1: channel["fee_rate_of_node1"].to_i(16), + fee_rate_of_node2: channel["fee_rate_of_node2"].to_i(16), capacity: channel["capacity"].to_i(16), chain_hash: channel["chain_hash"], open_transaction_id: open_transaction&.id, diff --git a/db/migrate/20250103072945_update_fiber_graph_channels.rb b/db/migrate/20250103072945_update_fiber_graph_channels.rb new file mode 100644 index 000000000..a2aa3417f --- /dev/null +++ b/db/migrate/20250103072945_update_fiber_graph_channels.rb @@ -0,0 +1,14 @@ +class UpdateFiberGraphChannels < ActiveRecord::Migration[7.0] + def change + remove_column :fiber_graph_channels, :funding_tx_block_number, :bigint + remove_column :fiber_graph_channels, :funding_tx_index, :integer + remove_column :fiber_graph_channels, :last_updated_timestamp, :bigint + remove_column :fiber_graph_channels, :node1_to_node2_fee_rate, :decimal, precision: 30, default: 0.0 + remove_column :fiber_graph_channels, :node2_to_node1_fee_rate, :decimal, precision: 30, default: 0.0 + + add_column :fiber_graph_channels, :last_updated_timestamp_of_node1, :bigint + add_column :fiber_graph_channels, :last_updated_timestamp_of_node2, :bigint + add_column :fiber_graph_channels, :fee_rate_of_node1, :decimal, precision: 30, default: 0.0 + add_column :fiber_graph_channels, :fee_rate_of_node2, :decimal, precision: 30, default: 0.0 + end +end diff --git a/db/structure.sql b/db/structure.sql index fb806dee9..c762c3a7f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1755,21 +1755,20 @@ ALTER SEQUENCE public.fiber_channels_id_seq OWNED BY public.fiber_channels.id; CREATE TABLE public.fiber_graph_channels ( id bigint NOT NULL, channel_outpoint character varying, - funding_tx_block_number bigint, - funding_tx_index integer, node1 character varying, node2 character varying, - last_updated_timestamp bigint, created_timestamp bigint, - node1_to_node2_fee_rate numeric(30,0) DEFAULT 0.0, - node2_to_node1_fee_rate numeric(30,0) DEFAULT 0.0, capacity numeric(64,2) DEFAULT 0.0, chain_hash character varying, created_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL, udt_id bigint, open_transaction_id bigint, - closed_transaction_id bigint + closed_transaction_id bigint, + last_updated_timestamp_of_node1 bigint, + last_updated_timestamp_of_node2 bigint, + fee_rate_of_node1 numeric(30,0) DEFAULT 0.0, + fee_rate_of_node2 numeric(30,0) DEFAULT 0.0 ); @@ -4747,7 +4746,7 @@ CREATE UNIQUE INDEX index_bitcoin_annotations_on_ckb_transaction_id ON public.bi -- Name: index_bitcoin_statistics_on_timestamp; Type: INDEX; Schema: public; Owner: - -- -CREATE UNIQUE INDEX index_bitcoin_statistics_on_timestamp ON public.bitcoin_statistics USING btree ("timestamp"); +CREATE INDEX index_bitcoin_statistics_on_timestamp ON public.bitcoin_statistics USING btree ("timestamp"); -- @@ -6317,6 +6316,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20241223023654'), ('20241223060331'), ('20241225045757'), -('20241231022644'); +('20241231022644'), +('20250103072945'); From 1d3c2e23f76cc89098520e5b816a30588246af6a Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Fri, 3 Jan 2025 20:11:54 +0900 Subject: [PATCH 2/3] fix: catch daily statistic charts worker's error (#2385) Signed-off-by: Miles Zhang --- app/services/charts/daily_statistic_generator.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/services/charts/daily_statistic_generator.rb b/app/services/charts/daily_statistic_generator.rb index ddf801bec..5f45cfd92 100644 --- a/app/services/charts/daily_statistic_generator.rb +++ b/app/services/charts/daily_statistic_generator.rb @@ -15,9 +15,8 @@ def call daily_statistic = ::DailyStatistic.find_or_create_by!(created_at_unixtimestamp: to_be_counted_date.to_i) daily_statistic.from_scratch = from_scratch daily_statistic.reset!(updated_attrs) - daily_statistic - rescue Exception => e + rescue StandardError => e Rails.logger.error "Error occurred during DailyStatisticGenerator error: #{e.message}" end From 244cacfd8855541354f4d2fcb600d85f9ee64924 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Sun, 5 Jan 2025 18:22:52 +0900 Subject: [PATCH 3/3] fix: update address not nil attributes (#2390) Signed-off-by: Miles Zhang --- app/models/ckb_sync/new_node_data_processor.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index ae2134539..d27834518 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -355,7 +355,17 @@ def update_addresses_dao_info(addrs_deposit_info) is_depositor: address_info[:is_depositor], } end - Address.upsert_all(addresses_deposit_attributes, record_timestamps: true) if addresses_deposit_attributes.present? + if addresses_deposit_attributes.present? + Address.upsert_all( + addresses_deposit_attributes, + record_timestamps: true, + on_duplicate: Arel.sql( + "dao_deposit = COALESCE(EXCLUDED.dao_deposit, addresses.dao_deposit), " \ + "interest = COALESCE(EXCLUDED.interest, addresses.interest), " \ + "is_depositor = COALESCE(EXCLUDED.is_depositor, addresses.is_depositor)", + ), + ) + end end def update_or_create_udt_accounts!(local_block)