|
2 | 2 | crate::{
|
3 | 3 | accounts::{
|
4 | 4 | PriceAccount,
|
| 5 | + PriceAccountFlags, |
5 | 6 | PriceComponent,
|
6 | 7 | PythAccount,
|
7 | 8 | },
|
|
33 | 34 | std::mem::size_of,
|
34 | 35 | };
|
35 | 36 |
|
| 37 | +pub const ENABLE_ACCUMULATOR_V2: [u8; 32] = [ |
| 38 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, |
| 39 | +]; |
| 40 | +pub const DISABLE_ACCUMULATOR_V2: [u8; 32] = [ |
| 41 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, |
| 42 | +]; |
| 43 | + |
36 | 44 | /// Add publisher to symbol account
|
37 | 45 | // account[0] funding account [signer writable]
|
38 | 46 | // account[1] price account [signer writable]
|
@@ -62,14 +70,19 @@ pub fn add_publisher(
|
62 | 70 | &cmd_args.header,
|
63 | 71 | )?;
|
64 | 72 |
|
65 |
| - |
66 | 73 | let mut price_data = load_checked::<PriceAccount>(price_account, cmd_args.header.version)?;
|
67 | 74 |
|
68 |
| - // Use the call with the default pubkey (000..) as a trigger to sort the publishers as a |
69 |
| - // migration step from unsorted list to sorted list. |
70 |
| - if cmd_args.publisher == Pubkey::default() { |
71 |
| - let num_comps = try_convert::<u32, usize>(price_data.num_)?; |
72 |
| - sort_price_comps(&mut price_data.comp_, num_comps)?; |
| 75 | + if cmd_args.publisher == Pubkey::from(ENABLE_ACCUMULATOR_V2) { |
| 76 | + // Hack: we use add_publisher instruction to configure the `ACCUMULATOR_V2` flag. Using a new |
| 77 | + // instruction would be cleaner but it would require more work in the tooling. |
| 78 | + // These special cases can be removed along with the v1 aggregation code once the transition |
| 79 | + // is complete. |
| 80 | + price_data.flags.insert(PriceAccountFlags::ACCUMULATOR_V2); |
| 81 | + return Ok(()); |
| 82 | + } else if cmd_args.publisher == Pubkey::from(DISABLE_ACCUMULATOR_V2) { |
| 83 | + price_data |
| 84 | + .flags |
| 85 | + .remove(PriceAccountFlags::ACCUMULATOR_V2 | PriceAccountFlags::MESSAGE_BUFFER_CLEARED); |
73 | 86 | return Ok(());
|
74 | 87 | }
|
75 | 88 |
|
@@ -224,7 +237,6 @@ mod test {
|
224 | 237 | let mut rust_std_sorted_comps = comps.get(..num_comps).unwrap().to_vec();
|
225 | 238 | rust_std_sorted_comps.sort_by_key(|x| x.pub_);
|
226 | 239 |
|
227 |
| - |
228 | 240 | assert_eq!(sort_price_comps(&mut comps, num_comps), Ok(()));
|
229 | 241 | assert_eq!(comps.get(..num_comps).unwrap(), rust_std_sorted_comps);
|
230 | 242 | }
|
|
0 commit comments