Skip to content

Commit

Permalink
Reorganized upgrade/publish transaction checks. Reordered max publish…
Browse files Browse the repository at this point in the history
… checks (MystenLabs#15374)

## Description 

- Combined upgrade/publish checks for clarity
- Reordered max publish checks before checking validity 


## Test Plan 

- 👀 

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
tnowacki authored Dec 14, 2023
1 parent 7ab5bc2 commit ec8aa96
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions crates/sui-types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,18 +833,7 @@ impl Command {
}
);
}
Command::Publish(modules, _dep_ids) => {
fp_ensure!(!modules.is_empty(), UserInputError::EmptyCommandInput);
fp_ensure!(
modules.len() < config.max_modules_in_publish() as usize,
UserInputError::SizeLimitExceeded {
limit: "maximum modules in a programmable transaction publish command"
.to_string(),
value: config.max_modules_in_publish().to_string()
}
);
}
Command::Upgrade(modules, _, _, _) => {
Command::Publish(modules, _) | Command::Upgrade(modules, _, _, _) => {
fp_ensure!(!modules.is_empty(), UserInputError::EmptyCommandInput);
fp_ensure!(
modules.len() < config.max_modules_in_publish() as usize,
Expand Down Expand Up @@ -918,15 +907,11 @@ impl ProgrammableTransaction {
for input in inputs {
input.validity_check(config)?
}
let mut publish_count = 0u64;
for command in commands {
command.validity_check(config)?;
match command {
Command::Publish(_, _) | Command::Upgrade(_, _, _, _) => publish_count += 1,
_ => (),
}
}
if let Some(max_publish_commands) = config.max_publish_or_upgrade_per_ptb_as_option() {
let publish_count = commands
.iter()
.filter(|c| matches!(c, Command::Publish(_, _) | Command::Upgrade(_, _, _, _)))
.count() as u64;
fp_ensure!(
publish_count <= max_publish_commands,
UserInputError::MaxPublishCountExceeded {
Expand All @@ -935,6 +920,10 @@ impl ProgrammableTransaction {
}
);
}
for command in commands {
command.validity_check(config)?;
}

Ok(())
}

Expand Down

0 comments on commit ec8aa96

Please sign in to comment.