Use a separate context when updating the NSC (#16209)

There is a race condition introduced in #16149 in which the update to
the NSC happens with a context that may be cancelled by the time the
routine is called. This PR starts a new context with a deadline to call
the routine in the background.

fixes #16205
This commit is contained in:
Potuz
2026-01-02 13:43:34 -03:00
committed by GitHub
parent d4ea8fafd6
commit c2527c82cd
2 changed files with 10 additions and 1 deletions

View File

@@ -106,7 +106,12 @@ func (s *Service) postBlockProcess(cfg *postBlockProcessConfig) error {
// Pre-Fulu the caches are updated when computing the payload attributes
if cfg.postState.Version() >= version.Fulu {
go s.updateCachesPostBlockProcessing(cfg)
go func() {
ctx, cancel := context.WithTimeout(s.ctx, slotDeadline)
defer cancel()
cfg.ctx = ctx
s.updateCachesPostBlockProcessing(cfg)
}()
}
return nil
}
@@ -929,6 +934,8 @@ func (s *Service) lateBlockTasks(ctx context.Context) {
// After Fulu, we can update the caches asynchronously after sending FCU to the engine
defer func() {
go func() {
ctx, cancel := context.WithTimeout(s.ctx, slotDeadline)
defer cancel()
lastState.CopyAllTries()
if err := transition.UpdateNextSlotCache(ctx, lastRoot, lastState); err != nil {
log.WithError(err).Debug("Could not update next slot state cache")

View File

@@ -0,0 +1,2 @@
### Changed
- Use a separate context when updating the slot cache.