Skip to content

Commit

Permalink
Remove common bootstrapper (#2297)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Nov 27, 2023
1 parent 9ad213c commit 590ad12
Show file tree
Hide file tree
Showing 22 changed files with 482 additions and 723 deletions.
57 changes: 24 additions & 33 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,21 +878,17 @@ func (m *manager) createAvalancheChain(

// create bootstrap gear
bootstrapCfg := smbootstrap.Config{
Config: common.Config{
Ctx: ctx,
Beacons: vdrs,
SampleK: sampleK,
Alpha: bootstrapWeight/2 + 1, // must be > 50%
StartupTracker: startupTracker,
Sender: snowmanMessageSender,
BootstrapTracker: sb,
Timer: h,
AncestorsMaxContainersReceived: m.BootstrapAncestorsMaxContainersReceived,
SharedCfg: &common.SharedConfig{},
},
AllGetsServer: snowGetHandler,
Blocked: blockBlocker,
VM: vmWrappingProposerVM,
AllGetsServer: snowGetHandler,
Ctx: ctx,
Beacons: vdrs,
SampleK: sampleK,
StartupTracker: startupTracker,
Sender: snowmanMessageSender,
BootstrapTracker: sb,
Timer: h,
AncestorsMaxContainersReceived: m.BootstrapAncestorsMaxContainersReceived,
Blocked: blockBlocker,
VM: vmWrappingProposerVM,
}
var snowmanBootstrapper common.BootstrapableEngine
snowmanBootstrapper, err = smbootstrap.New(
Expand Down Expand Up @@ -1224,24 +1220,19 @@ func (m *manager) createSnowmanChain(
}

// create bootstrap gear
alpha := bootstrapWeight/2 + 1 // must be > 50%
bootstrapCfg := smbootstrap.Config{
Config: common.Config{
Ctx: ctx,
Beacons: beacons,
SampleK: sampleK,
StartupTracker: startupTracker,
Alpha: alpha,
Sender: messageSender,
BootstrapTracker: sb,
Timer: h,
AncestorsMaxContainersReceived: m.BootstrapAncestorsMaxContainersReceived,
SharedCfg: &common.SharedConfig{},
},
AllGetsServer: snowGetHandler,
Blocked: blocked,
VM: vm,
Bootstrapped: bootstrapFunc,
AllGetsServer: snowGetHandler,
Ctx: ctx,
Beacons: beacons,
SampleK: sampleK,
StartupTracker: startupTracker,
Sender: messageSender,
BootstrapTracker: sb,
Timer: h,
AncestorsMaxContainersReceived: m.BootstrapAncestorsMaxContainersReceived,
Blocked: blocked,
VM: vm,
Bootstrapped: bootstrapFunc,
}
var bootstrapper common.BootstrapableEngine
bootstrapper, err = smbootstrap.New(
Expand All @@ -1264,7 +1255,7 @@ func (m *manager) createSnowmanChain(
messageSender,
beacons,
sampleK,
alpha,
bootstrapWeight/2+1, // must be > 50%
m.StateSyncBeacons,
vm,
)
Expand Down
16 changes: 10 additions & 6 deletions snow/engine/avalanche/bootstrap/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const (
stripeWidth = 5
cacheSize = 100000

// statusUpdateFrequency is how many containers should be processed between
// logs
statusUpdateFrequency = 5000

// maxOutstandingGetAncestorsRequests is the maximum number of GetAncestors
// sent but not yet responded to/failed
maxOutstandingGetAncestorsRequests = 10
Expand Down Expand Up @@ -333,7 +337,7 @@ func (b *bootstrapper) Start(ctx context.Context, startReqID uint32) error {
return fmt.Errorf("failed to get linearization status: %w", err)
}
if linearized {
return b.ForceAccepted(ctx, nil)
return b.startSyncing(ctx, nil)
}

// If a stop vertex is well known, accept that.
Expand All @@ -342,7 +346,7 @@ func (b *bootstrapper) Start(ctx context.Context, startReqID uint32) error {
zap.Stringer("vtxID", b.Config.StopVertexID),
)

return b.ForceAccepted(ctx, []ids.ID{b.Config.StopVertexID})
return b.startSyncing(ctx, []ids.ID{b.Config.StopVertexID})
}

// If a stop vertex isn't well known, treat the current state as the final
Expand All @@ -364,7 +368,7 @@ func (b *bootstrapper) Start(ctx context.Context, startReqID uint32) error {
zap.Stringer("vtxID", stopVertexID),
)

return b.ForceAccepted(ctx, nil)
return b.startSyncing(ctx, nil)
}

func (b *bootstrapper) HealthCheck(ctx context.Context) (interface{}, error) {
Expand Down Expand Up @@ -490,7 +494,7 @@ func (b *bootstrapper) process(ctx context.Context, vtxs ...avalanche.Vertex) er
b.numFetchedVts.Inc()

verticesFetchedSoFar := b.VtxBlocked.Jobs.PendingJobs()
if verticesFetchedSoFar%common.StatusUpdateFrequency == 0 { // Periodically print progress
if verticesFetchedSoFar%statusUpdateFrequency == 0 { // Periodically print progress
b.Ctx.Log.Info("fetched vertices",
zap.Uint64("numVerticesFetched", verticesFetchedSoFar),
)
Expand Down Expand Up @@ -536,8 +540,8 @@ func (b *bootstrapper) process(ctx context.Context, vtxs ...avalanche.Vertex) er
return b.fetch(ctx)
}

// ForceAccepted starts bootstrapping. Process the vertices in [accepterContainerIDs].
func (b *bootstrapper) ForceAccepted(ctx context.Context, acceptedContainerIDs []ids.ID) error {
// startSyncing starts bootstrapping. Process the vertices in [accepterContainerIDs].
func (b *bootstrapper) startSyncing(ctx context.Context, acceptedContainerIDs []ids.ID) error {
pendingContainerIDs := b.VtxBlocked.MissingIDs()
// Append the list of accepted container IDs to pendingContainerIDs to ensure
// we iterate over every container that must be traversed.
Expand Down
14 changes: 1 addition & 13 deletions snow/engine/common/bootstrapable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@

package common

import (
"context"

"github.com/ava-labs/avalanchego/ids"
)
import "context"

type BootstrapableEngine interface {
Bootstrapable
Engine
}

// Bootstrapable defines the functionality required to support bootstrapping
type Bootstrapable interface {
// Force the provided containers to be accepted. Only returns fatal errors
// if they occur.
ForceAccepted(ctx context.Context, acceptedContainerIDs []ids.ID) error

// Clear removes all containers to be processed upon bootstrapping
Clear(ctx context.Context) error
Expand Down
208 changes: 0 additions & 208 deletions snow/engine/common/bootstrapper.go

This file was deleted.

Loading

0 comments on commit 590ad12

Please sign in to comment.