Skip to content

Commit

Permalink
feat: update fiber graph node attributes (#2397)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz authored Jan 8, 2025
1 parent 2bb5375 commit e46063e
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v2/fiber/graph_nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/fiber_graph_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/suggest_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/serializers/fiber_graph_node_serializer.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/views/api/v2/fiber/graph_nodes/index.jbuilder
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/api/v2/fiber/graph_nodes/show.jbuilder
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions app/workers/fiber_graph_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20250108053433_rename_alias_to_node_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameAliasToNodeName < ActiveRecord::Migration[7.0]
def change
rename_column :fiber_graph_nodes, :alias, :node_name
end
end
5 changes: 3 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -6317,6 +6317,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20241223060331'),
('20241225045757'),
('20241231022644'),
('20250103072945');
('20250103072945'),
('20250108053433');


0 comments on commit e46063e

Please sign in to comment.