Cleanup - require_static_program_ids_in_transaction (#31767)
require_static_program_ids_in_transaction
This commit is contained in:
parent
989e61318b
commit
ee2c2ef6c7
|
@ -178,7 +178,6 @@ fn simulate_transaction(
|
|||
MessageHash::Compute,
|
||||
Some(false), // is_simple_vote_tx
|
||||
bank,
|
||||
true, // require_static_program_ids
|
||||
) {
|
||||
Err(err) => {
|
||||
return BanksTransactionResultWithSimulation {
|
||||
|
@ -330,7 +329,6 @@ impl Banks for BanksServer {
|
|||
MessageHash::Compute,
|
||||
Some(false), // is_simple_vote_tx
|
||||
bank.as_ref(),
|
||||
true, // require_static_program_ids
|
||||
) {
|
||||
Ok(tx) => tx,
|
||||
Err(err) => return Some(Err(err)),
|
||||
|
|
|
@ -1697,7 +1697,6 @@ mod tests {
|
|||
MessageHash::Compute,
|
||||
Some(false),
|
||||
bank.as_ref(),
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -157,7 +157,6 @@ mod tests {
|
|||
MessageHash::Compute,
|
||||
Some(false),
|
||||
bank,
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ fn bench_gpusigverify(bencher: &mut Bencher) {
|
|||
message_hash,
|
||||
None,
|
||||
SimpleAddressLoader::Disabled,
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
}?;
|
||||
|
||||
|
@ -82,7 +81,6 @@ fn bench_cpusigverify(bencher: &mut Bencher) {
|
|||
message_hash,
|
||||
None,
|
||||
SimpleAddressLoader::Disabled,
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
}?;
|
||||
|
||||
|
|
|
@ -1041,7 +1041,6 @@ mod tests {
|
|||
message_hash,
|
||||
None,
|
||||
SimpleAddressLoader::Disabled,
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
}?;
|
||||
|
||||
|
|
|
@ -922,7 +922,6 @@ fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String>
|
|||
MessageHash::Compute,
|
||||
None,
|
||||
SimpleAddressLoader::Disabled,
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.map_err(|err| {
|
||||
warn!("Failed to compute cost of transaction: {:?}", err);
|
||||
|
|
|
@ -1984,12 +1984,7 @@ impl Blockstore {
|
|||
.into_iter()
|
||||
.flat_map(|entry| entry.transactions)
|
||||
.map(|transaction| {
|
||||
if let Err(err) = transaction.sanitize(
|
||||
// Don't enable additional sanitization checks until
|
||||
// all clusters have activated the static program id
|
||||
// feature gate so that bigtable upload isn't affected
|
||||
false, // require_static_program_ids
|
||||
) {
|
||||
if let Err(err) = transaction.sanitize() {
|
||||
warn!(
|
||||
"Blockstore::get_block sanitize failed: {:?}, \
|
||||
slot: {:?}, \
|
||||
|
@ -2376,9 +2371,7 @@ impl Blockstore {
|
|||
.cloned()
|
||||
.flat_map(|entry| entry.transactions)
|
||||
.map(|transaction| {
|
||||
if let Err(err) = transaction.sanitize(
|
||||
true, // require_static_program_ids
|
||||
) {
|
||||
if let Err(err) = transaction.sanitize() {
|
||||
warn!(
|
||||
"Blockstore::find_transaction_in_slot sanitize failed: {:?}, \
|
||||
slot: {:?}, \
|
||||
|
|
|
@ -4516,14 +4516,8 @@ fn sanitize_transaction(
|
|||
transaction: VersionedTransaction,
|
||||
address_loader: impl AddressLoader,
|
||||
) -> Result<SanitizedTransaction> {
|
||||
SanitizedTransaction::try_create(
|
||||
transaction,
|
||||
MessageHash::Compute,
|
||||
None,
|
||||
address_loader,
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.map_err(|err| Error::invalid_params(format!("invalid transaction: {err}")))
|
||||
SanitizedTransaction::try_create(transaction, MessageHash::Compute, None, address_loader)
|
||||
.map_err(|err| Error::invalid_params(format!("invalid transaction: {err}")))
|
||||
}
|
||||
|
||||
pub fn create_validator_exit(exit: Arc<AtomicBool>) -> Arc<RwLock<Exit>> {
|
||||
|
|
|
@ -349,7 +349,6 @@ pub(crate) mod tests {
|
|||
MessageHash::Compute,
|
||||
None,
|
||||
SimpleAddressLoader::Disabled,
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -3763,16 +3763,7 @@ impl Bank {
|
|||
pub fn prepare_entry_batch(&self, txs: Vec<VersionedTransaction>) -> Result<TransactionBatch> {
|
||||
let sanitized_txs = txs
|
||||
.into_iter()
|
||||
.map(|tx| {
|
||||
SanitizedTransaction::try_create(
|
||||
tx,
|
||||
MessageHash::Compute,
|
||||
None,
|
||||
self,
|
||||
self.feature_set
|
||||
.is_active(&feature_set::require_static_program_ids_in_transaction::ID),
|
||||
)
|
||||
})
|
||||
.map(|tx| SanitizedTransaction::try_create(tx, MessageHash::Compute, None, self))
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
let tx_account_lock_limit = self.get_transaction_account_lock_limit();
|
||||
let lock_results = self
|
||||
|
@ -6852,14 +6843,7 @@ impl Bank {
|
|||
tx.message.hash()
|
||||
};
|
||||
|
||||
SanitizedTransaction::try_create(
|
||||
tx,
|
||||
message_hash,
|
||||
None,
|
||||
self,
|
||||
self.feature_set
|
||||
.is_active(&feature_set::require_static_program_ids_in_transaction::ID),
|
||||
)
|
||||
SanitizedTransaction::try_create(tx, message_hash, None, self)
|
||||
}?;
|
||||
|
||||
if verification_mode == TransactionVerificationMode::HashAndVerifyPrecompiles
|
||||
|
|
|
@ -367,7 +367,6 @@ mod tests {
|
|||
MessageHash::Compute,
|
||||
Some(true),
|
||||
SimpleAddressLoader::Disabled,
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.unwrap();
|
||||
let mut tx_cost = TransactionCost::new_with_capacity(1);
|
||||
|
|
|
@ -39,10 +39,10 @@ pub enum VersionedMessage {
|
|||
}
|
||||
|
||||
impl VersionedMessage {
|
||||
pub fn sanitize(&self, require_static_program_ids: bool) -> Result<(), SanitizeError> {
|
||||
pub fn sanitize(&self) -> Result<(), SanitizeError> {
|
||||
match self {
|
||||
Self::Legacy(message) => message.sanitize(),
|
||||
Self::V0(message) => message.sanitize(require_static_program_ids),
|
||||
Self::V0(message) => message.sanitize(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ impl TryFrom<VersionedMessage> for SanitizedVersionedMessage {
|
|||
|
||||
impl SanitizedVersionedMessage {
|
||||
pub fn try_new(message: VersionedMessage) -> Result<Self, SanitizeError> {
|
||||
message.sanitize(true /* require_static_program_ids */)?;
|
||||
message.sanitize()?;
|
||||
Ok(Self { message })
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ pub struct Message {
|
|||
|
||||
impl Message {
|
||||
/// Sanitize message fields and compiled instruction indexes
|
||||
pub fn sanitize(&self, reject_dynamic_program_ids: bool) -> Result<(), SanitizeError> {
|
||||
pub fn sanitize(&self) -> Result<(), SanitizeError> {
|
||||
let num_static_account_keys = self.account_keys.len();
|
||||
if usize::from(self.header.num_required_signatures)
|
||||
.saturating_add(usize::from(self.header.num_readonly_unsigned_accounts))
|
||||
|
@ -143,18 +143,15 @@ impl Message {
|
|||
.checked_sub(1)
|
||||
.expect("message doesn't contain any account keys");
|
||||
|
||||
// switch to rejecting program ids loaded from lookup tables so that
|
||||
// static analysis on program instructions can be performed without
|
||||
// loading on-chain data from a bank
|
||||
let max_program_id_ix = if reject_dynamic_program_ids {
|
||||
// reject program ids loaded from lookup tables so that
|
||||
// static analysis on program instructions can be performed
|
||||
// without loading on-chain data from a bank
|
||||
let max_program_id_ix =
|
||||
// `expect` is safe because of earlier check that
|
||||
// `num_static_account_keys` is non-zero
|
||||
num_static_account_keys
|
||||
.checked_sub(1)
|
||||
.expect("message doesn't contain any static account keys")
|
||||
} else {
|
||||
max_account_ix
|
||||
};
|
||||
.expect("message doesn't contain any static account keys");
|
||||
|
||||
for ci in &self.instructions {
|
||||
if usize::from(ci.program_id_index) > max_program_id_ix {
|
||||
|
@ -375,9 +372,7 @@ mod tests {
|
|||
account_keys: vec![Pubkey::new_unique()],
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
|
@ -396,9 +391,7 @@ mod tests {
|
|||
}],
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
|
@ -417,9 +410,7 @@ mod tests {
|
|||
}],
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
|
@ -444,13 +435,7 @@ mod tests {
|
|||
..Message::default()
|
||||
};
|
||||
|
||||
assert!(message.sanitize(
|
||||
false, // require_static_program_ids
|
||||
).is_ok());
|
||||
|
||||
assert!(message.sanitize(
|
||||
true, // require_static_program_ids
|
||||
).is_err());
|
||||
assert!(message.sanitize().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -473,9 +458,7 @@ mod tests {
|
|||
}],
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
|
@ -486,9 +469,7 @@ mod tests {
|
|||
account_keys: vec![Pubkey::new_unique()],
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_err());
|
||||
}
|
||||
|
||||
|
@ -503,9 +484,7 @@ mod tests {
|
|||
account_keys: vec![Pubkey::new_unique()],
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_err());
|
||||
}
|
||||
|
||||
|
@ -524,9 +503,7 @@ mod tests {
|
|||
}],
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_err());
|
||||
}
|
||||
|
||||
|
@ -540,9 +517,7 @@ mod tests {
|
|||
account_keys: (0..=u8::MAX).map(|_| Pubkey::new_unique()).collect(),
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
|
@ -556,9 +531,7 @@ mod tests {
|
|||
account_keys: (0..=256).map(|_| Pubkey::new_unique()).collect(),
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_err());
|
||||
}
|
||||
|
||||
|
@ -577,9 +550,7 @@ mod tests {
|
|||
}],
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
|
@ -598,9 +569,7 @@ mod tests {
|
|||
}],
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_err());
|
||||
}
|
||||
|
||||
|
@ -625,12 +594,7 @@ mod tests {
|
|||
..Message::default()
|
||||
};
|
||||
|
||||
assert!(message
|
||||
.sanitize(true /* require_static_program_ids */)
|
||||
.is_err());
|
||||
assert!(message
|
||||
.sanitize(false /* require_static_program_ids */)
|
||||
.is_err());
|
||||
assert!(message.sanitize().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -653,9 +617,7 @@ mod tests {
|
|||
}],
|
||||
..Message::default()
|
||||
}
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.sanitize()
|
||||
.is_err());
|
||||
}
|
||||
|
||||
|
|
|
@ -95,9 +95,8 @@ impl SanitizedTransaction {
|
|||
message_hash: impl Into<MessageHash>,
|
||||
is_simple_vote_tx: Option<bool>,
|
||||
address_loader: impl AddressLoader,
|
||||
require_static_program_ids: bool,
|
||||
) -> Result<Self> {
|
||||
tx.sanitize(require_static_program_ids)?;
|
||||
tx.sanitize()?;
|
||||
|
||||
let message_hash = match message_hash.into() {
|
||||
MessageHash::Compute => tx.message.hash(),
|
||||
|
|
|
@ -115,11 +115,8 @@ impl VersionedTransaction {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn sanitize(
|
||||
&self,
|
||||
require_static_program_ids: bool,
|
||||
) -> std::result::Result<(), SanitizeError> {
|
||||
self.message.sanitize(require_static_program_ids)?;
|
||||
pub fn sanitize(&self) -> std::result::Result<(), SanitizeError> {
|
||||
self.message.sanitize()?;
|
||||
self.sanitize_signatures()?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1131,13 +1131,7 @@ impl EncodedTransaction {
|
|||
.and_then(|bytes| bincode::deserialize(&bytes).ok()),
|
||||
};
|
||||
|
||||
transaction.filter(|transaction| {
|
||||
transaction
|
||||
.sanitize(
|
||||
true, // require_static_program_ids
|
||||
)
|
||||
.is_ok()
|
||||
})
|
||||
transaction.filter(|transaction| transaction.sanitize().is_ok())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue