dir : core/blockchain.go
dc에 block, receipts, state 기록
if err := bc.writeBlockWithState(block, receipts, state); err != nil {
return NonStatTy, err
}
Reorganization이 필요한지 확인 - Reorg에 대한 정보는 해당 페이지 참조
currentBlock := bc.CurrentBlock()
reorg, err := bc.forker.ReorgNeeded(currentBlock.Header(), block.Header())
if err != nil {
return NonStatTy, err
}
재조직 되었다면 CanonStatTy, 그렇지 않다면 SideStatTy
if reorg {
if block.ParentHash() != currentBlock.Hash() {
if err := bc.reorg(currentBlock, block); err != nil {
return NonStatTy, err
}
}
status = CanonStatTy
} else {
status = SideStatTy
}
CanonStatTy라면 head block 교제
if status == CanonStatTy {
bc.writeHeadBlock(block)
}
bc.futureBlocks.Remove(block.Hash())
evt broadcast
if status == CanonStatTy {
bc.chainFeed.Send(ChainEvent{Block : block, Hash : block.HAsh(), Logs : logs})
if len(logs) > 0 {
bc.logsFeed.Send(logs)
}
if emitHeadEvent {
bc.chainHeadFeed.Send(ChainHeadEvent{ Block : block })
}
} else {
bc.chainSideFeed.Send(ChainSideEvent{Block : block})
}