diff --git a/integration-tests/relayinterface/lookups_test.go b/integration-tests/relayinterface/lookups_test.go index 1b91dc8df..0313e1632 100644 --- a/integration-tests/relayinterface/lookups_test.go +++ b/integration-tests/relayinterface/lookups_test.go @@ -126,7 +126,7 @@ func TestAccountLookups(t *testing.T) { } func TestPDALookups(t *testing.T) { - programID := solana.SystemProgramID + programID := chainwriter.GetRandomPubKey(t) t.Run("PDALookup resolves valid PDA with constant address seeds", func(t *testing.T) { seed := chainwriter.GetRandomPubKey(t) diff --git a/pkg/solana/chainwriter/chain_writer_test.go b/pkg/solana/chainwriter/chain_writer_test.go index ef7b399af..4b18566de 100644 --- a/pkg/solana/chainwriter/chain_writer_test.go +++ b/pkg/solana/chainwriter/chain_writer_test.go @@ -273,7 +273,7 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) { Name: "DataAccountPDA", PublicKey: chainwriter.AccountConstant{Name: "WriteTest", Address: programID.String()}, Seeds: []chainwriter.Lookup{ - // extract seed2 for PDA lookup + // extract seed1 for PDA lookup chainwriter.AccountLookup{Name: "seed1", Location: "seed1"}, }, IsSigner: true, diff --git a/pkg/solana/chainwriter/lookups.go b/pkg/solana/chainwriter/lookups.go index 9f1071c46..06903c1fa 100644 --- a/pkg/solana/chainwriter/lookups.go +++ b/pkg/solana/chainwriter/lookups.go @@ -52,10 +52,6 @@ type InternalField struct { Location string } -type ValueLookup struct { - Location string -} - // LookupTables represents a list of lookup tables that are used to derive addresses for a program. type LookupTables struct { DerivedLookupTables []DerivedLookupTable @@ -212,7 +208,6 @@ func decodeBorshIntoType(data []byte, typ reflect.Type) (interface{}, error) { // It handles both AddressSeeds (which are public keys) and ValueSeeds (which are byte arrays from input args). func getSeedBytes(ctx context.Context, lookup PDALookups, args any, derivedTableMap map[string]map[string][]*solana.AccountMeta, reader client.Reader) ([][]byte, error) { var seedBytes [][]byte - maxSeedLength := 32 for _, seed := range lookup.Seeds { if lookupSeed, ok := seed.(AccountLookup); ok { @@ -223,8 +218,8 @@ func getSeedBytes(ctx context.Context, lookup PDALookups, args any, derivedTable } // validate seed length for _, b := range bytes { - if len(b) > maxSeedLength { - return nil, fmt.Errorf("seed byte array exceeds maximum length of %d: got %d bytes", maxSeedLength, len(b)) + if len(b) > solana.MaxSeedLength { + return nil, fmt.Errorf("seed byte array exceeds maximum length of %d: got %d bytes", solana.MaxSeedLength, len(b)) } seedBytes = append(seedBytes, b) } @@ -247,7 +242,7 @@ func getSeedBytes(ctx context.Context, lookup PDALookups, args any, derivedTable // generatePDAs generates program-derived addresses (PDAs) from public keys and seeds. func generatePDAs(publicKeys []*solana.AccountMeta, seeds [][]byte, lookup PDALookups) ([]*solana.AccountMeta, error) { - if len(seeds) > 16 { + if len(seeds) > solana.MaxSeeds { return nil, fmt.Errorf("seed maximum exceeded: %d", len(seeds)) } var addresses []*solana.AccountMeta @@ -271,6 +266,8 @@ func (s *SolanaChainWriterService) ResolveLookupTables(ctx context.Context, args // Read derived lookup tables for _, derivedLookup := range lookupTables.DerivedLookupTables { + // Load the lookup table - note: This could be multiple tables if the lookup is a PDALookups that resovles to more + // than one address lookupTableMap, _, err := s.LoadTable(ctx, args, derivedLookup, s.reader, derivedTableMap) if err != nil { return nil, nil, fmt.Errorf("error loading derived lookup table: %w", err) @@ -312,12 +309,13 @@ func (s *SolanaChainWriterService) LoadTable(ctx context.Context, args any, rlt return nil, nil, fmt.Errorf("error resolving addresses for lookup table: %w", err) } + // Nested map in case the lookup table resolves to multiple addresses resultMap := make(map[string]map[string][]*solana.AccountMeta) var lookupTableMetas []*solana.AccountMeta // Iterate over each address of the lookup table for _, addressMeta := range lookupTableAddresses { - // Fetch account info + // Read the full list of addresses from the lookup table addresses, err := getLookupTableAddresses(ctx, reader, addressMeta.PublicKey) if err != nil { return nil, nil, fmt.Errorf("error fetching lookup table address: %w", err)