MCPcopy Index your code
hub / github.com/chain/Core / BlockSoonWaiter

Method BlockSoonWaiter

protocol/protocol.go:186–205  ·  view source on GitHub ↗

BlockSoonWaiter returns a channel that waits for the block at the given height, but it is an error to wait for a block far in the future. WaitForBlockSoon will timeout if the context times out. To wait unconditionally, the caller should use WaitForBlock.

(ctx context.Context, height uint64)

Source from the content-addressed store, hash-verified

184// WaitForBlockSoon will timeout if the context times out.
185// To wait unconditionally, the caller should use WaitForBlock.
186func (c *Chain) BlockSoonWaiter(ctx context.Context, height uint64) <-chan error {
187 ch := make(chan error, 1)
188
189 go func() {
190 const slop = 3
191 if height > c.Height()+slop {
192 ch <- ErrTheDistantFuture
193 return
194 }
195
196 select {
197 case <-c.BlockWaiter(height):
198 ch <- nil
199 case <-ctx.Done():
200 ch <- ctx.Err()
201 }
202 }()
203
204 return ch
205}
206
207// BlockWaiter returns a channel that
208// waits for the block at the given height.

Callers 6

getBlockRPCMethod · 0.80
ValidateAndSignBlockMethod · 0.80

Calls 3

HeightMethod · 0.95
BlockWaiterMethod · 0.95
ErrMethod · 0.45