Skip to content

Commit 3b43729

Browse files
authored
Merge pull request #2450 from nervosnetwork/testnet
Deploy to mainnet
2 parents 329cb70 + f02928d commit 3b43729

File tree

13 files changed

+98
-24
lines changed

13 files changed

+98
-24
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,4 @@ gem "jwt"
126126

127127
gem "active_interaction", "~> 5.3"
128128
gem "bitcoinrb", require: "bitcoin"
129+
gem "paranoia", "~> 2.6.4"

Gemfile.lock

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,14 @@ GEM
308308
net-protocol
309309
newrelic_rpm (8.12.0)
310310
nio4r (2.7.3)
311-
nokogiri (1.17.1)
311+
nokogiri (1.18.3)
312312
mini_portile2 (~> 2.8.2)
313313
racc (~> 1.4)
314-
nokogiri (1.17.1-arm64-darwin)
315-
racc (~> 1.4)
316-
nokogiri (1.17.1-x86_64-linux)
317-
racc (~> 1.4)
318314
pagy (5.10.1)
319315
activesupport
320316
parallel (1.22.1)
317+
paranoia (2.6.4)
318+
activerecord (>= 5.1, < 7.2)
321319
parser (3.2.2.0)
322320
ast (~> 2.4.1)
323321
pg (1.4.5)
@@ -348,7 +346,7 @@ GEM
348346
nio4r (~> 2.0)
349347
raabro (1.4.0)
350348
racc (1.8.1)
351-
rack (2.2.10)
349+
rack (2.2.13)
352350
rack-attack (6.6.1)
353351
rack (>= 1.0, < 3)
354352
rack-cache (1.13.0)
@@ -526,6 +524,7 @@ DEPENDENCIES
526524
net-smtp
527525
newrelic_rpm
528526
pagy
527+
paranoia (~> 2.6.4)
529528
pg (>= 0.18, < 2.0)
530529
pry
531530
pry-byebug

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ def index
77
@page_size = params.fetch(:page_size, FiberGraphNode.default_per_page)
88
@nodes =
99
if params[:q].present?
10-
FiberGraphNode.where("node_name = :q or peer_id = :q or node_id = :q", q: params[:q]).page(@page).per(@page_size)
10+
FiberGraphNode.with_deleted.where("node_name = :q or peer_id = :q or node_id = :q", q: params[:q]).page(@page).per(@page_size)
1111
else
12-
FiberGraphNode.all.page(@page).per(@page_size)
12+
FiberGraphNode.with_deleted.page(@page).per(@page_size)
1313
end
1414
end
1515

1616
def show
17-
@node = FiberGraphNode.find_by(node_id: params[:node_id])
17+
@node = FiberGraphNode.with_deleted.find_by(node_id: params[:node_id])
1818
raise Api::V2::Exceptions::FiberGraphNodeNotFoundError unless @node
1919

20-
@graph_channels = FiberGraphChannel.where(node1: params[:node_id]).or(
21-
FiberGraphChannel.where(node2: params[:node_id]),
20+
@graph_channels = FiberGraphChannel.with_deleted.where(node1: params[:node_id]).or(
21+
FiberGraphChannel.with_deleted.where(node2: params[:node_id]),
2222
)
2323

2424
if params[:status] == "closed"
25-
@graph_channels = @graph_channels.where.not(closed_transaction_id: nil)
25+
@graph_channels = @graph_channels.with_deleted.where.not(closed_transaction_id: nil)
2626
end
2727
end
2828

app/models/fiber_graph_channel.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class FiberGraphChannel < ApplicationRecord
2+
acts_as_paranoid
3+
24
MAX_PAGINATES_PER = 100
35
DEFAULT_PAGINATES_PER = 10
46
paginates_per DEFAULT_PAGINATES_PER
@@ -45,6 +47,12 @@ def funding_cell
4547
lock_scripts: { code_hash: Settings.fiber_funding_code_hash },
4648
)
4749
end
50+
51+
def deleted_at_timestamp
52+
return unless deleted_at
53+
54+
(deleted_at.to_f * 1000).to_i.to_s
55+
end
4856
end
4957

5058
# == Schema Information
@@ -67,8 +75,10 @@ def funding_cell
6775
# last_updated_timestamp_of_node2 :bigint
6876
# fee_rate_of_node1 :decimal(30, ) default(0)
6977
# fee_rate_of_node2 :decimal(30, ) default(0)
78+
# deleted_at :datetime
7079
#
7180
# Indexes
7281
#
7382
# index_fiber_graph_channels_on_channel_outpoint (channel_outpoint) UNIQUE
83+
# index_fiber_graph_channels_on_deleted_at (deleted_at)
7484
#

app/models/fiber_graph_node.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
class FiberGraphNode < ApplicationRecord
2+
acts_as_paranoid
3+
24
MAX_PAGINATES_PER = 100
35
DEFAULT_PAGINATES_PER = 10
46
paginates_per DEFAULT_PAGINATES_PER
57
max_paginates_per MAX_PAGINATES_PER
68

7-
has_many :fiber_udt_cfg_infos, dependent: :delete_all
9+
has_many :fiber_udt_cfg_infos, dependent: :destroy
810

911
def channel_links
1012
FiberGraphChannel.where(node1: node_id).or(FiberGraphChannel.where(node2: node_id)).
@@ -27,6 +29,23 @@ def connected_node_ids
2729
def open_channels_count
2830
channel_links.count
2931
end
32+
33+
def last_updated_timestamp
34+
node1_timestamps = FiberGraphChannel.where(node1: node_id).pluck(:last_updated_timestamp_of_node1)
35+
node2_timestamps = FiberGraphChannel.where(node2: node_id).pluck(:last_updated_timestamp_of_node2)
36+
closed_transaction_ids = FiberGraphChannel.where(node1: node_id).
37+
or(FiberGraphChannel.where(node2: node_id)).
38+
where.not(closed_transaction_id: nil).pluck(:closed_transaction_id)
39+
block_timestamps = CkbTransaction.where(id: closed_transaction_ids).pluck(:block_timestamp)
40+
41+
[timestamp, *node1_timestamps, *node2_timestamps, *block_timestamps].compact.max.to_s
42+
end
43+
44+
def deleted_at_timestamp
45+
return unless deleted_at
46+
47+
(deleted_at.to_f * 1000).to_i.to_s
48+
end
3049
end
3150

3251
# == Schema Information
@@ -43,8 +62,10 @@ def open_channels_count
4362
# created_at :datetime not null
4463
# updated_at :datetime not null
4564
# peer_id :string
65+
# deleted_at :datetime
4666
#
4767
# Indexes
4868
#
49-
# index_fiber_graph_nodes_on_node_id (node_id) UNIQUE
69+
# index_fiber_graph_nodes_on_deleted_at (deleted_at)
70+
# index_fiber_graph_nodes_on_node_id (node_id) UNIQUE
5071
#

app/models/fiber_udt_cfg_info.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class FiberUdtCfgInfo < ApplicationRecord
2+
acts_as_paranoid
3+
24
belongs_to :fiber_graph_node
35
belongs_to :udt
46

@@ -17,8 +19,10 @@ def udt_info
1719
# auto_accept_amount :decimal(64, 2) default(0.0)
1820
# created_at :datetime not null
1921
# updated_at :datetime not null
22+
# deleted_at :datetime
2023
#
2124
# Indexes
2225
#
26+
# index_fiber_udt_cfg_infos_on_deleted_at (deleted_at)
2327
# index_fiber_udt_cfg_infos_on_fiber_graph_node_id_and_udt_id (fiber_graph_node_id,udt_id) UNIQUE
2428
#

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, :node_name, :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, :last_updated_timestamp, :deleted_at_timestamp)
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
json.data do
2-
json.(@node, :node_name, :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, :last_updated_timestamp, :deleted_at_timestamp)
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
66
json.udt_cfg_infos @node.udt_cfg_infos
77

88
json.fiber_graph_channels @graph_channels do |channel|
9-
json.(channel, :channel_outpoint, :node1, :node2, :chain_hash, :open_transaction_info, :closed_transaction_info, :udt_info)
9+
json.(channel, :channel_outpoint, :node1, :node2, :chain_hash, :open_transaction_info, :closed_transaction_info, :udt_info, :deleted_at_timestamp)
1010
json.last_updated_timestamp_of_node1 channel.last_updated_timestamp_of_node1.to_s
1111
json.last_updated_timestamp_of_node2 channel.last_updated_timestamp_of_node2.to_s
1212
json.fee_rate_of_node1 channel.fee_rate_of_node1.to_s

app/workers/fiber_graph_detect_worker.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def upsert_node_with_cfg_info(node)
6262
chain_hash: node["chain_hash"],
6363
peer_id: extract_peer_id(node["addresses"]),
6464
auto_accept_min_ckb_funding_amount: node["auto_accept_min_ckb_funding_amount"],
65+
deleted_at: nil,
6566
}
6667
@graph_node_ids << node_attributes[:node_id]
6768
fiber_graph_node = FiberGraphNode.upsert(node_attributes, unique_by: %i[node_id], returning: %i[id])
@@ -76,6 +77,7 @@ def upsert_node_with_cfg_info(node)
7677
fiber_graph_node_id: fiber_graph_node[0]["id"],
7778
udt_id: udt.id,
7879
auto_accept_amount: info["auto_accept_amount"].to_i(16),
80+
deleted_at: nil,
7981
}
8082
end.compact
8183

@@ -104,6 +106,7 @@ def build_channel_attributes(channel)
104106
chain_hash: channel["chain_hash"],
105107
open_transaction_id: open_transaction&.id,
106108
udt_id: udt&.id,
109+
deleted_at: nil,
107110
}
108111
end
109112

app/workers/pool_transaction_check_worker.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ class PoolTransactionCheckWorker
66

77
def perform
88
pending_transactions = CkbTransaction.tx_pending.where("created_at < ?",
9-
5.minutes.ago).limit(100)
9+
10.minutes.ago).limit(100)
1010
pending_transactions.each do |tx|
1111
committed_tx = CkbTransaction.find_by(tx_hash: tx.tx_hash, tx_status: "committed")
12-
if committed_tx
12+
if committed_tx && tx.reload.tx_pending?
1313
tx.cell_inputs.delete_all
1414
tx.delete
1515
else

0 commit comments

Comments
 (0)