Skip to content

Commit 4a637ba

Browse files
committed
fixup! pyth: introduce pyth accumulator library
1 parent c2275e2 commit 4a637ba

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@ exclude = [
9595
resolver = "2"
9696

9797
[patch.crates-io]
98-
serde_wormhole = { git = "https://github.com/wormhole-foundation/wormhole" }
98+
serde_wormhole = { git = "https://github.com/wormhole-foundation/wormhole", tag = "v2.17.1" }

runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ num-derive = { version = "0.3" }
3232
num-traits = { version = "0.2" }
3333
num_cpus = "1.13.1"
3434
ouroboros = "0.14.2"
35-
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", version = "1.13.6" }
35+
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", version = "1.13.6", rev = "407252000643f0c933ad23194ceabb6a6f0a4bf9" }
3636
rand = "0.7.0"
3737
rayon = "1.5.1"
3838
regex = "1.5.4"

runtime/src/bank.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,7 +2512,8 @@ impl Bank {
25122512
{
25132513
return;
25142514
}
2515-
2515+
2516+
info!("Updating accumulator. Parent_epoch: {}", self.slot());
25162517
if let Err(e) = self.update_accumulator_impl() {
25172518
error!("Error updating accumulator: {:?}", e);
25182519
}
@@ -2530,7 +2531,7 @@ impl Bank {
25302531
};
25312532

25322533
// Use the current Clock to determine the index into the accumulator ring buffer.
2533-
let ring_index = (self.clock().slot % 10_000) as u32;
2534+
let ring_index = (self.slot() % 10_000) as u32;
25342535

25352536
// Find all accounts owned by the Message Buffer program using get_program_accounts, and
25362537
// extract the account data.
@@ -2604,7 +2605,7 @@ impl Bank {
26042605
let acc_state_magic = &mut b"PAS1".to_vec();
26052606
let accounts_data = &mut accounts.clone().collect::<Vec<_>>().try_to_vec()?;
26062607
data.append(acc_state_magic);
2607-
data.append(&mut self.clock().slot.try_to_vec()?);
2608+
data.append(&mut self.slot().try_to_vec()?);
26082609
data.append(&mut ACCUMULATOR_RING_SIZE.try_to_vec()?);
26092610
data.append(accounts_data);
26102611
let owner = solana_sdk::system_program::id();
@@ -2676,7 +2677,7 @@ impl Bank {
26762677
sequence: sequence.sequence,
26772678
emitter_chain: 26,
26782679
emitter_address: ACCUMULATOR_EMITTER_ADDRESS,
2679-
payload: acc.serialize(self.clock().slot, ACCUMULATOR_RING_SIZE),
2680+
payload: acc.serialize(self.slot(), ACCUMULATOR_RING_SIZE),
26802681
},
26812682
};
26822683

@@ -15108,7 +15109,7 @@ pub(crate) mod tests {
1510815109
let (wormhole_message_pubkey, _bump) = Pubkey::find_program_address(
1510915110
&[
1511015111
b"AccumulatorMessage",
15111-
&(bank.clock().slot as u32).to_be_bytes(),
15112+
&(bank.slot() as u32).to_be_bytes(),
1511215113
],
1511315114
&Pubkey::new_from_array(pythnet_sdk::pythnet::WORMHOLE_PID),
1511415115
);
@@ -15158,7 +15159,7 @@ pub(crate) mod tests {
1515815159
bank = new_from_parent(&Arc::new(bank));
1515915160

1516015161
// get the timestamp & slot for the message
15161-
let ring_index = (bank.clock().slot % ACCUMULATOR_RING_SIZE as u64) as u32;
15162+
let ring_index = (bank.slot() % ACCUMULATOR_RING_SIZE as u64) as u32;
1516215163
let wormhole_message_account = get_wormhole_message_account(&bank, ring_index);
1516315164

1516415165
assert_ne!(wormhole_message_account.data().len(), 0);
@@ -15171,7 +15172,7 @@ pub(crate) mod tests {
1517115172
let expected_accumulator =
1517215173
MerkleAccumulator::<Keccak160>::from_set(accumulator_elements).unwrap();
1517315174
let expected_wormhole_message_payload =
15174-
expected_accumulator.serialize(bank.clock().slot, ACCUMULATOR_RING_SIZE);
15175+
expected_accumulator.serialize(bank.slot(), ACCUMULATOR_RING_SIZE);
1517515176
assert_eq!(
1517615177
wormhole_message.message.payload,
1517715178
expected_wormhole_message_payload
@@ -15213,7 +15214,7 @@ pub(crate) mod tests {
1521315214
let acc_state_ring_size = LittleEndian::read_u32(&accumulator_state[12..16]);
1521415215

1521515216
assert_eq!(acc_state_magic, b"PAS1");
15216-
assert_eq!(acc_state_slot, bank.clock().slot);
15217+
assert_eq!(acc_state_slot, bank.slot());
1521715218
assert_eq!(acc_state_ring_size, ACCUMULATOR_RING_SIZE);
1521815219

1521915220
let mut cursor = std::io::Cursor::new(&accumulator_state[16..]);
@@ -15238,15 +15239,15 @@ pub(crate) mod tests {
1523815239

1523915240
// verify ring buffer cycles
1524015241
let ring_index_before_buffer_cycle =
15241-
(bank.clock().slot % ACCUMULATOR_RING_SIZE as u64) as u32;
15242+
(bank.slot() % ACCUMULATOR_RING_SIZE as u64) as u32;
1524215243
let target_slot = bank.slot() + ACCUMULATOR_RING_SIZE as u64;
1524315244
// advance ACCUMULATOR_RING_SIZE slots using warp_from_parent since doing large loops
1524415245
// with new_from_parent takes a long time. warp_from_parent results in a bank that is frozen.
1524515246
bank = Bank::warp_from_parent(&Arc::new(bank), &Pubkey::default(), target_slot);
1524615247

1524715248
// accumulator messages should still be the same before looping around
1524815249
let ring_index_after_buffer_cycle =
15249-
(bank.clock().slot % ACCUMULATOR_RING_SIZE as u64) as u32;
15250+
(bank.slot() % ACCUMULATOR_RING_SIZE as u64) as u32;
1525015251
assert_eq!(
1525115252
ring_index_before_buffer_cycle,
1525215253
ring_index_after_buffer_cycle
@@ -15282,7 +15283,7 @@ pub(crate) mod tests {
1528215283
// Run accumulator, update clock & other sysvars etc
1528315284
bank = new_from_parent(&Arc::new(bank));
1528415285

15285-
let ring_index = (bank.clock().slot % ACCUMULATOR_RING_SIZE as u64) as u32;
15286+
let ring_index = (bank.slot() % ACCUMULATOR_RING_SIZE as u64) as u32;
1528615287
let updated_wormhole_message_account = get_wormhole_message_account(&bank, ring_index);
1528715288

1528815289
let updated_wormhole_message =
@@ -15303,7 +15304,7 @@ pub(crate) mod tests {
1530315304
MerkleAccumulator::<Keccak160>::from_set(updated_accumulator_elements).unwrap();
1530415305
assert_eq!(
1530515306
updated_wormhole_message.message.payload,
15306-
expected_accumulator.serialize(bank.clock().slot, ACCUMULATOR_RING_SIZE)
15307+
expected_accumulator.serialize(bank.slot(), ACCUMULATOR_RING_SIZE)
1530715308
);
1530815309

1530915310
let expected_wormhole_message = PostedMessageUnreliableData {
@@ -15317,7 +15318,7 @@ pub(crate) mod tests {
1531715318
sequence: wh_sequence_before_acc_update,
1531815319
emitter_chain: 26,
1531915320
emitter_address: ACCUMULATOR_EMITTER_ADDRESS,
15320-
payload: expected_accumulator.serialize(bank.clock().slot, ACCUMULATOR_RING_SIZE),
15321+
payload: expected_accumulator.serialize(bank.slot(), ACCUMULATOR_RING_SIZE),
1532115322
},
1532215323
};
1532315324

sdk/program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ lazy_static = "1.4.0"
2525
log = "0.4.14"
2626
num-derive = "0.3"
2727
num-traits = "0.2"
28-
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", version = "1.13.6" }
28+
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", version = "1.13.6", rev = "407252000643f0c933ad23194ceabb6a6f0a4bf9" }
2929
rustversion = "1.0.3"
3030
serde = "1.0.112"
3131
schemars = "0.8.8"

0 commit comments

Comments
 (0)