-
Notifications
You must be signed in to change notification settings - Fork 17
serviceability: halt and resume a feed #4307
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
Open
bgm-malbeclabs
wants to merge
2
commits into
main
Choose a base branch
from
feat/feed-halt-and-resume
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,10 @@ use crate::common; | |
| use doublezero_serviceability::{ | ||
| instructions::DoubleZeroInstruction, | ||
| pda::{get_feed_pda, get_globalstate_pda}, | ||
| processors::feed::{create::FeedCreateArgs, delete::FeedDeleteArgs, update::FeedUpdateArgs}, | ||
| processors::feed::{ | ||
| create::FeedCreateArgs, delete::FeedDeleteArgs, halt::FeedHaltArgs, resume::FeedResumeArgs, | ||
| update::FeedUpdateArgs, | ||
| }, | ||
| }; | ||
| use solana_program::{ | ||
| instruction::{AccountMeta, Instruction}, | ||
|
|
@@ -91,6 +94,41 @@ pub fn delete_feed( | |
| ) | ||
| } | ||
|
|
||
| /// `HaltFeed` (variant 120). Accounts: `[feed, globalstate]`. | ||
| /// | ||
| /// Stops a feed publishing, reversibly. Unlike the other feed instructions, the feed's own | ||
| /// `builder` may sign this one, so a builder can rotate its upstream source without an operator. | ||
| /// A `FEED_AUTHORITY` or `FOUNDATION` key can sign it too, which is why this stays on the | ||
| /// permission-appending path. | ||
| pub fn halt_feed(program_id: &Pubkey, payer: &Pubkey, feed: &Pubkey) -> Instruction { | ||
| let (globalstate, _) = get_globalstate_pda(program_id); | ||
| common::build_with_permission( | ||
| program_id, | ||
| DoubleZeroInstruction::HaltFeed(FeedHaltArgs {}), | ||
| vec![ | ||
| AccountMeta::new(*feed, false), | ||
| AccountMeta::new(globalstate, false), | ||
| ], | ||
| payer, | ||
| ) | ||
| } | ||
|
|
||
| /// `ResumeFeed` (variant 121). Accounts: `[feed, globalstate]`. | ||
| /// | ||
| /// Puts a halted feed back to publishing. Signed by the same keys `halt_feed` accepts. | ||
| pub fn resume_feed(program_id: &Pubkey, payer: &Pubkey, feed: &Pubkey) -> Instruction { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Minor] Omits the stake mirror account, so resuming a staked feed always fails |
||
| let (globalstate, _) = get_globalstate_pda(program_id); | ||
| common::build_with_permission( | ||
| program_id, | ||
| DoubleZeroInstruction::ResumeFeed(FeedResumeArgs {}), | ||
| vec![ | ||
| AccountMeta::new(*feed, false), | ||
| AccountMeta::new(globalstate, false), | ||
| ], | ||
| payer, | ||
| ) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
@@ -151,6 +189,16 @@ mod tests { | |
| let delete = delete_feed(&pid, &payer, &feed, FeedDeleteArgs {}); | ||
| assert_eq!(delete.data[0], 114); | ||
| assert_eq!(delete.accounts, expected); | ||
|
|
||
| // The lifecycle verbs take the same accounts. `unpack` matches the leading byte by hand | ||
| // with a catch-all, so a wrong tag here reaches the program as `InvalidInstructionData` | ||
| // rather than as a compile error. | ||
| let halt = halt_feed(&pid, &payer, &feed); | ||
| assert_eq!(halt.data[0], 120); | ||
| assert_eq!(halt.accounts, expected); | ||
| let resume = resume_feed(&pid, &payer, &feed); | ||
| assert_eq!(resume.data[0], 121); | ||
| assert_eq!(resume.accounts, expected); | ||
| } | ||
|
|
||
| /// Tripwire for the module-doc note: `FEED_AUTHORITY` is currently absent from | ||
|
|
||
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
77 changes: 77 additions & 0 deletions
77
smartcontract/programs/doublezero-serviceability/src/processors/feed/halt.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,77 @@ | ||
| 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}, | ||
| entrypoint::ProgramResult, | ||
| msg, | ||
| pubkey::Pubkey, | ||
| }; | ||
|
|
||
| #[derive(BorshSerialize, BorshDeserializeIncremental, PartialEq, Debug, Clone, Default)] | ||
| #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
| pub struct FeedHaltArgs {} | ||
|
|
||
| /// Stop a feed publishing, reversibly. | ||
| /// | ||
| /// Halt is the builder's own lever and doubles as a way to rotate the upstream source without | ||
| /// redeploying, so it is reversible and touches neither the stake nor the seats already sold. | ||
| /// Retirement is the terminal path and is not this. | ||
| pub fn process_halt_feed( | ||
| program_id: &Pubkey, | ||
| accounts: &[AccountInfo], | ||
| _value: &FeedHaltArgs, | ||
| ) -> 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, | ||
| &globalstate, | ||
| &feed, | ||
| )?; | ||
|
|
||
| // Only a publishing feed can stop publishing. Pending has not started and Retired is terminal, | ||
| // so neither is a halt this instruction can honor. | ||
| if feed.status != FeedStatus::Active { | ||
| msg!( | ||
| "Feed {} is {}, so there is nothing to halt", | ||
| feed_account.key, | ||
| feed.status | ||
| ); | ||
| return Err(DoubleZeroError::FeedNotHaltable.into()); | ||
| } | ||
|
|
||
| feed.status = FeedStatus::Halted; | ||
| // Recorded so resume can tell an operator's halt from the builder's own. | ||
| feed.halted_by = *payer_account.key; | ||
| try_acc_write(&feed, feed_account, payer_account, accounts)?; | ||
|
|
||
| msg!("Halted feed: {}", feed_account.key); | ||
|
|
||
| Ok(()) | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Minor]
halt_feedandresume_feedhave no test;test_feed_pubkey_verbspins the tag byte and account metas for update and delete but not for 120/121.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in
d0a6b09c9.test_feed_pubkey_verbsnow pins 120 and 121 alongside 113 and 114, tag byte and account metas both.Worth saying why that test earns its keep here specifically:
DoubleZeroInstruction::unpackmatches the leading byte by hand and ends in a catch-all, so a wrong or missing tag compiles cleanly and arrives at the program asInvalidInstructionData. That is exactly how it failed the first time I ran these tests, and the tag assertion is what would have caught it at the crate boundary instead.