Remove demote_program_write_locks feature (#19877)
* Remove demote_program_write_locks feature * Update test
This commit is contained in:
@@ -14,8 +14,6 @@ fn make_instructions() -> Vec<Instruction> {
|
||||
vec![inst; 4]
|
||||
}
|
||||
|
||||
const DEMOTE_PROGRAM_WRITE_LOCKS: bool = true;
|
||||
|
||||
#[bench]
|
||||
fn bench_bincode_instruction_serialize(b: &mut Bencher) {
|
||||
let instructions = make_instructions();
|
||||
@@ -29,7 +27,7 @@ fn bench_manual_instruction_serialize(b: &mut Bencher) {
|
||||
let instructions = make_instructions();
|
||||
let message = Message::new(&instructions, None);
|
||||
b.iter(|| {
|
||||
test::black_box(message.serialize_instructions(DEMOTE_PROGRAM_WRITE_LOCKS));
|
||||
test::black_box(message.serialize_instructions());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -46,7 +44,7 @@ fn bench_bincode_instruction_deserialize(b: &mut Bencher) {
|
||||
fn bench_manual_instruction_deserialize(b: &mut Bencher) {
|
||||
let instructions = make_instructions();
|
||||
let message = Message::new(&instructions, None);
|
||||
let serialized = message.serialize_instructions(DEMOTE_PROGRAM_WRITE_LOCKS);
|
||||
let serialized = message.serialize_instructions();
|
||||
b.iter(|| {
|
||||
for i in 0..instructions.len() {
|
||||
test::black_box(instructions::load_instruction_at(i, &serialized).unwrap());
|
||||
@@ -58,7 +56,7 @@ fn bench_manual_instruction_deserialize(b: &mut Bencher) {
|
||||
fn bench_manual_instruction_deserialize_single(b: &mut Bencher) {
|
||||
let instructions = make_instructions();
|
||||
let message = Message::new(&instructions, None);
|
||||
let serialized = message.serialize_instructions(DEMOTE_PROGRAM_WRITE_LOCKS);
|
||||
let serialized = message.serialize_instructions();
|
||||
b.iter(|| {
|
||||
test::black_box(instructions::load_instruction_at(3, &serialized).unwrap());
|
||||
});
|
||||
|
@@ -373,7 +373,7 @@ impl Message {
|
||||
self.program_position(i).is_some()
|
||||
}
|
||||
|
||||
pub fn is_writable(&self, i: usize, demote_program_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
|
||||
@@ -383,21 +383,18 @@ impl Message {
|
||||
let key = self.account_keys[i];
|
||||
sysvar::is_sysvar_id(&key) || BUILTIN_PROGRAMS_KEYS.contains(&key)
|
||||
}
|
||||
&& !(demote_program_write_locks && self.is_key_called_as_program(i))
|
||||
&& !self.is_key_called_as_program(i)
|
||||
}
|
||||
|
||||
pub fn is_signer(&self, i: usize) -> bool {
|
||||
i < self.header.num_required_signatures as usize
|
||||
}
|
||||
|
||||
pub fn get_account_keys_by_lock_type(
|
||||
&self,
|
||||
demote_program_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_program_write_locks) {
|
||||
if self.is_writable(i) {
|
||||
writable_keys.push(key);
|
||||
} else {
|
||||
readonly_keys.push(key);
|
||||
@@ -419,7 +416,7 @@ impl Message {
|
||||
// 35..67 - program_id
|
||||
// 67..69 - data len - u16
|
||||
// 69..data_len - data
|
||||
pub fn serialize_instructions(&self, demote_program_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);
|
||||
@@ -434,7 +431,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_program_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;
|
||||
@@ -873,13 +870,12 @@ mod tests {
|
||||
recent_blockhash: Hash::default(),
|
||||
instructions: vec![],
|
||||
};
|
||||
let demote_program_write_locks = true;
|
||||
assert!(message.is_writable(0, demote_program_write_locks));
|
||||
assert!(!message.is_writable(1, demote_program_write_locks));
|
||||
assert!(!message.is_writable(2, demote_program_write_locks));
|
||||
assert!(message.is_writable(3, demote_program_write_locks));
|
||||
assert!(message.is_writable(4, demote_program_write_locks));
|
||||
assert!(!message.is_writable(5, demote_program_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]
|
||||
@@ -907,7 +903,7 @@ mod tests {
|
||||
Some(&id1),
|
||||
);
|
||||
assert_eq!(
|
||||
message.get_account_keys_by_lock_type(/*demote_program_write_locks=*/ true),
|
||||
message.get_account_keys_by_lock_type(),
|
||||
(vec![&id1, &id0], vec![&id3, &id2, &program_id])
|
||||
);
|
||||
}
|
||||
@@ -937,7 +933,7 @@ mod tests {
|
||||
];
|
||||
|
||||
let message = Message::new(&instructions, Some(&id1));
|
||||
let serialized = message.serialize_instructions(/*demote_program_write_locks=*/ true);
|
||||
let serialized = message.serialize_instructions();
|
||||
for (i, instruction) in instructions.iter().enumerate() {
|
||||
assert_eq!(
|
||||
Message::deserialize_instruction(i, &serialized).unwrap(),
|
||||
@@ -958,7 +954,7 @@ mod tests {
|
||||
];
|
||||
|
||||
let message = Message::new(&instructions, Some(&id1));
|
||||
let serialized = message.serialize_instructions(/*demote_program_write_locks=*/ true);
|
||||
let serialized = message.serialize_instructions();
|
||||
assert_eq!(
|
||||
Message::deserialize_instruction(instructions.len(), &serialized).unwrap_err(),
|
||||
SanitizeError::IndexOutOfBounds,
|
||||
|
@@ -166,10 +166,6 @@ pub mod spl_token_v2_set_authority_fix {
|
||||
solana_sdk::declare_id!("FToKNBYyiF4ky9s8WsmLBXHCht17Ek7RXaLZGHzzQhJ1");
|
||||
}
|
||||
|
||||
pub mod demote_program_write_locks {
|
||||
solana_sdk::declare_id!("3E3jV7v9VcdJL8iYZUMax9DiDno8j7EWUVbhm9RtShj2");
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
/// Map of feature identifiers to user-visible description
|
||||
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
|
||||
@@ -210,7 +206,6 @@ lazy_static! {
|
||||
(libsecp256k1_0_5_upgrade_enabled::id(), "upgrade libsecp256k1 to v0.5.0"),
|
||||
(merge_nonce_error_into_system_error::id(), "merge NonceError into SystemError"),
|
||||
(spl_token_v2_set_authority_fix::id(), "spl-token set_authority fix"),
|
||||
(demote_program_write_locks::id(), "demote program write locks to readonly #19593"),
|
||||
/*************** ADD NEW FEATURES HERE ***************/
|
||||
]
|
||||
.iter()
|
||||
|
Reference in New Issue
Block a user