Skip to content

Commit

Permalink
feat: process the genesis block correctly when there is no local block
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Aug 1, 2019
1 parent 62164f9 commit ec43466
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/models/ckb_sync/node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module CkbSync
class NodeDataProcessor
def call
local_tip_block = Block.recent.first
target_block = CkbSync::Api.instance.get_block_by_number(local_tip_block.number + 1)
target_block_number = local_tip_block.present? ? local_tip_block.number + 1 : 0
target_block = CkbSync::Api.instance.get_block_by_number(target_block_number)
return if target_block.blank?

if !forked?(target_block, local_tip_block)
Expand Down Expand Up @@ -36,6 +37,8 @@ def process_block(node_block)
private

def forked?(target_block, local_tip_block)
return false if local_tip_block.blank?

target_block.header.parent_hash != local_tip_block.block_hash
end

Expand Down

0 comments on commit ec43466

Please sign in to comment.