Remove feature switch for demoting sysvar write locks (#18373)

This commit is contained in:
Justin Starry
2021-07-06 16:22:22 -05:00
committed by GitHub
parent 5dd399dafa
commit 100fabf469
12 changed files with 71 additions and 186 deletions

View File

@ -391,7 +391,7 @@ impl Message {
self.program_position(i).is_some()
}
pub fn is_writable(&self, i: usize, demote_sysvar_write_locks: bool) -> bool {
pub fn is_writable(&self, i: usize) -> bool {
(i < (self.header.num_required_signatures - self.header.num_readonly_signed_accounts)
as usize
|| (i >= self.header.num_required_signatures as usize
@ -399,8 +399,7 @@ impl Message {
- self.header.num_readonly_unsigned_accounts as usize))
&& !{
let key = self.account_keys[i];
demote_sysvar_write_locks
&& (sysvar::is_sysvar_id(&key) || BUILTIN_PROGRAMS_KEYS.contains(&key))
sysvar::is_sysvar_id(&key) || BUILTIN_PROGRAMS_KEYS.contains(&key)
}
}
@ -408,14 +407,11 @@ impl Message {
i < self.header.num_required_signatures as usize
}
pub fn get_account_keys_by_lock_type(
&self,
demote_sysvar_write_locks: bool,
) -> (Vec<&Pubkey>, Vec<&Pubkey>) {
pub fn get_account_keys_by_lock_type(&self) -> (Vec<&Pubkey>, Vec<&Pubkey>) {
let mut writable_keys = vec![];
let mut readonly_keys = vec![];
for (i, key) in self.account_keys.iter().enumerate() {
if self.is_writable(i, demote_sysvar_write_locks) {
if self.is_writable(i) {
writable_keys.push(key);
} else {
readonly_keys.push(key);
@ -437,7 +433,7 @@ impl Message {
// 35..67 - program_id
// 67..69 - data len - u16
// 69..data_len - data
pub fn serialize_instructions(&self, demote_sysvar_write_locks: bool) -> Vec<u8> {
pub fn serialize_instructions(&self) -> Vec<u8> {
// 64 bytes is a reasonable guess, calculating exactly is slower in benchmarks
let mut data = Vec::with_capacity(self.instructions.len() * (32 * 2));
append_u16(&mut data, self.instructions.len() as u16);
@ -452,7 +448,7 @@ impl Message {
for account_index in &instruction.accounts {
let account_index = *account_index as usize;
let is_signer = self.is_signer(account_index);
let is_writable = self.is_writable(account_index, demote_sysvar_write_locks);
let is_writable = self.is_writable(account_index);
let mut meta_byte = 0;
if is_signer {
meta_byte |= 1 << Self::IS_SIGNER_BIT;
@ -891,13 +887,12 @@ mod tests {
recent_blockhash: Hash::default(),
instructions: vec![],
};
let demote_sysvar_write_locks = true;
assert!(message.is_writable(0, demote_sysvar_write_locks));
assert!(!message.is_writable(1, demote_sysvar_write_locks));
assert!(!message.is_writable(2, demote_sysvar_write_locks));
assert!(message.is_writable(3, demote_sysvar_write_locks));
assert!(message.is_writable(4, demote_sysvar_write_locks));
assert!(!message.is_writable(5, demote_sysvar_write_locks));
assert!(message.is_writable(0));
assert!(!message.is_writable(1));
assert!(!message.is_writable(2));
assert!(message.is_writable(3));
assert!(message.is_writable(4));
assert!(!message.is_writable(5));
}
#[test]
@ -925,9 +920,7 @@ mod tests {
Some(&id1),
);
assert_eq!(
message.get_account_keys_by_lock_type(
true, // demote_sysvar_write_locks
),
message.get_account_keys_by_lock_type(),
(vec![&id1, &id0], vec![&id3, &id2, &program_id])
);
}
@ -957,9 +950,7 @@ mod tests {
];
let message = Message::new(&instructions, Some(&id1));
let serialized = message.serialize_instructions(
true, // demote_sysvar_write_locks
);
let serialized = message.serialize_instructions();
for (i, instruction) in instructions.iter().enumerate() {
assert_eq!(
Message::deserialize_instruction(i, &serialized).unwrap(),
@ -980,9 +971,7 @@ mod tests {
];
let message = Message::new(&instructions, Some(&id1));
let serialized = message.serialize_instructions(
true, // demote_sysvar_write_locks
);
let serialized = message.serialize_instructions();
assert_eq!(
Message::deserialize_instruction(instructions.len(), &serialized).unwrap_err(),
SanitizeError::IndexOutOfBounds,