Skip to content

Commit 8294627

Browse files
committed
Merge branch 'main' into lowhung/313-query-error-type
# Conflicts: # modules/accounts_state/src/accounts_state.rs # modules/address_state/src/address_state.rs # modules/assets_state/src/assets_state.rs # modules/chain_store/src/chain_store.rs # modules/drep_state/src/drep_state.rs # modules/epochs_state/src/epochs_state.rs # modules/governance_state/src/governance_state.rs # modules/historical_accounts_state/src/historical_accounts_state.rs # modules/rest_blockfrost/src/handlers/accounts.rs # modules/rest_blockfrost/src/handlers/addresses.rs # modules/rest_blockfrost/src/handlers/assets.rs # modules/rest_blockfrost/src/handlers/blocks.rs # modules/rest_blockfrost/src/handlers/epochs.rs # modules/rest_blockfrost/src/handlers/governance.rs # modules/rest_blockfrost/src/handlers/pools.rs # modules/spo_state/src/spo_state.rs # modules/utxo_state/src/utxo_state.rs
2 parents c925633 + 12b75f1 commit 8294627

File tree

11 files changed

+77
-66
lines changed

11 files changed

+77
-66
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ SHELL := bash
66
CARGO := cargo
77
PYTHON := python3
88
PROCESS_PKG := acropolis_process_omnibus
9+
LOG_LEVEL ?= info
10+
911

1012
# Test snapshots
1113
SNAPSHOT_SMALL ?= tests/fixtures/snapshot-small.cbor
@@ -28,6 +30,7 @@ help:
2830
@echo "Build & Test:"
2931
@echo " all Format, lint, and test"
3032
@echo " build Build the omnibus process"
33+
@echo " run Run the omnibus"
3134
@echo " test Run all tests"
3235
@echo " fmt Run cargo fmt"
3336
@echo " clippy Run cargo clippy -D warnings"
@@ -37,9 +40,11 @@ help:
3740
@echo ""
3841
@echo "Variables:"
3942
@echo " SNAPSHOT=<path> Path to snapshot file (default: Conway epoch 507)"
43+
@echo " LOG_LEVEL=<level> Set log level (default: info, options: error, warn, info, debug, trace)"
4044
@echo ""
4145
@echo "Examples:"
4246
@echo " make snap-test-streaming"
47+
@echo " make run LOG_LEVEL=debug"
4348
@echo " make snap-test-streaming SNAPSHOT=path/to/snapshot.cbor"
4449

4550
all: fmt clippy test
@@ -51,7 +56,7 @@ test:
5156
$(CARGO) test
5257

5358
run:
54-
$(CARGO) run -p $(PROCESS_PKG)
59+
cd processes/omnibus && RUST_LOG=$(LOG_LEVEL) $(CARGO) run --release --bin $(PROCESS_PKG)
5560

5661
fmt:
5762
$(CARGO) fmt --all

modules/accounts_state/src/accounts_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl AccountsState {
485485
async move {
486486
let Message::StateQuery(StateQuery::Accounts(query)) = message.as_ref() else {
487487
return Arc::new(Message::StateQueryResponse(StateQueryResponse::Accounts(
488-
AccountsStateQueryResponse::Error(QueryError::invalid_request(
488+
AccountsStateQueryResponse::Error(QueryError::internal_error(
489489
"Invalid message for accounts-state",
490490
)),
491491
)));

modules/address_state/src/address_state.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl AddressState {
199199
async move {
200200
let Message::StateQuery(StateQuery::Addresses(query)) = message.as_ref() else {
201201
return Arc::new(Message::StateQueryResponse(StateQueryResponse::Addresses(
202-
AddressStateQueryResponse::Error(QueryError::invalid_request(
202+
AddressStateQueryResponse::Error(QueryError::internal_error(
203203
"Invalid message for address-state",
204204
)),
205205
)));
@@ -210,9 +210,16 @@ impl AddressState {
210210
AddressStateQuery::GetAddressUTxOs { address } => {
211211
match state.get_address_utxos(address).await {
212212
Ok(Some(utxos)) => AddressStateQueryResponse::AddressUTxOs(utxos),
213-
Ok(None) => AddressStateQueryResponse::Error(QueryError::not_found(
214-
"Address not found",
215-
)),
213+
Ok(None) => match address.to_string() {
214+
Ok(addr_str) => AddressStateQueryResponse::Error(
215+
QueryError::not_found(format!("Address {}", addr_str)),
216+
),
217+
Err(e) => {
218+
AddressStateQueryResponse::Error(QueryError::internal_error(
219+
format!("Could not convert address to string: {}", e),
220+
))
221+
}
222+
},
216223
Err(e) => AddressStateQueryResponse::Error(QueryError::internal_error(
217224
e.to_string(),
218225
)),
@@ -221,9 +228,16 @@ impl AddressState {
221228
AddressStateQuery::GetAddressTransactions { address } => {
222229
match state.get_address_transactions(address).await {
223230
Ok(Some(txs)) => AddressStateQueryResponse::AddressTransactions(txs),
224-
Ok(None) => AddressStateQueryResponse::Error(QueryError::not_found(
225-
"Address not found",
226-
)),
231+
Ok(None) => match address.to_string() {
232+
Ok(addr_str) => AddressStateQueryResponse::Error(
233+
QueryError::not_found(format!("Address {}", addr_str)),
234+
),
235+
Err(e) => {
236+
AddressStateQueryResponse::Error(QueryError::internal_error(
237+
format!("Could not convert address to string: {}", e),
238+
))
239+
}
240+
},
227241
Err(e) => AddressStateQueryResponse::Error(QueryError::internal_error(
228242
e.to_string(),
229243
)),

modules/assets_state/src/assets_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl AssetsState {
282282
async move {
283283
let Message::StateQuery(StateQuery::Assets(query)) = message.as_ref() else {
284284
return Arc::new(Message::StateQueryResponse(StateQueryResponse::Assets(
285-
AssetsStateQueryResponse::Error(QueryError::invalid_request(
285+
AssetsStateQueryResponse::Error(QueryError::internal_error(
286286
"Invalid message for assets-state",
287287
)),
288288
)));

modules/chain_store/src/chain_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ impl ChainStore {
6666
async move {
6767
let Message::StateQuery(StateQuery::Blocks(query)) = req.as_ref() else {
6868
return Arc::new(Message::StateQueryResponse(StateQueryResponse::Blocks(
69-
BlocksStateQueryResponse::Error(QueryError::invalid_request(
69+
BlocksStateQueryResponse::Error(QueryError::internal_error(
7070
"Invalid message for blocks-state",
7171
)),
7272
)));
7373
};
7474
let Some(state) = query_history.lock().await.current().cloned() else {
7575
return Arc::new(Message::StateQueryResponse(StateQueryResponse::Blocks(
7676
BlocksStateQueryResponse::Error(QueryError::internal_error(
77-
"Uninitialized state",
77+
"uninitialized state",
7878
)),
7979
)));
8080
};

modules/drep_state/src/drep_state.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl DRepState {
266266
async move {
267267
let Message::StateQuery(StateQuery::Governance(query)) = message.as_ref() else {
268268
return Arc::new(Message::StateQueryResponse(StateQueryResponse::Governance(
269-
GovernanceStateQueryResponse::Error(QueryError::invalid_request(
269+
GovernanceStateQueryResponse::Error(QueryError::internal_error(
270270
"Invalid message for governance-state",
271271
)),
272272
)));
@@ -318,9 +318,11 @@ impl DRepState {
318318
}
319319
}
320320

321-
Ok(None) => GovernanceStateQueryResponse::Error(
322-
QueryError::not_found(format!("DRep {:?}", drep_credential)),
323-
),
321+
Ok(None) => {
322+
GovernanceStateQueryResponse::Error(QueryError::not_found(
323+
format!("DRep {:?} not found", drep_credential),
324+
))
325+
}
324326
Err(msg) => GovernanceStateQueryResponse::Error(
325327
QueryError::internal_error(msg),
326328
),
@@ -340,11 +342,12 @@ impl DRepState {
340342
},
341343
)
342344
}
343-
Ok(None) => {
344-
GovernanceStateQueryResponse::Error(QueryError::not_found(
345-
format!("DRep delegators for {:?}", drep_credential),
346-
))
347-
}
345+
Ok(None) => GovernanceStateQueryResponse::Error(
346+
QueryError::not_found(format!(
347+
"DRep delegators for {:?} not found",
348+
drep_credential
349+
)),
350+
),
348351
Err(msg) => GovernanceStateQueryResponse::Error(
349352
QueryError::internal_error(msg),
350353
),
@@ -360,11 +363,12 @@ impl DRepState {
360363
Ok(Some(anchor)) => GovernanceStateQueryResponse::DRepMetadata(
361364
Some(Some(anchor.clone())),
362365
),
363-
Ok(None) => {
364-
GovernanceStateQueryResponse::Error(QueryError::not_found(
365-
format!("DRep metadata for {:?}", drep_credential),
366-
))
367-
}
366+
Ok(None) => GovernanceStateQueryResponse::Error(
367+
QueryError::not_found(format!(
368+
"DRep metadata for {:?} not found",
369+
drep_credential
370+
)),
371+
),
368372
Err(msg) => GovernanceStateQueryResponse::Error(
369373
QueryError::internal_error(msg),
370374
),
@@ -385,7 +389,7 @@ impl DRepState {
385389
}
386390
Ok(None) => {
387391
GovernanceStateQueryResponse::Error(QueryError::not_found(
388-
format!("DRep updates for {:?}", drep_credential),
392+
format!("DRep updates for {:?} not found", drep_credential),
389393
))
390394
}
391395
Err(msg) => GovernanceStateQueryResponse::Error(
@@ -419,7 +423,7 @@ impl DRepState {
419423
),
420424
}
421425
}
422-
_ => GovernanceStateQueryResponse::Error(QueryError::invalid_request(format!(
426+
_ => GovernanceStateQueryResponse::Error(QueryError::internal_error(format!(
423427
"Unimplemented governance query: {query:?}"
424428
))),
425429
};

modules/epochs_state/src/epochs_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl EpochsState {
338338
)
339339
}
340340

341-
_ => EpochsStateQueryResponse::Error(QueryError::invalid_request(format!(
341+
_ => EpochsStateQueryResponse::Error(QueryError::not_implemented(format!(
342342
"Unimplemented query variant: {:?}",
343343
query
344344
))),
@@ -349,7 +349,7 @@ impl EpochsState {
349349
}
350350
});
351351

352-
// Start run task
352+
// Start the run task
353353
context.run(async move {
354354
Self::run(
355355
history,

modules/governance_state/src/governance_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl GovernanceState {
203203
})
204204
}
205205
None => GovernanceStateQueryResponse::Error(QueryError::not_found(
206-
format!("Proposal not found {}", proposal),
206+
format!("Proposal {} not found", proposal),
207207
)),
208208
}
209209
}
@@ -213,7 +213,7 @@ impl GovernanceState {
213213
GovernanceStateQueryResponse::ProposalVotes(ProposalVotes { votes })
214214
}
215215
Err(_) => GovernanceStateQueryResponse::Error(QueryError::not_found(
216-
format!("Proposal not found {}", proposal),
216+
format!("Proposal {} not found", proposal),
217217
)),
218218
}
219219
}

modules/historical_accounts_state/src/historical_accounts_state.rs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl HistoricalAccountsState {
302302
async move {
303303
let Message::StateQuery(StateQuery::Accounts(query)) = message.as_ref() else {
304304
return Arc::new(Message::StateQueryResponse(StateQueryResponse::Accounts(
305-
AccountsStateQueryResponse::Error(QueryError::invalid_request(
305+
AccountsStateQueryResponse::Error(QueryError::internal_error(
306306
"Invalid message for accounts-state",
307307
)),
308308
)));
@@ -317,13 +317,11 @@ impl HistoricalAccountsState {
317317
)
318318
}
319319
Ok(None) => AccountsStateQueryResponse::Error(QueryError::not_found(
320-
format!("Account {}", account),
320+
format!("Account {} not found", account),
321321
)),
322-
Err(e) => {
323-
AccountsStateQueryResponse::Error(QueryError::internal_error(
324-
format!("Failed to get registration history: {}", e),
325-
))
326-
}
322+
Err(e) => AccountsStateQueryResponse::Error(
323+
QueryError::internal_error(e.to_string()),
324+
),
327325
}
328326
}
329327
AccountsStateQuery::GetAccountDelegationHistory { account } => {
@@ -334,11 +332,9 @@ impl HistoricalAccountsState {
334332
Ok(None) => AccountsStateQueryResponse::Error(QueryError::not_found(
335333
format!("Account {}", account),
336334
)),
337-
Err(e) => {
338-
AccountsStateQueryResponse::Error(QueryError::internal_error(
339-
format!("Failed to get delegation history: {}", e),
340-
))
341-
}
335+
Err(e) => AccountsStateQueryResponse::Error(
336+
QueryError::internal_error(e.to_string()),
337+
),
342338
}
343339
}
344340
AccountsStateQuery::GetAccountMIRHistory { account } => {
@@ -347,11 +343,9 @@ impl HistoricalAccountsState {
347343
Ok(None) => AccountsStateQueryResponse::Error(QueryError::not_found(
348344
format!("Account {}", account),
349345
)),
350-
Err(e) => {
351-
AccountsStateQueryResponse::Error(QueryError::internal_error(
352-
format!("Failed to get MIR history: {}", e),
353-
))
354-
}
346+
Err(e) => AccountsStateQueryResponse::Error(
347+
QueryError::internal_error(e.to_string()),
348+
),
355349
}
356350
}
357351
AccountsStateQuery::GetAccountWithdrawalHistory { account } => {
@@ -362,11 +356,9 @@ impl HistoricalAccountsState {
362356
Ok(None) => AccountsStateQueryResponse::Error(QueryError::not_found(
363357
format!("Account {}", account),
364358
)),
365-
Err(e) => {
366-
AccountsStateQueryResponse::Error(QueryError::internal_error(
367-
format!("Failed to get withdrawal history: {}", e),
368-
))
369-
}
359+
Err(e) => AccountsStateQueryResponse::Error(
360+
QueryError::internal_error(e.to_string()),
361+
),
370362
}
371363
}
372364
AccountsStateQuery::GetAccountRewardHistory { account } => {
@@ -377,11 +369,9 @@ impl HistoricalAccountsState {
377369
Ok(None) => AccountsStateQueryResponse::Error(QueryError::not_found(
378370
format!("Account {}", account),
379371
)),
380-
Err(e) => {
381-
AccountsStateQueryResponse::Error(QueryError::internal_error(
382-
format!("Failed to get reward history: {}", e),
383-
))
384-
}
372+
Err(e) => AccountsStateQueryResponse::Error(
373+
QueryError::internal_error(e.to_string()),
374+
),
385375
}
386376
}
387377
AccountsStateQuery::GetAccountAssociatedAddresses { account } => {
@@ -392,11 +382,9 @@ impl HistoricalAccountsState {
392382
Ok(None) => AccountsStateQueryResponse::Error(QueryError::not_found(
393383
format!("Account {}", account),
394384
)),
395-
Err(e) => {
396-
AccountsStateQueryResponse::Error(QueryError::internal_error(
397-
format!("Failed to get associated addresses: {}", e),
398-
))
399-
}
385+
Err(e) => AccountsStateQueryResponse::Error(
386+
QueryError::internal_error(e.to_string()),
387+
),
400388
}
401389
}
402390
_ => AccountsStateQueryResponse::Error(QueryError::not_implemented(format!(

modules/spo_state/src/spo_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl SPOState {
499499
async move {
500500
let Message::StateQuery(StateQuery::Pools(query)) = message.as_ref() else {
501501
return Arc::new(Message::StateQueryResponse(StateQueryResponse::Pools(
502-
PoolsStateQueryResponse::Error(QueryError::invalid_request(
502+
PoolsStateQueryResponse::Error(QueryError::internal_error(
503503
"Invalid message for pools-state",
504504
)),
505505
)));

0 commit comments

Comments
 (0)