Skip to content

Commit

Permalink
Fix two builder regressions (#1791)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsachiherman authored Nov 18, 2024
1 parent 0d38ed8 commit e6ceba9
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ func (vm *VM) Initialize(
) error {
vm.DataDir = filepath.Join(snowCtx.ChainDataDir, vmDataDir)
vm.snowCtx = snowCtx
// Init channels before initializing other structs
vm.toEngine = toEngine
vm.pkBytes = bls.PublicKeyToCompressedBytes(vm.snowCtx.PublicKey)
vm.seenValidityWindow = make(chan struct{})
vm.ready = make(chan struct{})
Expand Down Expand Up @@ -252,24 +254,6 @@ func (vm *VM) Initialize(
ctx, span := vm.tracer.Start(ctx, "VM.Initialize")
defer span.End()

txGossiper, err := gossiper.NewProposer(vm, gossiper.DefaultProposerConfig())
if err != nil {
return err
}

// Set defaults
vm.gossiper = txGossiper
options := &Options{}
for _, Option := range vm.options {
config := vm.config.ServiceConfig[Option.Namespace]
opt, err := Option.optionFunc(vm, config)
if err != nil {
return err
}
opt.apply(options)
}
vm.applyOptions(options)

// Setup profiler
if cfg := vm.config.ContinuousProfilerConfig; cfg.Enabled {
vm.profiler = profiler.NewContinuous(cfg.Dir, cfg.Freq, cfg.MaxNumFiles)
Expand Down Expand Up @@ -305,9 +289,6 @@ func (vm *VM) Initialize(
// core to signature verification.
vm.authVerifiers = workers.NewParallel(vm.config.AuthVerificationCores, 100) // TODO: make job backlog a const

// Init channels before initializing other structs
vm.toEngine = toEngine

vm.parsedBlocks = &avacache.LRU[ids.ID, *StatefulBlock]{Size: vm.config.ParsedBlockCacheSize}
vm.verifiedBlocks = make(map[ids.ID]*StatefulBlock)
vm.acceptedBlocksByID, err = cache.NewFIFO[ids.ID, *StatefulBlock](vm.config.AcceptedBlockWindowCache)
Expand All @@ -331,13 +312,20 @@ func (vm *VM) Initialize(

vm.mempool = mempool.New[*chain.Transaction](vm.tracer, vm.config.MempoolSize, vm.config.MempoolSponsorSize)

vm.builder = builder.NewTime(toEngine, snowCtx.Log, vm.mempool, func(t int64) (int64, int64, error) {
blk, err := vm.GetStatefulBlock(context.TODO(), vm.preferred)
// Set defaults
options := &Options{}
for _, Option := range vm.options {
config := vm.config.ServiceConfig[Option.Namespace]
opt, err := Option.optionFunc(vm, config)
if err != nil {
return 0, 0, err
return err
}
return blk.Tmstmp, vm.ruleFactory.GetRules(t).GetMinBlockGap(), nil
})
opt.apply(options)
}
err = vm.applyOptions(options)
if err != nil {
return fmt.Errorf("failed to apply options : %w", err)
}

vm.chainTimeValidityWindow = chain.NewTimeValidityWindow(vm.snowCtx.Log, vm.tracer, vm)
registerer := prometheus.NewRegistry()
Expand Down Expand Up @@ -535,15 +523,30 @@ func (vm *VM) Initialize(
return nil
}

func (vm *VM) applyOptions(o *Options) {
func (vm *VM) applyOptions(o *Options) error {
vm.blockSubscriptionFactories = o.blockSubscriptionFactories
vm.vmAPIHandlerFactories = o.vmAPIHandlerFactories
if o.builder {
vm.builder = builder.NewManual(vm.toEngine, vm.snowCtx.Log)
} else {
vm.builder = builder.NewTime(vm.toEngine, vm.snowCtx.Log, vm.mempool, func(t int64) (int64, int64, error) {
blk, err := vm.GetStatefulBlock(context.TODO(), vm.preferred)
if err != nil {
return 0, 0, err
}
return blk.Tmstmp, vm.ruleFactory.GetRules(t).GetMinBlockGap(), nil
})
}
if o.gossiper {
vm.gossiper = gossiper.NewManual(vm)
} else {
txGossiper, err := gossiper.NewProposer(vm, gossiper.DefaultProposerConfig())
if err != nil {
return err
}
vm.gossiper = txGossiper
}
return nil
}

func (vm *VM) checkActivity(ctx context.Context) {
Expand Down

0 comments on commit e6ceba9

Please sign in to comment.