Skip to content

Set Rate Limit Admin #1101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 28, 2025
Merged

Set Rate Limit Admin #1101

merged 6 commits into from
Jul 28, 2025

Conversation

agusaldasoro
Copy link
Contributor

@agusaldasoro agusaldasoro commented Jul 23, 2025

Expose a message to modify the Rate Limit Admin in the Token Pool

@@ -187,6 +187,25 @@ impl BaseConfig {
self.can_accept_liquidity = allow;
Ok(())
}

pub fn set_rate_limit_admin(&mut self, new_rate_limit_admin: Pubkey) -> Result<()> {
require_keys_neq!(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this expected?

@agusaldasoro agusaldasoro requested a review from toblich July 23, 2025 15:38
@agusaldasoro agusaldasoro marked this pull request as ready for review July 23, 2025 15:38
@agusaldasoro agusaldasoro requested a review from a team as a code owner July 23, 2025 15:38
Copy link
Contributor

@toblich toblich left a comment

Choose a reason for hiding this comment

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

Could you please add a basic integration test for the new method?

],
bump,
)]
pub state: Account<'info, State>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also check the state version here (same comment applies to other contexts)

seeds = [POOL_STATE_SEED, mint.key().as_ref()],
bump,
)]
pub state: Account<'info, State>,
#[account(mut, constraint = authority.key() == state.config.owner)]
#[account(mut, constraint = authority.key() == state.config.owner @ CcipTokenPoolError::Unauthorized)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick

Suggested change
#[account(mut, constraint = authority.key() == state.config.owner @ CcipTokenPoolError::Unauthorized)]
#[account(mut, address = state.config.owner @ CcipTokenPoolError::Unauthorized)]

Same comment applies to other address checks

@@ -454,6 +454,56 @@ func TestTokenPool(t *testing.T) {
}
})

t.Run("Rate Limit Admin", func(t *testing.T) {
// set invalid rate limit admin
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix comment plz


testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ixRatesValid}, user, config.DefaultCommitment)

// set invalid rate limit admin
Copy link
Contributor

Choose a reason for hiding this comment

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

fix comment plz

).ValidateAndBuild()
require.NoError(t, err)

testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ixRateAdmin}, anotherAdmin, config.DefaultCommitment)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a suggestion: Consider packing some of these ixs in a single tx, so that it has fewer side-effects that can break other parallel tests. For example, maybe a single tx could do

  • Set user as RL admin
  • user sets low RL value
  • owner sets back original RL value (or slightly different one even)

Thus, as the tx is atomic, no concurrent test will face issues. And you can check in the intermediate events and in the final state that everything worked as expected.

Copy link

Metric feat/ratelimiter-admin main
Coverage 70.0% 69.6%

Copy link
Contributor

@toblich toblich left a comment

Choose a reason for hiding this comment

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

Approved, though if you have time to improve the test please do so (see comment)

}, poolConfig, p.Chain[config.EvmChainSelector], user.PublicKey(), solana.SystemProgramID).ValidateAndBuild()
require.NoError(t, err)

testutils.SendAndFailWith(ctx, t, solanaGoClient, []solana.Instruction{ixRateAdmin, ixRatesValid, ixRateAdmin2, ixRates}, user, config.DefaultCommitment, []string{"SetChainRateLimit"}, common.AddSigners(anotherAdmin))
Copy link
Contributor

Choose a reason for hiding this comment

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

That []string{"SetChainRateLimit"} only checks that that string is present in the logs, meaning that it will only check that the method was invoked. It won't enforce that that is the method that's failing, nor which of the two invocations you're making to is the one that fails.

I'll approve the PR anyway as I think this is minor compared to other priorities, but if you have the time to improve this check, please do so 🙂. You could check the events to make sure that the first call to that method did work for example.

)]
pub chain_config: Account<'info, ChainConfig>,

#[account(mut, constraint = authority.key() == state.config.owner @ CcipTokenPoolError::Unauthorized)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick

Suggested change
#[account(mut, constraint = authority.key() == state.config.owner @ CcipTokenPoolError::Unauthorized)]
#[account(mut, address = state.config.owner @ CcipTokenPoolError::Unauthorized)]

@@ -638,7 +673,21 @@ pub struct EditChainConfig<'info> {
)]
pub chain_config: Account<'info, ChainConfig>,

#[account(mut, constraint = authority.key() == state.config.owner || authority.key() == state.config.rate_limit_admin)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks a lot for finding this and fixing it 🫶

@agusaldasoro agusaldasoro enabled auto-merge July 28, 2025 09:10
@agusaldasoro agusaldasoro added this pull request to the merge queue Jul 28, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jul 28, 2025
* Set Rate Limit Admin

* Add tests for set rate limit admin

* Fix comment in test

* Send all instructions in the same transaction

* Validate State version

* Improve validation
Merged via the queue into main with commit 4fd7b48 Jul 28, 2025
53 of 54 checks passed
@mateusz-sekara mateusz-sekara deleted the feat/ratelimiter-admin branch July 28, 2025 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants