diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f5db9d302..b1acc6736 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,5 @@ name: Pull, build docker image and push to repository -on: +on: workflow_call: secrets: GHCR_USERNAME: @@ -7,14 +7,20 @@ on: GHCR_TOKEN: required: true outputs: - image: - description: URL for docker image with tag - value: ${{ jobs.build.outputs.image }} -jobs: + # Image name + image-name: + description: URL for docker image + value: ${{ jobs.build.outputs.image-name }} + # Image tag (version) + image-tag: + description: image tag(version) + value: ${{ jobs.build.outputs.image-tag }} +jobs: build: runs-on: ubuntu-latest outputs: - image: '${{ steps.docker_build.outputs.imageFullName }}:${{ steps.docker_build.outputs.tags }}' + image-name: '${{ steps.docker_build.outputs.imageFullName }}' + image-tag: '${{ steps.docker_build.outputs.tags }}' steps: - uses: actions/checkout@v3 with: diff --git a/.github/workflows/mainnet.yml b/.github/workflows/mainnet.yml index 8ecc89cfe..8ce082a40 100644 --- a/.github/workflows/mainnet.yml +++ b/.github/workflows/mainnet.yml @@ -17,5 +17,6 @@ jobs: with: k8s-namespace: mainnet k8s-workload: ${{ matrix.workload }} - image: ${{ needs.build.outputs.image }} + image-name: ${{ needs.build.outputs.image-name }} + image-tag: ${{ needs.build.outputs.image-tag }} secrets: inherit diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 06aa5ca3b..fe821e85c 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -1,6 +1,6 @@ name: Deploy to staging -on: +on: push: branches: - develop @@ -10,16 +10,17 @@ on: - '*-rc*' jobs: build: - uses: ./.github/workflows/build.yml + uses: ./.github/workflows/build.yml secrets: inherit deploy-update: needs: build strategy: matrix: - workload: [ckb-explorer-api, ckb-explorer-syncer, ckb-explorer-worker] - uses: ./.github/workflows/update-image.yml + workload: [ckb-explorer-api, ckb-explorer-poolsyncer, ckb-explorer-scheduler, ckb-explorer-blocksyncer] + uses: ./.github/workflows/update-image.yml with: k8s-namespace: staging k8s-workload: ${{ matrix.workload }} - image: ${{ needs.build.outputs.image }} + image-name: ${{ needs.build.outputs.image-name }} + image-tag: ${{ needs.build.outputs.image-tag }} secrets: inherit diff --git a/.github/workflows/testnet.yml b/.github/workflows/testnet.yml index 271e18a8e..145515115 100644 --- a/.github/workflows/testnet.yml +++ b/.github/workflows/testnet.yml @@ -1,21 +1,22 @@ name: Deploy to testnet -on: +on: push: branches: - testnet jobs: build: - uses: ./.github/workflows/build.yml + uses: ./.github/workflows/build.yml secrets: inherit deploy-update: needs: build strategy: matrix: - workload: [ckb-explorer-api, ckb-explorer-syncer, ckb-explorer-worker] - uses: ./.github/workflows/update-image.yml + workload: [ckb-explorer-api, ckb-explorer-poolsyncer, ckb-explorer-scheduler, ckb-explorer-blocksyncer] + uses: ./.github/workflows/update-image.yml with: k8s-namespace: testnet k8s-workload: ${{ matrix.workload }} - image: ${{ needs.build.outputs.image }} + image-name: ${{ needs.build.outputs.image-name }} + image-tag: ${{ needs.build.outputs.image-tag }} secrets: inherit diff --git a/.github/workflows/update-image.yml b/.github/workflows/update-image.yml index a631ca8bc..baefa41d9 100644 --- a/.github/workflows/update-image.yml +++ b/.github/workflows/update-image.yml @@ -1,8 +1,11 @@ name: Update K8S workload image -on: +on: workflow_call: inputs: - image: + image-name: + required: true + type: string + image-tag: required: true type: string k8s-namespace: @@ -24,18 +27,14 @@ jobs: steps: - name: Update image on K8S + id: http-request uses: fjogeleit/http-request-action@v1 with: url: ${{ secrets.KUBOARD_API_URL }}/cluster/ckb/kind/CICDApi/ops/resource/updateImageTag method: 'PUT' customHeaders: '{"Content-Type": "application/json", "Cookie": "KuboardUsername=${{ secrets.KUBOARD_USERNAME }}; KuboardAccessKey=${{ secrets.KUBOARD_ACCESS_KEY }}"}' - data: '{"kind":"deployments","namespace":"${{ inputs.k8s-namespace }}","name":"${{ inputs.k8s-workload }}","images":{"${{ inputs.k8s-workload }}":"${{ inputs.image }}"}}' - - name: Restart container - uses: fjogeleit/http-request-action@v1 - with: - url: ${{ secrets.KUBOARD_API_URL }}/cluster/ckb/kind/CICDApi/ops/resource/restartWorkload - method: 'PUT' - customHeaders: '{"Content-Type": "application/json", "Cookie": "KuboardUsername=${{ secrets.KUBOARD_USERNAME }}; KuboardAccessKey=${{ secrets.KUBOARD_ACCESS_KEY }}"}' - data: '{"kind":"deployments","namespace":"${{ inputs.k8s-namespace }}","name":"${{ inputs.k8s-workload }}"}' - - + data: '{"kind":"deployments","namespace":"${{ inputs.k8s-namespace }}","name":"${{ inputs.k8s-workload }}","images":{"${{ inputs.image-name }}":"${{ inputs.image-name }}:${{ inputs.image-tag }}"}}' + - name: Display Response + run: | + echo "Response response: ${{ steps.http-request.outputs.response }}" + echo "Response headers: ${{ steps.http-request.outputs.headers }}" diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index 6e1b9d8e9..b6acc2652 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -1072,6 +1072,7 @@ def cell_output_attributes(output, address, ckb_transaction, local_block, cell_i lock_script_id: lock_script.id, type_script_id: type_script&.id, udt_amount: udt_amount, + status: "live", created_at: Time.current, updated_at: Time.current } diff --git a/lib/tasks/migration/update_output_cells_status.rake b/lib/tasks/migration/update_output_cells_status.rake new file mode 100644 index 000000000..fc48f7a48 --- /dev/null +++ b/lib/tasks/migration/update_output_cells_status.rake @@ -0,0 +1,79 @@ +class UpdateCellOutputsStatus + include Rake::DSL + + def initialize + @address_ids = [] + + namespace :migration do + desc "Usage: RAILS_ENV=production bundle exec rake migration:update_output_cells_status" + task update_output_cells_status: :environment do + ApplicationRecord.transaction do + CellOutput.pending.includes(:ckb_transaction).where(ckb_transaction: { tx_status: "committed" }).find_each do |output| + puts "output id: #{output.id}" + + output.live! + update_udt_account(output) + @address_ids << output.address_id + end + end + + update_addresses_live_cells_count + + puts "done" + end + end + end + + private + + def update_addresses_live_cells_count + Address.where(id: @address_ids.uniq).find_each do |address| + address.live_cells_count = address.cell_outputs.live.count + address.cal_balance! + address.save! + end + end + + def update_udt_account(udt_output) + return unless udt_output.cell_type.in?(%w(udt m_nft_token nrc_721_token)) + + address = Address.find(udt_output.address_id) + udt_type = udt_type(udt_output.cell_type) + udt_account = address.udt_accounts.where(type_hash: udt_output.type_hash, udt_type: udt_type).first + amount = udt_account_amount(udt_type, udt_output.type_hash, address) + + if udt_account.present? + udt_account.update(amount: amount) + else + puts "udt_account not: #{udt_output.id}" + + udt = Udt.where(type_hash: udt_output.type_hash, udt_type: udt_type).take! + nft_token_id = + udt_type == "nrc_721_token" ? CkbUtils.parse_nrc_721_args(udt_output.type_script.args).token_id : nil + new_udt_accounts_attribute = { + address_id: udt_output.address_id, udt_type: udt.udt_type, full_name: udt.full_name, symbol: udt.symbol, decimal: udt.decimal, + published: udt.published, code_hash: udt.code_hash, type_hash: udt.type_hash, amount: amount, udt_id: udt.id, nft_token_id: nft_token_id, + created_at: Time.current, updated_at: Time.current + } + + UdtAccount.insert!(new_udt_accounts_attribute) + end + end + + def udt_type(cell_type) + cell_type == "udt" ? "sudt" : cell_type + end + + def udt_account_amount(udt_type, type_hash, address) + case udt_type + when "sudt" + address.cell_outputs.live.udt.where(type_hash: type_hash).sum(:udt_amount) + when "m_nft_token" + address.cell_outputs.live.m_nft_token.where(type_hash: type_hash).sum(:udt_amount) + else + 0 + end + end +end + +UpdateCellOutputsStatus.new diff --git a/lib/websocket.rb b/lib/websocket.rb index 3bff70e1f..65c1ac8d9 100644 --- a/lib/websocket.rb +++ b/lib/websocket.rb @@ -48,6 +48,13 @@ def subscribe(connection, topic) }) rescue StandardError => e Rails.logger.error "Error occurred during ImportTransactionJob data: #{data}, error: #{e.message}" + Sentry.capture_message( + "Import pending transaction", + extra: { + tx_hash: data["transaction"]["hash"], + timestamp: data["timestamp"].hex + } + ) end end end