Skip to content

Commit 9b080f7

Browse files
authored
Merge pull request #2587 from nervosnetwork/develop
Deploy to testnet
2 parents 2dc00d2 + d386ab8 commit 9b080f7

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

app/workers/pool_transaction_check_worker.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ def perform
2020
if reason["status"] == "rejected"
2121
ApplicationRecord.transaction do
2222
tx.update! tx_status: "rejected"
23+
tx.cell_outputs.update_all(status: "rejected")
2324
tx.create_reject_reason!(message: reason["reason"])
2425
end
2526
end
2627

2728
if reason["status"] == "unknown"
2829
ApplicationRecord.transaction do
2930
tx.update! tx_status: "rejected"
31+
tx.cell_outputs.update_all(status: "rejected")
3032
tx.create_reject_reason!(message: "unknown")
3133
end
3234
end
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
namespace :migration do
2+
desc "Usage: RAILS_ENV=production bundle exec rake migration:check_cell_output_data[0,1000000]"
3+
task :check_cell_output_data, %i[start_block end_block] => :environment do |_, args|
4+
$retry_ids = Set.new
5+
@api = CKB::API.new(host: ENV.fetch("CKB_NODE_URL", nil),
6+
timeout_config: {
7+
open_timeout: 1, read_timeout: 3,
8+
write_timeout: 1
9+
})
10+
(args[:start_block].to_i..args[:end_block].to_i).to_a.each_slice(100).to_a.each do |range|
11+
compare_output(range, 0)
12+
end
13+
nil
14+
15+
puts "=============="
16+
puts "retry IDS:"
17+
puts $retry_ids.join(",")
18+
puts "done"
19+
end
20+
21+
def compare_output(range, retry_count)
22+
request_body =
23+
range.map do |number|
24+
["get_block_by_number", number]
25+
end
26+
response = @api.batch_request(*request_body)
27+
response.each do |r|
28+
r[:transactions].each do |tx|
29+
tx[:outputs].each_with_index do |_output, index|
30+
output_data = tx[:outputs_data][index]
31+
binary_data = CKB::Utils.hex_to_bin(output_data)
32+
data_hash = nil
33+
data_size = 0
34+
if binary_data&.bytesize&.positive?
35+
data_size = binary_data.bytesize
36+
data_hash = CKB::Utils.bin_to_hex(CKB::Blake2b.digest(binary_data))
37+
end
38+
co = CellOutput.find_by(tx_hash: tx[:hash], cell_index: index)
39+
40+
if co.data_size != data_size || co.data_hash != data_hash
41+
puts co.id
42+
co.update!(data_hash:, data_size:)
43+
if data_size.zero?
44+
co.cell_datum.destroy if co.cell_datum.present?
45+
elsif co.cell_datum.present?
46+
co.cell_datum.update!(data: binary_data)
47+
else
48+
co.cell_datum.create!(data: binary_data)
49+
end
50+
end
51+
end
52+
end
53+
end
54+
rescue StandardError => _e
55+
retry_count += 1
56+
if retry_count > 2
57+
$retry_ids << range.first
58+
else
59+
compare_output(range, retry_count)
60+
end
61+
end
62+
end

0 commit comments

Comments
 (0)