-
Notifications
You must be signed in to change notification settings - Fork 17
serviceability: retire a feed, with the notice its seat holders are owed #4310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
07fc676
serviceability: retire a feed, with the notice its seat holders are owed
bgm-malbeclabs f5d21f3
serviceability: format the lifecycle test the way CI does
bgm-malbeclabs 3e7dad1
serviceability: keep serving seat holders through the retirement notice
bgm-malbeclabs ec84f65
serviceability: pin both halves of the retirement admission rule
bgm-malbeclabs 0ed1138
serviceability: close the two ways around a retirement notice
bgm-malbeclabs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Binary file not shown.
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
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
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
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
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
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
80 changes: 80 additions & 0 deletions
80
smartcontract/programs/doublezero-serviceability/src/processors/feed/finalize_retirement.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| use crate::{ | ||
| error::DoubleZeroError, | ||
| serializer::try_acc_write, | ||
| state::feed::{Feed, FeedStatus}, | ||
| }; | ||
| use borsh::BorshSerialize; | ||
| use borsh_incremental::BorshDeserializeIncremental; | ||
| use solana_program::{ | ||
| account_info::{next_account_info, AccountInfo}, | ||
| clock::Clock, | ||
| entrypoint::ProgramResult, | ||
| msg, | ||
| pubkey::Pubkey, | ||
| sysvar::Sysvar, | ||
| }; | ||
|
|
||
| #[derive(BorshSerialize, BorshDeserializeIncremental, PartialEq, Debug, Clone, Default)] | ||
| #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
| pub struct FeedFinalizeRetirementArgs {} | ||
|
|
||
| /// Move a feed from `Retiring` to `Retired` once its notice has elapsed. | ||
| /// | ||
| /// Permissionless, unlike every other feed instruction. The outcome is fixed the moment retirement | ||
| /// starts: the clock decides, and this instruction can only agree with it. Requiring an authority | ||
| /// would add a way for a feed to sit in `Retiring` forever because whoever held the key stopped | ||
| /// caring, and a seat holder given a date deserves the date rather than someone's attention. | ||
| pub fn process_finalize_feed_retirement( | ||
| program_id: &Pubkey, | ||
| accounts: &[AccountInfo], | ||
| _value: &FeedFinalizeRetirementArgs, | ||
| ) -> ProgramResult { | ||
| let accounts_iter = &mut accounts.iter(); | ||
|
|
||
| let feed_account = next_account_info(accounts_iter)?; | ||
| let payer_account = next_account_info(accounts_iter)?; | ||
| let _system_program = next_account_info(accounts_iter)?; | ||
|
|
||
| assert!(payer_account.is_signer, "Payer must be a signer"); | ||
| assert_eq!(feed_account.owner, program_id, "Invalid PDA Account Owner"); | ||
| assert!(feed_account.is_writable, "PDA Account is not writable"); | ||
|
|
||
| let mut feed = Feed::try_from(feed_account)?; | ||
|
|
||
| if feed.status != FeedStatus::Retiring { | ||
| msg!( | ||
| "Feed {} is {}, so it has no retirement to finish", | ||
| feed_account.key, | ||
| feed.status | ||
| ); | ||
| return Err(DoubleZeroError::FeedNotRetiring.into()); | ||
| } | ||
|
|
||
| let now = Clock::get()?.unix_timestamp; | ||
| if now < feed.retires_at { | ||
| msg!( | ||
| "Feed {} retires at {}, and it is {}", | ||
| feed_account.key, | ||
| feed.retires_at, | ||
| now | ||
| ); | ||
| return Err(DoubleZeroError::RetirementNoticeNotElapsed.into()); | ||
| } | ||
|
|
||
| feed.status = FeedStatus::Retired; | ||
| try_acc_write(&feed, feed_account, payer_account, accounts)?; | ||
|
|
||
| // The `FeedRetired` event, as a log line. This program has no event mechanism: no | ||
| // `sol_log_data`, no return data, only `msg!`. Nothing consumes this yet, because releasing | ||
| // the stake on retirement waits for the slashing work, so inventing a mechanism for a single | ||
| // absent consumer would buy nothing. The shape is fixed so that whoever consumes it can parse | ||
| // it without this line changing. | ||
| msg!( | ||
| "FeedRetired feed={} builder={} stake_ref={}", | ||
| feed_account.key, | ||
| feed.builder, | ||
| feed.stake_ref | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } |
2 changes: 2 additions & 0 deletions
2
smartcontract/programs/doublezero-serviceability/src/processors/feed/mod.rs
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
96 changes: 96 additions & 0 deletions
96
smartcontract/programs/doublezero-serviceability/src/processors/feed/retire.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| use crate::{ | ||
| error::DoubleZeroError, | ||
| processors::feed::require_feed_writer, | ||
| serializer::try_acc_write, | ||
| state::{ | ||
| feed::{Feed, FeedStatus}, | ||
| globalstate::GlobalState, | ||
| }, | ||
| }; | ||
| use borsh::BorshSerialize; | ||
| use borsh_incremental::BorshDeserializeIncremental; | ||
| use solana_program::{ | ||
| account_info::{next_account_info, AccountInfo}, | ||
| clock::Clock, | ||
| entrypoint::ProgramResult, | ||
| msg, | ||
| pubkey::Pubkey, | ||
| sysvar::Sysvar, | ||
| }; | ||
|
|
||
| /// The notice a feed owes its seat holders before publication stops. | ||
| pub const RETIREMENT_NOTICE_SECONDS: i64 = 30 * 24 * 60 * 60; | ||
|
|
||
| #[derive(BorshSerialize, BorshDeserializeIncremental, PartialEq, Debug, Clone, Default)] | ||
| #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
| pub struct FeedRetireArgs {} | ||
|
|
||
| /// Start a feed's retirement and the notice that runs with it. | ||
| /// | ||
| /// One way in and no way back: `Retiring` is not resumable, and the only state after it is | ||
| /// `Retired`. That is what makes retirement terminal where halt is reversible. | ||
| pub fn process_retire_feed( | ||
| program_id: &Pubkey, | ||
| accounts: &[AccountInfo], | ||
| _value: &FeedRetireArgs, | ||
| ) -> ProgramResult { | ||
| let accounts_iter = &mut accounts.iter(); | ||
|
|
||
| let feed_account = next_account_info(accounts_iter)?; | ||
| let globalstate_account = next_account_info(accounts_iter)?; | ||
| let payer_account = next_account_info(accounts_iter)?; | ||
| let _system_program = next_account_info(accounts_iter)?; | ||
|
|
||
| assert!(payer_account.is_signer, "Payer must be a signer"); | ||
| assert_eq!(feed_account.owner, program_id, "Invalid PDA Account Owner"); | ||
| assert_eq!( | ||
| globalstate_account.owner, program_id, | ||
| "Invalid GlobalState Account Owner" | ||
| ); | ||
| assert!(feed_account.is_writable, "PDA Account is not writable"); | ||
|
|
||
| let mut feed = Feed::try_from(feed_account)?; | ||
| let globalstate = GlobalState::try_from(globalstate_account)?; | ||
| require_feed_writer( | ||
| program_id, | ||
| accounts_iter, | ||
| payer_account.key, | ||
|
bgm-malbeclabs marked this conversation as resolved.
|
||
| &globalstate, | ||
| &feed, | ||
| )?; | ||
|
|
||
| // A feed already retiring or retired has nothing left to start. Everything else can retire, | ||
| // including `Pending`: `DeleteFeed` refuses a staked feed, so refusing here as well would | ||
| // leave a feed that never went live with no way out at all. | ||
| if matches!(feed.status, FeedStatus::Retiring | FeedStatus::Retired) { | ||
| msg!( | ||
| "Feed {} is {}, so its retirement has already started", | ||
| feed_account.key, | ||
| feed.status | ||
| ); | ||
| return Err(DoubleZeroError::FeedNotRetirable.into()); | ||
| } | ||
|
|
||
| let now = Clock::get()?.unix_timestamp; | ||
|
|
||
| // The notice exists for seat holders, and a feed that was never `Active` has none: it admits | ||
| // no subscriber until it publishes. So the wait is zero rather than absent, which keeps one | ||
| // path through retirement instead of two. | ||
| feed.retires_at = if feed.status == FeedStatus::Pending { | ||
| now | ||
| } else { | ||
| now.checked_add(RETIREMENT_NOTICE_SECONDS) | ||
| .ok_or(DoubleZeroError::InvalidArgument)? | ||
| }; | ||
| feed.status = FeedStatus::Retiring; | ||
|
bgm-malbeclabs marked this conversation as resolved.
bgm-malbeclabs marked this conversation as resolved.
|
||
|
|
||
| try_acc_write(&feed, feed_account, payer_account, accounts)?; | ||
|
|
||
| msg!( | ||
| "Retiring feed: {} notice ends at {}", | ||
| feed_account.key, | ||
| feed.retires_at | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.