Commit 992bff72 authored by EvanJRichard's avatar EvanJRichard

Don't discard the err in client.BlockByNumber, and also, check ctx.Done.

parent 5de8206d
...@@ -99,6 +99,8 @@ func WaitForBlock(number *big.Int, client *ethclient.Client, timeout time.Durati ...@@ -99,6 +99,8 @@ func WaitForBlock(number *big.Int, client *ethclient.Client, timeout time.Durati
} }
case err := <-headSub.Err(): case err := <-headSub.Err():
return nil, fmt.Errorf("error in head subscription: %w", err) return nil, fmt.Errorf("error in head subscription: %w", err)
case <-ctx.Done():
return nil, ctx.Err()
} }
} }
} }
...@@ -122,14 +124,22 @@ func waitForBlockTag(number *big.Int, client *ethclient.Client, timeout time.Dur ...@@ -122,14 +124,22 @@ func waitForBlockTag(number *big.Int, client *ethclient.Client, timeout time.Dur
tagBigInt := big.NewInt(tag.Int64()) tagBigInt := big.NewInt(tag.Int64())
// Use a loop to periodically check the block number.
for range ticker.C { for range ticker.C {
block, _ := client.BlockByNumber(ctx, tagBigInt) block, err := client.BlockByNumber(ctx, tagBigInt)
if block != nil && block.NumberU64() >= number.Uint64() { if err != nil {
return client.BlockByNumber(ctx, number) return nil, err
} }
if block.NumberU64() >= number.Uint64() {
return client.BlockByNumber(ctx, number)
} }
// Context deadline exceeded or some other error. select {
case <-ctx.Done():
return nil, ctx.Err() return nil, ctx.Err()
default:
// Continue polling
}
}
return nil, ctx.Err() // In case the loop somehow exits without meeting the condition
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment