Skip to content

Commit 28cbba2

Browse files
committed
fix rpc cannot find tx occasionally
1 parent 3553545 commit 28cbba2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

apps/solana/rpc.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func (c *Client) RPCGetMultipleAccounts(ctx context.Context, accounts solana.Pub
176176
}
177177

178178
func (c *Client) RPCGetTransaction(ctx context.Context, signature string) (*rpc.GetTransactionResult, error) {
179+
retry := 5
179180
for {
180181
r, err := c.rpcClient.GetTransaction(ctx,
181182
solana.MustSignatureFromBase58(signature),
@@ -189,10 +190,15 @@ func (c *Client) RPCGetTransaction(ctx context.Context, signature string) (*rpc.
189190
time.Sleep(1 * time.Second)
190191
continue
191192
}
192-
if err != nil || r.Meta == nil {
193-
if strings.Contains(err.Error(), "not found") {
193+
if err != nil && strings.Contains(err.Error(), "not found") {
194+
if retry == 0 {
194195
return nil, nil
195196
}
197+
retry -= 1
198+
time.Sleep(1 * time.Second)
199+
continue
200+
}
201+
if err != nil || r.Meta == nil {
196202
return nil, fmt.Errorf("solana.GetTransaction(%s) => %v", signature, err)
197203
}
198204

0 commit comments

Comments
 (0)