主页 > tp钱包和imtoken钱包通用吗 > 【区块链| 智能合约】以太坊源码(11)
【区块链| 智能合约】以太坊源码(11)
tp钱包和imtoken钱包通用吗 2023-07-21 05:10:46
前面几节一直在分析以太坊的通信协议以太坊智能链ethg,如何广播,如何同步,如何下载。 本节讲以太坊的核心模块Blockchain,也就是以太坊的区块链。
1. 区块链初始化
当以太坊服务初始化 func init() 时,它会调用 core.SetupGenesisBlock 来加载创世块。 顾名思义,创世块是以太坊区块链中的第一个块以太坊智能链ethg,编号为0。随后调用
stack, backend := makeFullNode(ctx) utils.RegisterEthService(stack, &cfg.Eth)
backend, err := eth.New(stack, cfg)
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit)
加载以太坊区块链。
// NewBlockChain returns a fully initialised block chain using information
// available in the database. It initialises the default Ethereum Validator
// and Processor. NewBlockChain使用数据库中可用的信息返回完全初始化的区块链。它初始化默认的以太坊验证器和处理器。
func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine,