Skip to content

Commit 9b02e90

Browse files
committed
Suggestions from jstarry and buffalojoec
1 parent 061586c commit 9b02e90

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed

proposals/0315-loader-v3-v4-migration.md

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,33 @@ loader-v4.
2323

2424
## Alternatives Considered
2525

26-
None.
26+
### Loader-v1 programs
27+
28+
Programs of loader-v1 have ABI v0, which is incompatible with ABI v1 used
29+
by programs of loader-v2, v3 and v4. Thus there is no way to migrate these.
30+
31+
### Loader-v2 programs
32+
33+
The two loader-v3 accounts per program in their sum are always larger than
34+
the one resulting loader-v4 account. Thus there is no need for additional
35+
funding. This would not be the case when migrating from loader-v2. Meaning
36+
that expanding this SIMD to cover it as well would require a funding source.
37+
38+
### Global Migration: Coordinated in valiator or out of validator
39+
40+
The global migration could be implemented in the validator, however:
41+
42+
- If the global migration mechanism is inside the validator, the risk of it
43+
being detrimental to block production outweights any possible benefits.
44+
- It would have to be coordinated across all validator implementations,
45+
tested, fuzzed, etc. simply a whole lot more work for something which is only
46+
used once.
47+
- It being triggered manually per program or once (via a feature gate) for all
48+
programs changes nothing about it being controlled by a single key.
49+
- The only difference is in having more fine granular control over the
50+
timing in when a specific programs migration is triggered.
51+
- Doing it outside of the validator allows for the process to be aborted or
52+
patched quickly in case things start going sideways.
2753

2854
## New Terminology
2955

@@ -51,8 +77,9 @@ instruction `UpgradeableLoaderInstruction::Migrate`.
5177
otherwise throw `NotEnoughAccountKeys`
5278
- Check that the program data account is writable,
5379
otherwise throw `InvalidArgument`
54-
- Check that the program data was last modified before the current slot
55-
if the program data has the state `ProgramData`,
80+
- Check that the last modified slot (stored in the program data accounts
81+
header) is less than the current slot if the program data has the state
82+
`ProgramData`,
5683
otherwise throw `InvalidArgument`
5784
- Check that the provided authority is either:
5885
- the migration authority
@@ -67,26 +94,26 @@ instruction `UpgradeableLoaderInstruction::Migrate`.
6794
otherwise throw `InvalidArgument`
6895
- Check that the program account is owned by loader-v3,
6996
otherwise throw `IncorrectProgramId`
70-
- Check that the program account has the state `Program`,
71-
otherwise throw `InvalidAccountData`
72-
- Check that the program account points to the program data account,
73-
otherwise throw `InvalidArgument`
74-
- Clear the program account (setting its size to zero)
75-
- Transfer all funds from the program data account to the program account
76-
- Assign ownership of the program account to loader-v4
77-
- If the program data account was not closed / empty or uninitialized:
78-
- CPI loader-v4 `SetProgramLength` the program account to the size of the
79-
program data account minus the loader-v3 header size and use the migration
80-
authority.
97+
- If the program account has the state `Program` and
98+
the referenced program data account is owned by loader-v3:
99+
- Set the length of the program account to 0
100+
- Transfer all funds from the program data account to the program account
101+
- Assign ownership of the program account to loader-v4
102+
- CPI loader-v4 `SetProgramLength` the program account to the program data
103+
account size minus the loader-v3 header size (45 bytes) and use the
104+
provided authority.
81105
- CPI loader-v4 `Copy` the program data account into the program account
82106
- CPI loader-v4 `Deploy` the program account
83107
- If the program data account was finalized (upgrade authority is `None`):
84108
- CPI loader-v4 `Finalize` without a next version forwarding
85109
- otherwise, if the program data account was not finalized and the
86110
migration authority (as opposed to the upgrade authority) was provided:
87111
- CPI loader-v4 `TransferAuthority` to the upgrade authority
88-
- Clear the program data account (setting its size to zero)
89-
- Assign ownership of the program data account to the system program
112+
- Set the length of the program data account to 0 (removing the header too)
113+
- otherwise, if the program account is empty, has the state `Buffer` or has
114+
the state `Program` but the program data account is not owned by loader-v3:
115+
- Set the length of the program account to 0
116+
- Set the `is_executable` flag of the program account to `false`
90117

91118
## Impact
92119

0 commit comments

Comments
 (0)