10
10
MessageType ,
11
11
PriceFeedsWithUpdateData ,
12
12
RequestTime ,
13
+ Slot ,
13
14
Update ,
14
15
} ,
15
16
} ,
@@ -32,19 +33,14 @@ use {
32
33
derive_builder:: Builder ,
33
34
moka:: future:: Cache ,
34
35
pyth_sdk:: PriceIdentifier ,
35
- std:: {
36
- ops:: Rem ,
37
- time:: Duration ,
38
- } ,
36
+ std:: time:: Duration ,
39
37
wormhole_sdk:: Vaa ,
40
38
} ;
41
39
42
40
pub mod proof;
43
41
pub mod storage;
44
42
pub mod types;
45
43
46
- pub type RingIndex = u32 ;
47
-
48
44
#[ derive( Clone , PartialEq , Debug , Builder ) ]
49
45
#[ builder( derive( Debug ) , pattern = "immutable" ) ]
50
46
pub struct AccumulatorState {
@@ -55,7 +51,7 @@ pub struct AccumulatorState {
55
51
#[ derive( Clone ) ]
56
52
pub struct Store {
57
53
pub storage : StorageInstance ,
58
- pub pending_accumulations : Cache < RingIndex , AccumulatorStateBuilder > ,
54
+ pub pending_accumulations : Cache < Slot , AccumulatorStateBuilder > ,
59
55
}
60
56
61
57
impl Store {
@@ -73,7 +69,7 @@ impl Store {
73
69
74
70
/// Stores the update data in the store
75
71
pub async fn store_update ( & self , update : Update ) -> Result < ( ) > {
76
- let ring_index = match update {
72
+ let slot = match update {
77
73
Update :: Vaa ( vaa_bytes) => {
78
74
let vaa = serde_wormhole:: from_slice :: < Vaa < Vec < u8 > > > ( & vaa_bytes) ?;
79
75
let payload = WormholePayload :: try_from_bytes ( & vaa. payload , & vaa_bytes) ?;
@@ -83,41 +79,42 @@ impl Store {
83
79
84
80
match payload {
85
81
WormholePayload :: Merkle ( proof) => {
86
- log:: info!( "Storing merkle proof for state index {:?}" , proof) ;
82
+ log:: info!(
83
+ "Storing merkle proof for slot {:?}: {:?}" ,
84
+ proof. slot,
85
+ proof
86
+ ) ;
87
87
store_wormhole_merkle_verified_message ( self , proof. clone ( ) ) . await ?;
88
- proof. state_index
88
+ proof. slot
89
89
}
90
90
}
91
91
}
92
92
Update :: AccumulatorMessages ( accumulator_messages) => {
93
93
// FIXME: Move this constant to a better place
94
- const RING_SIZE : u32 = 10_000 ;
95
- let ring_index = accumulator_messages. slot . rem ( RING_SIZE as u64 ) as u32 ;
94
+
95
+ let slot = accumulator_messages. slot ;
96
96
97
97
log:: info!(
98
- "Storing accumulator messages for ring index {:?}: {:?}" ,
99
- ring_index ,
98
+ "Storing accumulator messages for slot {:?}: {:?}" ,
99
+ slot ,
100
100
accumulator_messages
101
101
) ;
102
102
103
103
let pending_acc = self
104
104
. pending_accumulations
105
- . entry ( ring_index )
105
+ . entry ( slot )
106
106
. or_default ( )
107
107
. await
108
108
. into_value ( ) ;
109
109
self . pending_accumulations
110
- . insert (
111
- ring_index,
112
- pending_acc. accumulator_messages ( accumulator_messages) ,
113
- )
110
+ . insert ( slot, pending_acc. accumulator_messages ( accumulator_messages) )
114
111
. await ;
115
112
116
- ring_index
113
+ slot
117
114
}
118
115
} ;
119
116
120
- let pending_state = self . pending_accumulations . get ( & ring_index ) ;
117
+ let pending_state = self . pending_accumulations . get ( & slot ) ;
121
118
let pending_state = match pending_state {
122
119
Some ( pending_state) => pending_state,
123
120
// Due to some race conditions this might happen when it's processed before
@@ -159,7 +156,7 @@ impl Store {
159
156
160
157
self . storage . store_message_states ( message_states) ?;
161
158
162
- self . pending_accumulations . invalidate ( & ring_index ) . await ;
159
+ self . pending_accumulations . invalidate ( & slot ) . await ;
163
160
164
161
Ok ( ( ) )
165
162
}
0 commit comments