Skip to content

Commit 2beabee

Browse files
authored
Merge pull request #664 from nervosnetwork/rc/v0.9.8
2 parents 0c22ffa + 3a305a1 commit 2beabee

23 files changed

+918
-803
lines changed

.github/workflows/ruby.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
name: Ruby
2-
3-
on: [push]
1+
name: Explorer service
2+
on: push
43

54
jobs:
65
build:
7-
86
runs-on: ubuntu-latest
97
services:
8+
postgres:
9+
image: postgres
10+
env:
11+
POSTGRES_PASSWORD: postgres
12+
options: >-
13+
--health-cmd pg_isready
14+
--health-interval 10s
15+
--health-timeout 5s
16+
--health-retries 5
17+
ports:
18+
- 5432:5432
1019
redis:
1120
image: redis
1221
ports: ['6379:6379']
1322
options: --entrypoint redis-server
1423
steps:
15-
- uses: actions/checkout@v1
24+
- uses: actions/checkout@v2
1625
- name: Set up Ruby 2.6.4
1726
run: |
1827
sudo apt-get update
@@ -25,13 +34,6 @@ jobs:
2534
- name: Set up SECP256k1
2635
run: |
2736
git clone https://github.com/bitcoin-core/secp256k1.git && cd secp256k1 && ./autogen.sh && ./configure && make && ./tests && sudo make install && cd ..
28-
- name: Set up PostgreSQL
29-
run: |
30-
sudo apt install postgresql postgresql-contrib
31-
sudo sed -i 's/peer/trust/gI' /etc/postgresql/10/main/pg_hba.conf
32-
sudo sed -i 's/md5/trust/gI' /etc/postgresql/10/main/pg_hba.conf
33-
sudo systemctl restart postgresql.service
34-
psql -c 'create database "ckb_explorer_test";' -U postgres
3537
- name: Build and test with Rake
3638
run: |
3739
source /usr/share/rvm/scripts/rvm

CHANGELOG.md

Lines changed: 723 additions & 702 deletions
Large diffs are not rendered by default.

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ gem "kaminari"
6464

6565
gem "ruby-progressbar", require: false
6666

67+
gem "sentry-raven"
68+
6769
# Deployment
6870
gem "mina", require: false
6971
gem "mina-multistage", require: false

Gemfile.lock

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,58 +24,58 @@ GIT
2424
GEM
2525
remote: https://rubygems.org/
2626
specs:
27-
actioncable (6.0.3.1)
28-
actionpack (= 6.0.3.1)
27+
actioncable (6.0.3.2)
28+
actionpack (= 6.0.3.2)
2929
nio4r (~> 2.0)
3030
websocket-driver (>= 0.6.1)
31-
actionmailbox (6.0.3.1)
32-
actionpack (= 6.0.3.1)
33-
activejob (= 6.0.3.1)
34-
activerecord (= 6.0.3.1)
35-
activestorage (= 6.0.3.1)
36-
activesupport (= 6.0.3.1)
31+
actionmailbox (6.0.3.2)
32+
actionpack (= 6.0.3.2)
33+
activejob (= 6.0.3.2)
34+
activerecord (= 6.0.3.2)
35+
activestorage (= 6.0.3.2)
36+
activesupport (= 6.0.3.2)
3737
mail (>= 2.7.1)
38-
actionmailer (6.0.3.1)
39-
actionpack (= 6.0.3.1)
40-
actionview (= 6.0.3.1)
41-
activejob (= 6.0.3.1)
38+
actionmailer (6.0.3.2)
39+
actionpack (= 6.0.3.2)
40+
actionview (= 6.0.3.2)
41+
activejob (= 6.0.3.2)
4242
mail (~> 2.5, >= 2.5.4)
4343
rails-dom-testing (~> 2.0)
44-
actionpack (6.0.3.1)
45-
actionview (= 6.0.3.1)
46-
activesupport (= 6.0.3.1)
44+
actionpack (6.0.3.2)
45+
actionview (= 6.0.3.2)
46+
activesupport (= 6.0.3.2)
4747
rack (~> 2.0, >= 2.0.8)
4848
rack-test (>= 0.6.3)
4949
rails-dom-testing (~> 2.0)
5050
rails-html-sanitizer (~> 1.0, >= 1.2.0)
51-
actiontext (6.0.3.1)
52-
actionpack (= 6.0.3.1)
53-
activerecord (= 6.0.3.1)
54-
activestorage (= 6.0.3.1)
55-
activesupport (= 6.0.3.1)
51+
actiontext (6.0.3.2)
52+
actionpack (= 6.0.3.2)
53+
activerecord (= 6.0.3.2)
54+
activestorage (= 6.0.3.2)
55+
activesupport (= 6.0.3.2)
5656
nokogiri (>= 1.8.5)
57-
actionview (6.0.3.1)
58-
activesupport (= 6.0.3.1)
57+
actionview (6.0.3.2)
58+
activesupport (= 6.0.3.2)
5959
builder (~> 3.1)
6060
erubi (~> 1.4)
6161
rails-dom-testing (~> 2.0)
6262
rails-html-sanitizer (~> 1.1, >= 1.2.0)
63-
activejob (6.0.3.1)
64-
activesupport (= 6.0.3.1)
63+
activejob (6.0.3.2)
64+
activesupport (= 6.0.3.2)
6565
globalid (>= 0.3.6)
66-
activemodel (6.0.3.1)
67-
activesupport (= 6.0.3.1)
68-
activerecord (6.0.3.1)
69-
activemodel (= 6.0.3.1)
70-
activesupport (= 6.0.3.1)
66+
activemodel (6.0.3.2)
67+
activesupport (= 6.0.3.2)
68+
activerecord (6.0.3.2)
69+
activemodel (= 6.0.3.2)
70+
activesupport (= 6.0.3.2)
7171
activerecord-import (1.0.3)
7272
activerecord (>= 3.2)
73-
activestorage (6.0.3.1)
74-
actionpack (= 6.0.3.1)
75-
activejob (= 6.0.3.1)
76-
activerecord (= 6.0.3.1)
73+
activestorage (6.0.3.2)
74+
actionpack (= 6.0.3.2)
75+
activejob (= 6.0.3.2)
76+
activerecord (= 6.0.3.2)
7777
marcel (~> 0.3.1)
78-
activesupport (6.0.3.1)
78+
activesupport (6.0.3.2)
7979
concurrent-ruby (~> 1.0, >= 1.0.2)
8080
i18n (>= 0.7, < 2)
8181
minitest (~> 5.1)
@@ -155,6 +155,8 @@ GEM
155155
factory_bot_rails (5.0.2)
156156
factory_bot (~> 5.0.2)
157157
railties (>= 4.2.0)
158+
faraday (1.0.1)
159+
multipart-post (>= 1.2, < 3)
158160
fast_jsonapi (1.5)
159161
activesupport (>= 4.2)
160162
ffi (1.13.1)
@@ -165,7 +167,7 @@ GEM
165167
activesupport (>= 4.2.0)
166168
hashdiff (1.0.0)
167169
hiredis (0.6.3)
168-
i18n (1.8.2)
170+
i18n (1.8.3)
169171
concurrent-ruby (~> 1.0)
170172
jaro_winkler (1.5.2)
171173
json (2.2.0)
@@ -185,7 +187,7 @@ GEM
185187
rb-fsevent (~> 0.9, >= 0.9.4)
186188
rb-inotify (~> 0.9, >= 0.9.7)
187189
ruby_dep (~> 1.2)
188-
loofah (2.5.0)
190+
loofah (2.6.0)
189191
crass (~> 1.0.2)
190192
nokogiri (>= 1.5.9)
191193
mail (2.7.1)
@@ -211,6 +213,7 @@ GEM
211213
mocha (1.8.0)
212214
metaclass (~> 0.0.1)
213215
msgpack (1.2.10)
216+
multipart-post (2.1.1)
214217
net-http-persistent (3.0.1)
215218
connection_pool (~> 2.2)
216219
newrelic_rpm (6.4.0.356)
@@ -235,7 +238,7 @@ GEM
235238
puma (4.3.5)
236239
nio4r (~> 2.0)
237240
raabro (1.1.6)
238-
rack (2.2.2)
241+
rack (2.2.3)
239242
rack-attack (6.2.1)
240243
rack (>= 1.0, < 3)
241244
rack-cors (1.0.5)
@@ -244,29 +247,29 @@ GEM
244247
rack
245248
rack-test (1.1.0)
246249
rack (>= 1.0, < 3)
247-
rails (6.0.3.1)
248-
actioncable (= 6.0.3.1)
249-
actionmailbox (= 6.0.3.1)
250-
actionmailer (= 6.0.3.1)
251-
actionpack (= 6.0.3.1)
252-
actiontext (= 6.0.3.1)
253-
actionview (= 6.0.3.1)
254-
activejob (= 6.0.3.1)
255-
activemodel (= 6.0.3.1)
256-
activerecord (= 6.0.3.1)
257-
activestorage (= 6.0.3.1)
258-
activesupport (= 6.0.3.1)
250+
rails (6.0.3.2)
251+
actioncable (= 6.0.3.2)
252+
actionmailbox (= 6.0.3.2)
253+
actionmailer (= 6.0.3.2)
254+
actionpack (= 6.0.3.2)
255+
actiontext (= 6.0.3.2)
256+
actionview (= 6.0.3.2)
257+
activejob (= 6.0.3.2)
258+
activemodel (= 6.0.3.2)
259+
activerecord (= 6.0.3.2)
260+
activestorage (= 6.0.3.2)
261+
activesupport (= 6.0.3.2)
259262
bundler (>= 1.3.0)
260-
railties (= 6.0.3.1)
263+
railties (= 6.0.3.2)
261264
sprockets-rails (>= 2.0.0)
262265
rails-dom-testing (2.0.3)
263266
activesupport (>= 4.2.0)
264267
nokogiri (>= 1.6)
265268
rails-html-sanitizer (1.3.0)
266269
loofah (~> 2.3)
267-
railties (6.0.3.1)
268-
actionpack (= 6.0.3.1)
269-
activesupport (= 6.0.3.1)
270+
railties (6.0.3.2)
271+
actionpack (= 6.0.3.2)
272+
activesupport (= 6.0.3.2)
270273
method_source
271274
rake (>= 0.8.7)
272275
thor (>= 0.20.3, < 2.0)
@@ -293,6 +296,8 @@ GEM
293296
ruby-progressbar (1.10.1)
294297
ruby_dep (1.5.0)
295298
safe_yaml (1.0.5)
299+
sentry-raven (3.0.0)
300+
faraday (>= 1.0)
296301
shoulda-context (1.2.2)
297302
shoulda-matchers (4.1.0)
298303
activesupport (>= 4.2.0)
@@ -326,7 +331,7 @@ GEM
326331
spring-watcher-listen (2.0.1)
327332
listen (>= 2.7, < 4.0)
328333
spring (>= 1.2, < 3.0)
329-
sprockets (4.0.0)
334+
sprockets (4.0.2)
330335
concurrent-ruby (~> 1.0)
331336
rack (> 1, < 3)
332337
sprockets-rails (3.2.1)
@@ -401,6 +406,7 @@ DEPENDENCIES
401406
rubocop-performance
402407
rubocop-rails
403408
ruby-progressbar
409+
sentry-raven
404410
shoulda-context
405411
shoulda-matchers
406412
sidekiq

app/controllers/api/v1/blocks_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ def index
99
blocks = Block.recent.limit(ENV["HOMEPAGE_BLOCK_RECORDS_COUNT"].to_i)
1010
options = {}
1111
else
12-
blocks = Block.recent.page(@page).per(@page_size)
13-
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: blocks, page: @page, page_size: @page_size).call
12+
block_timestamps = Block.recent.select(:timestamp).page(@page).per(@page_size)
13+
blocks = Block.where(timestamp: block_timestamps.map { |block| block.timestamp }).select(:id, :miner_hash, :number, :timestamp, :reward, :ckb_transactions_count, :live_cell_changes)
14+
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: block_timestamps, page: @page, page_size: @page_size).call
1415
end
1516

1617
render json: BlockListSerializer.new(blocks, options)

app/controllers/application_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class ApplicationController < ActionController::API
2-
before_action :check_header_info
2+
before_action :check_header_info, :set_raven_context
3+
34
rescue_from Api::V1::Exceptions::Error, with: :api_error
45
rescue_from ActionController::RoutingError do |exception|
56
render json: { message: exception.message }, status: :not_found
@@ -15,6 +16,10 @@ def catch_404
1516

1617
private
1718

19+
def set_raven_context
20+
Raven.extra_context(params: params.to_unsafe_h, url: request.url)
21+
end
22+
1823
def api_error(error)
1924
render json: RequestErrorSerializer.new([error], message: error.title), status: error.status
2025
end

app/models/block.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ def invalid!
143143
# live_cell_changes :integer
144144
# block_time :decimal(13, )
145145
# block_size :integer
146+
# proposal_reward :decimal(30, )
147+
# commit_reward :decimal(30, )
146148
#
147149
# Indexes
148150
#

app/models/cellbase.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ class Cellbase
44
def initialize(block)
55
@block = block
66
@target_block_number = @block.target_block.present? ? @block.target_block_number : 0
7-
@cellbase_output_capacity_details = CkbSync::Api.instance.get_cellbase_output_capacity_details(block.block_hash)
87
end
98

109
def proposal_reward
@@ -33,5 +32,17 @@ def secondary_reward
3332

3433
private
3534

36-
attr_reader :cellbase_output_capacity_details, :block
35+
attr_reader :block
36+
37+
def cellbase_output_capacity_details
38+
@cellbase_output_capacity_details ||=
39+
begin
40+
if block.target_block_reward_status == "issued"
41+
target_block = block.target_block
42+
OpenStruct.new(primary: target_block.primary_reward, secondary: target_block.secondary_reward, proposal_reward: target_block.proposal_reward, tx_fee: target_block.commit_reward)
43+
else
44+
CkbSync::Api.instance.get_cellbase_output_capacity_details(block.block_hash)
45+
end
46+
end
47+
end
3748
end

app/models/ckb_sync/api.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module CkbSync
22
class Api
33
include Singleton
44

5-
METHOD_NAMES = %w(system_script_out_point dry_run_transaction set_system_script_cell system_script_cell system_script_cell_hash genesis_block get_block_by_number genesis_block_hash get_block_hash get_block get_tip_header get_tip_block_number get_cells_by_lock_hash get_transaction get_live_cell local_node_info get_current_epoch get_epoch_by_number get_peers tx_pool_info get_blockchain_info get_peers_state compute_transaction_hash get_cellbase_output_capacity_details calculate_dao_maximum_withdraw compute_script_hash).freeze
5+
METHOD_NAMES = %w(system_script_out_point dry_run_transaction set_system_script_cell system_script_cell system_script_cell_hash genesis_block get_block_by_number genesis_block_hash get_block_hash get_block get_tip_header get_tip_block_number get_cells_by_lock_hash get_transaction get_live_cell local_node_info get_current_epoch get_epoch_by_number get_peers tx_pool_info get_blockchain_info get_peers_state compute_transaction_hash get_cellbase_output_capacity_details calculate_dao_maximum_withdraw compute_script_hash get_block_economic_state).freeze
66

77
def initialize
88
@api = CKB::API.new(host: ENV["CKB_NODE_URL"])

app/models/ckb_transaction.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def cellbase_display_outputs
7878
cellbase = Cellbase.new(block)
7979
cell_outputs_for_display.map do |output|
8080
consumed_tx_hash = output.live? ? nil : output.consumed_by.tx_hash
81-
CkbUtils.hash_value_to_s({ id: output.id, capacity: output.capacity, address_hash: output.address_hash, target_block_number: cellbase.target_block_number, base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward, secondary_reward: cellbase.secondary_reward, status: output.status, consumed_tx_hash: consumed_tx_hash })
81+
CkbUtils.hash_value_to_s(id: output.id, capacity: output.capacity, address_hash: output.address_hash, target_block_number: cellbase.target_block_number, base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward, secondary_reward: cellbase.secondary_reward, status: output.status, consumed_tx_hash: consumed_tx_hash)
8282
end
8383
end
8484

@@ -119,7 +119,7 @@ def attributes_for_dao_input(nervos_dao_withdrawing_cell, is_phase2 = true)
119119

120120
def cellbase_display_inputs
121121
cellbase = Cellbase.new(block)
122-
[CkbUtils.hash_value_to_s({ id: nil, from_cellbase: true, capacity: nil, address_hash: nil, target_block_number: cellbase.target_block_number, generated_tx_hash: tx_hash })]
122+
[CkbUtils.hash_value_to_s(id: nil, from_cellbase: true, capacity: nil, address_hash: nil, target_block_number: cellbase.target_block_number, generated_tx_hash: tx_hash)]
123123
end
124124

125125
def recover_dead_cell

0 commit comments

Comments
 (0)