4
4
use acropolis_common:: {
5
5
messages:: { CardanoMessage , Message , ProtocolParamsMessage , StateQuery , StateQueryResponse } ,
6
6
queries:: parameters:: {
7
- LatestParameters , ParametersStateQuery , ParametersStateQueryResponse ,
8
- DEFAULT_PARAMETERS_QUERY_TOPIC ,
7
+ ParametersStateQuery , ParametersStateQueryResponse , DEFAULT_PARAMETERS_QUERY_TOPIC ,
9
8
} ,
10
- rest_helper:: handle_rest,
11
9
state_history:: { StateHistory , StateHistoryStore } ,
12
10
BlockInfo , BlockStatus ,
13
11
} ;
@@ -17,20 +15,14 @@ use config::Config;
17
15
use std:: sync:: Arc ;
18
16
use tokio:: sync:: Mutex ;
19
17
use tracing:: { error, info, info_span, Instrument } ;
20
-
21
18
mod alonzo_genesis;
22
19
mod genesis_params;
23
20
mod parameters_updater;
24
- mod rest;
25
21
mod state;
26
-
27
22
use parameters_updater:: ParametersUpdater ;
28
- use rest:: handle_current;
29
23
use state:: State ;
30
24
31
25
const DEFAULT_ENACT_STATE_TOPIC : ( & str , & str ) = ( "enact-state-topic" , "cardano.enact.state" ) ;
32
- const DEFAULT_HANDLE_CURRENT_TOPIC : ( & str , & str ) =
33
- ( "handle-current-params-topic" , "rest.get.epoch.parameters" ) ;
34
26
const DEFAULT_PROTOCOL_PARAMETERS_TOPIC : ( & str , & str ) =
35
27
( "publish-parameters-topic" , "cardano.protocol.parameters" ) ;
36
28
const DEFAULT_NETWORK_NAME : ( & str , & str ) = ( "network-name" , "mainnet" ) ;
@@ -48,7 +40,6 @@ struct ParametersStateConfig {
48
40
pub context : Arc < Context < Message > > ,
49
41
pub network_name : String ,
50
42
pub enact_state_topic : String ,
51
- pub handle_current_topic : String ,
52
43
pub protocol_parameters_topic : String ,
53
44
pub parameters_query_topic : String ,
54
45
pub store_history : bool ,
@@ -72,7 +63,6 @@ impl ParametersStateConfig {
72
63
context,
73
64
network_name : Self :: conf ( config, DEFAULT_NETWORK_NAME ) ,
74
65
enact_state_topic : Self :: conf ( config, DEFAULT_ENACT_STATE_TOPIC ) ,
75
- handle_current_topic : Self :: conf ( config, DEFAULT_HANDLE_CURRENT_TOPIC ) ,
76
66
protocol_parameters_topic : Self :: conf ( config, DEFAULT_PROTOCOL_PARAMETERS_TOPIC ) ,
77
67
parameters_query_topic : Self :: conf ( config, DEFAULT_PARAMETERS_QUERY_TOPIC ) ,
78
68
store_history : Self :: conf_bool ( config, DEFAULT_STORE_HISTORY ) ,
@@ -155,9 +145,10 @@ impl ParametersState {
155
145
pub async fn init ( & self , context : Arc < Context < Message > > , config : Arc < Config > ) -> Result < ( ) > {
156
146
let cfg = ParametersStateConfig :: new ( context. clone ( ) , & config) ;
157
147
let enact = cfg. context . subscribe ( & cfg. enact_state_topic ) . await ?;
148
+ let store_history = cfg. store_history ;
158
149
159
150
// Initalize state history
160
- let history = if cfg . store_history {
151
+ let history = if store_history {
161
152
Arc :: new ( Mutex :: new ( StateHistory :: < State > :: new (
162
153
"ParameterState" ,
163
154
StateHistoryStore :: Unbounded ,
@@ -171,11 +162,6 @@ impl ParametersState {
171
162
172
163
let query_state = history. clone ( ) ;
173
164
174
- let state_rest = history. clone ( ) ;
175
- handle_rest ( cfg. context . clone ( ) , & cfg. handle_current_topic , move || {
176
- handle_current ( state_rest. clone ( ) )
177
- } ) ;
178
-
179
165
// Handle parameters queries
180
166
context. handle ( & cfg. parameters_query_topic , move |message| {
181
167
let history = query_state. clone ( ) ;
@@ -188,12 +174,27 @@ impl ParametersState {
188
174
) ) ) ;
189
175
} ;
190
176
191
- let state = history. lock ( ) . await . get_current_state ( ) ;
177
+ let lock = history. lock ( ) . await ;
192
178
let response = match query {
193
- ParametersStateQuery :: GetLatestParameters => {
194
- ParametersStateQueryResponse :: LatestParameters ( LatestParameters {
195
- parameters : state. current_params . get_params ( ) ,
196
- } )
179
+ ParametersStateQuery :: GetLatestEpochParameters => {
180
+ ParametersStateQueryResponse :: LatestEpochParameters (
181
+ lock. get_current_state ( ) . current_params . get_params ( ) ,
182
+ )
183
+ }
184
+ ParametersStateQuery :: GetEpochParameters { epoch_number } => {
185
+ if !store_history {
186
+ ParametersStateQueryResponse :: Error (
187
+ "Historical protocol parameter storage disabled by config"
188
+ . to_string ( ) ,
189
+ )
190
+ } else {
191
+ match lock. get_at_or_before ( * epoch_number) {
192
+ Some ( state) => ParametersStateQueryResponse :: EpochParameters (
193
+ state. current_params . get_params ( ) ,
194
+ ) ,
195
+ None => ParametersStateQueryResponse :: NotFound ,
196
+ }
197
+ }
197
198
}
198
199
} ;
199
200
Arc :: new ( Message :: StateQueryResponse ( StateQueryResponse :: Parameters (
0 commit comments