@@ -23,7 +23,33 @@ loader-v4.
23
23
24
24
## Alternatives Considered
25
25
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.
27
53
28
54
## New Terminology
29
55
@@ -51,8 +77,9 @@ instruction `UpgradeableLoaderInstruction::Migrate`.
51
77
otherwise throw ` NotEnoughAccountKeys `
52
78
- Check that the program data account is writable,
53
79
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 ` ,
56
83
otherwise throw ` InvalidArgument `
57
84
- Check that the provided authority is either:
58
85
- the migration authority
@@ -67,26 +94,26 @@ instruction `UpgradeableLoaderInstruction::Migrate`.
67
94
otherwise throw ` InvalidArgument `
68
95
- Check that the program account is owned by loader-v3,
69
96
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.
81
105
- CPI loader-v4 ` Copy ` the program data account into the program account
82
106
- CPI loader-v4 ` Deploy ` the program account
83
107
- If the program data account was finalized (upgrade authority is ` None ` ):
84
- - CPI loader-v4 ` Finalize ` without a next version forwarding
108
+ - CPI loader-v4 ` Finalize `
85
109
- otherwise, if the program data account was not finalized and the
86
110
migration authority (as opposed to the upgrade authority) was provided:
87
111
- 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 `
90
117
91
118
## Impact
92
119
0 commit comments