Skip to content

Commit

Permalink
fixing skipped block handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Jan 16, 2024
1 parent 4659287 commit 8de6cb0
Show file tree
Hide file tree
Showing 7 changed files with 222,998 additions and 493 deletions.
19 changes: 16 additions & 3 deletions block/fetcher/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
"github.com/gagliardetto/solana-go/rpc/jsonrpc"
bin "github.com/streamingfast/binary"
pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1"
pbsol "github.com/streamingfast/firehose-solana/pb/sf/solana/type/v1"
Expand Down Expand Up @@ -78,10 +79,22 @@ func (f *RPCFetcher) Fetch(ctx context.Context, requestedSlot uint64) (out *pbbs
break
}

blockResult, err := f.rpcClient.GetBlockWithOpts(ctx, requestedSlot, GetBlockOpts)
if err != nil {
return nil, fmt.Errorf("fetching block %d: %w", requestedSlot, err)
//todo : if err is a type skipped block error here, requestedSlot will be requestSlot + 1 while it's returning no skipped error
var blockResult *rpc.GetBlockResult

for {
blockResult, err = f.rpcClient.GetBlockWithOpts(ctx, requestedSlot, GetBlockOpts)
if err != nil {
rpcErr := err.(*jsonrpc.RPCError)
if rpcErr != nil && rpcErr.Code == -32009 {
requestedSlot += 1
continue
}
return nil, fmt.Errorf("fetching block %d: %w", requestedSlot, err)
}
break
}

block, err := blockFromBlockResult(requestedSlot, f.latestConfirmedSlot, f.latestFinalizedSlot, blockResult)
if err != nil {
return nil, fmt.Errorf("decoding block %d: %w", requestedSlot, err)
Expand Down
15 changes: 15 additions & 0 deletions block/fetcher/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@ package fetcher

import (
"bytes"
"context"
"testing"
"time"

"go.uber.org/zap"

"github.com/gagliardetto/solana-go/rpc"
bin "github.com/streamingfast/binary"
"github.com/test-go/testify/require"
)

func Test_ToPBTransaction(t *testing.T) {
ctx := context.Background()
rpcClient := rpc.New("https://icy-old-cloud.solana-mainnet.quiknode.pro/75682dc94e37cd35ccf9351e11669dcabc3ad176/")
f := NewRPC(rpcClient, 0*time.Millisecond, 0*time.Millisecond, zap.NewNop())
_, err := f.Fetch(ctx, 240816644)

require.NoError(t, err)

}

func Test_TrxErrorEncode(t *testing.T) {
cases := []struct {
name string
Expand Down
Loading

0 comments on commit 8de6cb0

Please sign in to comment.