Skip to content

Commit

Permalink
Revert "Added location parsing for IsWritable and IsSignable on Accou…
Browse files Browse the repository at this point in the history
…ntLookups"

This reverts commit d9cec54.
  • Loading branch information
silaslenihan committed Jan 17, 2025
1 parent ad753cd commit e5474e3
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 120 deletions.
186 changes: 75 additions & 111 deletions pkg/solana/chainwriter/ccip_example_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ func TestConfig() {
routerProgramAddress := "4Nn9dsYBcSTzRbK9hg9kzCUdrCSkMZq1UR6Vw1Tkaf6B"
commonAddressesLookupTable := solana.MustPublicKeyFromBase58("4Nn9dsYBcSTzRbK9hg9kzCUdrCSkMZq1UR6Vw1Tkaf6H")

computeBudgetProgramAddress := solana.ComputeBudget.String()
sysvarInstructionsAddress := solana.SysVarInstructionsPubkey.String()

fromAddress := "4Nn9dsYBcSTzRbK9hg9kzCUdrCSkMZq1UR6Vw1Tkaf6J"
Expand All @@ -31,24 +30,27 @@ func TestConfig() {
// d. Lastly, the lookup table is used to compress the size of the transaction.
DerivedLookupTables: []DerivedLookupTable{
{
Name: "RegistryTokenState",
Name: "PoolLookupTable",
// In this case, the user configured the lookup table accounts to use a PDALookup, which
// generates a list of one of more PDA accounts based on the input parameters. Specifically,
// there will be multiple PDA accounts if there are multiple addresses in the message, otherwise,
// there will only be one PDA account to read from. The PDA account corresponds to the lookup table.
// there will only be one PDA account to read from. The internal field LookupTable
// of the PDA account corresponds to the pool lookup table(s).
Accounts: PDALookups{
Name: "RegistryTokenState",
Name: "TokenAdminRegistry",
PublicKey: AccountConstant{
Address: routerProgramAddress,
IsSigner: false,
IsWritable: false,
Address: routerProgramAddress,
},
// Seeds would be used if the user needed to look up addresses to use as seeds, which isn't the case here.
Seeds: []Seed{
{Dynamic: AccountLookup{Location: "Message.TokenAmounts.DestTokenAddress"}},
{Static: []byte("token_admin_registry")},
{Dynamic: AccountLookup{Location: "AbstractReport.Message.TokenAmounts.DestTokenAddress"}},
},
IsSigner: false,
IsWritable: false,
InternalField: InternalField{
Location: "LookupTable",
},
},
},
},
Expand Down Expand Up @@ -91,10 +93,10 @@ func TestConfig() {
PublicKey: AccountConstant{
Address: routerProgramAddress,
},
// Similar to the RegistryTokenState above, the user is looking up PDA accounts based on the dest tokens.
// Similar to the TokenAdminRegistry above, the user is looking up PDA accounts based on the dest tokens.
Seeds: []Seed{
{Static: []byte("source_chain_state")},
{Dynamic: AccountLookup{Location: "Message.Header.DestChainSelector"}},
{Dynamic: AccountLookup{Location: "AbstractReport.Message.Header.DestChainSelector"}},
},
IsSigner: false,
IsWritable: false,
Expand All @@ -108,10 +110,10 @@ func TestConfig() {
},
Seeds: []Seed{
{Static: []byte("commit_report")},
{Dynamic: AccountLookup{Location: "Message.Header.DestChainSelector"}},
{Dynamic: AccountLookup{Location: "AbstractReport.Message.Header.DestChainSelector"}},
{Dynamic: AccountLookup{
// The seed is the merkle root of the report, as passed into the input params.
Location: "Info.MerkleRoot",
Location: "Info.MerkleRootChain.MerkleRoot",
}},
},
IsSigner: false,
Expand Down Expand Up @@ -147,7 +149,7 @@ func TestConfig() {
AccountConstant{
Name: "SysvarInstructions",
Address: sysvarInstructionsAddress,
IsSigner: true,
IsSigner: false,
IsWritable: false,
},
// Static PDA lookup
Expand All @@ -164,8 +166,10 @@ func TestConfig() {
},
// User specified accounts - formatted as AccountMeta
AccountLookup{
Name: "UserAccounts",
Location: "Message.ExtraArgs.Accounts",
Name: "UserAccounts",
Location: "AbstractReport.Message.ExtraArgs.Accounts",
IsWritable: MetaBool{BitmapLocation: "AbstractReport.Message.ExtraArgs.AccountsBitmap"},
IsSigner: MetaBool{Value: false},
},
// PDA Account Lookup - Based on an account lookup and an address lookup
PDALookups{
Expand All @@ -175,92 +179,78 @@ func TestConfig() {
},
Seeds: []Seed{
// receiver address
{Dynamic: AccountLookup{Location: "Message.Receiver"}},
// token program
{Dynamic: AccountLookup{Location: "AbstractReport.Message.Receiver"}},
// token programs
{Dynamic: AccountsFromLookupTable{
LookupTableName: "RegistryTokenState",
IncludeIndexes: []int{5},
LookupTableName: "PoolLookupTable",
IncludeIndexes: []int{6},
}},
// mint
{Dynamic: AccountLookup{Location: "Message.TokenAmounts.DestTokenAddress"}},
},
},
PDALookups{
Name: "PerChainTokenConfig",
// PublicKey is a constant account in this case, not a lookup.
PublicKey: AccountConstant{
Address: routerProgramAddress,
},
// Similar to the RegistryTokenState above, the user is looking up PDA accounts based on the dest tokens.
Seeds: []Seed{
{Dynamic: AccountLookup{Location: "Message.TokenAmounts.DestTokenAddress"}},
{Dynamic: AccountLookup{Location: "Message.Header.DestChainSelector"}},
{Dynamic: AccountLookup{Location: "AbstractReport.Message.TokenAmounts.DestTokenAddress"}},
},
IsSigner: false,
IsWritable: false,
},
// Lookup Table content - Get the accounts from the derived lookup table above
AccountsFromLookupTable{
LookupTableName: "RegistryTokenState",
IncludeIndexes: []int{}, // If left empty, all addresses will be included. Otherwise, only the specified indexes will be included.
},
// PDA Lookup for the RegistryTokenConfig.
// PDA Account Lookup - Based on an account lookup and an address lookup
PDALookups{
Name: "RegistryTokenConfig",
// constant public key
Name: "SenderAssociatedTokenAccount",
PublicKey: AccountConstant{
Address: routerProgramAddress,
IsSigner: false,
IsWritable: false,
Address: solana.SPLAssociatedTokenAccountProgramID.String(),
},
// The seed, once again, is the destination token address.
Seeds: []Seed{
{Dynamic: AccountLookup{Location: "Message.TokenAmounts.DestTokenAddress"}},
// sender address
{Static: []byte(fromAddress)},
// token program
{Dynamic: AccountsFromLookupTable{
LookupTableName: "PoolLookupTable",
IncludeIndexes: []int{6},
}},
// mint
{Dynamic: AccountLookup{Location: "AbstractReport.Message.TokenAmounts.DestTokenAddress"}},
},
IsSigner: false,
IsWritable: false,
},
// PDA lookup to get UserNoncePerChain
PDALookups{
Name: "UserNoncePerChain",
// The public key is a constant Router address.
Name: "PerChainTokenConfig",
// PublicKey is a constant account in this case, not a lookup.
PublicKey: AccountConstant{
Address: routerProgramAddress,
IsSigner: false,
IsWritable: false,
Address: routerProgramAddress,
},
// In this case, the user configured multiple seeds. These will be used in conjunction
// with the public key to generate one or multiple PDA accounts.
// Similar to the TokenAdminRegistry above, the user is looking up PDA accounts based on the dest tokens.
Seeds: []Seed{
{Dynamic: AccountLookup{Location: "Message.Receiver"}},
{Dynamic: AccountLookup{Location: "Message.Header.DestChainSelector"}},
{Static: []byte("ccip_tokenpool_billing")},
{Dynamic: AccountLookup{Location: "AbstractReport.Message.Header.DestChainSelector"}},
{Dynamic: AccountLookup{Location: "AbstractReport.Message.TokenAmounts.DestTokenAddress"}},
},
IsSigner: false,
IsWritable: false,
},
// PDA lokoup with constant seed
PDALookups{
Name: "CPISigner",
PublicKey: AccountConstant{
Address: routerProgramAddress,
IsSigner: false,
IsWritable: false,
Name: "PoolChainConfig",
// constant public key
PublicKey: AccountsFromLookupTable{
LookupTableName: "PoolLookupTable",
// PoolProgram
IncludeIndexes: []int{2},
},
Seeds: []Seed{
{Static: []byte("external_token_pools_signer")},
{Static: []byte("ccip_tokenpool_chainconfig")},
{Dynamic: AccountLookup{Location: "AbstractReport.Message.Header.DestChainSelector"}},
{Dynamic: AccountLookup{Location: "AbstractReport.Message.TokenAmounts.DestTokenAddress"}},
},
IsSigner: false,
IsWritable: false,
},
// Account constant
AccountConstant{
Name: "ComputeBudgetProgram",
Address: computeBudgetProgramAddress,
IsSigner: true,
IsWritable: false,
// Lookup Table content - Get the accounts from the derived lookup table(s)
AccountsFromLookupTable{
LookupTableName: "PoolLookupTable",
IncludeIndexes: []int{}, // If left empty, all addresses will be included. Otherwise, only the specified indexes will be included.
},
},
// TBD where this will be in the report
// This will be appended to every error message
DebugIDLocation: "Message.MessageID",
DebugIDLocation: "AbstractReport.Message.MessageID",
}

commitConfig := MethodConfig{
Expand Down Expand Up @@ -291,48 +281,13 @@ func TestConfig() {
PublicKey: AccountConstant{
Address: routerProgramAddress,
},
// Similar to the RegistryTokenState above, the user is looking up PDA accounts based on the dest tokens.
// Similar to the TokenAdminRegistry above, the user is looking up PDA accounts based on the dest tokens.
Seeds: []Seed{
{Static: []byte("source_chain_state")},
{Dynamic: AccountLookup{Location: "MerkleRoot.DestChainSelector"}},
},
IsSigner: false,
IsWritable: false,
},
// Account constant
AccountConstant{
Name: "RouterProgram",
Address: routerProgramAddress,
IsSigner: false,
IsWritable: false,
},
// PDA lokoup with constant seed
PDALookups{
Name: "RouterAccountConfig",
PublicKey: AccountConstant{
Address: routerProgramAddress,
IsSigner: false,
IsWritable: false,
},
Seeds: []Seed{
{Static: []byte("config")},
},
IsSigner: false,
IsWritable: false,
},
// PDA lokoup with constant seed
PDALookups{
Name: "RouterAccountState",
PublicKey: AccountConstant{
Address: routerProgramAddress,
IsSigner: false,
IsWritable: false,
},
Seeds: []Seed{
{Static: []byte("state")},
},
IsSigner: false,
IsWritable: false,
IsWritable: true,
},
// PDA lookup to get the Router Report Accounts.
PDALookups{
Expand All @@ -344,26 +299,35 @@ func TestConfig() {
IsWritable: false,
},
Seeds: []Seed{
{Static: []byte("commit_report")},
{Dynamic: AccountLookup{Location: "AbstractReport.MerkleRoots.ChainSel"}},
{Dynamic: AccountLookup{
// The seed is the merkle root of the report, as passed into the input params.
Location: "args.MerkleRoots",
Location: "AbstractReport.MerkleRoots.MerkleRoot",
}},
},
IsSigner: false,
IsWritable: false,
},
// Account constant
// feePayer/authority address
AccountConstant{
Name: "ComputeBudgetProgram",
Address: computeBudgetProgramAddress,
Name: "Authority",
Address: fromAddress,
IsSigner: true,
IsWritable: true,
},
// Account constant
AccountConstant{
Name: "SystemProgram",
Address: solana.SystemProgramID.String(),
IsSigner: false,
IsWritable: false,
},
// Account constant
AccountConstant{
Name: "SysvarInstructions",
Address: sysvarInstructionsAddress,
IsSigner: true,
IsSigner: false,
IsWritable: false,
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/solana/chainwriter/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GetValuesAtLocation(args any, location string) ([][]byte, error) {
binary.LittleEndian.PutUint64(buf, num)
vals = append(vals, buf)
} else {
return nil, fmt.Errorf("invalid value format at path: %s, type: %s", location, reflect.TypeOf(value).String())
return nil, fmt.Errorf("invalid value format at path: %s", location)
}
}

Expand Down
10 changes: 2 additions & 8 deletions pkg/solana/chainwriter/lookups.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,10 @@ func (ac AccountConstant) Resolve(_ context.Context, _ any, _ map[string]map[str
}, nil
}

func (al AccountLookup) Resolve(
_ context.Context,
args any,
_ map[string]map[string][]*solana.AccountMeta,
_ client.Reader,
) ([]*solana.AccountMeta, error) {
func (al AccountLookup) Resolve(_ context.Context, args any, _ map[string]map[string][]*solana.AccountMeta, _ client.Reader) ([]*solana.AccountMeta, error) {
derivedValues, err := GetValuesAtLocation(args, al.Location)
if err != nil {
return nil, fmt.Errorf("error getting account from '%s': %w", al.Location, err)
return nil, fmt.Errorf("error getting account from lookup: %w", err)
}

var metas []*solana.AccountMeta
Expand All @@ -131,7 +126,6 @@ func (al AccountLookup) Resolve(
IsWritable: isWritable,
})
}

return metas, nil
}

Expand Down

0 comments on commit e5474e3

Please sign in to comment.