Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy to mainnet #2139

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/models/ckb_sync/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ def xudt_code_hash
Settings.xudt_code_hash
end

def xudt_compatible_code_hash
Settings.xudt_compatible_code_hash
def xudt_compatible_code_hashes
if mode == CKB::MODE::MAINNET
[Settings.xudt_compatible_code_hash]
else
[Settings.xudt_compatible_code_hash, Settings.xudt_compatible2_code_hash]
end
end

def unique_cell_code_hash
Expand Down
6 changes: 2 additions & 4 deletions app/models/ckb_sync/new_node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1246,11 +1246,10 @@ def cell_input_attributes(input, ckb_transaction_id, local_block_id,
def build_ckb_transactions!(node_block, local_block, inputs, outputs, outputs_data)
cycles = CkbSync::Api.instance.get_block_cycles node_block.header.hash
ckb_transactions_attributes = []
tx_index = 0
hashes = []
header_deps = {}
witnesses = {}
node_block.transactions.each do |tx|
node_block.transactions.each_with_index do |tx, tx_index|
attrs = ckb_transaction_attributes(local_block, tx, tx_index)
if cycles
attrs[:cycles] = tx_index > 0 ? cycles[tx_index - 1]&.hex : nil
Expand All @@ -1263,8 +1262,6 @@ def build_ckb_transactions!(node_block, local_block, inputs, outputs, outputs_da
inputs[tx_index] = tx.inputs
outputs[tx_index] = tx.outputs
outputs_data[tx_index] = tx.outputs_data

tx_index += 1
end
# First update status thus we can use upsert later. otherwise, we may not be able to
# locate correct record according to tx_hash
Expand Down Expand Up @@ -1358,6 +1355,7 @@ def ckb_transaction_attributes(local_block, tx, tx_index)
is_cellbase: tx_index.zero?,
live_cell_changes: live_cell_changes(tx, tx_index),
bytes: tx.serialized_size_in_block,
tx_index: tx_index
}
end

Expand Down
1 change: 1 addition & 0 deletions app/models/ckb_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def log_deletion_chain
# bytes :bigint default(0)
# cycles :bigint
# confirmation_time :integer
# tx_index :integer
#
# Indexes
#
Expand Down
4 changes: 2 additions & 2 deletions app/utils/ckb_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def self.cell_type(type_script, output_data)
CkbSync::Api.instance.issuer_script_code_hash, CkbSync::Api.instance.token_class_script_code_hash,
CkbSync::Api.instance.token_script_code_hash, CkbSync::Api.instance.cota_registry_code_hash,
CkbSync::Api.instance.cota_regular_code_hash, CkbSync::Api.instance.omiga_inscription_info_code_hash,
CkbSync::Api.instance.xudt_code_hash, CkbSync::Api.instance.unique_cell_code_hash, CkbSync::Api.instance.xudt_compatible_code_hash, CkbSync::Api.instance.did_cell_code_hash
CkbSync::Api.instance.xudt_code_hash, CkbSync::Api.instance.unique_cell_code_hash, *CkbSync::Api.instance.xudt_compatible_code_hashes, CkbSync::Api.instance.did_cell_code_hash
].include?(type_script&.code_hash) && type_script&.hash_type == "type") ||
is_nrc_721_token_cell?(output_data) ||
is_nrc_721_factory_cell?(output_data) ||
Expand Down Expand Up @@ -457,7 +457,7 @@ def self.cell_type(type_script, output_data)
"did_cell"
when CkbSync::Api.instance.omiga_inscription_info_code_hash
"omiga_inscription_info"
when CkbSync::Api.instance.xudt_compatible_code_hash
when *CkbSync::Api.instance.xudt_compatible_code_hashes
"xudt_compatible"
when CkbSync::Api.instance.xudt_code_hash
Rails.cache.fetch(type_script.compute_hash) do
Expand Down
1 change: 1 addition & 0 deletions config/settings.testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ unique_cell_code_hash: "0x8e341bcfec6393dcd41e635733ff2dca00a6af546949f70c57a706

# xudt compatible
xudt_compatible_code_hash: "0x98701eaf939113606a8a70013fd2e8f27b8f1e234acdc329f3d71f9e9d3d3233"
xudt_compatible2_code_hash: "0x1142755a044bf2ee358cba9f2da187ce928c91cd4dc8692ded0337efa677d21a"

# hash length of an attribute(especially which comes from bytea column),
# e.g. Block.uncle_block_hashes: "0x587f354162afd133b4a4f7a4b621d11e043c3c08b0af2801f1686b5403b14953", which has a length of 66 ( 2 + 64)
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240822024448_add_tx_index_to_ckb_transaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTxIndexToCkbTransaction < ActiveRecord::Migration[7.0]
def change
add_column :ckb_transactions, :tx_index, :integer
end
end
27 changes: 14 additions & 13 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--

-- *not* creating schema, since initdb creates it


--
-- Name: btree_gin; Type: EXTENSION; Schema: -; Owner: -
--
Expand Down Expand Up @@ -1350,7 +1343,8 @@ CREATE TABLE public.ckb_transactions (
tags character varying[] DEFAULT '{}'::character varying[],
bytes bigint DEFAULT 0,
cycles bigint,
confirmation_time integer
confirmation_time integer,
tx_index integer
)
PARTITION BY LIST (tx_status);

Expand Down Expand Up @@ -1395,7 +1389,8 @@ CREATE TABLE public.ckb_transactions_committed (
tags character varying[] DEFAULT '{}'::character varying[],
bytes bigint DEFAULT 0,
cycles bigint,
confirmation_time integer
confirmation_time integer,
tx_index integer
);


Expand All @@ -1420,7 +1415,8 @@ CREATE TABLE public.ckb_transactions_pending (
tags character varying[] DEFAULT '{}'::character varying[],
bytes bigint DEFAULT 0,
cycles bigint,
confirmation_time integer
confirmation_time integer,
tx_index integer
);


Expand All @@ -1445,7 +1441,8 @@ CREATE TABLE public.ckb_transactions_proposed (
tags character varying[] DEFAULT '{}'::character varying[],
bytes bigint DEFAULT 0,
cycles bigint,
confirmation_time integer
confirmation_time integer,
tx_index integer
);


Expand All @@ -1470,7 +1467,8 @@ CREATE TABLE public.ckb_transactions_rejected (
tags character varying[] DEFAULT '{}'::character varying[],
bytes bigint DEFAULT 0,
cycles bigint,
confirmation_time integer
confirmation_time integer,
tx_index integer
);


Expand Down Expand Up @@ -6098,4 +6096,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20240709131020'),
('20240709131132'),
('20240709131713'),
('20240709142013');
('20240709142013'),
('20240822024448');


43 changes: 43 additions & 0 deletions lib/tasks/migration/fill_tx_index.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace :migration do
desc "Usage: RAILS_ENV=production bundle exec rake migration:fill_tx_index"
task fill_tx_index: :environment do
$retry_ids = Set.new
@api = CKB::API.new(host: ENV["CKB_NODE_URL"],

Check warning on line 5 in lib/tasks/migration/fill_tx_index.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/fill_tx_index.rake#L4-L5

Added lines #L4 - L5 were not covered by tests
timeout_config: {
open_timeout: 1, read_timeout: 3,
write_timeout: 1
})
first_tx = CkbTransaction.tx_committed.where(tx_index: nil).order("block_number asc").select(:block_number).first
last_tx = CkbTransaction.tx_committed.where(tx_index: nil).order("block_number desc").select(:block_number).first

Check warning on line 11 in lib/tasks/migration/fill_tx_index.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/fill_tx_index.rake#L10-L11

Added lines #L10 - L11 were not covered by tests

(first_tx.block_number..last_tx.block_number).to_a.each_slice(100).to_a.each do |range|
fill_missed_tx_index(range, 0)

Check warning on line 14 in lib/tasks/migration/fill_tx_index.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/fill_tx_index.rake#L13-L14

Added lines #L13 - L14 were not covered by tests
end; nil

puts "retry IDS:"
puts $retry_ids.join(",")
puts "done"

Check warning on line 19 in lib/tasks/migration/fill_tx_index.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/fill_tx_index.rake#L17-L19

Added lines #L17 - L19 were not covered by tests
end

def fill_missed_tx_index(range, retry_count)
request_body =
range.map do |number|
["get_block_by_number", number]

Check warning on line 25 in lib/tasks/migration/fill_tx_index.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/fill_tx_index.rake#L24-L25

Added lines #L24 - L25 were not covered by tests
end
response = @api.batch_request(*request_body)
attrs = []
response.each do |r|
r[:transactions].each_with_index do |tx, index|
attrs << { tx_hash: tx[:hash], tx_status: "committed", tx_index: index }

Check warning on line 31 in lib/tasks/migration/fill_tx_index.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/fill_tx_index.rake#L27-L31

Added lines #L27 - L31 were not covered by tests
end
end; nil
CkbTransaction.upsert_all(attrs, unique_by: %i[tx_status tx_hash])

Check warning on line 34 in lib/tasks/migration/fill_tx_index.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/fill_tx_index.rake#L34

Added line #L34 was not covered by tests
rescue StandardError => _e
retry_count += 1
if retry_count > 2
$retry_ids << range.first

Check warning on line 38 in lib/tasks/migration/fill_tx_index.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/fill_tx_index.rake#L36-L38

Added lines #L36 - L38 were not covered by tests
else
fill_missed_tx_index(range, retry_count)

Check warning on line 40 in lib/tasks/migration/fill_tx_index.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/fill_tx_index.rake#L40

Added line #L40 was not covered by tests
end
end
end
Loading