Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit d6d1120

Browse files
grtlrAlex Coats
and
Alex Coats
authored
feat(inx): update to latest version of packable and bee-inx (#729)
* WIP: bump `bee-inx` * More WIP * Even more WIP * Finish bin impls * Use more realisitic protocol parameters and fmt * Fmt * Fix * Add more instrumentation * Use testnet by default * Right folder * Fix payload type (#735) * Debug info * Bump bee-inx * Fix payload type * Fmt * Use `iotaledgeer/bee-inx` * Bump `bee-block` and `bee-inx` * Bump `bee-api-types` * `TryFrom` * Don't use `TryFromWithContext` in INX writer * Revert structure change Co-authored-by: Alex Coats <[email protected]>
1 parent 46509d6 commit d6d1120

35 files changed

+595
-285
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ed25519-dalek = { version = "1.0", default-features = false, features = [ "u64_b
5959
hex = { version = "0.4", default-features = false, optional = true }
6060
hyper = { version = "0.14", default-features = false, features = [ "server", "tcp", "stream" ], optional = true }
6161
lazy_static = { version = "1.4", default-features = false, optional = true }
62-
packable = { version = "=0.6.1", default-features = false, optional = true }
62+
packable = { version = "0.6", default-features = false, optional = true }
6363
rand = { version = "0.8", default-features = false, features = [ "std" ], optional = true }
6464
regex = { version = "1.5", default-features = false, features = [ "std" ], optional = true }
6565
rust-argon2 = { version = "1.0.0", default-features = false, optional = true }
@@ -69,7 +69,7 @@ tower-http = { version = "0.3", default-features = false, features = [ "cors", "
6969
zeroize = { version = "1.5", default-features = false, features = [ "std" ], optional = true }
7070

7171
# INX
72-
bee-inx = { version = "1.0.0-beta.5", default-features = false, optional = true }
72+
bee-inx = { version = "1.0.0-beta.6", default-features = false, optional = true }
7373
tonic = { version = "0.8", default-features = false, optional = true }
7474

7575
# Metrics
@@ -81,8 +81,8 @@ opentelemetry-jaeger = { version = "0.17", default-features = false, features =
8181
tracing-opentelemetry = { version = "0.18", default-features = false, features = ["tracing-log"], optional = true }
8282

8383
# Stardust types
84-
bee-api-types-stardust = { package = "bee-api-types", version = "1.0.0-beta.7", default-features = false, features = ["axum"], optional = true }
85-
bee-block-stardust = { package = "bee-block", version = "1.0.0-beta.7", default-features = false, features = [ "dto", "std", "serde" ], optional = true }
84+
bee-api-types-stardust = { package = "bee-api-types", version = "1.0.0", default-features = false, features = ["axum"], optional = true }
85+
bee-block-stardust = { package = "bee-block", version = "1.0.0", default-features = false, features = [ "dto", "std", "rand", "serde"], optional = true }
8686

8787
[dev-dependencies]
8888
rand = { version = "0.8", default-features = false, features = [ "std" ] }

docker/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ services:
5656
cap_drop:
5757
- ALL
5858
volumes:
59-
- ./data/hornet:/app/alphanet
60-
- ./config.alphanet.hornet.json:/app/config.json:ro
59+
- ./data/hornet:/app/testnet
60+
- ./config.testnet.hornet.json:/app/config.json:ro
6161
command:
6262
- "-c"
6363
- "config.json"

src/bin/inx-chronicle/api/stardust/core/routes.rs

Lines changed: 95 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use chronicle::{
3131
MongoDb,
3232
},
3333
types::{
34+
context::{TryFromWithContext, TryIntoWithContext},
3435
stardust::block::{
3536
output::OutputId,
3637
payload::{milestone::MilestoneId, transaction::TransactionId},
@@ -134,17 +135,19 @@ pub async fn info(database: Extension<MongoDb>) -> ApiResult<InfoResponse> {
134135

135136
let latest_milestone = LatestMilestoneResponse {
136137
index: newest_milestone.milestone_index.0,
137-
timestamp: newest_milestone.milestone_timestamp.0,
138-
milestone_id: bee_block_stardust::payload::milestone::MilestoneId::from(
139-
database
140-
.collection::<MilestoneCollection>()
141-
.get_milestone_id(newest_milestone.milestone_index)
142-
.await?
143-
.ok_or(ApiError::Internal(InternalApiError::CorruptState(
144-
"no milestone in the database",
145-
)))?,
146-
)
147-
.to_string(),
138+
timestamp: Some(newest_milestone.milestone_timestamp.0),
139+
milestone_id: Some(
140+
bee_block_stardust::payload::milestone::MilestoneId::from(
141+
database
142+
.collection::<MilestoneCollection>()
143+
.get_milestone_id(newest_milestone.milestone_index)
144+
.await?
145+
.ok_or(ApiError::Internal(InternalApiError::CorruptState(
146+
"no milestone in the database",
147+
)))?,
148+
)
149+
.to_string(),
150+
),
148151
};
149152

150153
// Unfortunately, there is a distinction between `LatestMilestoneResponse` and `ConfirmedMilestoneResponse` in Bee.
@@ -160,6 +163,7 @@ pub async fn info(database: Extension<MongoDb>) -> ApiResult<InfoResponse> {
160163
protocol: ProtocolResponse {
161164
version: protocol.version,
162165
network_name: protocol.network_name,
166+
below_max_depth: protocol.below_max_depth,
163167
bech32_hrp: protocol.bech32_hrp,
164168
min_pow_score: protocol.min_pow_score,
165169
rent_structure: RentStructureResponse {
@@ -202,7 +206,19 @@ async fn block(
202206
.get_block(&block_id)
203207
.await?
204208
.ok_or(ApiError::NoResults)?;
205-
Ok(BlockResponse::Json(BlockDto::try_from(block)?))
209+
210+
let protocol_params = database
211+
.collection::<ProtocolUpdateCollection>()
212+
.get_protocol_parameters_for_version(block.protocol_version)
213+
.await?
214+
.ok_or(ApiError::NoResults)?
215+
.parameters
216+
.try_into()?;
217+
218+
Ok(BlockResponse::Json(BlockDto::try_from_with_context(
219+
&protocol_params,
220+
block,
221+
)?))
206222
}
207223

208224
async fn block_metadata(
@@ -272,9 +288,17 @@ async fn output(database: Extension<MongoDb>, Path(output_id): Path<String>) ->
272288

273289
let metadata = create_output_metadata_response(metadata, ledger_index);
274290

291+
let protocol_params = database
292+
.collection::<ProtocolUpdateCollection>()
293+
.get_protocol_parameters_for_ledger_index(ledger_index)
294+
.await?
295+
.ok_or(ApiError::NoResults)?
296+
.parameters
297+
.try_into()?;
298+
275299
Ok(OutputResponse {
276300
metadata,
277-
output: OutputDto::try_from(output)?,
301+
output: OutputDto::try_from_with_context(&protocol_params, output)?,
278302
})
279303
}
280304

@@ -308,14 +332,33 @@ async fn transaction_included_block(
308332
.await?
309333
.ok_or(ApiError::NoResults)?;
310334

311-
Ok(BlockResponse::Json(BlockDto::try_from(block)?))
335+
let protocol_params = database
336+
.collection::<ProtocolUpdateCollection>()
337+
.get_protocol_parameters_for_version(block.protocol_version)
338+
.await?
339+
.ok_or(ApiError::NoResults)?
340+
.parameters
341+
.try_into()?;
342+
343+
Ok(BlockResponse::Json(BlockDto::try_from_with_context(
344+
&protocol_params,
345+
block,
346+
)?))
312347
}
313348

314349
async fn receipts(database: Extension<MongoDb>) -> ApiResult<ReceiptsResponse> {
315350
let mut receipts_at = database.collection::<MilestoneCollection>().get_all_receipts().await?;
316351
let mut receipts = Vec::new();
317352
while let Some((receipt, at)) = receipts_at.try_next().await? {
318-
let receipt: &bee_block_stardust::payload::milestone::MilestoneOption = &receipt.try_into()?;
353+
let protocol_params = database
354+
.collection::<ProtocolUpdateCollection>()
355+
.get_protocol_parameters_for_ledger_index(at)
356+
.await?
357+
.ok_or(ApiError::NoResults)?
358+
.parameters
359+
.try_into()?;
360+
let receipt: &bee_block_stardust::payload::milestone::MilestoneOption =
361+
&receipt.try_into_with_context(&protocol_params)?;
319362
let receipt: bee_block_stardust::payload::milestone::option::dto::MilestoneOptionDto = receipt.into();
320363

321364
if let MilestoneOptionDto::Receipt(receipt) = receipt {
@@ -335,9 +378,17 @@ async fn receipts_migrated_at(database: Extension<MongoDb>, Path(index): Path<u3
335378
.collection::<MilestoneCollection>()
336379
.get_receipts_migrated_at(index.into())
337380
.await?;
381+
let protocol_params = database
382+
.collection::<ProtocolUpdateCollection>()
383+
.get_protocol_parameters_for_ledger_index(index.into())
384+
.await?
385+
.ok_or(ApiError::NoResults)?
386+
.parameters
387+
.try_into()?;
338388
let mut receipts = Vec::new();
339389
while let Some((receipt, at)) = receipts_at.try_next().await? {
340-
let receipt: &bee_block_stardust::payload::milestone::MilestoneOption = &receipt.try_into()?;
390+
let receipt: &bee_block_stardust::payload::milestone::MilestoneOption =
391+
&receipt.try_into_with_context(&protocol_params)?;
341392
let receipt: bee_block_stardust::payload::milestone::option::dto::MilestoneOptionDto = receipt.into();
342393

343394
if let MilestoneOptionDto::Receipt(receipt) = receipt {
@@ -376,14 +427,26 @@ async fn milestone(
376427
.await?
377428
.ok_or(ApiError::NoResults)?;
378429

430+
let protocol_params = database
431+
.collection::<ProtocolUpdateCollection>()
432+
.get_protocol_parameters_for_ledger_index(milestone_payload.essence.index)
433+
.await?
434+
.ok_or(ApiError::NoResults)?
435+
.parameters
436+
.try_into()?;
437+
379438
if let Some(value) = headers.get(axum::http::header::ACCEPT) {
380439
if value.eq(&*BYTE_CONTENT_HEADER) {
381-
let milestone_payload = bee_block_stardust::payload::MilestonePayload::try_from(milestone_payload)?;
440+
let milestone_payload = bee_block_stardust::payload::MilestonePayload::try_from_with_context(
441+
&protocol_params,
442+
milestone_payload,
443+
)?;
382444
return Ok(MilestoneResponse::Raw(milestone_payload.pack_to_vec()));
383445
}
384446
}
385447

386-
Ok(MilestoneResponse::Json(MilestonePayloadDto::try_from(
448+
Ok(MilestoneResponse::Json(MilestonePayloadDto::try_from_with_context(
449+
&protocol_params,
387450
milestone_payload,
388451
)?))
389452
}
@@ -399,14 +462,26 @@ async fn milestone_by_index(
399462
.await?
400463
.ok_or(ApiError::NoResults)?;
401464

465+
let protocol_params = database
466+
.collection::<ProtocolUpdateCollection>()
467+
.get_protocol_parameters_for_ledger_index(milestone_payload.essence.index)
468+
.await?
469+
.ok_or(ApiError::NoResults)?
470+
.parameters
471+
.try_into()?;
472+
402473
if let Some(value) = headers.get(axum::http::header::ACCEPT) {
403474
if value.eq(&*BYTE_CONTENT_HEADER) {
404-
let milestone_payload = bee_block_stardust::payload::MilestonePayload::try_from(milestone_payload)?;
475+
let milestone_payload = bee_block_stardust::payload::MilestonePayload::try_from_with_context(
476+
&protocol_params,
477+
milestone_payload,
478+
)?;
405479
return Ok(MilestoneResponse::Raw(milestone_payload.pack_to_vec()));
406480
}
407481
}
408482

409-
Ok(MilestoneResponse::Json(MilestonePayloadDto::try_from(
483+
Ok(MilestoneResponse::Json(MilestonePayloadDto::try_from_with_context(
484+
&protocol_params,
410485
milestone_payload,
411486
)?))
412487
}

0 commit comments

Comments
 (0)