Skip to content

Commit 0222394

Browse files
authored
cli: Add deactivate_feature flag to solana-test-validator config in Anchor.toml (otter-sec#2872)
1 parent b9dfa5b commit 0222394

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The minor version will be incremented upon a breaking change and the patch versi
3939
- cli: Add priority fees to idl commands ([#2845](https://github.com/coral-xyz/anchor/pull/2845)).
4040
- ts: Add `prepend` option to MethodBuilder `preInstructions` method ([#2863](https://github.com/coral-xyz/anchor/pull/2863)).
4141
- lang: Add `declare_program!` macro ([#2857](https://github.com/coral-xyz/anchor/pull/2857)).
42+
- cli: Add `deactivate_feature` flag to `solana-test-validator` config in Anchor.toml ([#2872](https://github.com/coral-xyz/anchor/pull/2872)).
4243

4344
### Fixes
4445

cli/src/config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,9 @@ pub struct _Validator {
10591059
// Warp the ledger to WARP_SLOT after starting the validator.
10601060
#[serde(skip_serializing_if = "Option::is_none")]
10611061
pub warp_slot: Option<String>,
1062+
// Deactivate one or more features.
1063+
#[serde(skip_serializing_if = "Option::is_none")]
1064+
pub deactivate_feature: Option<Vec<String>>,
10621065
}
10631066

10641067
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
@@ -1094,6 +1097,8 @@ pub struct Validator {
10941097
pub ticks_per_slot: Option<u16>,
10951098
#[serde(skip_serializing_if = "Option::is_none")]
10961099
pub warp_slot: Option<String>,
1100+
#[serde(skip_serializing_if = "Option::is_none")]
1101+
pub deactivate_feature: Option<Vec<String>>,
10971102
}
10981103

10991104
impl From<_Validator> for Validator {
@@ -1122,6 +1127,7 @@ impl From<_Validator> for Validator {
11221127
slots_per_epoch: _validator.slots_per_epoch,
11231128
ticks_per_slot: _validator.ticks_per_slot,
11241129
warp_slot: _validator.warp_slot,
1130+
deactivate_feature: _validator.deactivate_feature,
11251131
}
11261132
}
11271133
}
@@ -1146,6 +1152,7 @@ impl From<Validator> for _Validator {
11461152
slots_per_epoch: validator.slots_per_epoch,
11471153
ticks_per_slot: validator.ticks_per_slot,
11481154
warp_slot: validator.warp_slot,
1155+
deactivate_feature: validator.deactivate_feature,
11491156
}
11501157
}
11511158
}
@@ -1235,6 +1242,9 @@ impl Merge for _Validator {
12351242
.or_else(|| self.slots_per_epoch.take()),
12361243
ticks_per_slot: other.ticks_per_slot.or_else(|| self.ticks_per_slot.take()),
12371244
warp_slot: other.warp_slot.or_else(|| self.warp_slot.take()),
1245+
deactivate_feature: other
1246+
.deactivate_feature
1247+
.or_else(|| self.deactivate_feature.take()),
12381248
};
12391249
}
12401250
}

cli/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,6 +3338,24 @@ fn validator_flags(
33383338
flags.push("--clone".to_string());
33393339
flags.push(pubkey.to_string());
33403340
}
3341+
} else if key == "deactivate_feature" {
3342+
// Verify that the feature flags are valid pubkeys
3343+
let pubkeys_result: Result<Vec<Pubkey>, _> = value
3344+
.as_array()
3345+
.unwrap()
3346+
.iter()
3347+
.map(|entry| {
3348+
let feature_flag = entry.as_str().unwrap();
3349+
Pubkey::from_str(feature_flag).map_err(|_| {
3350+
anyhow!("Invalid pubkey (feature flag) {}", feature_flag)
3351+
})
3352+
})
3353+
.collect();
3354+
let features = pubkeys_result?;
3355+
for feature in features {
3356+
flags.push("--deactivate-feature".to_string());
3357+
flags.push(feature.to_string());
3358+
}
33413359
} else {
33423360
// Remaining validator flags are non-array types
33433361
flags.push(format!("--{}", key.replace('_', "-")));

0 commit comments

Comments
 (0)