Skip to content
10 changes: 10 additions & 0 deletions chain_capabilities/solana/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const (
SuffixLogTriggerFilterID = "-solana-log-trigger"
defaultQueryLimit = 1000
defaultMaxPagesPerPoll = 5
maxSubkeysPerTrigger = 4
maxComparersPerSubkey = 10
)

func publicKeyFromBytes(fieldName string, raw []byte) (solana.PublicKey, error) {
Expand Down Expand Up @@ -64,11 +66,16 @@ func validateFilterConfig(config *solanacappb.FilterLogTriggerRequest) error {
return fmt.Errorf("event idl json cannot be empty")
}

if len(config.Subkeys) > maxSubkeysPerTrigger {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subkeys are 2d slices. Should we enforce a limit for both dimensions?

return fmt.Errorf("too many subkeys: maximum supported is %d, got %d", maxSubkeysPerTrigger, len(config.Subkeys))
}

if config.CpiFilterConfig != nil {
if _, err := publicKeyFromBytes("cpi filter destination address", config.CpiFilterConfig.DestAddress); err != nil {
return err
}
}

return validateSubkeyComparers(config.Subkeys)
}

Expand All @@ -77,6 +84,9 @@ func validateSubkeyComparers(subkeys []*solanacappb.SubkeyConfig) error {
if subkey == nil || len(subkey.Comparers) < 2 {
continue
}
if len(subkey.Comparers) > maxComparersPerSubkey {
return fmt.Errorf("subkey %d has too many comparers: %d limit: %d", i, len(subkey.Comparers), maxComparersPerSubkey)
}

eqValues := make(map[string]struct{})
for _, comp := range subkey.Comparers {
Expand Down
18 changes: 18 additions & 0 deletions chain_capabilities/solana/trigger/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ func TestRegisterLogTrigger(t *testing.T) {
mockSolana.AssertExpectations(t)
})

t.Run("too many subkeys", func(t *testing.T) {
service, mockSolana := setupTest(t)
request := createTestRequest()
request.Subkeys = []*solanacappb.SubkeyConfig{
{Path: []string{"f1"}},
{Path: []string{"f2"}},
{Path: []string{"f3"}},
{Path: []string{"f4"}},
{Path: []string{"f5"}},
}

_, err := service.RegisterLogTrigger(ctx, testTriggerID, testRequestMetadata(), request)

require.NotNil(t, err)
assert.Contains(t, err.Error(), "maximum supported is 4")
mockSolana.AssertExpectations(t)
})

t.Run("register log tracking fails", func(t *testing.T) {
service, mockSolana := setupTest(t)
request := createTestRequest()
Expand Down
Loading