diff --git a/app/controllers/api/v1/udts_controller.rb b/app/controllers/api/v1/udts_controller.rb index fdac9405b..ccc31a978 100644 --- a/app/controllers/api/v1/udts_controller.rb +++ b/app/controllers/api/v1/udts_controller.rb @@ -93,6 +93,7 @@ def holder_allocation { name: allocation.contract.name, code_hash: allocation.contract.code_hash, + hash_type: allocation.contract.hash_type, holder_count: allocation.ckb_holder_count, } end diff --git a/app/models/cell_output.rb b/app/models/cell_output.rb index faded8e64..05bd0aaa8 100644 --- a/app/models/cell_output.rb +++ b/app/models/cell_output.rb @@ -1,6 +1,8 @@ class CellOutput < ApplicationRecord include CellOutputs::ExtraInfo + self.primary_key = :id + SYSTEM_TX_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000".freeze MAXIMUM_DOWNLOADABLE_SIZE = 64000 MIN_SUDT_AMOUNT_BYTESIZE = 16 @@ -298,11 +300,10 @@ def self.update_cell_types_for_cota # # id :bigint not null, primary key # capacity :decimal(64, 2) -# data :binary # ckb_transaction_id :bigint # created_at :datetime not null # updated_at :datetime not null -# status :integer default("live") +# status :integer default("live"), not null # address_id :decimal(30, ) # block_id :decimal(30, ) # tx_hash :binary @@ -322,17 +323,13 @@ def self.update_cell_types_for_cota # # Indexes # -# index_cell_outputs_on_address_id_and_status (address_id,status) +# index_cell_outputs_on_address_id (address_id) # index_cell_outputs_on_block_id (block_id) # index_cell_outputs_on_block_timestamp (block_timestamp) -# index_cell_outputs_on_cell_type (cell_type) -# index_cell_outputs_on_ckb_transaction_id_and_cell_index (ckb_transaction_id,cell_index) UNIQUE # index_cell_outputs_on_consumed_block_timestamp (consumed_block_timestamp) # index_cell_outputs_on_consumed_by_id (consumed_by_id) -# index_cell_outputs_on_data_hash (data_hash) USING hash # index_cell_outputs_on_lock_script_id (lock_script_id) -# index_cell_outputs_on_status (status) -# index_cell_outputs_on_tx_hash_and_cell_index (tx_hash,cell_index) UNIQUE +# index_cell_outputs_on_tx_hash_and_cell_index_and_status (tx_hash,cell_index,status) UNIQUE +# index_cell_outputs_on_tx_id_and_cell_index_and_status (ckb_transaction_id,cell_index,status) UNIQUE # index_cell_outputs_on_type_script_id (type_script_id) -# index_cell_outputs_on_type_script_id_and_id (type_script_id,id) # diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index 84751cf2a..0a2d04e0a 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -846,7 +846,10 @@ def build_cells_and_locks!( build_cell_outputs!(node_block, outputs, ckb_txs, local_block, cell_outputs_attributes, output_capacities, tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes, token_transfer_ckb_tx_ids) if cell_outputs_attributes.present? - id_hashes = CellOutput.upsert_all(cell_outputs_attributes, unique_by: %i[tx_hash cell_index], + tx_hashes = cell_outputs_attributes.map { |attr| attr[:tx_hash] } + binary_hashes = CkbUtils.hexes_to_bins_sql(tx_hashes) + CellOutput.pending.where("tx_hash IN (#{binary_hashes})").update_all(status: :live) + id_hashes = CellOutput.upsert_all(cell_outputs_attributes, unique_by: %i[tx_hash cell_index status], returning: %i[id data_hash]) cell_data_attrs = [] @@ -873,8 +876,11 @@ def build_cells_and_locks!( CellInput.upsert_all(cell_inputs_attributes, unique_by: %i[ckb_transaction_id index]) if prev_cell_outputs_attributes.present? + cell_ouput_ids = prev_cell_outputs_attributes.map { |attr| attr[:id] } + CellOutput.live.where(id: cell_ouput_ids).update_all(status: :dead) CellOutput.upsert_all(prev_cell_outputs_attributes, - unique_by: %i[tx_hash cell_index]) + unique_by: %i[tx_hash cell_index status], + record_timestamps: true) end ScriptTransaction.create_from_scripts TypeScript.where(id: type_script_ids) @@ -906,13 +912,13 @@ def prepare_script_ids(outputs) local_cache.fetch("NodeData/LockScript/#{output.lock.code_hash}-#{output.lock.hash_type}-#{output.lock.args}") do # TODO use LockScript.where(script_hash: output.lock.compute_hash).select(:id)&.first replace search by code_hash, hash_type and args query after script_hash has been filled LockScript.where(code_hash: output.lock.code_hash, hash_type: output.lock.hash_type, - args: output.lock.args).select(:id).take! + args: output.lock.args).take! end if output.type.present? local_cache.fetch("NodeData/TypeScript/#{output.type.code_hash}-#{output.type.hash_type}-#{output.type.args}") do # TODO use TypeScript.where(script_hash: output.type.compute_hash).select(:id)&.first replace search by code_hash, hash_type and args query after script_hash has been filled TypeScript.where(code_hash: output.type.code_hash, hash_type: output.type.hash_type, - args: output.type.args).select(:id).take! + args: output.type.args).take! end end end @@ -1141,7 +1147,7 @@ def cell_output_attributes(output, address, ckb_transaction, local_block, cell_i attrs = { ckb_transaction_id: ckb_transaction["id"], capacity: output.capacity, - occupied_capacity: 0, + occupied_capacity: CkbUtils.cal_cell_min_capacity(lock_script, type_script, output.capacity, binary_data), address_id: address.id, block_id: local_block.id, tx_hash: ckb_transaction["tx_hash"], @@ -1221,11 +1227,9 @@ def cell_input_attributes(input, ckb_transaction_id, local_block_id, previous_output: { id: previous_output.id, cell_type: previous_output.cell_type, - created_at: previous_output.created_at, tx_hash: input.previous_output.tx_hash, cell_index: input.previous_output.index, status: "dead", - updated_at: Time.current, consumed_by_id: ckb_transaction_id, consumed_block_timestamp: CkbTransaction.find(ckb_transaction_id).block_timestamp, }, diff --git a/app/models/daily_statistic.rb b/app/models/daily_statistic.rb index 6c27c871f..e19c1b6c4 100644 --- a/app/models/daily_statistic.rb +++ b/app/models/daily_statistic.rb @@ -5,7 +5,7 @@ class DailyStatistic < ApplicationRecord transactions_count addresses_count total_dao_deposit live_cells_count dead_cells_count avg_hash_rate avg_difficulty uncle_rate total_depositors_count address_balance_distribution total_tx_fee occupied_capacity daily_dao_deposit daily_dao_depositors_count circulation_ratio daily_dao_withdraw nodes_count circulating_supply burnt locked_capacity treasury_amount mining_reward - deposit_compensation liquidity created_at_unixtimestamp ckb_hodl_wave + deposit_compensation liquidity created_at_unixtimestamp ckb_hodl_wave holder_count ).freeze MILLISECONDS_IN_DAY = BigDecimal(24 * 60 * 60 * 1000) GENESIS_TIMESTAMP = 1573852190812 @@ -398,6 +398,17 @@ def liquidity base_attrs.merge(total_supply: total_live_capacities).transform_values { |value| (value.to_f / 10**8).truncate(8) } end + define_logic :holder_count do + ActiveRecord::Base.connection.execute("SET statement_timeout = 0") + live_query = CellOutput.live.generated_before(to_be_counted_date.to_i * 1000 - 1).select(:address_id).to_sql + dead_query = CellOutput.dead.generated_before(to_be_counted_date.to_i * 1000 - 1).consumed_after(to_be_counted_date.to_i * 1000).select(:address_id).to_sql + combined_query = "#{live_query} UNION #{dead_query}" + count_query = "SELECT COUNT(DISTINCT address_id) AS count FROM (#{combined_query}) AS combined_results;" + count = ActiveRecord::Base.connection.execute(count_query).first["count"] + ActiveRecord::Base.connection.execute("RESET statement_timeout") + count + end + private def to_be_counted_date @@ -558,6 +569,7 @@ def aggron_first_day? # nodes_count :integer # locked_capacity :decimal(30, ) # ckb_hodl_wave :jsonb +# holder_count :integer # # Indexes # diff --git a/app/models/referring_cell.rb b/app/models/referring_cell.rb index 2deaba7d1..9ae25ebf2 100644 --- a/app/models/referring_cell.rb +++ b/app/models/referring_cell.rb @@ -56,6 +56,5 @@ def self.create_initial_data_for_ckb_transaction(ckb_transaction) # # Indexes # -# index_referring_cells_on_cell_output_id (cell_output_id) UNIQUE # index_referring_cells_on_contract_id_and_cell_output_id (contract_id,cell_output_id) UNIQUE # diff --git a/app/serializers/daily_statistic_serializer.rb b/app/serializers/daily_statistic_serializer.rb index 675012aa9..7baa598a5 100644 --- a/app/serializers/daily_statistic_serializer.rb +++ b/app/serializers/daily_statistic_serializer.rb @@ -128,4 +128,10 @@ class DailyStatisticSerializer attribute :ckb_hodl_wave, if: Proc.new { |_record, params| params.present? && params[:indicator].include?("ckb_hodl_wave") } + + attribute :holder_count, if: Proc.new { |_record, params| + params.present? && params[:indicator].include?("holder_count") + } do |object| + object.holder_count.to_s + end end diff --git a/app/services/charts/daily_statistic_generator.rb b/app/services/charts/daily_statistic_generator.rb index 48d6e04bb..343909873 100644 --- a/app/services/charts/daily_statistic_generator.rb +++ b/app/services/charts/daily_statistic_generator.rb @@ -36,7 +36,7 @@ def updated_attrs treasury_amount estimated_apc live_cells_count dead_cells_count avg_hash_rate avg_difficulty uncle_rate address_balance_distribution total_tx_fee occupied_capacity daily_dao_deposit total_supply block_time_distribution - epoch_time_distribution epoch_length_distribution locked_capacity ckb_hodl_wave + epoch_time_distribution epoch_length_distribution locked_capacity ckb_hodl_wave holder_count } established_order + others diff --git a/app/utils/ckb_utils.rb b/app/utils/ckb_utils.rb index fe547c4af..38c555b08 100644 --- a/app/utils/ckb_utils.rb +++ b/app/utils/ckb_utils.rb @@ -11,6 +11,14 @@ def self.calculate_cell_min_capacity(output, data) output.calculate_min_capacity(data) end + def self.cal_cell_min_capacity(lock_script, type_script, capacity, binary_data) + lock = CKB::Types::Script.new(**lock_script.to_node) + type = type_script.present? ? CKB::Types::Script.new(**type_script.to_node) : nil + CKB::Types::Output.new(capacity: capacity.to_i, lock:, type:) + CKB::Utils.byte_to_shannon([8, binary_data&.bytesize || 0, lock_script.calculate_bytesize, + type_script&.calculate_bytesize || 0].sum) + end + def self.block_cell_consumed(transactions) transactions.reduce(0) do |memo, transaction| outputs_data = transaction.outputs_data diff --git a/app/workers/generate_statistics_data_worker.rb b/app/workers/generate_statistics_data_worker.rb index d715fc22d..e11a9c7b0 100644 --- a/app/workers/generate_statistics_data_worker.rb +++ b/app/workers/generate_statistics_data_worker.rb @@ -14,26 +14,5 @@ def perform(block_id) if epoch_stats && epoch_stats.largest_block_size.to_i < block_size epoch_stats.update(largest_block_size: block_size, largest_block_number: block.number) end - - cell_outputs = block.cell_outputs.select(:id, :created_at, :data, :capacity, :lock_script_id, :type_script_id).to_a - cell_outputs_attributes = [] - cell_outputs.each do |cell_output| - data_size = - if cell_output.data - CKB::Utils.hex_to_bin(cell_output.data).bytesize - else - 0 - end - - cell_outputs_attributes << { - id: cell_output.id, - data_size:, - occupied_capacity: CkbUtils.calculate_cell_min_capacity(cell_output.node_output, cell_output.data), - created_at: cell_output.created_at, - updated_at: Time.current, - } - end - - CellOutput.upsert_all(cell_outputs_attributes) if cell_outputs_attributes.present? end end diff --git a/config/database.yml b/config/database.yml index da6cb7916..2405ef716 100644 --- a/config/database.yml +++ b/config/database.yml @@ -21,14 +21,14 @@ default: &default # http://guides.rubyonrails.org/configuring.html#database-pooling host: <%= ENV.fetch("DB_HOST") { "localhost" } %> port: <%= ENV.fetch("DB_PORT") { "5432" } %> - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 25 } %> + pool: <%= ENV.fetch("DB_POOL") { 5 } %> username: <%= ENV.fetch("DB_USERNAME") { "postgres" } %> password: <%= ENV.fetch("DB_PASSWORD") { "postgres" } %> reaping_frequency: 60 # every 60s check pool timeout: 5000 # over 5s will timeout variables: - statement_timeout: 120000 # query timemout over 120s - idle_in_transaction_session_timeout: 60000 # idle transaction over 60s + statement_timeout: 60000 # query timemout over 60s + idle_in_transaction_session_timeout: 120000 # idle transaction over 120s development: <<: *default @@ -88,5 +88,5 @@ test: # url: <%= ENV['DATABASE_URL'] %> # production: + <<: *default url: <%= ENV['DATABASE_URL'] %> - pool: <%= ENV["DB_POOL"] || ENV['RAILS_MAX_THREADS'] || 5 %> diff --git a/db/migrate/20240704092919_add_holder_count_to_daily_statistic.rb b/db/migrate/20240704092919_add_holder_count_to_daily_statistic.rb new file mode 100644 index 000000000..2b5eb0a69 --- /dev/null +++ b/db/migrate/20240704092919_add_holder_count_to_daily_statistic.rb @@ -0,0 +1,5 @@ +class AddHolderCountToDailyStatistic < ActiveRecord::Migration[7.0] + def change + add_column :daily_statistics, :holder_count, :integer + end +end diff --git a/db/migrate/20240709131020_rename_cell_outputs_to_cell_outputs_old.rb b/db/migrate/20240709131020_rename_cell_outputs_to_cell_outputs_old.rb new file mode 100644 index 000000000..54bcfe74b --- /dev/null +++ b/db/migrate/20240709131020_rename_cell_outputs_to_cell_outputs_old.rb @@ -0,0 +1,9 @@ +class RenameCellOutputsToCellOutputsOld < ActiveRecord::Migration[7.0] + def up + rename_table :cell_outputs, :cell_outputs_old + end + + def down + rename_table :cell_outputs_old, :cell_outputs + end +end diff --git a/db/migrate/20240709131132_create_cell_outputs.rb b/db/migrate/20240709131132_create_cell_outputs.rb new file mode 100644 index 000000000..d19f4e1ad --- /dev/null +++ b/db/migrate/20240709131132_create_cell_outputs.rb @@ -0,0 +1,47 @@ +class CreateCellOutputs < ActiveRecord::Migration[7.0] + def up + execute <<-SQL + CREATE TABLE cell_outputs ( + id bigserial NOT NULL, + capacity numeric(64,2), + ckb_transaction_id bigint, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL, + status smallint DEFAULT 0, + address_id numeric(30,0), + block_id numeric(30,0), + tx_hash bytea, + cell_index integer, + consumed_by_id numeric(30,0), + cell_type integer DEFAULT 0, + data_size integer, + occupied_capacity numeric(30,0), + block_timestamp numeric(30,0), + consumed_block_timestamp numeric(30,0), + type_hash character varying, + udt_amount numeric(40,0), + dao character varying, + lock_script_id bigint, + type_script_id bigint, + data_hash bytea, + primary key (id, status) + ) PARTITION BY LIST (status); + + CREATE TABLE cell_outputs_live PARTITION OF cell_outputs + FOR VALUES IN (0); + + CREATE TABLE cell_outputs_dead PARTITION OF cell_outputs + FOR VALUES IN (1); + + CREATE TABLE cell_outputs_pending PARTITION OF cell_outputs + FOR VALUES IN (2); + + CREATE TABLE cell_outputs_rejected PARTITION OF cell_outputs + FOR VALUES IN (3); + SQL + end + + def down + drop_table :cell_outputs + end +end diff --git a/db/migrate/20240709131713_import_cell_outputs_old_to_cell_outputs.rb b/db/migrate/20240709131713_import_cell_outputs_old_to_cell_outputs.rb new file mode 100644 index 000000000..8ce4ce42c --- /dev/null +++ b/db/migrate/20240709131713_import_cell_outputs_old_to_cell_outputs.rb @@ -0,0 +1,18 @@ +class ImportCellOutputsOldToCellOutputs < ActiveRecord::Migration[7.0] + def up + execute <<~SQL + SET statement_timeout = 0; + + INSERT INTO cell_outputs (id, capacity, ckb_transaction_id, status, address_id, block_id, tx_hash, cell_index, consumed_by_id, cell_type, data_size, occupied_capacity, block_timestamp, consumed_block_timestamp, type_hash, udt_amount, dao, lock_script_id, type_script_id, data_hash, created_at, updated_at) + SELECT id, capacity, ckb_transaction_id, status, address_id, block_id, tx_hash, cell_index, consumed_by_id, cell_type, data_size, occupied_capacity, block_timestamp, consumed_block_timestamp, type_hash, udt_amount, dao, lock_script_id, type_script_id, data_hash, created_at, updated_at FROM cell_outputs_old; + + SELECT setval('cell_outputs_id_seq', (SELECT max(id) FROM cell_outputs)); + SQL + end + + def down + execute <<~SQL + TRUNCATE TABLE cell_outputs; + SQL + end +end diff --git a/db/migrate/20240709142013_add_index_to_cell_outputs.rb b/db/migrate/20240709142013_add_index_to_cell_outputs.rb new file mode 100644 index 000000000..5326630eb --- /dev/null +++ b/db/migrate/20240709142013_add_index_to_cell_outputs.rb @@ -0,0 +1,13 @@ +class AddIndexToCellOutputs < ActiveRecord::Migration[7.0] + def change + add_index :cell_outputs, :address_id + add_index :cell_outputs, :block_id + add_index :cell_outputs, :consumed_by_id + add_index :cell_outputs, :lock_script_id + add_index :cell_outputs, :type_script_id + add_index :cell_outputs, %i[ckb_transaction_id cell_index status], unique: true, name: "index_cell_outputs_on_tx_id_and_cell_index_and_status" + add_index :cell_outputs, %i[tx_hash cell_index status], unique: true, name: "index_cell_outputs_on_tx_hash_and_cell_index_and_status" + add_index :cell_outputs, :block_timestamp + add_index :cell_outputs, :consumed_block_timestamp + end +end diff --git a/db/structure.sql b/db/structure.sql index a2d1b67c7..c099ed0ba 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -9,6 +9,13 @@ 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: - -- @@ -23,6 +30,20 @@ CREATE EXTENSION IF NOT EXISTS btree_gin WITH SCHEMA public; COMMENT ON EXTENSION btree_gin IS 'support for indexing common datatypes in GIN'; +-- +-- Name: pg_buffercache; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS pg_buffercache WITH SCHEMA public; + + +-- +-- Name: EXTENSION pg_buffercache; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION pg_buffercache IS 'examine the shared buffer cache'; + + -- -- Name: array_subtract(anyarray, anyarray); Type: FUNCTION; Schema: public; Owner: - -- @@ -174,7 +195,7 @@ begin insert into account_books (ckb_transaction_id, address_id) values (row.id, i) ON CONFLICT DO NOTHING; end loop; - END LOOP; + END LOOP; close c; end $$; @@ -196,21 +217,21 @@ DECLARE if new.contained_address_ids is null then new.contained_address_ids := array[]::int[]; end if; - if old is null + if old is null then to_add := new.contained_address_ids; to_remove := array[]::int[]; else - + to_add := array_subtract(new.contained_address_ids, old.contained_address_ids); - to_remove := array_subtract(old.contained_address_ids, new.contained_address_ids); + to_remove := array_subtract(old.contained_address_ids, new.contained_address_ids); end if; if to_add is not null then FOREACH i IN ARRAY to_add - LOOP + LOOP RAISE NOTICE 'ckb_tx_addr_id(%)', i; - insert into account_books (ckb_transaction_id, address_id) + insert into account_books (ckb_transaction_id, address_id) values (new.id, i); END LOOP; end if; @@ -415,9 +436,9 @@ CREATE TABLE public.addresses ( dao_deposit numeric(30,0) DEFAULT 0.0, interest numeric(30,0) DEFAULT 0.0, block_timestamp bigint, + visible boolean DEFAULT true, live_cells_count bigint DEFAULT 0.0, mined_blocks_count integer DEFAULT 0, - visible boolean DEFAULT true, average_deposit_time bigint, unclaimed_compensation numeric(30,0), is_depositor boolean DEFAULT false, @@ -470,7 +491,6 @@ CREATE TABLE public.blocks ( "timestamp" bigint, transactions_root bytea, proposals_hash bytea, - uncles_count integer, extra_hash bytea, uncle_block_hashes bytea, version integer, @@ -497,6 +517,7 @@ CREATE TABLE public.blocks ( nonce numeric(50,0) DEFAULT 0.0, start_number numeric(30,0) DEFAULT 0.0, length numeric(30,0) DEFAULT 0.0, + uncles_count integer, compact_target numeric(20,0), live_cell_changes integer, block_time bigint, @@ -506,8 +527,8 @@ CREATE TABLE public.blocks ( miner_message character varying, extension jsonb, median_timestamp bigint DEFAULT 0.0, - ckb_node_version character varying, - cycles bigint + cycles bigint, + ckb_node_version character varying ); @@ -1095,11 +1116,10 @@ ALTER SEQUENCE public.cell_inputs_id_seq OWNED BY public.cell_inputs.id; CREATE TABLE public.cell_outputs ( id bigint NOT NULL, capacity numeric(64,2), - data bytea, ckb_transaction_id bigint, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - status smallint DEFAULT 0, + status smallint DEFAULT 0 NOT NULL, address_id numeric(30,0), block_id numeric(30,0), tx_hash bytea, @@ -1116,7 +1136,8 @@ CREATE TABLE public.cell_outputs ( lock_script_id bigint, type_script_id bigint, data_hash bytea -); +) +PARTITION BY LIST (status); -- @@ -1138,6 +1159,176 @@ CREATE SEQUENCE public.cell_outputs_id_seq ALTER SEQUENCE public.cell_outputs_id_seq OWNED BY public.cell_outputs.id; +-- +-- Name: cell_outputs_dead; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.cell_outputs_dead ( + id bigint DEFAULT nextval('public.cell_outputs_id_seq'::regclass) NOT NULL, + capacity numeric(64,2), + ckb_transaction_id bigint, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL, + status smallint DEFAULT 0 NOT NULL, + address_id numeric(30,0), + block_id numeric(30,0), + tx_hash bytea, + cell_index integer, + consumed_by_id numeric(30,0), + cell_type integer DEFAULT 0, + data_size integer, + occupied_capacity numeric(30,0), + block_timestamp numeric(30,0), + consumed_block_timestamp numeric(30,0), + type_hash character varying, + udt_amount numeric(40,0), + dao character varying, + lock_script_id bigint, + type_script_id bigint, + data_hash bytea +); + + +-- +-- Name: cell_outputs_live; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.cell_outputs_live ( + id bigint DEFAULT nextval('public.cell_outputs_id_seq'::regclass) NOT NULL, + capacity numeric(64,2), + ckb_transaction_id bigint, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL, + status smallint DEFAULT 0 NOT NULL, + address_id numeric(30,0), + block_id numeric(30,0), + tx_hash bytea, + cell_index integer, + consumed_by_id numeric(30,0), + cell_type integer DEFAULT 0, + data_size integer, + occupied_capacity numeric(30,0), + block_timestamp numeric(30,0), + consumed_block_timestamp numeric(30,0), + type_hash character varying, + udt_amount numeric(40,0), + dao character varying, + lock_script_id bigint, + type_script_id bigint, + data_hash bytea +); + + +-- +-- Name: cell_outputs_old; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.cell_outputs_old ( + id bigint NOT NULL, + capacity numeric(64,2), + data bytea, + ckb_transaction_id bigint, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL, + status smallint DEFAULT 0, + address_id numeric(30,0), + block_id numeric(30,0), + tx_hash bytea, + cell_index integer, + consumed_by_id numeric(30,0), + cell_type integer DEFAULT 0, + data_size integer, + occupied_capacity numeric(30,0), + block_timestamp numeric(30,0), + consumed_block_timestamp numeric(30,0), + type_hash character varying, + udt_amount numeric(40,0), + dao character varying, + lock_script_id bigint, + type_script_id bigint, + data_hash bytea +); + + +-- +-- Name: cell_outputs_old_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.cell_outputs_old_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: cell_outputs_old_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.cell_outputs_old_id_seq OWNED BY public.cell_outputs_old.id; + + +-- +-- Name: cell_outputs_pending; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.cell_outputs_pending ( + id bigint DEFAULT nextval('public.cell_outputs_id_seq'::regclass) NOT NULL, + capacity numeric(64,2), + ckb_transaction_id bigint, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL, + status smallint DEFAULT 0 NOT NULL, + address_id numeric(30,0), + block_id numeric(30,0), + tx_hash bytea, + cell_index integer, + consumed_by_id numeric(30,0), + cell_type integer DEFAULT 0, + data_size integer, + occupied_capacity numeric(30,0), + block_timestamp numeric(30,0), + consumed_block_timestamp numeric(30,0), + type_hash character varying, + udt_amount numeric(40,0), + dao character varying, + lock_script_id bigint, + type_script_id bigint, + data_hash bytea +); + + +-- +-- Name: cell_outputs_rejected; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.cell_outputs_rejected ( + id bigint DEFAULT nextval('public.cell_outputs_id_seq'::regclass) NOT NULL, + capacity numeric(64,2), + ckb_transaction_id bigint, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL, + status smallint DEFAULT 0 NOT NULL, + address_id numeric(30,0), + block_id numeric(30,0), + tx_hash bytea, + cell_index integer, + consumed_by_id numeric(30,0), + cell_type integer DEFAULT 0, + data_size integer, + occupied_capacity numeric(30,0), + block_timestamp numeric(30,0), + consumed_block_timestamp numeric(30,0), + type_hash character varying, + udt_amount numeric(40,0), + dao character varying, + lock_script_id bigint, + type_script_id bigint, + data_hash bytea +); + + -- -- Name: ckb_transactions; Type: TABLE; Schema: public; Owner: - -- @@ -1335,9 +1526,9 @@ ALTER SEQUENCE public.contracts_id_seq OWNED BY public.contracts.id; CREATE TABLE public.daily_statistics ( id bigint NOT NULL, - transactions_count character varying DEFAULT 0, - addresses_count character varying DEFAULT 0, - total_dao_deposit character varying DEFAULT 0.0, + transactions_count character varying DEFAULT '0'::character varying, + addresses_count character varying DEFAULT '0'::character varying, + total_dao_deposit character varying DEFAULT '0.0'::character varying, block_timestamp numeric(30,0), created_at_unixtimestamp integer, created_at timestamp(6) without time zone NOT NULL, @@ -1356,8 +1547,8 @@ CREATE TABLE public.daily_statistics ( avg_difficulty character varying DEFAULT '0'::character varying, uncle_rate character varying DEFAULT '0'::character varying, total_depositors_count character varying DEFAULT '0'::character varying, - total_tx_fee numeric(30,0), address_balance_distribution jsonb, + total_tx_fee numeric(30,0), occupied_capacity numeric(30,0), daily_dao_deposit numeric(30,0), daily_dao_depositors_count integer, @@ -1372,7 +1563,8 @@ CREATE TABLE public.daily_statistics ( nodes_distribution jsonb, nodes_count integer, locked_capacity numeric(30,0), - ckb_hodl_wave jsonb + ckb_hodl_wave jsonb, + holder_count integer ); @@ -1557,7 +1749,6 @@ CREATE TABLE public.forked_blocks ( "timestamp" bigint, transactions_root bytea, proposals_hash bytea, - uncles_count integer, extra_hash bytea, uncle_block_hashes bytea, version integer, @@ -1584,6 +1775,7 @@ CREATE TABLE public.forked_blocks ( nonce numeric(50,0) DEFAULT 0.0, start_number numeric(30,0) DEFAULT 0.0, length numeric(30,0) DEFAULT 0.0, + uncles_count integer, compact_target numeric(20,0), live_cell_changes integer, block_time numeric(13,0), @@ -1593,8 +1785,8 @@ CREATE TABLE public.forked_blocks ( miner_message character varying, extension jsonb, median_timestamp numeric DEFAULT 0.0, - ckb_node_version character varying, - cycles bigint + cycles bigint, + ckb_node_version character varying ); @@ -2673,6 +2865,34 @@ CREATE SEQUENCE public.xudt_tags_id_seq ALTER SEQUENCE public.xudt_tags_id_seq OWNED BY public.xudt_tags.id; +-- +-- Name: cell_outputs_dead; Type: TABLE ATTACH; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cell_outputs ATTACH PARTITION public.cell_outputs_dead FOR VALUES IN ('1'); + + +-- +-- Name: cell_outputs_live; Type: TABLE ATTACH; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cell_outputs ATTACH PARTITION public.cell_outputs_live FOR VALUES IN ('0'); + + +-- +-- Name: cell_outputs_pending; Type: TABLE ATTACH; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cell_outputs ATTACH PARTITION public.cell_outputs_pending FOR VALUES IN ('2'); + + +-- +-- Name: cell_outputs_rejected; Type: TABLE ATTACH; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cell_outputs ATTACH PARTITION public.cell_outputs_rejected FOR VALUES IN ('3'); + + -- -- Name: ckb_transactions_committed; Type: TABLE ATTACH; Schema: public; Owner: - -- @@ -2841,6 +3061,13 @@ ALTER TABLE ONLY public.cell_inputs ALTER COLUMN id SET DEFAULT nextval('public. ALTER TABLE ONLY public.cell_outputs ALTER COLUMN id SET DEFAULT nextval('public.cell_outputs_id_seq'::regclass); +-- +-- Name: cell_outputs_old id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cell_outputs_old ALTER COLUMN id SET DEFAULT nextval('public.cell_outputs_old_id_seq'::regclass); + + -- -- Name: ckb_transactions id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3258,7 +3485,47 @@ ALTER TABLE ONLY public.cell_inputs -- ALTER TABLE ONLY public.cell_outputs - ADD CONSTRAINT cell_outputs_pkey PRIMARY KEY (id); + ADD CONSTRAINT cell_outputs_pkey PRIMARY KEY (id, status); + + +-- +-- Name: cell_outputs_dead cell_outputs_dead_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cell_outputs_dead + ADD CONSTRAINT cell_outputs_dead_pkey PRIMARY KEY (id, status); + + +-- +-- Name: cell_outputs_live cell_outputs_live_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cell_outputs_live + ADD CONSTRAINT cell_outputs_live_pkey PRIMARY KEY (id, status); + + +-- +-- Name: cell_outputs_old cell_outputs_old_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cell_outputs_old + ADD CONSTRAINT cell_outputs_old_pkey PRIMARY KEY (id); + + +-- +-- Name: cell_outputs_pending cell_outputs_pending_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cell_outputs_pending + ADD CONSTRAINT cell_outputs_pending_pkey PRIMARY KEY (id, status); + + +-- +-- Name: cell_outputs_rejected cell_outputs_rejected_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cell_outputs_rejected + ADD CONSTRAINT cell_outputs_rejected_pkey PRIMARY KEY (id, status); -- @@ -3689,84 +3956,399 @@ CREATE UNIQUE INDEX cell_deps_tx_cell_idx ON public.cell_dependencies USING btre -- --- Name: idx_ckb_txs_for_blocks; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_on_address_id; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX idx_ckb_txs_for_blocks ON ONLY public.ckb_transactions USING btree (block_id, block_timestamp); +CREATE INDEX index_cell_outputs_on_address_id ON ONLY public.cell_outputs USING btree (address_id); -- --- Name: ckb_transactions_committed_block_id_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - +-- Name: cell_outputs_dead_address_id_idx; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX ckb_transactions_committed_block_id_block_timestamp_idx ON public.ckb_transactions_committed USING btree (block_id, block_timestamp); +CREATE INDEX cell_outputs_dead_address_id_idx ON public.cell_outputs_dead USING btree (address_id); -- --- Name: idx_ckb_txs_timestamp; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_on_block_id; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX idx_ckb_txs_timestamp ON ONLY public.ckb_transactions USING btree (block_timestamp DESC NULLS LAST, id); +CREATE INDEX index_cell_outputs_on_block_id ON ONLY public.cell_outputs USING btree (block_id); -- --- Name: ckb_transactions_committed_block_timestamp_id_idx; Type: INDEX; Schema: public; Owner: - +-- Name: cell_outputs_dead_block_id_idx; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX ckb_transactions_committed_block_timestamp_id_idx ON public.ckb_transactions_committed USING btree (block_timestamp DESC NULLS LAST, id); +CREATE INDEX cell_outputs_dead_block_id_idx ON public.cell_outputs_dead USING btree (block_id); -- --- Name: index_ckb_transactions_on_tags; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_on_block_timestamp; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_ckb_transactions_on_tags ON ONLY public.ckb_transactions USING gin (tags); +CREATE INDEX index_cell_outputs_on_block_timestamp ON ONLY public.cell_outputs USING btree (block_timestamp); -- --- Name: ckb_transactions_committed_tags_idx; Type: INDEX; Schema: public; Owner: - +-- Name: cell_outputs_dead_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX ckb_transactions_committed_tags_idx ON public.ckb_transactions_committed USING gin (tags); +CREATE INDEX cell_outputs_dead_block_timestamp_idx ON public.cell_outputs_dead USING btree (block_timestamp); -- --- Name: index_ckb_transactions_on_tx_hash; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_on_tx_id_and_cell_index_and_status; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_ckb_transactions_on_tx_hash ON ONLY public.ckb_transactions USING hash (tx_hash); +CREATE UNIQUE INDEX index_cell_outputs_on_tx_id_and_cell_index_and_status ON ONLY public.cell_outputs USING btree (ckb_transaction_id, cell_index, status); -- --- Name: ckb_transactions_committed_tx_hash_idx; Type: INDEX; Schema: public; Owner: - +-- Name: cell_outputs_dead_ckb_transaction_id_cell_index_status_idx; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX ckb_transactions_committed_tx_hash_idx ON public.ckb_transactions_committed USING hash (tx_hash); +CREATE UNIQUE INDEX cell_outputs_dead_ckb_transaction_id_cell_index_status_idx ON public.cell_outputs_dead USING btree (ckb_transaction_id, cell_index, status); -- --- Name: ckb_transactions_pending_block_id_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_on_consumed_block_timestamp; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX ckb_transactions_pending_block_id_block_timestamp_idx ON public.ckb_transactions_pending USING btree (block_id, block_timestamp); +CREATE INDEX index_cell_outputs_on_consumed_block_timestamp ON ONLY public.cell_outputs USING btree (consumed_block_timestamp); -- --- Name: ckb_transactions_pending_block_timestamp_id_idx; Type: INDEX; Schema: public; Owner: - +-- Name: cell_outputs_dead_consumed_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX ckb_transactions_pending_block_timestamp_id_idx ON public.ckb_transactions_pending USING btree (block_timestamp DESC NULLS LAST, id); +CREATE INDEX cell_outputs_dead_consumed_block_timestamp_idx ON public.cell_outputs_dead USING btree (consumed_block_timestamp); -- --- Name: ckb_transactions_pending_tags_idx; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_on_consumed_by_id; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX ckb_transactions_pending_tags_idx ON public.ckb_transactions_pending USING gin (tags); +CREATE INDEX index_cell_outputs_on_consumed_by_id ON ONLY public.cell_outputs USING btree (consumed_by_id); -- --- Name: ckb_transactions_pending_tx_hash_idx; Type: INDEX; Schema: public; Owner: - +-- Name: cell_outputs_dead_consumed_by_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_dead_consumed_by_id_idx ON public.cell_outputs_dead USING btree (consumed_by_id); + + +-- +-- Name: index_cell_outputs_on_lock_script_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_cell_outputs_on_lock_script_id ON ONLY public.cell_outputs USING btree (lock_script_id); + + +-- +-- Name: cell_outputs_dead_lock_script_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_dead_lock_script_id_idx ON public.cell_outputs_dead USING btree (lock_script_id); + + +-- +-- Name: index_cell_outputs_on_tx_hash_and_cell_index_and_status; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_cell_outputs_on_tx_hash_and_cell_index_and_status ON ONLY public.cell_outputs USING btree (tx_hash, cell_index, status); + + +-- +-- Name: cell_outputs_dead_tx_hash_cell_index_status_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX cell_outputs_dead_tx_hash_cell_index_status_idx ON public.cell_outputs_dead USING btree (tx_hash, cell_index, status); + + +-- +-- Name: index_cell_outputs_on_type_script_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_cell_outputs_on_type_script_id ON ONLY public.cell_outputs USING btree (type_script_id); + + +-- +-- Name: cell_outputs_dead_type_script_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_dead_type_script_id_idx ON public.cell_outputs_dead USING btree (type_script_id); + + +-- +-- Name: cell_outputs_live_address_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_live_address_id_idx ON public.cell_outputs_live USING btree (address_id); + + +-- +-- Name: cell_outputs_live_block_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_live_block_id_idx ON public.cell_outputs_live USING btree (block_id); + + +-- +-- Name: cell_outputs_live_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_live_block_timestamp_idx ON public.cell_outputs_live USING btree (block_timestamp); + + +-- +-- Name: cell_outputs_live_ckb_transaction_id_cell_index_status_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX cell_outputs_live_ckb_transaction_id_cell_index_status_idx ON public.cell_outputs_live USING btree (ckb_transaction_id, cell_index, status); + + +-- +-- Name: cell_outputs_live_consumed_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_live_consumed_block_timestamp_idx ON public.cell_outputs_live USING btree (consumed_block_timestamp); + + +-- +-- Name: cell_outputs_live_consumed_by_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_live_consumed_by_id_idx ON public.cell_outputs_live USING btree (consumed_by_id); + + +-- +-- Name: cell_outputs_live_lock_script_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_live_lock_script_id_idx ON public.cell_outputs_live USING btree (lock_script_id); + + +-- +-- Name: cell_outputs_live_tx_hash_cell_index_status_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX cell_outputs_live_tx_hash_cell_index_status_idx ON public.cell_outputs_live USING btree (tx_hash, cell_index, status); + + +-- +-- Name: cell_outputs_live_type_script_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_live_type_script_id_idx ON public.cell_outputs_live USING btree (type_script_id); + + +-- +-- Name: cell_outputs_pending_address_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_pending_address_id_idx ON public.cell_outputs_pending USING btree (address_id); + + +-- +-- Name: cell_outputs_pending_block_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_pending_block_id_idx ON public.cell_outputs_pending USING btree (block_id); + + +-- +-- Name: cell_outputs_pending_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_pending_block_timestamp_idx ON public.cell_outputs_pending USING btree (block_timestamp); + + +-- +-- Name: cell_outputs_pending_ckb_transaction_id_cell_index_status_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX cell_outputs_pending_ckb_transaction_id_cell_index_status_idx ON public.cell_outputs_pending USING btree (ckb_transaction_id, cell_index, status); + + +-- +-- Name: cell_outputs_pending_consumed_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_pending_consumed_block_timestamp_idx ON public.cell_outputs_pending USING btree (consumed_block_timestamp); + + +-- +-- Name: cell_outputs_pending_consumed_by_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_pending_consumed_by_id_idx ON public.cell_outputs_pending USING btree (consumed_by_id); + + +-- +-- Name: cell_outputs_pending_lock_script_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_pending_lock_script_id_idx ON public.cell_outputs_pending USING btree (lock_script_id); + + +-- +-- Name: cell_outputs_pending_tx_hash_cell_index_status_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX cell_outputs_pending_tx_hash_cell_index_status_idx ON public.cell_outputs_pending USING btree (tx_hash, cell_index, status); + + +-- +-- Name: cell_outputs_pending_type_script_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_pending_type_script_id_idx ON public.cell_outputs_pending USING btree (type_script_id); + + +-- +-- Name: cell_outputs_rejected_address_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_rejected_address_id_idx ON public.cell_outputs_rejected USING btree (address_id); + + +-- +-- Name: cell_outputs_rejected_block_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_rejected_block_id_idx ON public.cell_outputs_rejected USING btree (block_id); + + +-- +-- Name: cell_outputs_rejected_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_rejected_block_timestamp_idx ON public.cell_outputs_rejected USING btree (block_timestamp); + + +-- +-- Name: cell_outputs_rejected_ckb_transaction_id_cell_index_status_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX cell_outputs_rejected_ckb_transaction_id_cell_index_status_idx ON public.cell_outputs_rejected USING btree (ckb_transaction_id, cell_index, status); + + +-- +-- Name: cell_outputs_rejected_consumed_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_rejected_consumed_block_timestamp_idx ON public.cell_outputs_rejected USING btree (consumed_block_timestamp); + + +-- +-- Name: cell_outputs_rejected_consumed_by_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_rejected_consumed_by_id_idx ON public.cell_outputs_rejected USING btree (consumed_by_id); + + +-- +-- Name: cell_outputs_rejected_lock_script_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_rejected_lock_script_id_idx ON public.cell_outputs_rejected USING btree (lock_script_id); + + +-- +-- Name: cell_outputs_rejected_tx_hash_cell_index_status_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX cell_outputs_rejected_tx_hash_cell_index_status_idx ON public.cell_outputs_rejected USING btree (tx_hash, cell_index, status); + + +-- +-- Name: cell_outputs_rejected_type_script_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX cell_outputs_rejected_type_script_id_idx ON public.cell_outputs_rejected USING btree (type_script_id); + + +-- +-- Name: idx_ckb_txs_for_blocks; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_ckb_txs_for_blocks ON ONLY public.ckb_transactions USING btree (block_id, block_timestamp); + + +-- +-- Name: ckb_transactions_committed_block_id_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX ckb_transactions_committed_block_id_block_timestamp_idx ON public.ckb_transactions_committed USING btree (block_id, block_timestamp); + + +-- +-- Name: idx_ckb_txs_timestamp; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_ckb_txs_timestamp ON ONLY public.ckb_transactions USING btree (block_timestamp DESC NULLS LAST, id); + + +-- +-- Name: ckb_transactions_committed_block_timestamp_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX ckb_transactions_committed_block_timestamp_id_idx ON public.ckb_transactions_committed USING btree (block_timestamp DESC NULLS LAST, id); + + +-- +-- Name: index_ckb_transactions_on_tags; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_ckb_transactions_on_tags ON ONLY public.ckb_transactions USING gin (tags); + + +-- +-- Name: ckb_transactions_committed_tags_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX ckb_transactions_committed_tags_idx ON public.ckb_transactions_committed USING gin (tags); + + +-- +-- Name: index_ckb_transactions_on_tx_hash; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_ckb_transactions_on_tx_hash ON ONLY public.ckb_transactions USING hash (tx_hash); + + +-- +-- Name: ckb_transactions_committed_tx_hash_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX ckb_transactions_committed_tx_hash_idx ON public.ckb_transactions_committed USING hash (tx_hash); + + +-- +-- Name: ckb_transactions_pending_block_id_block_timestamp_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX ckb_transactions_pending_block_id_block_timestamp_idx ON public.ckb_transactions_pending USING btree (block_id, block_timestamp); + + +-- +-- Name: ckb_transactions_pending_block_timestamp_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX ckb_transactions_pending_block_timestamp_id_idx ON public.ckb_transactions_pending USING btree (block_timestamp DESC NULLS LAST, id); + + +-- +-- Name: ckb_transactions_pending_tags_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX ckb_transactions_pending_tags_idx ON public.ckb_transactions_pending USING gin (tags); + + +-- +-- Name: ckb_transactions_pending_tx_hash_idx; Type: INDEX; Schema: public; Owner: - -- CREATE INDEX ckb_transactions_pending_tx_hash_idx ON public.ckb_transactions_pending USING hash (tx_hash); @@ -4123,94 +4705,94 @@ CREATE UNIQUE INDEX index_cell_inputs_on_ckb_transaction_id_and_index ON public. -- --- Name: index_cell_outputs_on_address_id_and_status; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_address_id_and_status; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_cell_outputs_on_address_id_and_status ON public.cell_outputs USING btree (address_id, status); +CREATE INDEX index_cell_outputs_old_on_address_id_and_status ON public.cell_outputs_old USING btree (address_id, status); -- --- Name: index_cell_outputs_on_block_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_block_id; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_cell_outputs_on_block_id ON public.cell_outputs USING btree (block_id); +CREATE INDEX index_cell_outputs_old_on_block_id ON public.cell_outputs_old USING btree (block_id); -- --- Name: index_cell_outputs_on_block_timestamp; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_block_timestamp; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_cell_outputs_on_block_timestamp ON public.cell_outputs USING btree (block_timestamp); +CREATE INDEX index_cell_outputs_old_on_block_timestamp ON public.cell_outputs_old USING btree (block_timestamp); -- --- Name: index_cell_outputs_on_cell_type; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_cell_type; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_cell_outputs_on_cell_type ON public.cell_outputs USING btree (cell_type); +CREATE INDEX index_cell_outputs_old_on_cell_type ON public.cell_outputs_old USING btree (cell_type); -- --- Name: index_cell_outputs_on_ckb_transaction_id_and_cell_index; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_ckb_transaction_id_and_cell_index; Type: INDEX; Schema: public; Owner: - -- -CREATE UNIQUE INDEX index_cell_outputs_on_ckb_transaction_id_and_cell_index ON public.cell_outputs USING btree (ckb_transaction_id, cell_index); +CREATE UNIQUE INDEX index_cell_outputs_old_on_ckb_transaction_id_and_cell_index ON public.cell_outputs_old USING btree (ckb_transaction_id, cell_index); -- --- Name: index_cell_outputs_on_consumed_block_timestamp; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_consumed_block_timestamp; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_cell_outputs_on_consumed_block_timestamp ON public.cell_outputs USING btree (consumed_block_timestamp); +CREATE INDEX index_cell_outputs_old_on_consumed_block_timestamp ON public.cell_outputs_old USING btree (consumed_block_timestamp); -- --- Name: index_cell_outputs_on_consumed_by_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_consumed_by_id; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_cell_outputs_on_consumed_by_id ON public.cell_outputs USING btree (consumed_by_id); +CREATE INDEX index_cell_outputs_old_on_consumed_by_id ON public.cell_outputs_old USING btree (consumed_by_id); -- --- Name: index_cell_outputs_on_data_hash; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_data_hash; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_cell_outputs_on_data_hash ON public.cell_outputs USING hash (data_hash); +CREATE INDEX index_cell_outputs_old_on_data_hash ON public.cell_outputs_old USING hash (data_hash); -- --- Name: index_cell_outputs_on_lock_script_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_lock_script_id; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_cell_outputs_on_lock_script_id ON public.cell_outputs USING btree (lock_script_id); +CREATE INDEX index_cell_outputs_old_on_lock_script_id ON public.cell_outputs_old USING btree (lock_script_id); -- --- Name: index_cell_outputs_on_status; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_status; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_cell_outputs_on_status ON public.cell_outputs USING btree (status); +CREATE INDEX index_cell_outputs_old_on_status ON public.cell_outputs_old USING btree (status); -- --- Name: index_cell_outputs_on_tx_hash_and_cell_index; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_tx_hash_and_cell_index; Type: INDEX; Schema: public; Owner: - -- -CREATE UNIQUE INDEX index_cell_outputs_on_tx_hash_and_cell_index ON public.cell_outputs USING btree (tx_hash, cell_index); +CREATE UNIQUE INDEX index_cell_outputs_old_on_tx_hash_and_cell_index ON public.cell_outputs_old USING btree (tx_hash, cell_index); -- --- Name: index_cell_outputs_on_type_script_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_type_script_id; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_cell_outputs_on_type_script_id ON public.cell_outputs USING btree (type_script_id); +CREATE INDEX index_cell_outputs_old_on_type_script_id ON public.cell_outputs_old USING btree (type_script_id); -- --- Name: index_cell_outputs_on_type_script_id_and_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_cell_outputs_old_on_type_script_id_and_id; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_cell_outputs_on_type_script_id_and_id ON public.cell_outputs USING btree (type_script_id, id); +CREATE INDEX index_cell_outputs_old_on_type_script_id_and_id ON public.cell_outputs_old USING btree (type_script_id, id); -- @@ -4409,13 +4991,6 @@ CREATE UNIQUE INDEX index_omiga_inscription_infos_on_udt_hash ON public.omiga_in CREATE UNIQUE INDEX index_portfolios_on_user_id_and_address_id ON public.portfolios USING btree (user_id, address_id); --- --- Name: index_referring_cells_on_cell_output_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_referring_cells_on_cell_output_id ON public.referring_cells USING btree (cell_output_id); - - -- -- Name: index_referring_cells_on_contract_id_and_cell_output_id; Type: INDEX; Schema: public; Owner: - -- @@ -4724,6 +5299,286 @@ CREATE UNIQUE INDEX pk ON public.udt_transactions USING btree (udt_id, ckb_trans CREATE UNIQUE INDEX tx_address_changes_alt_pk ON public.transaction_address_changes USING btree (address_id, ckb_transaction_id); +-- +-- Name: cell_outputs_dead_address_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_address_id ATTACH PARTITION public.cell_outputs_dead_address_id_idx; + + +-- +-- Name: cell_outputs_dead_block_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_block_id ATTACH PARTITION public.cell_outputs_dead_block_id_idx; + + +-- +-- Name: cell_outputs_dead_block_timestamp_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_block_timestamp ATTACH PARTITION public.cell_outputs_dead_block_timestamp_idx; + + +-- +-- Name: cell_outputs_dead_ckb_transaction_id_cell_index_status_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_tx_id_and_cell_index_and_status ATTACH PARTITION public.cell_outputs_dead_ckb_transaction_id_cell_index_status_idx; + + +-- +-- Name: cell_outputs_dead_consumed_block_timestamp_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_consumed_block_timestamp ATTACH PARTITION public.cell_outputs_dead_consumed_block_timestamp_idx; + + +-- +-- Name: cell_outputs_dead_consumed_by_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_consumed_by_id ATTACH PARTITION public.cell_outputs_dead_consumed_by_id_idx; + + +-- +-- Name: cell_outputs_dead_lock_script_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_lock_script_id ATTACH PARTITION public.cell_outputs_dead_lock_script_id_idx; + + +-- +-- Name: cell_outputs_dead_pkey; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.cell_outputs_pkey ATTACH PARTITION public.cell_outputs_dead_pkey; + + +-- +-- Name: cell_outputs_dead_tx_hash_cell_index_status_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_tx_hash_and_cell_index_and_status ATTACH PARTITION public.cell_outputs_dead_tx_hash_cell_index_status_idx; + + +-- +-- Name: cell_outputs_dead_type_script_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_type_script_id ATTACH PARTITION public.cell_outputs_dead_type_script_id_idx; + + +-- +-- Name: cell_outputs_live_address_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_address_id ATTACH PARTITION public.cell_outputs_live_address_id_idx; + + +-- +-- Name: cell_outputs_live_block_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_block_id ATTACH PARTITION public.cell_outputs_live_block_id_idx; + + +-- +-- Name: cell_outputs_live_block_timestamp_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_block_timestamp ATTACH PARTITION public.cell_outputs_live_block_timestamp_idx; + + +-- +-- Name: cell_outputs_live_ckb_transaction_id_cell_index_status_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_tx_id_and_cell_index_and_status ATTACH PARTITION public.cell_outputs_live_ckb_transaction_id_cell_index_status_idx; + + +-- +-- Name: cell_outputs_live_consumed_block_timestamp_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_consumed_block_timestamp ATTACH PARTITION public.cell_outputs_live_consumed_block_timestamp_idx; + + +-- +-- Name: cell_outputs_live_consumed_by_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_consumed_by_id ATTACH PARTITION public.cell_outputs_live_consumed_by_id_idx; + + +-- +-- Name: cell_outputs_live_lock_script_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_lock_script_id ATTACH PARTITION public.cell_outputs_live_lock_script_id_idx; + + +-- +-- Name: cell_outputs_live_pkey; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.cell_outputs_pkey ATTACH PARTITION public.cell_outputs_live_pkey; + + +-- +-- Name: cell_outputs_live_tx_hash_cell_index_status_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_tx_hash_and_cell_index_and_status ATTACH PARTITION public.cell_outputs_live_tx_hash_cell_index_status_idx; + + +-- +-- Name: cell_outputs_live_type_script_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_type_script_id ATTACH PARTITION public.cell_outputs_live_type_script_id_idx; + + +-- +-- Name: cell_outputs_pending_address_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_address_id ATTACH PARTITION public.cell_outputs_pending_address_id_idx; + + +-- +-- Name: cell_outputs_pending_block_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_block_id ATTACH PARTITION public.cell_outputs_pending_block_id_idx; + + +-- +-- Name: cell_outputs_pending_block_timestamp_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_block_timestamp ATTACH PARTITION public.cell_outputs_pending_block_timestamp_idx; + + +-- +-- Name: cell_outputs_pending_ckb_transaction_id_cell_index_status_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_tx_id_and_cell_index_and_status ATTACH PARTITION public.cell_outputs_pending_ckb_transaction_id_cell_index_status_idx; + + +-- +-- Name: cell_outputs_pending_consumed_block_timestamp_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_consumed_block_timestamp ATTACH PARTITION public.cell_outputs_pending_consumed_block_timestamp_idx; + + +-- +-- Name: cell_outputs_pending_consumed_by_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_consumed_by_id ATTACH PARTITION public.cell_outputs_pending_consumed_by_id_idx; + + +-- +-- Name: cell_outputs_pending_lock_script_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_lock_script_id ATTACH PARTITION public.cell_outputs_pending_lock_script_id_idx; + + +-- +-- Name: cell_outputs_pending_pkey; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.cell_outputs_pkey ATTACH PARTITION public.cell_outputs_pending_pkey; + + +-- +-- Name: cell_outputs_pending_tx_hash_cell_index_status_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_tx_hash_and_cell_index_and_status ATTACH PARTITION public.cell_outputs_pending_tx_hash_cell_index_status_idx; + + +-- +-- Name: cell_outputs_pending_type_script_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_type_script_id ATTACH PARTITION public.cell_outputs_pending_type_script_id_idx; + + +-- +-- Name: cell_outputs_rejected_address_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_address_id ATTACH PARTITION public.cell_outputs_rejected_address_id_idx; + + +-- +-- Name: cell_outputs_rejected_block_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_block_id ATTACH PARTITION public.cell_outputs_rejected_block_id_idx; + + +-- +-- Name: cell_outputs_rejected_block_timestamp_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_block_timestamp ATTACH PARTITION public.cell_outputs_rejected_block_timestamp_idx; + + +-- +-- Name: cell_outputs_rejected_ckb_transaction_id_cell_index_status_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_tx_id_and_cell_index_and_status ATTACH PARTITION public.cell_outputs_rejected_ckb_transaction_id_cell_index_status_idx; + + +-- +-- Name: cell_outputs_rejected_consumed_block_timestamp_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_consumed_block_timestamp ATTACH PARTITION public.cell_outputs_rejected_consumed_block_timestamp_idx; + + +-- +-- Name: cell_outputs_rejected_consumed_by_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_consumed_by_id ATTACH PARTITION public.cell_outputs_rejected_consumed_by_id_idx; + + +-- +-- Name: cell_outputs_rejected_lock_script_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_lock_script_id ATTACH PARTITION public.cell_outputs_rejected_lock_script_id_idx; + + +-- +-- Name: cell_outputs_rejected_pkey; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.cell_outputs_pkey ATTACH PARTITION public.cell_outputs_rejected_pkey; + + +-- +-- Name: cell_outputs_rejected_tx_hash_cell_index_status_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_tx_hash_and_cell_index_and_status ATTACH PARTITION public.cell_outputs_rejected_tx_hash_cell_index_status_idx; + + +-- +-- Name: cell_outputs_rejected_type_script_id_idx; Type: INDEX ATTACH; Schema: public; Owner: - +-- + +ALTER INDEX public.index_cell_outputs_on_type_script_id ATTACH PARTITION public.cell_outputs_rejected_type_script_id_idx; + + -- -- Name: ckb_transactions_committed_block_id_block_timestamp_idx; Type: INDEX ATTACH; Schema: public; Owner: - -- @@ -5238,6 +6093,9 @@ INSERT INTO "schema_migrations" (version) VALUES ('20240509074313'), ('20240513055849'), ('20240620083123'), -('20240625032839'); - - +('20240625032839'), +('20240704092919'), +('20240709131020'), +('20240709131132'), +('20240709131713'), +('20240709142013'); diff --git a/lib/scheduler.rb b/lib/scheduler.rb index 1f4465e57..126b30de8 100644 --- a/lib/scheduler.rb +++ b/lib/scheduler.rb @@ -32,7 +32,9 @@ def call_worker(clz) # Vacuum database periodically for better performance s.cron "0 2 * * 1" do + ActiveRecord::Base.connection.execute("SET statement_timeout = 0") ApplicationRecord.connection.execute "vacuum (verbose, analyze)" + ActiveRecord::Base.connection.execute("RESET statement_timeout") end s.cron "0 8 * * *" do diff --git a/test/services/charts/daily_statistic_generator_test.rb b/test/services/charts/daily_statistic_generator_test.rb index 50ed7bbe6..b876f8362 100644 --- a/test/services/charts/daily_statistic_generator_test.rb +++ b/test/services/charts/daily_statistic_generator_test.rb @@ -468,5 +468,19 @@ class DailyStatisticGeneratorTest < ActiveSupport::TestCase locked_capacity = Charts::DailyStatisticGenerator.new(@datetime).call.locked_capacity assert_equal locked_capacity_temp, locked_capacity end + + test "it should get holder_count" do + address1 = create(:address) + address2 = create(:address) + consumed_tx = create(:ckb_transaction) + + create(:cell_output, :with_full_transaction, + block_timestamp: @datetime.beginning_of_day.to_i * 1000 - 10000, block: @block, address_id: address1.id) + create(:cell_output, :with_full_transaction, + block_timestamp: @datetime.beginning_of_day.to_i * 1000 - 10000, block: @block, address_id: address2.id, status: :dead, consumed_block_timestamp: @datetime.beginning_of_day.to_i * 1000 + 10000, consumed_by_id: consumed_tx.id) + + holder_count = Charts::DailyStatisticGenerator.new(@datetime).call.holder_count + assert_equal 2, holder_count + end end end diff --git a/test/utils/ckb_utils_test.rb b/test/utils/ckb_utils_test.rb index c6ea21a42..5770e246e 100644 --- a/test/utils/ckb_utils_test.rb +++ b/test/utils/ckb_utils_test.rb @@ -205,6 +205,13 @@ class CkbUtilsTest < ActiveSupport::TestCase end end + test ".cal_cell_min_capacity should return output's min capacity" do + lock_script = create(:lock_script, code_hash: "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", hash_type: "type", args: "0x6a21bc1b72d1e654f8e2ded400cffa46075494c6") + type_script = create(:type_script, code_hash: "0x554cff969f3148e3c620749384004e9692e67c429f621554d139b505a281c7b8", hash_type: "type", args: "0x01") + assert_equal 9700000000, + CkbUtils.cal_cell_min_capacity(lock_script, type_script, 0.4e11, "\n\f") + end + test ".block_cell_consumed generated block's cell_consumed should equal to the sum of transactions output occupied capacity" do CkbSync::Api.any_instance.stubs(:get_block_cycles).returns( [