diff --git a/statefulsyncer/configuration.go b/statefulsyncer/configuration.go index d0f294a7..de1e37a0 100644 --- a/statefulsyncer/configuration.go +++ b/statefulsyncer/configuration.go @@ -59,7 +59,7 @@ func WithPruneSleepTime(sleepTime int) Option { } // WithSeenConcurrency overrides the number of concurrent -// invocations of BlockSeen we will make. We default +// invocations of BlockSeen we will handle. We default // to the value of runtime.NumCPU(). func WithSeenConcurrency(concurrency int64) Option { return func(s *StatefulSyncer) { diff --git a/statefulsyncer/stateful_syncer.go b/statefulsyncer/stateful_syncer.go index da8a8579..9056645c 100644 --- a/statefulsyncer/stateful_syncer.go +++ b/statefulsyncer/stateful_syncer.go @@ -68,9 +68,8 @@ type StatefulSyncer struct { adjustmentWindow int64 pruneSleepTime time.Duration - // SeenSemaphore controls how many concurrent - // invocations we make to the SeenBlock function - // in the handler. + // SeenSemaphore limits how many executions of + // BlockSeen occur concurrently. seenSemaphore *semaphore.Weighted seenSemaphoreSize int64 } diff --git a/storage/modules/block_storage.go b/storage/modules/block_storage.go index 910d35c6..42e519e0 100644 --- a/storage/modules/block_storage.go +++ b/storage/modules/block_storage.go @@ -634,7 +634,8 @@ func (b *BlockStorage) SeeBlock( ctx context.Context, block *types.Block, ) error { - transaction := b.db.WriteTransaction(ctx, block.BlockIdentifier.Hash, true) + _, key := getBlockHashKey(block.BlockIdentifier.Hash) + transaction := b.db.WriteTransaction(ctx, string(key), true) defer transaction.Discard(ctx) // Store all transactions in order and check for duplicates diff --git a/syncer/syncer.go b/syncer/syncer.go index 4b1d3f29..c4067233 100644 --- a/syncer/syncer.go +++ b/syncer/syncer.go @@ -555,7 +555,14 @@ func (s *Syncer) syncRange( s.concurrency = startingConcurrency s.goalConcurrency = s.concurrency - // Spawn syncing goroutines + // We create a separate derivative context here instead of + // replacing the provided ctx because the context returned + // by errgroup.WithContext is canceled as soon as Wait returns. + // If this canceled context is passed to a handler or helper, + // it can have unintended consequences (some functions + // return immediately if the context is canceled). + // + // Source: https://godoc.org/golang.org/x/sync/errgroup g, pipelineCtx := errgroup.WithContext(ctx) g.Go(func() error { return s.addBlockIndices(pipelineCtx, blockIndices, s.nextIndex, endIndex)