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 #2348

Merged
merged 22 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1b5f9ed
eIssue 256 (#2341)
rabbitz Dec 16, 2024
1deeccc
Merge pull request #2347 from nervosnetwork/develop
rabbitz Dec 16, 2024
1b35118
chore: update cell_outputs query (#2349)
rabbitz Dec 16, 2024
87dd3a1
Merge pull request #2350 from nervosnetwork/develop
rabbitz Dec 16, 2024
5b602c4
Feat/fiber (#2351)
rabbitz Dec 17, 2024
9fa846d
Merge pull request #2352 from nervosnetwork/develop
rabbitz Dec 17, 2024
68b6600
chore: adjust workflows config (#2353)
rabbitz Dec 17, 2024
6cee6d7
Merge pull request #2354 from nervosnetwork/develop
rabbitz Dec 17, 2024
c0bffec
Issue 256 (#2356)
rabbitz Dec 20, 2024
7a71a2e
Merge pull request #2357 from nervosnetwork/develop
rabbitz Dec 20, 2024
84e4ac0
chore: add new xudt compatible code hash (#2358)
zmcNotafraid Dec 20, 2024
d2e5a55
Merge pull request #2359 from nervosnetwork/develop
zmcNotafraid Dec 20, 2024
e9e14fe
Merge released refs/heads/master into develop (#2361)
github-actions[bot] Dec 20, 2024
373bd14
chore: update ft count filter (#2362)
rabbitz Dec 20, 2024
b9ab42e
Merge pull request #2363 from nervosnetwork/develop
rabbitz Dec 20, 2024
cf2f62a
chore: add rgbpp sidekiq queue (#2368)
zmcNotafraid Dec 22, 2024
99a38c8
Merge pull request #2369 from nervosnetwork/develop
zmcNotafraid Dec 22, 2024
5629fe4
Fix/issue 256 (#2370)
rabbitz Dec 23, 2024
1664d75
Merge pull request #2371 from nervosnetwork/develop
rabbitz Dec 23, 2024
cdb76c7
fix: query default limit set 5000 (#2355)
zmcNotafraid Dec 25, 2024
d43caaf
feat: show activity address by contract in daily statistic (#2372)
zmcNotafraid Dec 25, 2024
fbaebd5
Merge pull request #2373 from nervosnetwork/develop
zmcNotafraid Dec 25, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: satackey/[email protected]
# Ignore the failure of a step and avoid terminating the job.
continue-on-error: true
# - uses: satackey/[email protected]
# # Ignore the failure of a step and avoid terminating the job.
# continue-on-error: true
- name: Build and push
id: docker_build
uses: mr-smithers-excellent/docker-build-push@v5
Expand Down
24 changes: 24 additions & 0 deletions app/controllers/api/v2/rgbpp_assets_statistics_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Api
module V2
class RgbppAssetsStatisticsController < BaseController
def index
expires_in 15.minutes, public: true, stale_while_revalidate: 5.minutes, stale_if_error: 5.minutes

Check warning on line 5 in app/controllers/api/v2/rgbpp_assets_statistics_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/rgbpp_assets_statistics_controller.rb#L1-L5

Added lines #L1 - L5 were not covered by tests

statistics = RgbppAssetsStatistic.all.order(created_at_unixtimestamp: :asc)
statistics = statistics.where(network: params[:network]) if params[:network].present?
statistics = statistics.where(indicator: params[:indicators].split(",")) if params[:indicators].present?

Check warning on line 9 in app/controllers/api/v2/rgbpp_assets_statistics_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/rgbpp_assets_statistics_controller.rb#L7-L9

Added lines #L7 - L9 were not covered by tests

render json: {
data: statistics.map do |statistic|
{
indicator: statistic.indicator,
value: statistic.value.to_s,
network: statistic.network,
created_at_unixtimestamp: statistic.created_at_unixtimestamp.to_s,
}
end,
}
end
end
end
end

Check warning on line 24 in app/controllers/api/v2/rgbpp_assets_statistics_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/rgbpp_assets_statistics_controller.rb#L11-L24

Added lines #L11 - L24 were not covered by tests
4 changes: 2 additions & 2 deletions app/controllers/api/v2/scripts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def ckb_transactions
base_query = CkbTransaction.joins(:cell_dependencies).
where(cell_dependencies: { contract_cell_id: contract_cell_ids }).
order("cell_dependencies.block_number DESC, cell_dependencies.tx_index DESC").
limit(10000)
limit(Settings.query_default_limit)
@ckb_transactions = CkbTransaction.from("(#{base_query.to_sql}) AS ckb_transactions").
order("block_number DESC, tx_index DESC").
page(@page).
Expand All @@ -43,7 +43,7 @@ def referring_cells

scope = Contract.referring_cells_query(@contracts).
order("block_timestamp DESC, cell_index DESC").
limit(10000)
limit(Settings.query_default_limit)
if params[:args].present?
type_script = TypeScript.find_by(args: params[:args])
scope = scope.or(CellOutput.where(type_script_id: type_script.id))
Expand Down
28 changes: 28 additions & 0 deletions app/controllers/api/v2/udt_hourly_statistics_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Api
module V2
class UdtHourlyStatisticsController < BaseController
def show
expires_in 15.minutes, public: true, stale_while_revalidate: 5.minutes, stale_if_error: 5.minutes

Check warning on line 5 in app/controllers/api/v2/udt_hourly_statistics_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/udt_hourly_statistics_controller.rb#L1-L5

Added lines #L1 - L5 were not covered by tests

udt = Udt.find_by!(type_hash: params[:id], published: true)
hourly_statistics =
if udt.present?
UdtHourlyStatistic.where(udt:).order(created_at_unixtimestamp: :asc)
else
UdtHourlyStatistic.none
end

Check warning on line 13 in app/controllers/api/v2/udt_hourly_statistics_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/udt_hourly_statistics_controller.rb#L7-L13

Added lines #L7 - L13 were not covered by tests

render json: {
data: hourly_statistics.map do |statistic|
{
ckb_transactions_count: statistic.ckb_transactions_count.to_s,
amount: statistic.amount.to_s,
holders_count: statistic.holders_count.to_s,
created_at_unixtimestamp: statistic.created_at_unixtimestamp.to_s,
}
end,
}
end
end
end
end

Check warning on line 28 in app/controllers/api/v2/udt_hourly_statistics_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/udt_hourly_statistics_controller.rb#L15-L28

Added lines #L15 - L28 were not covered by tests
4 changes: 2 additions & 2 deletions app/interactions/addresses/ckb_transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def execute
raise AddressNotFoundError if address.is_a?(NullAddress)

address_id = address.map(&:id)
account_books = AccountBook.where(address_id:).order("ckb_transaction_id desc").select(:ckb_transaction_id).distinct.limit(5000)
account_books = AccountBook.where(address_id:).order("ckb_transaction_id desc").select(:ckb_transaction_id).distinct.limit(Settings.query_default_limit)
records = CkbTransaction.where(tx_status: :committed, id: account_books.map(&:ckb_transaction_id)).order(transactions_ordering).page(page).per(page_size)
options = paginate_options(records, address_id)
options.merge!(params: { previews: true, address: })
Expand All @@ -35,7 +35,7 @@ def transactions_ordering
def paginate_options(records, address_id)
total_count = AccountBook.where(address_id:).distinct.count
FastJsonapi::PaginationMetaGenerator.new(
request:, records:, page:, page_size:, total_count:,
request:, records:, page:, page_size:, total_pages: records.total_pages, total_count:,
).call
end

Expand Down
14 changes: 5 additions & 9 deletions app/lib/fast_jsonapi/pagination_meta_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ class PaginationMetaGenerator
DEFAULT_PAGE = 1
DEFAULT_PER_PAGE = 20

def initialize(request:, records:, page:, page_size:, records_counter: nil, total_count: nil)
def initialize(request:, records:, page:, page_size:, total_pages: nil, records_counter: nil, total_count: nil)
@url = request.base_url + request.path + query_string(request.query_parameters)
@page = page.to_i
@page_size = limit_page_size(records, page_size.to_i)
@records = records
@records_counter = records_counter || records
@total_count = total_count || @records_counter.total_count.to_i
@total_pages = total_pages
@hash = { links: {}, meta: { total: @total_count, page_size: @page_size } }
@total_pages = total_pages || calculated_total_pages
@hash = { links: {}, meta: { total: @total_count, page_size: @page_size, total_pages: @total_pages } }
end

def total_pages
(total_count / @page_size).ceil
def calculated_total_pages
(total_count.to_f / @page_size).ceil
end

def call
Expand All @@ -31,10 +31,6 @@ def current_page
records.current_page
end

def last_page?
current_page == total_pages
end

def next_page
current_page + 1 unless last_page? || out_of_range?
end
Expand Down
6 changes: 4 additions & 2 deletions app/models/cell_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def to_raw
# Table name: cell_dependencies
#
# id :bigint not null, primary key
# contract_id :bigint
# ckb_transaction_id :bigint not null
# dep_type :integer
# contract_cell_id :bigint not null
# script_id :bigint
# contract_id :bigint
# implicit :boolean
# implicit :boolean default(TRUE), not null
# block_number :bigint
# tx_index :integer
# contract_analyzed :boolean default(FALSE)
Expand All @@ -40,6 +40,8 @@ def to_raw
#
# index_cell_dependencies_on_block_number_and_tx_index (block_number,tx_index)
# index_cell_dependencies_on_contract_analyzed (contract_analyzed)
# index_cell_dependencies_on_contract_id (contract_id)
# index_cell_dependencies_on_script_id (script_id)
# index_cell_dependencies_on_tx_id_and_cell_id_and_dep_type (ckb_transaction_id,contract_cell_id,dep_type) UNIQUE
# index_on_cell_dependencies_contract_cell_block_tx (contract_cell_id,block_number DESC,tx_index DESC)
#
2 changes: 1 addition & 1 deletion app/models/ckb_sync/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def xudt_data_hash
end

def xudt_compatible_code_hashes
[Settings.xudt_compatible_code_hash, Settings.xudt_compatible2_code_hash, Settings.xudt_compatible3_code_hash]
[Settings.xudt_compatible_code_hash, Settings.xudt_compatible2_code_hash, Settings.xudt_compatible3_code_hash, Settings.xudt_compatible4_code_hash]
end

def unique_cell_code_hash
Expand Down
107 changes: 63 additions & 44 deletions app/models/daily_statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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 holder_count knowledge_size
deposit_compensation liquidity created_at_unixtimestamp ckb_hodl_wave holder_count knowledge_size activity_address_contract_distribution
).freeze
MILLISECONDS_IN_DAY = BigDecimal(24 * 60 * 60 * 1000)
GENESIS_TIMESTAMP = 1573852190812
Expand Down Expand Up @@ -409,8 +409,26 @@
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"]
count
ActiveRecord::Base.connection.execute(count_query).first["count"]
end

define_logic :activity_address_contract_distribution do
block_ids = blocks_in_current_period.pluck(:id)
uniq_address_ids = CellOutput.established_status.where(block_id: block_ids).select(:address_id).distinct.map { |cell_output| cell_output.address_id }
results = Address.joins(:lock_script).where(id: uniq_address_ids).group(:code_hash).count
parsed_results =
results.each_with_object({}) do |(key, value), hash|
hex_key = "0x#{key.unpack1('H*')}"
hash[hex_key] = value
end.sort_by { |_k, v| -v }

Check warning on line 423 in app/models/daily_statistic.rb

View check run for this annotation

Codecov / codecov/patch

app/models/daily_statistic.rb#L421-L423

Added lines #L421 - L423 were not covered by tests
data =
parsed_results.map do |result|
{ Contract.where(is_lock_script: true).where.not(name: nil).where("type_hash = ? OR data_hash = ?", result[0], result[0]).first&.name => result[1] }

Check warning on line 426 in app/models/daily_statistic.rb

View check run for this annotation

Codecov / codecov/patch

app/models/daily_statistic.rb#L426

Added line #L426 was not covered by tests
end
nil_sum = data.select { |item| item.keys.include?(nil) }.sum { |item| item[nil] }
filtered_data = data.reject { |item| item.keys.include?(nil) }
filtered_data << { "Others" => nil_sum } if nil_sum > 0
filtered_data
end

private
Expand Down Expand Up @@ -534,47 +552,48 @@
#
# Table name: daily_statistics
#
# id :bigint not null, primary key
# transactions_count :string default("0")
# addresses_count :string default("0")
# total_dao_deposit :string default("0.0")
# block_timestamp :decimal(30, )
# created_at_unixtimestamp :integer
# created_at :datetime not null
# updated_at :datetime not null
# dao_depositors_count :string default("0")
# unclaimed_compensation :string default("0")
# claimed_compensation :string default("0")
# average_deposit_time :string default("0")
# estimated_apc :string default("0")
# mining_reward :string default("0")
# deposit_compensation :string default("0")
# treasury_amount :string default("0")
# live_cells_count :string default("0")
# dead_cells_count :string default("0")
# avg_hash_rate :string default("0")
# avg_difficulty :string default("0")
# uncle_rate :string default("0")
# total_depositors_count :string default("0")
# total_tx_fee :decimal(30, )
# address_balance_distribution :jsonb
# occupied_capacity :decimal(30, )
# daily_dao_deposit :decimal(30, )
# daily_dao_depositors_count :integer
# daily_dao_withdraw :decimal(30, )
# circulation_ratio :decimal(, )
# total_supply :decimal(30, )
# circulating_supply :decimal(, )
# block_time_distribution :jsonb
# epoch_time_distribution :jsonb
# epoch_length_distribution :jsonb
# average_block_time :jsonb
# nodes_distribution :jsonb
# nodes_count :integer
# locked_capacity :decimal(30, )
# ckb_hodl_wave :jsonb
# holder_count :integer
# knowledge_size :decimal(30, )
# id :bigint not null, primary key
# transactions_count :string default("0")
# addresses_count :string default("0")
# total_dao_deposit :string default("0.0")
# block_timestamp :decimal(30, )
# created_at_unixtimestamp :integer
# created_at :datetime not null
# updated_at :datetime not null
# dao_depositors_count :string default("0")
# unclaimed_compensation :string default("0")
# claimed_compensation :string default("0")
# average_deposit_time :string default("0")
# estimated_apc :string default("0")
# mining_reward :string default("0")
# deposit_compensation :string default("0")
# treasury_amount :string default("0")
# live_cells_count :string default("0")
# dead_cells_count :string default("0")
# avg_hash_rate :string default("0")
# avg_difficulty :string default("0")
# uncle_rate :string default("0")
# total_depositors_count :string default("0")
# total_tx_fee :decimal(30, )
# address_balance_distribution :jsonb
# occupied_capacity :decimal(30, )
# daily_dao_deposit :decimal(30, )
# daily_dao_depositors_count :integer
# daily_dao_withdraw :decimal(30, )
# circulation_ratio :decimal(, )
# total_supply :decimal(30, )
# circulating_supply :decimal(, )
# block_time_distribution :jsonb
# epoch_time_distribution :jsonb
# epoch_length_distribution :jsonb
# average_block_time :jsonb
# nodes_distribution :jsonb
# nodes_count :integer
# locked_capacity :decimal(30, )
# ckb_hodl_wave :jsonb
# holder_count :integer
# knowledge_size :decimal(30, )
# activity_address_contract_distribution :jsonb
#
# Indexes
#
Expand Down
21 changes: 21 additions & 0 deletions app/models/rgbpp_assets_statistic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class RgbppAssetsStatistic < ApplicationRecord
enum :network, %i[global ckb btc]
enum :indicator, %i[ft_count dob_count holders_count transactions_count]
end

Check warning on line 4 in app/models/rgbpp_assets_statistic.rb

View check run for this annotation

Codecov / codecov/patch

app/models/rgbpp_assets_statistic.rb#L1-L4

Added lines #L1 - L4 were not covered by tests

# == Schema Information
#
# Table name: rgbpp_assets_statistics
#
# id :bigint not null, primary key
# indicator :integer not null
# value :decimal(40, ) default(0)
# network :integer default("global")
# created_at_unixtimestamp :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_on_indicator_and_network_and_created_at_unixtimestamp (indicator,network,created_at_unixtimestamp) UNIQUE
#
18 changes: 18 additions & 0 deletions app/models/rgbpp_hourly_statistic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class RgbppHourlyStatistic < ApplicationRecord
end

Check warning on line 2 in app/models/rgbpp_hourly_statistic.rb

View check run for this annotation

Codecov / codecov/patch

app/models/rgbpp_hourly_statistic.rb#L1-L2

Added lines #L1 - L2 were not covered by tests

# == Schema Information
#
# Table name: rgbpp_hourly_statistics
#
# id :bigint not null, primary key
# xudt_count :integer default(0)
# dob_count :integer default(0)
# created_at_unixtimestamp :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_rgbpp_hourly_statistics_on_created_at_unixtimestamp (created_at_unixtimestamp) UNIQUE
#
40 changes: 40 additions & 0 deletions app/models/udt_hourly_statistic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class UdtHourlyStatistic < ApplicationRecord
belongs_to :udt

Check warning on line 2 in app/models/udt_hourly_statistic.rb

View check run for this annotation

Codecov / codecov/patch

app/models/udt_hourly_statistic.rb#L1-L2

Added lines #L1 - L2 were not covered by tests

def percentage_change(attribute)
yesterday = previous_stat(udt_id, 1)
day_before_yesterday = previous_stat(udt_id, 2)

Check warning on line 6 in app/models/udt_hourly_statistic.rb

View check run for this annotation

Codecov / codecov/patch

app/models/udt_hourly_statistic.rb#L4-L6

Added lines #L4 - L6 were not covered by tests

return nil unless yesterday && day_before_yesterday

Check warning on line 8 in app/models/udt_hourly_statistic.rb

View check run for this annotation

Codecov / codecov/patch

app/models/udt_hourly_statistic.rb#L8

Added line #L8 was not covered by tests

yesterday_value = yesterday.public_send(attribute)
day_before_yesterday_value = day_before_yesterday.public_send(attribute)

Check warning on line 11 in app/models/udt_hourly_statistic.rb

View check run for this annotation

Codecov / codecov/patch

app/models/udt_hourly_statistic.rb#L10-L11

Added lines #L10 - L11 were not covered by tests

return nil if day_before_yesterday_value.zero?

Check warning on line 13 in app/models/udt_hourly_statistic.rb

View check run for this annotation

Codecov / codecov/patch

app/models/udt_hourly_statistic.rb#L13

Added line #L13 was not covered by tests

((yesterday_value - day_before_yesterday_value).to_f / day_before_yesterday_value * 100).round(2)
end

Check warning on line 16 in app/models/udt_hourly_statistic.rb

View check run for this annotation

Codecov / codecov/patch

app/models/udt_hourly_statistic.rb#L15-L16

Added lines #L15 - L16 were not covered by tests

def previous_stat(udt_id, days_ago)
timestamp = (Time.current - days_ago.days).beginning_of_day.to_i
self.class.find_by(udt_id:, created_at_unixtimestamp: timestamp)
end
end

Check warning on line 22 in app/models/udt_hourly_statistic.rb

View check run for this annotation

Codecov / codecov/patch

app/models/udt_hourly_statistic.rb#L18-L22

Added lines #L18 - L22 were not covered by tests

# == Schema Information
#
# Table name: udt_hourly_statistics
#
# id :bigint not null, primary key
# udt_id :bigint not null
# ckb_transactions_count :integer default(0)
# amount :decimal(40, ) default(0)
# holders_count :integer default(0)
# created_at_unixtimestamp :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_on_udt_id_and_unixtimestamp (udt_id,created_at_unixtimestamp) UNIQUE
#
4 changes: 4 additions & 0 deletions app/serializers/daily_statistic_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,8 @@ class DailyStatisticSerializer
attribute :knowledge_size, if: Proc.new { |_record, params|
params.present? && params[:indicator].include?("knowledge_size")
}

attribute :activity_address_contract_distribution, if: Proc.new { |_record, params|
params.present? && params[:indicator].include?("activity_address_contract_distribution")
}
end
2 changes: 1 addition & 1 deletion app/services/charts/daily_statistic_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 holder_count
epoch_time_distribution epoch_length_distribution locked_capacity ckb_hodl_wave holder_count activity_address_contract_distribution
}

established_order + others
Expand Down
Loading
Loading