Skip to content

Commit 084c02f

Browse files
committed
Suggestions from jstarry and buffalojoec
1 parent 061586c commit 084c02f

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

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

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

2424
## Alternatives Considered
2525

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

2849
## New Terminology
2950

@@ -51,8 +72,9 @@ instruction `UpgradeableLoaderInstruction::Migrate`.
5172
otherwise throw `NotEnoughAccountKeys`
5273
- Check that the program data account is writable,
5374
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`,
75+
- Check that the last modified slot (stored in the program data accounts
76+
header) is less than the current slot if the program data has the state
77+
`ProgramData`,
5678
otherwise throw `InvalidArgument`
5779
- Check that the provided authority is either:
5880
- the migration authority
@@ -67,26 +89,26 @@ instruction `UpgradeableLoaderInstruction::Migrate`.
6789
otherwise throw `InvalidArgument`
6890
- Check that the program account is owned by loader-v3,
6991
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.
92+
- If the program account has the state `Program` and
93+
the referenced program data account is owned by loader-v3:
94+
- Set the length of the program account to 0
95+
- Transfer all funds from the program data account to the program account
96+
- Assign ownership of the program account to loader-v4
97+
- CPI loader-v4 `SetProgramLength` the program account to the program data
98+
account size minus the loader-v3 header size (45 bytes) and use the
99+
provided authority.
81100
- CPI loader-v4 `Copy` the program data account into the program account
82101
- CPI loader-v4 `Deploy` the program account
83102
- If the program data account was finalized (upgrade authority is `None`):
84103
- CPI loader-v4 `Finalize` without a next version forwarding
85104
- otherwise, if the program data account was not finalized and the
86105
migration authority (as opposed to the upgrade authority) was provided:
87106
- 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
107+
- Set the length of the program data account to 0 (removing the header too)
108+
- otherwise, if the program account is empty, has the state `Buffer` or has
109+
the state `Program` but the program data account is not owned by loader-v3:
110+
- Set the length of the program account to 0
111+
- Set the `is_executable` flag of the program account to `false`
90112

91113
## Impact
92114

0 commit comments

Comments
 (0)