update_settings
Update window_size and/or range_signer in a Settings account
Updates the configuration of an existing Settings account. Only the current admin can call this instruction.
Signature
Section titled “Signature”pub fn update_settings( ctx: Context<UpdateSettings>, range_signer: Option<Pubkey>, window_size: Option<u64>,) -> Result<()>Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
range_signer | Option<Pubkey> | New trusted signer pubkey (optional) |
window_size | Option<u64> | New time window in seconds (optional) |
Accounts
Section titled “Accounts”| Account | Type | Description |
|---|---|---|
admin | Signer | Current admin of the Settings account |
settings | Account<Settings> | Settings PDA to update |
TypeScript
Section titled “TypeScript”import { buildUpdateSettingsInstruction } from './codama-ts-range-custom';
// Update both valuesconst instruction = await buildUpdateSettingsInstruction({ admin: walletPublicKey, rangeSigner: newBackendPublicKey, windowSize: 120n,});
// Update only window_sizeconst instruction2 = await buildUpdateSettingsInstruction({ admin: walletPublicKey, windowSize: 90n, // rangeSigner not provided - keeps current value});
// Update only range_signerconst instruction3 = await buildUpdateSettingsInstruction({ admin: walletPublicKey, rangeSigner: newBackendPublicKey, // windowSize not provided - keeps current value});Anchor
Section titled “Anchor”await program.methods .updateSettings( newRangeSigner, // Option<Pubkey> new BN(120) // Option<u64> ) .accounts({ admin: wallet.publicKey, settings: settingsPda, }) .rpc();Behavior
Section titled “Behavior”- Verifies caller is the current admin
- If
range_signerprovided, updates to new value - If
window_sizeprovided, updates to new value - Values not provided remain unchanged
Errors
Section titled “Errors”| Error | Cause |
|---|---|
| Constraint violation | Caller is not the admin |
| Account not found | Settings account doesn’t exist |
Use Cases
Section titled “Use Cases”Rotating Backend Keys
Section titled “Rotating Backend Keys”If your backend signing key is compromised or you want to rotate keys:
// Generate new backend keypairconst newRangeSigner = Keypair.generate();
const instruction = await buildUpdateSettingsInstruction({ admin: adminPublicKey, rangeSigner: newRangeSigner.publicKey,});
// After transaction confirms, update your backend to use newRangeSignerAdjusting Time Window
Section titled “Adjusting Time Window”If you’re seeing TimestampOutOfWindow errors due to network latency:
const instruction = await buildUpdateSettingsInstruction({ admin: adminPublicKey, windowSize: 120n, // Increase from 60 to 120 seconds});Emergency Key Rotation
Section titled “Emergency Key Rotation”If you suspect key compromise, rotate immediately:
async function emergencyKeyRotation( admin: Keypair, connection: Connection) { // Generate new keypair const newRangeSigner = Keypair.generate();
const instruction = await buildUpdateSettingsInstruction({ admin: admin.publicKey, rangeSigner: newRangeSigner.publicKey, });
// Use high priority for fast confirmation const transaction = new Transaction().add(instruction); transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash; transaction.feePayer = admin.publicKey; transaction.sign(admin);
const signature = await connection.sendRawTransaction( transaction.serialize(), { skipPreflight: false } );
console.log('Key rotated:', signature); console.log('New range_signer:', newRangeSigner.publicKey.toBase58());
// IMPORTANT: Immediately update backend with new keypair return newRangeSigner;}See Also
Section titled “See Also”- Settings Account - Understanding Settings
- initialize_settings - Creating Settings
- Security - Security best practices