Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Prevent the invoke and upgrade of programs in the same tx batch#14653

Merged
jackcmay merged 2 commits into
solana-labs:masterfrom
jackcmay:upgrade-locks
Jan 20, 2021
Merged

Prevent the invoke and upgrade of programs in the same tx batch#14653
jackcmay merged 2 commits into
solana-labs:masterfrom
jackcmay:upgrade-locks

Conversation

@jackcmay
Copy link
Copy Markdown
Contributor

Problem

Upgradeable programs cannot be invoked and upgraded in the same transaction batch but the programs are not locked as writeable

Summary of Changes

Identify upgrade instructions in the transaction batch and reject any single transaction that attempts to both upgrade and invoke and also lock any programs in the batch that are being upgraded.

Fixes #

@jackcmay jackcmay added work in progress This isn't quite right yet noCI Suppress CI on this Pull Request labels Jan 19, 2021
@jackcmay jackcmay added CI Pull Request is ready to enter CI and removed noCI Suppress CI on this Pull Request work in progress This isn't quite right yet labels Jan 19, 2021
@solana-grimes solana-grimes removed the CI Pull Request is ready to enter CI label Jan 19, 2021
@jackcmay jackcmay force-pushed the upgrade-locks branch 2 times, most recently from 0667b1d to 13897ea Compare January 19, 2021 09:12
@jackcmay jackcmay requested review from mvines and sakridge January 19, 2021 16:19
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 19, 2021

Codecov Report

Merging #14653 (6780605) into master (e99d7d3) will increase coverage by 0.0%.
The diff coverage is 98.1%.

@@           Coverage Diff           @@
##           master   #14653   +/-   ##
=======================================
  Coverage    80.3%    80.3%           
=======================================
  Files         403      403           
  Lines      101132   101172   +40     
=======================================
+ Hits        81286    81323   +37     
- Misses      19846    19849    +3     

@mvines
Copy link
Copy Markdown
Contributor

mvines commented Jan 19, 2021

@jackcmay - could we just require the program account be writable here, and enforce that in Upgrade instruction handling?

/// 1. [] The Program account.

@jackcmay
Copy link
Copy Markdown
Contributor Author

Yeah, that would probably work too, more efficient but weird 😜

@mvines
Copy link
Copy Markdown
Contributor

mvines commented Jan 19, 2021

Yeah, that would probably work too, more efficient but weird 😜

Why weird? Touching the core runtime to do this is pretty scary. Requiring a write lock the way I propose avoids special cases

@jackcmay
Copy link
Copy Markdown
Contributor Author

It's weird in the first place that we are pulling an account not specified in the tx so there's that. But requiring an executable to be loaded as writeable is non-intuitive and being enforced by the loader moves some of the knowledge away from accounts load/lock code. Don't get me wrong, I think it's an acceptable solution and comes with less overhead.

@sakridge
Copy link
Copy Markdown
Contributor

Yeah, that would probably work too, more efficient but weird 😜

Why weird? Touching the core runtime to do this is pretty scary. Requiring a write lock the way I propose avoids special cases

Yea. I like this idea to just require it as writable.

Copy link
Copy Markdown
Contributor

@bennofs bennofs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me. I agree that loading an account not specified in the TX sounds scary though, I'll think a little bit more about that.

@jackcmay
Copy link
Copy Markdown
Contributor Author

@mvines @sakridge Ready for re-review

Comment thread programs/bpf_loader/src/lib.rs Outdated
Copy link
Copy Markdown
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love there's no runtime/ changes anymore. Looks good except for the need for a feature gate :(

Comment thread sdk/src/feature_set.rs
(abort_on_all_cpi_failures::id(), "Abort on all CPI failures"),
(use_loaded_executables::id(), "Use loaded executable accounts"),
(turbine_retransmit_peers_patch::id(), "turbine retransmit peers patch #14631"),
(prevent_upgrade_and_invoke::id(), "Prevent upgrade and invoke in same tx batch"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this? nbd though

Suggested change
(prevent_upgrade_and_invoke::id(), "Prevent upgrade and invoke in same tx batch"),
(prevent_upgrade_and_invoke::id(), "require writeable program account during upgrade #14653"),

Comment thread sdk/program/src/loader_upgradeable_instruction.rs
@jackcmay jackcmay added the automerge Merge this Pull Request automatically once CI passes label Jan 19, 2021
@mergify mergify Bot removed the automerge Merge this Pull Request automatically once CI passes label Jan 19, 2021
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Jan 19, 2021

automerge label removed due to a CI failure

Copy link
Copy Markdown
Contributor

@sakridge sakridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jackcmay jackcmay merged commit e3bd9e5 into solana-labs:master Jan 20, 2021
@jackcmay jackcmay deleted the upgrade-locks branch January 20, 2021 00:24
mergify Bot pushed a commit that referenced this pull request Jan 20, 2021
* Prevent the invoke and upgrade of programs in the same tx batch

* Pass program address as writable in the upgrade instruction

(cherry picked from commit e3bd9e5)

# Conflicts:
#	programs/bpf/Cargo.lock
#	programs/bpf/Cargo.toml
#	programs/bpf/tests/programs.rs
mergify Bot pushed a commit that referenced this pull request Jan 20, 2021
* Prevent the invoke and upgrade of programs in the same tx batch

* Pass program address as writable in the upgrade instruction

(cherry picked from commit e3bd9e5)

# Conflicts:
#	programs/bpf/Cargo.lock
#	programs/bpf/Cargo.toml
mvines pushed a commit that referenced this pull request Jan 20, 2021
…14653) (#14679)

* Prevent the invoke and upgrade of programs in the same tx batch (#14653)

* Prevent the invoke and upgrade of programs in the same tx batch

* Pass program address as writable in the upgrade instruction

(cherry picked from commit e3bd9e5)

# Conflicts:
#	programs/bpf/Cargo.lock
#	programs/bpf/Cargo.toml
#	programs/bpf/tests/programs.rs

* fix conflicts

Co-authored-by: Jack May <jack@solana.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants