diff options
Diffstat (limited to 'les/backend.go')
-rw-r--r-- | les/backend.go | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/les/backend.go b/les/backend.go index 3cab75f33..d656cf41f 100644 --- a/les/backend.go +++ b/les/backend.go @@ -18,7 +18,6 @@ package les import ( - "errors" "fmt" "time" @@ -74,15 +73,19 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) { if err != nil { return nil, err } - if err := eth.SetupGenesisBlock(&chainDb, config); err != nil { - return nil, err + chainConfig, genesisHash, genesisErr := core.SetupGenesisBlock(chainDb, config.Genesis) + if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat { + return nil, genesisErr } + log.Info("Initialised chain configuration", "config", chainConfig) + odr := NewLesOdr(chainDb) relay := NewLesTxRelay() eth := &LightEthereum{ odr: odr, relay: relay, chainDb: chainDb, + chainConfig: chainConfig, eventMux: ctx.EventMux, accountManager: ctx.AccountManager, pow: eth.CreatePoW(ctx, config), @@ -91,17 +94,16 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) { solcPath: config.SolcPath, } - if config.ChainConfig == nil { - return nil, errors.New("missing chain config") - } - eth.chainConfig = config.ChainConfig eth.blockchain, err = light.NewLightChain(odr, eth.chainConfig, eth.pow, eth.eventMux) if err != nil { - if err == core.ErrNoGenesis { - return nil, fmt.Errorf(`Genesis block not found. Please supply a genesis block with the "--genesis /path/to/file" argument`) - } return nil, err } + // Rewind the chain in case of an incompatible config upgrade. + if compat, ok := genesisErr.(*params.ConfigCompatError); ok { + log.Warn("Rewinding chain to upgrade configuration", "err", compat) + eth.blockchain.SetHead(compat.RewindTo) + core.WriteChainConfig(chainDb, genesisHash, chainConfig) + } eth.txPool = light.NewTxPool(eth.chainConfig, eth.eventMux, eth.blockchain, eth.relay) if eth.protocolManager, err = NewProtocolManager(eth.chainConfig, config.LightMode, config.NetworkId, eth.eventMux, eth.pow, eth.blockchain, nil, chainDb, odr, relay); err != nil { |