Solana: Add min_validations to Controller#69
Open
GuidoDipietro wants to merge 4 commits intosolana/settlerfrom
Open
Solana: Add min_validations to Controller#69GuidoDipietro wants to merge 4 commits intosolana/settlerfrom
min_validations to Controller#69GuidoDipietro wants to merge 4 commits intosolana/settlerfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
min_validationsto Controller's global state, following EVM implementation.This implied a change in the Controller's state PDAs, two new instructions, and a small logic change in the Settler.
Note: Tests will fail until SDK version is bumped.
Changes
Controller
State
Adds
min_validations: u16tocontroller_settings.This field is added after all existing fields to not break the already deployed program. Eventually, if we take down this program and deploy another one, we can rearrange the fields to have
bumpbe the last one.Instructions
initializeAdds
min_validations: u16as a required parameter to set it upon initialization, with a> 0constraint.New instruction:
set_min_validationsThis is an admin-only instruction that lets admins update the
min_validationsfield onControllerSettings, with a> 0constraint.New instruction:
resize_settingsThis is an admin-only instruction that lets admins resize existing
ControllerSettingsPDAs.As the settings PDA is created using the minimum
INIT_SPACEon initialization (when callinginitialize), adding new fields requires a reallocation.A note on live programs and existing PDAs:
Typically, it is best to just allocate the PDA once with
_reserved: [u8; 500]as its last field to allocate more space than needed and not need reallocations when extending the struct, if we expect to extend the struct on later program upgrades. Another approach for live programs is to deprecate the PDA and use another one such asControllerSettings2, or rather, extend the state in yet another complementary PDA such asControllerMinValidationsonly with the extra fields. However, the approach used here is not only sensible too but also more reasonable given that we are in a development stage yet.Other notes about this instruction:
Admins should note that this instruction is expected to be called together (same transaction) with another instruction writing to the newly added settings field (in this case,
set_min_validations).If this instruction is called alone, the extra bytes added to the
ControllerSettingsPDA will be zeroed, meaning there might be inconsistent state. In this case, callingresize_settingson its own creates amin_validationfield equal to0, which is otherwise impossible through program logic.Settler
Instructions
create_intentIntent's
min_validationsare now set to the maximum ofintent.min_validationsandcontroller.min_validations, following EVM logic.Tests
Tests were updated and new cases added accordingly.
Naming was adjusted a bit in
settler.spec.tsas it differed slightly from the other test file.