Skip to content

Commit 1922268

Browse files
committed
merge upstream/main
Signed-off-by: William Hankins <[email protected]>
2 parents 959680d + 81eb75d commit 1922268

File tree

43 files changed

+1189
-365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1189
-365
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

common/src/address.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,12 @@ pub struct ShelleyAddressPointer {
148148
serde::Deserialize,
149149
minicbor::Encode,
150150
minicbor::Decode,
151+
Default,
151152
)]
152153
pub enum ShelleyAddressDelegationPart {
153154
/// No delegation (enterprise addresses)
154155
#[n(0)]
156+
#[default]
155157
None,
156158

157159
/// Delegation to stake key
@@ -167,12 +169,6 @@ pub enum ShelleyAddressDelegationPart {
167169
Pointer(#[n(0)] ShelleyAddressPointer),
168170
}
169171

170-
impl Default for ShelleyAddressDelegationPart {
171-
fn default() -> Self {
172-
Self::None
173-
}
174-
}
175-
176172
/// A Shelley-era address
177173
#[derive(
178174
Debug,
@@ -619,20 +615,15 @@ impl Default for StakeAddress {
619615
}
620616

621617
/// A Cardano address
622-
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
618+
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, Default)]
623619
pub enum Address {
620+
#[default]
624621
None,
625622
Byron(ByronAddress),
626623
Shelley(ShelleyAddress),
627624
Stake(StakeAddress),
628625
}
629626

630-
impl Default for Address {
631-
fn default() -> Self {
632-
Self::None
633-
}
634-
}
635-
636627
impl Address {
637628
/// Get the stake pointer if there is one
638629
pub fn get_pointer(&self) -> Option<ShelleyAddressPointer> {

common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub mod protocol_params;
1515
pub mod queries;
1616
pub mod rational_number;
1717
pub mod resolver;
18+
pub mod rest_error;
1819
pub mod rest_helper;
1920
pub mod serialization;
2021
pub mod snapshot;

common/src/messages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ pub enum CardanoMessage {
311311

312312
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
313313
pub enum SnapshotMessage {
314+
Startup, // subscribers should listen for incremental snapshot data
314315
Bootstrap(SnapshotStateMessage),
315316
DumpRequest(SnapshotDumpMessage),
316317
Dump(SnapshotStateMessage),

common/src/queries/accounts.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::HashMap;
22

3+
use crate::queries::errors::QueryError;
34
use crate::{
45
DRepChoice, PoolId, PoolLiveStakeInfo, RewardType, ShelleyAddress, StakeAddress, TxIdentifier,
56
};
@@ -78,9 +79,7 @@ pub enum AccountsStateQueryResponse {
7879
// DReps-related responses
7980
DrepDelegators(DrepDelegators),
8081
AccountsDrepDelegationsMap(HashMap<StakeAddress, Option<DRepChoice>>),
81-
82-
NotFound,
83-
Error(String),
82+
Error(QueryError),
8483
}
8584

8685
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]

common/src/queries/addresses.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::queries::errors::QueryError;
12
use crate::{
23
Address, AddressTotals, NativeAssets, ShelleyAddress, TxIdentifier, UTxOIdentifier, ValueDelta,
34
};
@@ -27,6 +28,5 @@ pub enum AddressStateQueryResponse {
2728
AddressesAssets(NativeAssets),
2829
AddressesTotals(ValueDelta),
2930
AddressesUTxOs(Vec<UTxOIdentifier>),
30-
NotFound,
31-
Error(String),
31+
Error(QueryError),
3232
}

common/src/queries/assets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::queries::errors::QueryError;
12
use crate::{
23
AssetAddressEntry, AssetInfoRecord, AssetMintRecord, AssetName, PolicyAsset, PolicyId,
34
TxIdentifier,
@@ -36,6 +37,5 @@ pub enum AssetsStateQueryResponse {
3637
AssetAddresses(AssetAddresses),
3738
AssetTransactions(AssetTransactions),
3839
PolicyIdAssets(PolicyAssets),
39-
NotFound,
40-
Error(String),
40+
Error(QueryError),
4141
}

common/src/queries/blocks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::queries::errors::QueryError;
12
use crate::{
23
queries::misc::Order,
34
serialization::{Bech32Conversion, Bech32WithHrp},
@@ -95,8 +96,7 @@ pub enum BlocksStateQueryResponse {
9596
BlockHashes(BlockHashes),
9697
TransactionHashes(TransactionHashes),
9798
UTxOHashes(UTxOHashes),
98-
NotFound,
99-
Error(String),
99+
Error(QueryError),
100100
}
101101

102102
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]

common/src/queries/epochs.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::queries::errors::QueryError;
12
use crate::{messages::EpochActivityMessage, protocol_params::ProtocolParams, PoolId};
23

34
pub const DEFAULT_EPOCHS_QUERY_TOPIC: (&str, &str) =
@@ -23,9 +24,7 @@ pub enum EpochsStateQueryResponse {
2324
EpochStakeDistribution(EpochStakeDistribution),
2425
EpochStakeDistributionByPool(EpochStakeDistributionByPool),
2526
LatestEpochBlocksMintedByPool(u64),
26-
27-
NotFound,
28-
Error(String),
27+
Error(QueryError),
2928
}
3029

3130
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]

common/src/queries/errors.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use serde::{Deserialize, Serialize};
2+
use thiserror::Error;
3+
4+
/// Common error type for all state query responses
5+
#[derive(Debug, Clone, Error, Serialize, Deserialize)]
6+
pub enum QueryError {
7+
/// The requested resource was not found
8+
#[error("Not found: {resource}")]
9+
NotFound { resource: String },
10+
11+
/// An error occurred while processing the query
12+
#[error("Internal error: {message}")]
13+
Internal { message: String },
14+
15+
/// Storage backend is disabled in configuration
16+
#[error("{storage_type} storage is not enabled")]
17+
StorageDisabled { storage_type: String },
18+
19+
/// Invalid request parameters
20+
#[error("Invalid request: {message}")]
21+
InvalidRequest { message: String },
22+
23+
/// Query variant is not implemented yet
24+
#[error("Query not implemented: {query}")]
25+
NotImplemented { query: String },
26+
}
27+
28+
impl QueryError {
29+
pub fn not_found(resource: impl Into<String>) -> Self {
30+
Self::NotFound {
31+
resource: resource.into(),
32+
}
33+
}
34+
35+
pub fn internal_error(message: impl Into<String>) -> Self {
36+
Self::Internal {
37+
message: message.into(),
38+
}
39+
}
40+
41+
pub fn storage_disabled(storage_type: impl Into<String>) -> Self {
42+
Self::StorageDisabled {
43+
storage_type: storage_type.into(),
44+
}
45+
}
46+
47+
pub fn invalid_request(message: impl Into<String>) -> Self {
48+
Self::InvalidRequest {
49+
message: message.into(),
50+
}
51+
}
52+
53+
pub fn not_implemented(query: impl Into<String>) -> Self {
54+
Self::NotImplemented {
55+
query: query.into(),
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)