dir : core/blockchain.go
td (total difficulty) 확인
ptd := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
// ...
externTd := new(big.Int).Add(block.Difficulty(), ptd)
canonical block 여부에 무관하게 block을 db에 기록
block의 모든 요소는 자동으로 기록되며, 여기에 block batch가 사용됨
blockBatch := bc.dc.NewBatch()
rawdb.WriteTd(blockBatch, block.Hash(), block.NumberU64(), externTd)
rawdb.WriteBlock(blockBatch, block)
rawdb.WriteReceipts(blockBatch, block.Hash(), block.NumberU64(), receipts)
rawdb.WritePreimages(blockBatch, state.Preimages())
if err := blockBatch.Write(); err != nil {
log.Crit("Failed to write block into disk", "err", err)
}
캐싱된 모든 state change를 메모리 db에 commit
root, err := state.Commit(bc.chainconfig.IsEIP158(block.Number()))
이 후 gc를 실행하고 nil을 반환