| 33 | } |
| 34 | |
| 35 | func (s *Store) ProcessBlocks(ctx context.Context, c *protocol.Chain, pinName string, cb func(context.Context, *legacy.Block) error) { |
| 36 | p := <-s.pin(pinName) |
| 37 | height := p.getHeight() |
| 38 | for { |
| 39 | select { |
| 40 | case <-ctx.Done(): // leader deposed |
| 41 | log.Error(ctx, ctx.Err()) |
| 42 | return |
| 43 | case <-c.BlockWaiter(height + 1): |
| 44 | select { |
| 45 | case <-ctx.Done(): |
| 46 | log.Error(ctx, ctx.Err()) |
| 47 | return |
| 48 | case p.sem <- true: |
| 49 | go p.processBlock(ctx, c, height+1, cb) |
| 50 | height++ |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func (s *Store) CreatePin(ctx context.Context, name string, height uint64) error { |
| 57 | s.mu.Lock() |