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

refactor: add cell dependencies sync worker #1599

Merged
merged 2 commits into from
Jan 22, 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
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,9 @@ Layout/InitialIndentation:
Enabled: false

Layout/LineLength:
Description: 'Limit lines to 80 characters.'
Description: 'Limit lines to 200 characters.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
Max: 80
Max: 200

# Lint

Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ gem "with_advisory_lock"

gem "nokogiri", ">= 1.11.0.rc4"

gem "benchmark_methods", require: false
gem "sentry-ruby"
gem "sentry-rails"
gem "sentry-sidekiq"
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ GEM
awesome_print (1.9.2)
backport (1.2.0)
benchmark (0.2.1)
benchmark_methods (0.7)
bigdecimal (3.1.4)
bootsnap (1.13.0)
msgpack (~> 1.2)
Expand Down Expand Up @@ -479,7 +478,6 @@ DEPENDENCIES
annotate
async-websocket (~> 0.22.1)
awesome_print
benchmark_methods
bigdecimal
bootsnap
ckb-sdk-ruby!
Expand Down
197 changes: 56 additions & 141 deletions app/models/ckb_sync/new_node_data_processor.rb

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions app/workers/generate_cell_dependencies_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class GenerateCellDependenciesWorker
include Sidekiq::Worker

def perform(block_id)
block = Block.find_by(id: block_id)
return unless block

tx_cell_deps = build_cell_deps(block.number)
block.ckb_transactions.each do |txs|
DeployedCell.create_initial_data_for_ckb_transaction(txs, tx_cell_deps[txs.tx_hash])
ReferringCell.create_initial_data_for_ckb_transaction(txs)
end
end

def build_cell_deps(number)
node_block = CkbSync::Api.instance.get_block_by_number(number)
node_block.transactions.each_with_object({}) do |tx, deps|
deps[tx.hash] = tx.cell_deps
end
end
end
1 change: 1 addition & 0 deletions test/models/address_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AddressTest < ActiveSupport::TestCase
],
)
GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true)
GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true)
end

context "associations" do
Expand Down
1 change: 1 addition & 0 deletions test/models/block_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class BlockTest < ActiveSupport::TestCase
create(:table_record_count, :ckb_transactions_counter)
CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet"))
GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true)
GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true)
CkbSync::Api.any_instance.stubs(:get_block_cycles).returns(
[
"0x100", "0x200", "0x300", "0x400", "0x500", "0x600", "0x700", "0x800", "0x900"
Expand Down
1 change: 1 addition & 0 deletions test/models/ckb_sync/dao_events_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DaoEventsTest < ActiveSupport::TestCase
create(:table_record_count, :ckb_transactions_counter)
CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet"))
GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true)
GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true)
CkbSync::Api.any_instance.stubs(:get_block_cycles).returns(
[
"0x100", "0x200", "0x300", "0x400", "0x500", "0x600", "0x700", "0x800", "0x900"
Expand Down
1 change: 1 addition & 0 deletions test/models/ckb_sync/node_data_processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
create(:table_record_count, :ckb_transactions_counter)
CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet"))
GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true)
GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true)
CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet"))
end

Expand Down
1 change: 1 addition & 0 deletions test/models/ckb_transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CkbTransactionTest < ActiveSupport::TestCase

test "#tx_hash should decodes packed string" do
GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true)
GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true)
VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}") do
CkbSync::Api.any_instance.stubs(:get_epoch_by_number).returns(
CKB::Types::Epoch.new(
Expand Down
1 change: 1 addition & 0 deletions test/models/lock_script_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class LockScriptTest < ActiveSupport::TestCase
create(:table_record_count, :ckb_transactions_counter)
CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet"))
GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true)
GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true)
CkbSync::Api.any_instance.stubs(:get_block_cycles).returns(
[
"0x100", "0x200", "0x300", "0x400", "0x500", "0x600", "0x700", "0x800", "0x900"
Expand Down
1 change: 1 addition & 0 deletions test/models/type_script_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class TypeScriptTest < ActiveSupport::TestCase

test "#code_hash should decodes packed string" do
GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true)
GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true)
CkbSync::Api.any_instance.stubs(:get_epoch_by_number).returns(
CKB::Types::Epoch.new(
compact_target: "0x1000",
Expand Down
1 change: 1 addition & 0 deletions test/models/uncle_block_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class UncleBlockTest < ActiveSupport::TestCase
create(:table_record_count, :ckb_transactions_counter)
CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet"))
GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true)
GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true)
CkbSync::Api.any_instance.stubs(:get_block_cycles).returns(
[
"0x100", "0x200", "0x300", "0x400", "0x500", "0x600", "0x700", "0x800", "0x900"
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
def prepare_node_data(node_tip_block_number = 30)
Sidekiq::Testing.inline!
GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true)
GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true)
CkbSync::Api.any_instance.stubs(:get_tip_block_number).returns(node_tip_block_number + 1)
CkbSync::Api.any_instance.stubs(:get_epoch_by_number).returns(
CKB::Types::Epoch.new(
Expand Down
1 change: 1 addition & 0 deletions test/utils/ckb_utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CkbUtilsTest < ActiveSupport::TestCase
],
)
GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true)
GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true)
end

test ".generate_address should return mainnet address when mode is mainnet" do
Expand Down