Skip to content

Commit

Permalink
block unavailable handling
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Jan 31, 2024
1 parent e638db0 commit b006b5c
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions block/fetcher/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"math"
"time"

"github.com/streamingfast/derr"

"golang.org/x/exp/slices"

"github.com/gagliardetto/solana-go"
Expand Down Expand Up @@ -105,23 +107,33 @@ func (f *RPCFetcher) Fetch(ctx context.Context, requestedSlot uint64) (out *pbbs
return block, false, nil
}

func (f *RPCFetcher) fetch(ctx context.Context, requestedSlot uint64) (out *rpc.GetBlockResult, skip bool, err error) {
func (f *RPCFetcher) fetch(ctx context.Context, requestedSlot uint64) (*rpc.GetBlockResult, bool, error) {
currentSlot := requestedSlot
var out *rpc.GetBlockResult
skipped := false
//f.logger.Info("getting block", zap.Uint64("block_num", currentSlot))
blockResult, err := f.rpcClient.GetBlockWithOpts(ctx, requestedSlot, GetBlockOpts)

if err != nil {
var rpcErr *jsonrpc.RPCError
if errors.As(err, &rpcErr) {
if rpcErr.Code == -32009 || rpcErr.Code == -32007 {
f.logger.Info("block was skipped", zap.Uint64("block_num", currentSlot))
currentSlot += 1
return nil, true, nil
err := derr.Retry(math.MaxFloat32, func(ctx context.Context) error {

Check failure on line 115 in block/fetcher/rpc.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

cannot use math.MaxFloat32 (untyped float constant 3.40282e+38) as uint64 value in argument to derr.Retry (truncated)
var innerErr error
out, innerErr = f.rpcClient.GetBlockWithOpts(ctx, requestedSlot, GetBlockOpts)

if innerErr != nil {
var rpcErr *jsonrpc.RPCError
if errors.As(innerErr, &rpcErr) {
if rpcErr.Code == -32004 {
f.logger.Warn("block not available. Retrying same block", zap.Uint64("block_num", currentSlot))
return innerErr
}
if rpcErr.Code == -32009 || rpcErr.Code == -32007 {
f.logger.Info("block was skipped", zap.Uint64("block_num", currentSlot))
currentSlot += 1
skipped = true
return nil
}
}
}
return nil, false, fmt.Errorf("fetching block %d: %w", currentSlot, err)
}
return blockResult, false, nil
return nil
})
return out, skipped, err
}

func blockFromBlockResult(slot uint64, finalizedSlot uint64, result *rpc.GetBlockResult) (*pbbstream.Block, error) {
Expand Down

0 comments on commit b006b5c

Please sign in to comment.