Skip to content

Commit e46063e

Browse files
authored
feat: update fiber graph node attributes (#2397)
1 parent 2bb5375 commit e46063e

File tree

9 files changed

+15
-10
lines changed

9 files changed

+15
-10
lines changed

app/controllers/api/v2/fiber/graph_nodes_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def index
77
@page_size = params.fetch(:page_size, FiberGraphNode.default_per_page)
88
@nodes =
99
if params[:q].present?
10-
FiberGraphNode.where("alias = :q or peer_id = :q or node_id = :q", q: params[:q]).page(@page).per(@page_size)
10+
FiberGraphNode.where("node_name = :q or peer_id = :q or node_id = :q", q: params[:q]).page(@page).per(@page_size)
1111
else
1212
FiberGraphNode.all.page(@page).per(@page_size)
1313
end

app/models/fiber_graph_node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def open_channels_count
3434
# Table name: fiber_graph_nodes
3535
#
3636
# id :bigint not null, primary key
37-
# alias :string
37+
# node_name :string
3838
# node_id :string
3939
# addresses :string default([]), is an Array
4040
# timestamp :bigint

app/models/suggest_query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def find_fiber_graph_nodes
163163
else
164164
query_key
165165
end
166-
fiber_graph_nodes = FiberGraphNode.where("alias = :query_key or peer_id = :query_key or node_id = :query_key", query_key: normalized_key)
166+
fiber_graph_nodes = FiberGraphNode.where("node_name = :query_key or peer_id = :query_key or node_id = :query_key", query_key: normalized_key)
167167
FiberGraphNodeSerializer.new(fiber_graph_nodes) if fiber_graph_nodes.present?
168168
end
169169
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class FiberGraphNodeSerializer
22
include FastJsonapi::ObjectSerializer
33

4-
attributes :id, :alias, :node_id, :peer_id, :addresses, :timestamp, :chain_hash,
4+
attributes :id, :node_name, :node_id, :peer_id, :addresses, :timestamp, :chain_hash,
55
:auto_accept_min_ckb_funding_amount
66
end

app/views/api/v2/fiber/graph_nodes/index.jbuilder

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
json.data do
22
json.fiber_graph_nodes @nodes do |node|
3-
json.(node, :alias, :node_id, :addresses, :peer_id, :timestamp, :chain_hash, :connected_node_ids, :open_channels_count)
3+
json.(node, :node_name, :node_id, :addresses, :peer_id, :timestamp, :chain_hash, :connected_node_ids, :open_channels_count)
44
json.timestamp node.timestamp.to_s
55
json.auto_accept_min_ckb_funding_amount node.auto_accept_min_ckb_funding_amount.to_s
66
json.total_capacity node.total_capacity.to_s

app/views/api/v2/fiber/graph_nodes/show.jbuilder

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
json.data do
2-
json.(@node, :alias, :node_id, :addresses, :peer_id, :timestamp, :chain_hash, :connected_node_ids)
2+
json.(@node, :node_name, :node_id, :addresses, :peer_id, :timestamp, :chain_hash, :connected_node_ids)
33
json.timestamp @node.timestamp.to_s
44
json.auto_accept_min_ckb_funding_amount @node.auto_accept_min_ckb_funding_amount.to_s
55
json.total_capacity @node.total_capacity.to_s

app/workers/fiber_graph_detect_worker.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def perform
1414
FiberGraphNode.where.not(node_id: @graph_node_ids).destroy_all
1515
# purge outdated graph channels
1616
FiberGraphChannel.where.not(channel_outpoint: @graph_channel_outpoints).destroy_all
17-
1817
# check channel is closed
1918
FiberGraphChannel.open_channels.each do |channel|
2019
funding_cell = channel.funding_cell
@@ -62,7 +61,7 @@ def fetch_channels(last_cursor)
6261

6362
def upsert_node_with_cfg_info(node)
6463
node_attributes = {
65-
alias: node["alias"],
64+
node_name: node["node_name"],
6665
node_id: node["node_id"],
6766
addresses: node["addresses"],
6867
timestamp: node["timestamp"].to_i(16),
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class RenameAliasToNodeName < ActiveRecord::Migration[7.0]
2+
def change
3+
rename_column :fiber_graph_nodes, :alias, :node_name
4+
end
5+
end

db/structure.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ ALTER SEQUENCE public.fiber_graph_channels_id_seq OWNED BY public.fiber_graph_ch
17971797

17981798
CREATE TABLE public.fiber_graph_nodes (
17991799
id bigint NOT NULL,
1800-
alias character varying,
1800+
node_name character varying,
18011801
node_id character varying,
18021802
addresses character varying[] DEFAULT '{}'::character varying[],
18031803
"timestamp" bigint,
@@ -6317,6 +6317,7 @@ INSERT INTO "schema_migrations" (version) VALUES
63176317
('20241223060331'),
63186318
('20241225045757'),
63196319
('20241231022644'),
6320-
('20250103072945');
6320+
('20250103072945'),
6321+
('20250108053433');
63216322

63226323

0 commit comments

Comments
 (0)