Skip to content

Commit

Permalink
fix all inbound solana signature query to avoid version0 error
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Dec 5, 2024
1 parent 9d6e9a6 commit 6bcb507
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
8 changes: 3 additions & 5 deletions zetaclient/chains/solana/observer/inbound_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"

"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
"github.com/pkg/errors"

solanarpc "github.com/zeta-chain/node/zetaclient/chains/solana/rpc"
zctx "github.com/zeta-chain/node/zetaclient/context"
clienttypes "github.com/zeta-chain/node/zetaclient/types"
)
Expand Down Expand Up @@ -61,10 +61,8 @@ func (ob *Observer) ProcessInboundTrackers(ctx context.Context) error {
// process inbound trackers
for _, tracker := range trackers {
signature := solana.MustSignatureFromBase58(tracker.TxHash)
txResult, err := ob.solClient.GetTransaction(ctx, signature, &rpc.GetTransactionOpts{
Commitment: rpc.CommitmentFinalized,
})
if err != nil {
txResult, err := solanarpc.GetTransaction(ctx, ob.solClient, signature)
if err != nil && !errors.Is(err, solanarpc.ErrUnsupportedTxVersion) {

Check warning on line 65 in zetaclient/chains/solana/observer/inbound_tracker.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/observer/inbound_tracker.go#L64-L65

Added lines #L64 - L65 were not covered by tests
return errors.Wrapf(err, "error GetTransaction for chain %d sig %s", chainID, signature)
}

Expand Down
9 changes: 3 additions & 6 deletions zetaclient/chains/solana/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,8 @@ func GetSignaturesForAddressUntil(
var allSignatures []*rpc.TransactionSignature

// make sure that the 'untilSig' exists to prevent undefined behavior on GetSignaturesForAddressWithOpts
_, err := client.GetTransaction(
ctx,
untilSig,
&rpc.GetTransactionOpts{Commitment: rpc.CommitmentFinalized},
)
if err != nil {
_, err := GetTransaction(ctx, client, untilSig)
if err != nil && !errors.Is(err, ErrUnsupportedTxVersion) {

Check warning on line 89 in zetaclient/chains/solana/rpc/rpc.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/rpc/rpc.go#L88-L89

Added lines #L88 - L89 were not covered by tests
return nil, errors.Wrapf(err, "error GetTransaction for untilSig %s", untilSig)
}

Expand Down Expand Up @@ -137,6 +133,7 @@ func GetTransaction(
sig solana.Signature,
) (*rpc.GetTransactionResult, error) {
txResult, err := client.GetTransaction(ctx, sig, &rpc.GetTransactionOpts{
Commitment: rpc.CommitmentFinalized,

Check warning on line 136 in zetaclient/chains/solana/rpc/rpc.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/rpc/rpc.go#L136

Added line #L136 was not covered by tests
MaxSupportedTransactionVersion: &rpc.MaxSupportedTransactionVersion0,
})

Expand Down
19 changes: 19 additions & 0 deletions zetaclient/chains/solana/rpc/rpc_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"github.com/gagliardetto/solana-go"
solanarpc "github.com/gagliardetto/solana-go/rpc"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/zetaclient/chains/solana/rpc"
"github.com/zeta-chain/node/zetaclient/common"
"github.com/zeta-chain/node/zetaclient/testutils"
)

// Test_SolanaRPCLive is a phony test to run all live tests
Expand All @@ -20,6 +22,7 @@ func Test_SolanaRPCLive(t *testing.T) {
LiveTest_GetTransactionWithVersion(t)
LiveTest_GetFirstSignatureForAddress(t)
LiveTest_GetSignaturesForAddressUntil(t)
LiveTest_GetSignaturesForAddressUntil_Version0(t)
LiveTest_CheckRPCStatus(t)
}

Expand Down Expand Up @@ -80,6 +83,22 @@ func LiveTest_GetSignaturesForAddressUntil(t *testing.T) {
}
}

func LiveTest_GetSignaturesForAddressUntil_Version0(t *testing.T) {
// create a Solana devnet RPC client
client := solanarpc.New(solanarpc.DevNet_RPC)

// program address and signature of version "0"
chain := chains.SolanaDevnet
address := solana.MustPublicKeyFromBase58(testutils.GatewayAddresses[chain.ChainId])
untilSig := solana.MustSignatureFromBase58(
"39fSgD2nteJCQRQP3ynqEcDMZAFSETCbfb61AUqLU6y7qbzSJL5rn2DHU2oM35zsf94Feb5C5QWd5L5UnncBsAay",
)

// should get all signatures for the address until a signature of version "0" successfully
_, err := rpc.GetSignaturesForAddressUntil(context.Background(), client, address, untilSig, 100)
require.NoError(t, err)
}

func LiveTest_CheckRPCStatus(t *testing.T) {
// create a Solana devnet RPC client
client := solanarpc.New(solanarpc.DevNet_RPC)
Expand Down

0 comments on commit 6bcb507

Please sign in to comment.