From 6f31b059ddbb5bbdd3bf6dde1ea1466094f0c09c Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Wed, 15 Mar 2023 14:22:44 -0400 Subject: [PATCH] Remove anonymous function calling handler.Consensus (#2736) Co-authored-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> --- chains/manager.go | 56 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/chains/manager.go b/chains/manager.go index b1c0007a49a5..bd8641dbc680 100644 --- a/chains/manager.go +++ b/chains/manager.go @@ -715,32 +715,6 @@ func (m *manager) createAvalancheChain( return nil, fmt.Errorf("couldn't initialize avalanche base message handler: %w", err) } - // create bootstrap gear - bootstrapperConfig := avbootstrap.Config{ - Config: commonCfg, - AllGetsServer: avaGetHandler, - VtxBlocked: vtxBlocker, - TxBlocked: txBlocker, - Manager: vtxManager, - VM: vm, - } - bootstrapper, err := avbootstrap.New( - context.TODO(), - bootstrapperConfig, - func(ctx context.Context, lastReqID uint32) error { - return handler.Consensus().Start(ctx, lastReqID+1) - }, - ) - if err != nil { - return nil, fmt.Errorf("error initializing avalanche bootstrapper: %w", err) - } - - if m.TracingEnabled { - bootstrapper = common.TraceBootstrapableEngine(bootstrapper, m.Tracer) - } - - handler.SetBootstrapper(bootstrapper) - var consensus avcon.Consensus = &avcon.Topological{} if m.TracingEnabled { consensus = avcon.Trace(consensus, m.Tracer) @@ -748,11 +722,11 @@ func (m *manager) createAvalancheChain( // create engine gear engineConfig := aveng.Config{ - Ctx: bootstrapperConfig.Ctx, + Ctx: ctx, AllGetsServer: avaGetHandler, - VM: bootstrapperConfig.VM, + VM: vm, Manager: vtxManager, - Sender: bootstrapperConfig.Sender, + Sender: messageSender, Validators: vdrs, Params: consensusParams, Consensus: consensus, @@ -768,6 +742,30 @@ func (m *manager) createAvalancheChain( handler.SetConsensus(engine) + // create bootstrap gear + bootstrapperConfig := avbootstrap.Config{ + Config: commonCfg, + AllGetsServer: avaGetHandler, + VtxBlocked: vtxBlocker, + TxBlocked: txBlocker, + Manager: vtxManager, + VM: vm, + } + bootstrapper, err := avbootstrap.New( + context.TODO(), + bootstrapperConfig, + engine.Start, + ) + if err != nil { + return nil, fmt.Errorf("error initializing avalanche bootstrapper: %w", err) + } + + if m.TracingEnabled { + bootstrapper = common.TraceBootstrapableEngine(bootstrapper, m.Tracer) + } + + handler.SetBootstrapper(bootstrapper) + // Register health check for this chain chainAlias := m.PrimaryAliasOrDefault(ctx.ChainID)