From 1426dc878d764fd3c81195c52a9e205028a9f710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20G=C3=B6rtler?= Date: Wed, 27 Jul 2022 14:54:33 +0200 Subject: [PATCH] feat(inx): use `bee-inx` (#470) * feat(inx): use `bee-inx` * Fmt * Small changes * update patch * waahhhhh * Remove patch --- Cargo.lock | 467 +++--------------- Cargo.toml | 13 +- bin/inx-chronicle/config.template.toml | 3 +- bin/inx-chronicle/src/launcher.rs | 10 +- .../src/stardust_inx/cone_stream.rs | 30 +- bin/inx-chronicle/src/stardust_inx/error.rs | 6 +- .../src/stardust_inx/ledger_update_stream.rs | 52 +- bin/inx-chronicle/src/stardust_inx/mod.rs | 90 ++-- bin/inx-chronicle/src/stardust_inx/syncer.rs | 10 +- docker/config.alphanet.hornet.json | 16 +- docker/config.testnet.hornet.json | 91 ++++ docker/docker-compose.hornet.yml | 3 +- docker/hornet_config.patch | 17 - docker/update_hornet_config.sh | 4 +- src/db/collections/outputs/indexer/alias.rs | 4 +- src/db/collections/outputs/indexer/basic.rs | 8 +- src/db/collections/outputs/indexer/foundry.rs | 4 +- src/db/collections/outputs/indexer/nft.rs | 8 +- src/db/collections/outputs/mod.rs | 5 +- src/db/collections/status.rs | 23 +- src/types/ledger/block_metadata.rs | 6 +- src/types/ledger/conflict_reason.rs | 22 - src/types/ledger/inclusion_state.rs | 10 +- src/types/ledger/output_metadata.rs | 32 +- src/types/stardust/block/address/mod.rs | 10 +- src/types/stardust/block/input.rs | 4 +- src/types/stardust/block/mod.rs | 10 +- src/types/stardust/block/output/alias.rs | 8 +- src/types/stardust/block/output/basic.rs | 4 +- src/types/stardust/block/output/feature.rs | 4 +- src/types/stardust/block/output/foundry.rs | 2 +- src/types/stardust/block/output/mod.rs | 50 +- .../stardust/block/output/native_token.rs | 6 +- src/types/stardust/block/output/nft.rs | 8 +- src/types/stardust/block/output/treasury.rs | 2 +- .../block/output/unlock_condition/mod.rs | 14 +- .../stardust/block/payload/milestone/mod.rs | 22 +- .../stardust/block/payload/tagged_data.rs | 2 +- .../stardust/block/payload/transaction.rs | 2 +- .../block/payload/treasury_transaction.rs | 4 +- src/types/stardust/block/signature.rs | 4 +- src/types/tangle/mod.rs | 6 +- src/types/tangle/protocol.rs | 59 +++ tests/block.rs | 2 +- 44 files changed, 508 insertions(+), 649 deletions(-) create mode 100644 docker/config.testnet.hornet.json delete mode 100644 docker/hornet_config.patch create mode 100644 src/types/tangle/protocol.rs diff --git a/Cargo.lock b/Cargo.lock index 8d3b6eb0f..2d14f46ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,9 +141,9 @@ dependencies = [ [[package]] name = "axum" -version = "0.5.13" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9496f0c1d1afb7a2af4338bbe1d969cddfead41d87a9fb3aaa6d0bbc7af648" +checksum = "c943a505c17b494638a38a9af129067f760c9c06794b9f57d499266909be8e72" dependencies = [ "async-trait", "axum-core 0.2.7", @@ -219,10 +219,11 @@ checksum = "c5738be7561b0eeb501ef1d5c5db3f24e01ceb55fededd9b00039aada34966ad" [[package]] name = "bee-api-types" -version = "1.0.0-alpha.1" -source = "git+https://github.com/iotaledger/bee.git?branch=shimmer-develop#ff52b003a2c3845e2987d23487a696af106c053c" +version = "1.0.0-beta.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d8c1d70108dde51cd3e3877248b4f302de4913e410c70f56ce2e267d54ed16a" dependencies = [ - "axum 0.5.13", + "axum 0.5.14", "bee-block", "bee-ledger-types", "serde", @@ -231,8 +232,9 @@ dependencies = [ [[package]] name = "bee-block" -version = "0.1.0" -source = "git+https://github.com/iotaledger/bee.git?branch=shimmer-develop#ff52b003a2c3845e2987d23487a696af106c053c" +version = "1.0.0-beta.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19986a689227ecf48f0f563a70db6b40e210b7153f6664e72e49d3eba73de2ed" dependencies = [ "bech32", "bee-pow", @@ -242,11 +244,13 @@ dependencies = [ "derive_more", "hashbrown", "hex", + "inx", "iota-crypto", "iterator-sorted", "packable", "prefix-hex", "primitive-types", + "rand", "serde", "serde-big-array", "serde_json", @@ -254,37 +258,23 @@ dependencies = [ ] [[package]] -name = "bee-ledger" -version = "0.7.0" -source = "git+https://github.com/iotaledger/bee.git?branch=shimmer-develop#ff52b003a2c3845e2987d23487a696af106c053c" +name = "bee-inx" +version = "1.0.0-beta.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "566cff9b8fe07d34cc0fa9644ad44cf9a23fd0c57ac9fcd2a0b1bb39f07e1965" dependencies = [ - "async-trait", "bee-block", - "bee-ledger-types", - "bee-runtime", - "bee-storage", - "bee-tangle", - "bytes", "futures", - "hashbrown", - "iota-crypto", - "log", + "inx", "packable", - "prefix-hex", - "ref-cast", - "reqwest", - "serde", "thiserror", - "time-helper", - "tokio", - "tokio-stream", - "url", ] [[package]] name = "bee-ledger-types" -version = "1.0.0-alpha.1" -source = "git+https://github.com/iotaledger/bee.git?branch=shimmer-develop#ff52b003a2c3845e2987d23487a696af106c053c" +version = "1.0.0-beta.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f71691001d120a2dc1223b1330fedf84fe3e09c121eb18940d9aec2954c08343" dependencies = [ "bee-block", "packable", @@ -316,50 +306,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "bee-runtime" -version = "0.1.1-alpha" -source = "git+https://github.com/iotaledger/bee.git?branch=shimmer-develop#ff52b003a2c3845e2987d23487a696af106c053c" -dependencies = [ - "async-trait", - "bee-storage", - "dashmap", - "futures", - "log", -] - -[[package]] -name = "bee-storage" -version = "0.12.0" -source = "git+https://github.com/iotaledger/bee.git?branch=shimmer-develop#ff52b003a2c3845e2987d23487a696af106c053c" -dependencies = [ - "packable", - "serde", - "thiserror", -] - -[[package]] -name = "bee-tangle" -version = "0.3.0" -source = "git+https://github.com/iotaledger/bee.git?branch=shimmer-develop#ff52b003a2c3845e2987d23487a696af106c053c" -dependencies = [ - "async-trait", - "bee-block", - "bee-runtime", - "bee-storage", - "bitflags", - "futures", - "hashbrown", - "log", - "packable", - "rand", - "ref-cast", - "serde", - "thiserror", - "tokio", - "tokio-stream", -] - [[package]] name = "bee-ternary" version = "1.0.0-alpha.1" @@ -371,20 +317,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bee-test" -version = "0.1.0" -source = "git+https://github.com/iotaledger/bee.git?branch=shimmer-develop#ff52b003a2c3845e2987d23487a696af106c053c" -dependencies = [ - "bee-block", - "bee-ledger", - "bee-tangle", - "bee-ternary", - "bytemuck", - "primitive-types", - "rand", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -474,9 +406,9 @@ checksum = "87c5fdd0166095e1d463fc6cc01aa8ce547ad77a4e84d42eb6762b084e28067e" [[package]] name = "bytemuck" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c53dfa917ec274df8ed3c572698f381a24eef2efba9492d797301b72b6db408a" +checksum = "a5377c8865e74a160d21f29c2d40669f53286db6eab59b88540cbb12ffc8b835" [[package]] name = "byteorder" @@ -486,9 +418,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" +checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" [[package]] name = "cc" @@ -509,11 +441,11 @@ dependencies = [ "async-recursion", "async-trait", "auth-helper", - "axum 0.5.13", + "axum 0.5.14", "bee-api-types", "bee-block", + "bee-inx", "bee-metrics", - "bee-test", "clap", "console-subscriber", "derive_more", @@ -526,7 +458,6 @@ dependencies = [ "hex", "humantime-serde", "hyper", - "inx", "lazy_static", "log", "mongodb", @@ -545,6 +476,7 @@ dependencies = [ "tokio", "tokio-stream", "toml", + "tonic", "tower", "tower-http 0.3.4", "uint", @@ -659,22 +591,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" - [[package]] name = "cpufeatures" version = "0.2.2" @@ -695,9 +611,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c02a4d71819009c192cf4872265391563fd6a84c81ff2c0f2a7026ca4c1d85c" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" dependencies = [ "cfg-if", "crossbeam-utils", @@ -705,9 +621,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83" +checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" dependencies = [ "cfg-if", "once_cell", @@ -777,18 +693,6 @@ dependencies = [ "syn", ] -[[package]] -name = "dashmap" -version = "5.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3495912c9c1ccf2e18976439f4443f3fee0fd61f424ff99fde6a66b15ecb448f" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "parking_lot_core", -] - [[package]] name = "data-encoding" version = "2.3.2" @@ -908,15 +812,6 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" -[[package]] -name = "encoding_rs" -version = "0.8.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" -dependencies = [ - "cfg-if", -] - [[package]] name = "enum-as-inner" version = "0.4.0" @@ -943,9 +838,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" dependencies = [ "instant", ] @@ -984,21 +879,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.0.1" @@ -1091,7 +971,6 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" dependencies = [ - "futures-channel", "futures-core", "futures-io", "futures-macro", @@ -1334,19 +1213,6 @@ dependencies = [ "tokio-io-timeout", ] -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "ident_case" version = "1.0.1" @@ -1414,13 +1280,11 @@ dependencies = [ [[package]] name = "inx" -version = "1.0.0-beta.1" -source = "git+https://github.com/iotaledger/inx#c6cdb616252cb5da728f124155758500fcb7e9e8" +version = "1.0.0-beta.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb13397ca8c1e0a5090669f89b2daa01a07d180e2ffdbadd15f94d8e3ec34959" dependencies = [ - "bee-block", - "packable", "prost", - "thiserror", "tonic", "tonic-build", ] @@ -1446,7 +1310,7 @@ dependencies = [ "socket2", "widestring", "winapi", - "winreg 0.7.0", + "winreg", ] [[package]] @@ -1478,9 +1342,9 @@ checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] name = "js-sys" -version = "0.3.58" +version = "0.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" +checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" dependencies = [ "wasm-bindgen", ] @@ -1532,7 +1396,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", - "serde", ] [[package]] @@ -1668,24 +1531,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "native-tls" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nom" version = "7.1.1" @@ -1746,51 +1591,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "openssl" -version = "0.10.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "os_info" version = "3.4.0" @@ -1966,12 +1766,6 @@ dependencies = [ "spki", ] -[[package]] -name = "pkg-config" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" - [[package]] name = "ppv-lite86" version = "0.2.16" @@ -2047,9 +1841,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.40" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" +checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" dependencies = [ "unicode-ident", ] @@ -2194,33 +1988,13 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "534cfe58d6a18cc17120fbf4635d53d14691c1fe4d951064df9bd326178d7d5a" dependencies = [ "bitflags", ] -[[package]] -name = "ref-cast" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "776c8940430cf563f66a93f9111d1cd39306dc6c68149ecc6b934742a44a828a" -dependencies = [ - "ref-cast-impl", -] - -[[package]] -name = "ref-cast-impl" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f26c4704460286103bff62ea1fb78d137febc86aaf76952e6c5a2249af01f54" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "regex" version = "1.6.0" @@ -2245,44 +2019,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "reqwest" -version = "0.11.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" -dependencies = [ - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "lazy_static", - "log", - "mime", - "native-tls", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-native-tls", - "tokio-util", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg 0.10.1", -] - [[package]] name = "resolv-conf" version = "0.7.0" @@ -2371,16 +2107,6 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" -[[package]] -name = "schannel" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" -dependencies = [ - "lazy_static", - "windows-sys", -] - [[package]] name = "scopeguard" version = "1.1.0" @@ -2397,29 +2123,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "security-framework" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "0.9.0" @@ -2580,9 +2283,12 @@ checksum = "f054c6c1a6e95179d6f23ed974060dcefb2d9388bb7256900badad682c499de4" [[package]] name = "slab" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] [[package]] name = "smallvec" @@ -2772,15 +2478,6 @@ dependencies = [ "time-macros", ] -[[package]] -name = "time-helper" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17c30f0091717eeeff0b556d830302d5563de8b72fd49127aa5899a06a369808" -dependencies = [ - "time 0.3.11", -] - [[package]] name = "time-macros" version = "0.2.4" @@ -2844,16 +2541,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.23.4" @@ -2907,7 +2594,7 @@ checksum = "5be9d60db39854b30b835107500cf0aca0b0d14d6e1c3de124217c23a29c2ddb" dependencies = [ "async-stream", "async-trait", - "axum 0.5.13", + "axum 0.5.14", "base64", "bytes", "futures-core", @@ -3061,9 +2748,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a713421342a5a666b7577783721d3117f1b69a393df803ee17bb73b1e122a59" +checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b" dependencies = [ "sharded-slab", "thread_local", @@ -3193,7 +2880,6 @@ dependencies = [ "idna", "matches", "percent-encoding", - "serde", ] [[package]] @@ -3221,12 +2907,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" @@ -3263,9 +2943,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" +checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3273,36 +2953,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" +checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" dependencies = [ "bumpalo", - "lazy_static", "log", + "once_cell", "proc-macro2", "quote", "syn", "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "wasm-bindgen-macro" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" +checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3310,9 +2978,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" +checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" dependencies = [ "proc-macro2", "quote", @@ -3323,15 +2991,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" +checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" [[package]] name = "web-sys" -version = "0.3.58" +version = "0.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" +checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" dependencies = [ "js-sys", "wasm-bindgen", @@ -3456,15 +3124,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] - [[package]] name = "wyz" version = "0.5.0" diff --git a/Cargo.toml b/Cargo.toml index 0e2de8225..11cd6d2d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,20 +65,22 @@ tower-http = { version = "0.3", default-features = false, features = ["cors", "c zeroize = { version = "1.5", default-features = false, features = ["std"], optional = true } # INX -inx = { git = "https://github.com/iotaledger/inx", version = "1.0.0-beta.1", default-features = false, features = ["types"], optional = true } +bee-inx = { version = "1.0.0-beta.2", default-features = false, optional = true } +tonic = { version = "0.7.2", default-features = false, optional = true } # Metrics bee-metrics = { git = "https://github.com/iotaledger/bee", branch = "mainnet-develop-0.4", default-features = false, features = ["sync"], optional = true } # Stardust types -bee-api-types-stardust = { package = "bee-api-types", git = "https://github.com/iotaledger/bee.git", branch = "shimmer-develop", default-features = false, optional = true } -bee-block-stardust = { package = "bee-block", git = "https://github.com/iotaledger/bee.git", branch = "shimmer-develop", default-features = false, features = ["std", "serde", "dto"], optional = true } +bee-api-types-stardust = { package = "bee-api-types", version = "1.0.0-beta.4", default-features = false, optional = true } +bee-block-stardust = { package = "bee-block", version = "1.0.0-beta.4", default-features = false, features = [ "dto", "std", "serde", ], optional = true } # Tokio Console console-subscriber = { version = "0.1", default-features = false, optional = true } + [dev-dependencies] -bee-test = { package = "bee-test", git = "https://github.com/iotaledger/bee.git", branch = "shimmer-develop", default-features = false } +bee-block-stardust = { package = "bee-block", version = "1.0.0-beta.4", default-features = false, features = [ "dto", "rand", "std", "serde", ] } packable = { version = "0.5", default-features = false } [features] @@ -111,7 +113,8 @@ console = [ "tokio/tracing", ] inx = [ - "dep:inx", + "dep:bee-inx", + "dep:tonic", ] metrics = [ "dep:bee-metrics", diff --git a/bin/inx-chronicle/config.template.toml b/bin/inx-chronicle/config.template.toml index 4e3bdec94..051be0edd 100644 --- a/bin/inx-chronicle/config.template.toml +++ b/bin/inx-chronicle/config.template.toml @@ -33,11 +33,10 @@ public_routes = [ "api/info", # Activated APIs. + "api/analytics/v2/*", "api/core/v2/*", "api/history/v2/*", "api/indexer/v1/*", - - "api/analytics/v2/addresses*", ] [inx] diff --git a/bin/inx-chronicle/src/launcher.rs b/bin/inx-chronicle/src/launcher.rs index aee571404..dc2ea0393 100644 --- a/bin/inx-chronicle/src/launcher.rs +++ b/bin/inx-chronicle/src/launcher.rs @@ -127,11 +127,11 @@ impl HandleEvent> for Launcher { cx.abort().await; } }, - InxError::Read(e) => match e.code() { - inx::tonic::Code::DeadlineExceeded - | inx::tonic::Code::ResourceExhausted - | inx::tonic::Code::Aborted - | inx::tonic::Code::Unavailable => { + InxError::BeeInx(bee_inx::Error::StatusCode(e)) => match e.code() { + tonic::Code::DeadlineExceeded + | tonic::Code::ResourceExhausted + | tonic::Code::Aborted + | tonic::Code::Unavailable => { cx.spawn_child(report.actor).await; } _ => { diff --git a/bin/inx-chronicle/src/stardust_inx/cone_stream.rs b/bin/inx-chronicle/src/stardust_inx/cone_stream.rs index 180a9c70c..403e314ff 100644 --- a/bin/inx-chronicle/src/stardust_inx/cone_stream.rs +++ b/bin/inx-chronicle/src/stardust_inx/cone_stream.rs @@ -2,31 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 use async_trait::async_trait; +use bee_inx::client::Inx; use chronicle::{ db::MongoDb, runtime::{Actor, ActorContext, HandleEvent}, types::tangle::MilestoneIndex, }; -use inx::{ - client::InxClient, - tonic::{Channel, Status}, - BlockWithMetadata, -}; use super::InxError; #[derive(Debug)] pub struct ConeStream { pub milestone_index: MilestoneIndex, - inx_client: InxClient, + inx: Inx, db: MongoDb, } impl ConeStream { - pub fn new(milestone_index: MilestoneIndex, inx_client: InxClient, db: MongoDb) -> Self { + pub fn new(milestone_index: MilestoneIndex, inx: Inx, db: MongoDb) -> Self { Self { milestone_index, - inx_client, + inx, db, } } @@ -38,11 +34,7 @@ impl Actor for ConeStream { type Error = InxError; async fn init(&mut self, cx: &mut ActorContext) -> Result { - let cone_stream = self - .inx_client - .read_milestone_cone(inx::proto::MilestoneRequest::from_index(self.milestone_index.0)) - .await? - .into_inner(); + let cone_stream = self.inx.read_milestone_cone(self.milestone_index.0.into()).await?; cx.add_stream(cone_stream); Ok(()) } @@ -69,21 +61,19 @@ impl Actor for ConeStream { } #[async_trait] -impl HandleEvent> for ConeStream { +impl HandleEvent> for ConeStream { async fn handle_event( &mut self, _cx: &mut ActorContext, - block_metadata_result: Result, + block_metadata_result: Result, _state: &mut Self::State, ) -> Result<(), Self::Error> { log::trace!("Received Stardust block event"); - let block_metadata = block_metadata_result?; - log::trace!("Block data: {:?}", block_metadata); - let inx_block_with_metadata: inx::BlockWithMetadata = block_metadata.try_into()?; - let BlockWithMetadata { metadata, block, raw } = inx_block_with_metadata; + let bee_inx::BlockWithMetadata { block, metadata } = block_metadata_result?; + log::trace!("Block id: {:?}", metadata.block_id); self.db - .insert_block_with_metadata(block.into(), raw, metadata.into()) + .insert_block_with_metadata(block.clone().inner()?.into(), block.data(), metadata.into()) .await?; log::trace!("Inserted block into database."); diff --git a/bin/inx-chronicle/src/stardust_inx/error.rs b/bin/inx-chronicle/src/stardust_inx/error.rs index 16ec5203d..d34b392a0 100644 --- a/bin/inx-chronicle/src/stardust_inx/error.rs +++ b/bin/inx-chronicle/src/stardust_inx/error.rs @@ -11,7 +11,7 @@ pub enum InxError { #[error("expected INX address with format `http://
:`, but found `{0}`")] InvalidAddress(String), #[error("INX type conversion error: {0:?}")] - InxTypeConversion(#[from] inx::Error), + InxTypeConversion(#[from] bee_block_stardust::InxError), #[error("missing milestone id for milestone index `{0}`")] MissingMilestoneInfo(MilestoneIndex), #[error(transparent)] @@ -21,11 +21,9 @@ pub enum InxError { #[error(transparent)] ParsingAddressFailed(#[from] url::ParseError), #[error(transparent)] - Read(#[from] inx::tonic::Status), - #[error(transparent)] Runtime(#[from] chronicle::runtime::RuntimeError), #[error(transparent)] - Tonic(#[from] inx::tonic::Error), + BeeInx(#[from] bee_inx::Error), } impl ErrorLevel for InxError { diff --git a/bin/inx-chronicle/src/stardust_inx/ledger_update_stream.rs b/bin/inx-chronicle/src/stardust_inx/ledger_update_stream.rs index f5c13688a..7fdf2b9dc 100644 --- a/bin/inx-chronicle/src/stardust_inx/ledger_update_stream.rs +++ b/bin/inx-chronicle/src/stardust_inx/ledger_update_stream.rs @@ -4,14 +4,11 @@ use std::ops::RangeInclusive; use async_trait::async_trait; +use bee_inx::client::Inx; use chronicle::{ db::MongoDb, runtime::{Actor, ActorContext, ActorError, HandleEvent, Report}, - types::tangle::MilestoneIndex, -}; -use inx::{ - client::InxClient, - tonic::{Channel, Status}, + types::tangle::{MilestoneIndex, ProtocolInfo, ProtocolParameters}, }; use super::{cone_stream::ConeStream, InxError}; @@ -19,12 +16,12 @@ use super::{cone_stream::ConeStream, InxError}; #[derive(Debug)] pub struct LedgerUpdateStream { db: MongoDb, - inx: InxClient, + inx: Inx, range: RangeInclusive, } impl LedgerUpdateStream { - pub fn new(db: MongoDb, inx: InxClient, range: RangeInclusive) -> Self { + pub fn new(db: MongoDb, inx: Inx, range: RangeInclusive) -> Self { Self { db, inx, range } } } @@ -38,12 +35,11 @@ impl Actor for LedgerUpdateStream { let ledger_update_stream = self .inx .listen_to_ledger_updates(if *self.range.end() == u32::MAX { - inx::proto::MilestoneRangeRequest::from(*self.range.start()..) + (self.range.start().0..).into() } else { - inx::proto::MilestoneRangeRequest::from(self.range.clone()) + (self.range.start().0..self.range.end().0).into() }) - .await? - .into_inner(); + .await?; cx.add_stream(ledger_update_stream); Ok(()) } @@ -81,31 +77,41 @@ impl HandleEvent> for LedgerUpdateStream { } #[async_trait] -impl HandleEvent> for LedgerUpdateStream { +impl HandleEvent> for LedgerUpdateStream { async fn handle_event( &mut self, cx: &mut ActorContext, - ledger_update_result: Result, + ledger_update_result: Result, _state: &mut Self::State, ) -> Result<(), Self::Error> { log::trace!("Received ledger update event {:#?}", ledger_update_result); - let ledger_update = inx::LedgerUpdate::try_from(ledger_update_result?)?; + let ledger_update = ledger_update_result?; - let output_updates_iter = Vec::from(ledger_update.created) + let output_updates = Vec::from(ledger_update.created) .into_iter() - .map(Into::into) - .chain(Vec::from(ledger_update.consumed).into_iter().map(Into::into)); + .map(TryInto::try_into) + .chain(Vec::from(ledger_update.consumed).into_iter().map(TryInto::try_into)) + .collect::, _>>()?; - self.db.insert_ledger_updates(output_updates_iter).await?; + self.db.insert_ledger_updates(output_updates.into_iter()).await?; - let milestone_request = inx::proto::MilestoneRequest::from_index(ledger_update.milestone_index); - - let milestone_proto = self.inx.read_milestone(milestone_request.clone()).await?.into_inner(); + let milestone = self.inx.read_milestone(ledger_update.milestone_index.into()).await?; + let parameters: ProtocolParameters = self + .inx + .read_protocol_parameters(ledger_update.milestone_index.into()) + .await? + .inner()? + .into(); - log::trace!("Received milestone: `{:?}`", milestone_proto); + self.db + .set_protocol_parameters(ProtocolInfo { + parameters, + tangle_index: ledger_update.milestone_index.into(), + }) + .await?; - let milestone: inx::Milestone = milestone_proto.try_into()?; + log::trace!("Received milestone: `{:?}`", milestone); let milestone_index = milestone.milestone_info.milestone_index.into(); let milestone_timestamp = milestone.milestone_info.milestone_timestamp.into(); diff --git a/bin/inx-chronicle/src/stardust_inx/mod.rs b/bin/inx-chronicle/src/stardust_inx/mod.rs index 0aa8ae431..7cfe6a8ae 100644 --- a/bin/inx-chronicle/src/stardust_inx/mod.rs +++ b/bin/inx-chronicle/src/stardust_inx/mod.rs @@ -8,20 +8,15 @@ mod ledger_update_stream; mod syncer; use async_trait::async_trait; +use bee_inx::client::Inx; use chronicle::{ db::MongoDb, runtime::{Actor, ActorContext, ActorError, HandleEvent, Report, Sender}, - types::tangle::MilestoneIndex, + types::tangle::{MilestoneIndex, ProtocolInfo, ProtocolParameters}, }; pub use config::InxConfig; pub use error::InxError; use futures::TryStreamExt; -use inx::{ - client::InxClient, - proto::NoParams, - tonic::{Channel, Code}, - NodeStatus, -}; pub use ledger_update_stream::LedgerUpdateStream; use self::syncer::{SyncNext, Syncer}; @@ -32,7 +27,7 @@ pub struct InxWorker { } impl InxWorker { - /// Creates an [`InxClient`] by connecting to the endpoint specified in `inx_config`. + /// Creates an [`Inx`] client by connecting to the endpoint specified in `inx_config`. pub fn new(db: &MongoDb, inx_config: &InxConfig) -> Self { Self { db: db.clone(), @@ -40,7 +35,7 @@ impl InxWorker { } } - pub async fn connect(inx_config: &InxConfig) -> Result, InxError> { + pub async fn connect(inx_config: &InxConfig) -> Result { let url = url::Url::parse(&inx_config.connect_url)?; if url.scheme() != "http" { @@ -48,7 +43,7 @@ impl InxWorker { } for i in 0..inx_config.connection_retry_count { - match InxClient::connect(inx_config.connect_url.clone()).await { + match Inx::connect(inx_config.connect_url.clone()).await { Ok(inx_client) => return Ok(inx_client), Err(_) => { log::warn!( @@ -63,34 +58,45 @@ impl InxWorker { Err(InxError::ConnectionError) } - async fn spawn_syncer( - &self, - cx: &mut ActorContext, - inx_client: &mut InxClient, - ) -> Result { + async fn spawn_syncer(&self, cx: &mut ActorContext, inx: &mut Inx) -> Result { // Request the node status so we can get the pruning index and latest confirmed milestone - let node_status = NodeStatus::try_from(inx_client.read_node_status(NoParams {}).await?.into_inner()) - .map_err(InxError::InxTypeConversion)?; + let node_status = inx.read_node_status().await?; + + let latest_milestone_index = node_status.confirmed_milestone.milestone_info.milestone_index; log::debug!( - "The node has a pruning index of `{}` and a latest confirmed milestone index of `{}`.", + "The node has a pruning index of `{}` and a latest confirmed milestone index of `{latest_milestone_index}`.", node_status.tangle_pruning_index, - node_status.confirmed_milestone.milestone_info.milestone_index ); - let node_config = inx_client.read_node_configuration(NoParams {}).await?.into_inner(); - - let network_name = node_config.protocol_parameters.unwrap().network_name; + let protocol_parameters: ProtocolParameters = inx + .read_protocol_parameters(latest_milestone_index.into()) + .await? + .inner()? + .into(); - log::debug!("Connected to network {}.", network_name); + log::debug!("Connected to network `{}`.", protocol_parameters.network_name); - if let Some(prev_network_name) = self.db.get_network_name().await? { - if prev_network_name != network_name { - return Err(InxError::NetworkChanged(prev_network_name, network_name)); + if let Some(db_protocol) = self.db.get_protocol_parameters().await? { + if db_protocol.parameters.network_name != protocol_parameters.network_name { + return Err(InxError::NetworkChanged( + db_protocol.parameters.network_name, + protocol_parameters.network_name, + )); } } else { - log::info!("Linking database {} to network {}.", self.db.name(), network_name); - self.db.set_network_name(network_name).await?; + log::info!( + "Linking database `{}` to network `{}`.", + self.db.name(), + protocol_parameters.network_name + ); + + let protocol_info = ProtocolInfo { + parameters: protocol_parameters, + tangle_index: latest_milestone_index.into(), + }; + + self.db.set_protocol_parameters(protocol_info).await?; } let first_ms = node_status.tangle_pruning_index + 1; @@ -102,7 +108,7 @@ impl InxWorker { .gaps; if !sync_data.is_empty() { let syncer = cx - .spawn_child(Syncer::new(sync_data, self.db.clone(), inx_client.clone())) + .spawn_child(Syncer::new(sync_data, self.db.clone(), inx.clone())) .await; syncer.send(SyncNext)?; } else { @@ -114,35 +120,35 @@ impl InxWorker { #[async_trait] impl Actor for InxWorker { - type State = InxClient; + type State = Inx; type Error = InxError; async fn init(&mut self, cx: &mut ActorContext) -> Result { log::info!("Connecting to INX at bind address `{}`.", &self.config.connect_url); - let mut inx_client = Self::connect(&self.config).await?; + let mut inx = Self::connect(&self.config).await?; log::info!("Connected to INX."); log::info!("Reading unspent outputs."); - let mut unspent_output_stream = inx_client.read_unspent_outputs(NoParams {}).await?.into_inner(); + let mut unspent_output_stream = inx.read_unspent_outputs().await?; let mut updates = Vec::new(); - while let Some(unspent_output) = unspent_output_stream.try_next().await? { - let inx::UnspentOutput { output, .. } = unspent_output.try_into()?; - updates.push(output.into()); + while let Some(bee_inx::UnspentOutput { output, .. }) = unspent_output_stream.try_next().await? { + log::trace!("Received unspent output: {}", output.block_id); + updates.push(output.try_into()?); } log::info!("Inserting {} unspent outputs.", updates.len()); self.db.insert_ledger_updates(updates).await?; - let latest_ms = self.spawn_syncer(cx, &mut inx_client).await?; + let latest_ms = self.spawn_syncer(cx, &mut inx).await?; cx.spawn_child(LedgerUpdateStream::new( self.db.clone(), - inx_client.clone(), + inx.clone(), latest_ms + 1..=u32::MAX.into(), )) .await; - Ok(inx_client) + Ok(inx) } fn name(&self) -> std::borrow::Cow<'static, str> { @@ -179,15 +185,15 @@ impl HandleEvent> for InxWorker { &mut self, cx: &mut ActorContext, event: Report, - inx_client: &mut Self::State, + inx: &mut Self::State, ) -> Result<(), Self::Error> { match event { Report::Success(_) => (), Report::Error(report) => match report.error { ActorError::Result(e) => match &e { - InxError::Read(s) => match s.code() { - Code::InvalidArgument => { - self.spawn_syncer(cx, inx_client).await?; + InxError::BeeInx(bee_inx::Error::StatusCode(s)) => match s.code() { + tonic::Code::InvalidArgument => { + self.spawn_syncer(cx, inx).await?; } _ => Err(e)?, }, diff --git a/bin/inx-chronicle/src/stardust_inx/syncer.rs b/bin/inx-chronicle/src/stardust_inx/syncer.rs index 165ee0c93..f7bd91bf4 100644 --- a/bin/inx-chronicle/src/stardust_inx/syncer.rs +++ b/bin/inx-chronicle/src/stardust_inx/syncer.rs @@ -4,12 +4,12 @@ use std::{collections::VecDeque, ops::RangeInclusive}; use async_trait::async_trait; +use bee_inx::client::Inx; use chronicle::{ db::MongoDb, runtime::{Actor, ActorContext, ActorError, HandleEvent, Report}, types::tangle::MilestoneIndex, }; -use inx::{client::InxClient, tonic::Channel}; use super::{InxError, LedgerUpdateStream}; @@ -18,15 +18,15 @@ use super::{InxError, LedgerUpdateStream}; pub struct Syncer { gaps: Gaps, db: MongoDb, - inx_client: InxClient, + inx: Inx, } impl Syncer { - pub fn new(gaps: Vec>, db: MongoDb, inx_client: InxClient) -> Self { + pub fn new(gaps: Vec>, db: MongoDb, inx: Inx) -> Self { Self { gaps: Gaps(gaps.into()), db, - inx_client, + inx, } } } @@ -104,7 +104,7 @@ impl HandleEvent for Syncer { ); cx.spawn_child(LedgerUpdateStream::new( self.db.clone(), - self.inx_client.clone(), + self.inx.clone(), *milestone_range.start()..=*milestone_range.end(), )) .await; diff --git a/docker/config.alphanet.hornet.json b/docker/config.alphanet.hornet.json index f506ac3f8..29df93f08 100644 --- a/docker/config.alphanet.hornet.json +++ b/docker/config.alphanet.hornet.json @@ -1,6 +1,6 @@ { "protocol": { - "targetNetworkName": "alphanet-8", + "targetNetworkName": "alphanet-9", "milestonePublicKeyCount": 3, "baseToken": { "name": "Shimmer", @@ -53,7 +53,13 @@ ] } }, + "tangle": { + "maxDeltaBlockYoungestConeRootIndexToCMI": 80, + "maxDeltaBlockOldestConeRootIndexToCMI": 130 + }, "snapshots": { + "depth": 500, + "interval": 2000, "fullPath": "alphanet/snapshots/full_snapshot.bin", "deltaPath": "alphanet/snapshots/delta_snapshot.bin", "downloadURLs": [ @@ -63,11 +69,7 @@ } ] }, - "inx": { - "enabled": true, - "bindAddress": "localhost:9029", - "pow": { - "workerCount": 0 - } + "warpsync": { + "advancementRange": 1500 } } diff --git a/docker/config.testnet.hornet.json b/docker/config.testnet.hornet.json new file mode 100644 index 000000000..782bc62e7 --- /dev/null +++ b/docker/config.testnet.hornet.json @@ -0,0 +1,91 @@ +{ + "protocol": { + "targetNetworkName": "testnet", + "milestonePublicKeyCount": 7, + "baseToken": { + "name": "Shimmer", + "tickerSymbol": "SMR", + "unit": "SMR", + "subunit": "glow", + "decimals": 6, + "useMetricPrefix": false + }, + "publicKeyRanges": [ + { + "key": "13ccdc2f5d3d9a3ebe06074c6b49b49090dd79ca72e04abf20f10f871ad8293b", + "start": 0, + "end": 0 + }, + { + "key": "f18f3f6a2d940b9bacd3084713f6877db22064ada4335cb53ae1da75044f978d", + "start": 0, + "end": 0 + }, + { + "key": "b3b4c920909720ba5f7c30dddc0f9169bf8243b529b601fc4776b8cb0a8ca253", + "start": 0, + "end": 0 + }, + { + "key": "bded01e93adf7a623118fd375fd93dc7d7ddf222324239cae33e4e4c47ec3b0e", + "start": 0, + "end": 0 + }, + { + "key": "488ac3fb1b8df5ef8c4acb4ef1f3e3d039c5d7197db87094a61af66320722313", + "start": 0, + "end": 0 + }, + { + "key": "61f95fed30b6e9bf0b2d03938f56d35789ff7f0ea122d01c5c1b7e869525e218", + "start": 0, + "end": 0 + }, + { + "key": "4587040de05907b70806c8725bdae1f7370785993b2a139208e247885d4ed1f8", + "start": 0, + "end": 0 + }, + { + "key": "aa6b36116206cc7d6c8f688e22113aa46f0de88d51aa7acf881ec2bd9d015f62", + "start": 0, + "end": 0 + }, + { + "key": "ede9760c7f2aaa4618a58a1357705cdc1874962ad369309543230394bb77548b", + "start": 0, + "end": 0 + }, + { + "key": "98d1f907caa99f9320f0e0eb64a5cf208751c2171c7938da5659328061e82a8e", + "start": 0, + "end": 0 + } + ] + }, + "db": { + "path": "testnet/database" + }, + "p2p": { + "db": { + "path": "testnet/p2pstore" + }, + "autopeering": { + "enabled": true, + "entryNodes": [ + "/dns/entry-hornet-0.h.testnet.shimmer.network/udp/14626/autopeering/ANrRwJv2xs1S7TonyenM9qzkB8hfZ4Y6Gg2xsNUGozTJ", + "/dns/entry-hornet-1.h.testnet.shimmer.network/udp/14626/autopeering/3bTUFwKXzhHSv2kBs6gja8BbeawHNzMwUdJraXWmLkNk" + ] + } + }, + "snapshots": { + "fullPath": "testnet/snapshots/full_snapshot.bin", + "deltaPath": "testnet/snapshots/delta_snapshot.bin", + "downloadURLs": [ + { + "full": "https://files.testnet.shimmer.network/snapshots/latest-full_snapshot.bin", + "delta": "https://files.testnet.shimmer.network/snapshots/latest-delta_snapshot.bin" + } + ] + } +} \ No newline at end of file diff --git a/docker/docker-compose.hornet.yml b/docker/docker-compose.hornet.yml index db7409389..e08284572 100644 --- a/docker/docker-compose.hornet.yml +++ b/docker/docker-compose.hornet.yml @@ -32,7 +32,7 @@ services: - ../bin/inx-chronicle/config.template.toml:/app/config.toml:ro hornet: - image: iotaledger/hornet:2.0.0-alpha.25 + image: iotaledger/hornet:2.0.0-beta.3 container_name: hornet ulimits: nofile: @@ -55,4 +55,5 @@ services: command: - "-c" - "config.json" + - "--inx.enabled=true" - "--inx.bindAddress=hornet:9029" diff --git a/docker/hornet_config.patch b/docker/hornet_config.patch deleted file mode 100644 index b1dbcfb6b..000000000 --- a/docker/hornet_config.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/docker/config.alphanet.hornet.json b/docker/config.alphanet.hornet.json -index 609d941..9ab337c 100644 ---- a/docker/config.alphanet.hornet.json -+++ b/docker/config.alphanet.hornet.json -@@ -62,5 +62,12 @@ - "delta": "https://files.alphanet.iotaledger.net/snapshots/latest-delta_snapshot.bin" - } - ] -+ }, -+ "inx": { -+ "enabled": true, -+ "bindAddress": "localhost:9029", -+ "pow": { -+ "workerCount": 0 -+ } - } - } diff --git a/docker/update_hornet_config.sh b/docker/update_hornet_config.sh index df7a2925b..ad4722d37 100755 --- a/docker/update_hornet_config.sh +++ b/docker/update_hornet_config.sh @@ -2,6 +2,4 @@ DIR=$(dirname ${BASH_SOURCE[0]}) wget https://raw.githubusercontent.com/gohornet/hornet/develop/config_alphanet.json -O ${DIR}/config.alphanet.hornet.json - -# We apply a patch to enable INX -git apply docker/hornet_config.patch +wget https://raw.githubusercontent.com/gohornet/hornet/develop/config_testnet.json -O ${DIR}/config.testnet.hornet.json diff --git a/src/db/collections/outputs/indexer/alias.rs b/src/db/collections/outputs/indexer/alias.rs index d8f599ff5..a8e8096bc 100644 --- a/src/db/collections/outputs/indexer/alias.rs +++ b/src/db/collections/outputs/indexer/alias.rs @@ -55,7 +55,9 @@ mod test { #[test] fn test_alias_query_everything() { - let address = Address::from(bee::Address::Ed25519(bee_test::rand::address::rand_ed25519_address())); + let address = Address::from(bee::Address::Ed25519( + bee_block_stardust::rand::address::rand_ed25519_address(), + )); let query = AliasOutputsQuery { state_controller: Some(address), governor: Some(address), diff --git a/src/db/collections/outputs/indexer/basic.rs b/src/db/collections/outputs/indexer/basic.rs index e916ddd8d..e967ed9d0 100644 --- a/src/db/collections/outputs/indexer/basic.rs +++ b/src/db/collections/outputs/indexer/basic.rs @@ -78,7 +78,9 @@ mod test { #[test] fn test_basic_query_everything() { - let address = Address::from(bee::Address::Ed25519(bee_test::rand::address::rand_ed25519_address())); + let address = Address::from(bee::Address::Ed25519( + bee_block_stardust::rand::address::rand_ed25519_address(), + )); let query = BasicOutputsQuery { address: Some(address), has_native_tokens: Some(true), @@ -139,7 +141,9 @@ mod test { #[test] fn test_basic_query_all_false() { - let address = Address::from(bee::Address::Ed25519(bee_test::rand::address::rand_ed25519_address())); + let address = Address::from(bee::Address::Ed25519( + bee_block_stardust::rand::address::rand_ed25519_address(), + )); let query = BasicOutputsQuery { address: Some(address), has_native_tokens: Some(false), diff --git a/src/db/collections/outputs/indexer/foundry.rs b/src/db/collections/outputs/indexer/foundry.rs index 3c67b7f2a..0068cb824 100644 --- a/src/db/collections/outputs/indexer/foundry.rs +++ b/src/db/collections/outputs/indexer/foundry.rs @@ -47,7 +47,9 @@ mod test { #[test] fn test_foundry_query_everything() { - let address = Address::from(bee::Address::Ed25519(bee_test::rand::address::rand_ed25519_address())); + let address = Address::from(bee::Address::Ed25519( + bee_block_stardust::rand::address::rand_ed25519_address(), + )); let query = FoundryOutputsQuery { alias_address: Some(address), has_native_tokens: Some(true), diff --git a/src/db/collections/outputs/indexer/nft.rs b/src/db/collections/outputs/indexer/nft.rs index 679ba7e81..598a65128 100644 --- a/src/db/collections/outputs/indexer/nft.rs +++ b/src/db/collections/outputs/indexer/nft.rs @@ -80,7 +80,9 @@ mod test { #[test] fn test_nft_query_everything() { - let address = Address::from(bee::Address::Ed25519(bee_test::rand::address::rand_ed25519_address())); + let address = Address::from(bee::Address::Ed25519( + bee_block_stardust::rand::address::rand_ed25519_address(), + )); let query = NftOutputsQuery { address: Some(address), issuer: Some(address), @@ -146,7 +148,9 @@ mod test { #[test] fn test_nft_query_all_false() { - let address = Address::from(bee::Address::Ed25519(bee_test::rand::address::rand_ed25519_address())); + let address = Address::from(bee::Address::Ed25519( + bee_block_stardust::rand::address::rand_ed25519_address(), + )); let query = NftOutputsQuery { address: Some(address), issuer: None, diff --git a/src/db/collections/outputs/mod.rs b/src/db/collections/outputs/mod.rs index d7a0ee418..46f4d75aa 100644 --- a/src/db/collections/outputs/mod.rs +++ b/src/db/collections/outputs/mod.rs @@ -18,7 +18,7 @@ pub use self::indexer::{ use crate::{ db::MongoDb, types::{ - ledger::{MilestoneIndexTimestamp, OutputMetadata, OutputWithMetadata, SpentMetadata}, + ledger::{MilestoneIndexTimestamp, OutputMetadata, OutputWithMetadata, RentStructureBytes, SpentMetadata}, stardust::block::{Address, BlockId, Output, OutputId}, tangle::MilestoneIndex, }, @@ -43,12 +43,14 @@ struct OutputDetails { #[serde(skip_serializing_if = "Option::is_none")] address: Option
, is_trivial_unlock: bool, + rent_structure: RentStructureBytes, } impl From for OutputDocument { fn from(rec: OutputWithMetadata) -> Self { let address = rec.output.owning_address().copied(); let is_trivial_unlock = rec.output.is_trivial_unlock(); + let rent_structure = rec.output.rent_structure(); Self { output: rec.output, @@ -56,6 +58,7 @@ impl From for OutputDocument { details: OutputDetails { address, is_trivial_unlock, + rent_structure, }, } } diff --git a/src/db/collections/status.rs b/src/db/collections/status.rs index 7821b22e8..0d815641b 100644 --- a/src/db/collections/status.rs +++ b/src/db/collections/status.rs @@ -1,40 +1,47 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use mongodb::{bson::doc, error::Error, options::UpdateOptions}; +use mongodb::{ + bson::{doc, to_document}, + error::Error, + options::UpdateOptions, +}; use serde::{Deserialize, Serialize}; -use crate::{db::MongoDb, types::tangle::MilestoneIndex}; +use crate::{ + db::MongoDb, + types::tangle::{MilestoneIndex, ProtocolInfo}, +}; /// Provides the information about the status of the node. #[derive(Clone, Debug, Serialize, Deserialize)] struct StatusDocument { - network_name: Option, + protocol: Option, ledger_index: Option, } impl StatusDocument { /// The status collection name. - const COLLECTION: &'static str = "status"; + const COLLECTION: &'static str = "stardust_status"; } impl MongoDb { /// Get the name of the network. - pub async fn get_network_name(&self) -> Result, Error> { + pub async fn get_protocol_parameters(&self) -> Result, Error> { self.0 .collection::(StatusDocument::COLLECTION) .find_one(doc! {}, None) .await - .map(|doc| doc.and_then(|doc| doc.network_name)) + .map(|doc| doc.and_then(|doc| doc.protocol)) } /// Sets the name of the network. - pub async fn set_network_name(&self, network_name: String) -> Result<(), Error> { + pub async fn set_protocol_parameters(&self, protocol_info: ProtocolInfo) -> Result<(), Error> { self.0 .collection::(StatusDocument::COLLECTION) .update_one( doc! {}, - doc! { "$set": { "network_name": network_name } }, + doc! { "$set": { "protocol.parameters": to_document(&protocol_info)? } }, UpdateOptions::builder().upsert(true).build(), ) .await?; diff --git a/src/types/ledger/block_metadata.rs b/src/types/ledger/block_metadata.rs index fcf2fdc58..f3004ca34 100644 --- a/src/types/ledger/block_metadata.rs +++ b/src/types/ledger/block_metadata.rs @@ -32,11 +32,11 @@ pub struct BlockMetadata { } #[cfg(feature = "inx")] -impl From for BlockMetadata { - fn from(metadata: inx::BlockMetadata) -> Self { +impl From for BlockMetadata { + fn from(metadata: bee_inx::BlockMetadata) -> Self { Self { block_id: metadata.block_id.into(), - parents: metadata.parents.into_iter().map(|id| id.into()).collect(), + parents: metadata.parents.iter().map(|&id| id.into()).collect(), is_solid: metadata.is_solid, should_promote: metadata.should_promote, should_reattach: metadata.should_reattach, diff --git a/src/types/ledger/conflict_reason.rs b/src/types/ledger/conflict_reason.rs index 95208d4bc..6c14ac657 100644 --- a/src/types/ledger/conflict_reason.rs +++ b/src/types/ledger/conflict_reason.rs @@ -24,28 +24,6 @@ pub enum ConflictReason { SemanticValidationFailed = 255, } -#[cfg(feature = "inx")] -impl From for ConflictReason { - fn from(value: inx::ConflictReason) -> Self { - match value { - inx::ConflictReason::None => Self::None, - inx::ConflictReason::InputAlreadySpent => Self::InputUtxoAlreadySpent, - inx::ConflictReason::InputAlreadySpentInThisMilestone => Self::InputUtxoAlreadySpentInThisMilestone, - inx::ConflictReason::InputNotFound => Self::InputUtxoNotFound, - inx::ConflictReason::InputOutputSumMismatch => Self::CreatedConsumedAmountMismatch, - inx::ConflictReason::InvalidSignature => Self::InvalidSignature, - inx::ConflictReason::TimelockNotExpired => Self::TimelockNotExpired, - inx::ConflictReason::InvalidNativeTokens => Self::InvalidNativeTokens, - inx::ConflictReason::ReturnAmountNotFulfilled => Self::StorageDepositReturnUnfulfilled, - inx::ConflictReason::InvalidInputUnlock => Self::InvalidUnlock, - inx::ConflictReason::InvalidInputsCommitment => Self::InputsCommitmentsMismatch, - inx::ConflictReason::InvalidSender => Self::UnverifiedSender, - inx::ConflictReason::InvalidChainStateTransition => Self::InvalidChainStateTransition, - inx::ConflictReason::SemanticValidationFailed => Self::SemanticValidationFailed, - } - } -} - impl From for ConflictReason { fn from(value: bee::ConflictReason) -> Self { match value { diff --git a/src/types/ledger/inclusion_state.rs b/src/types/ledger/inclusion_state.rs index 4d67f6677..d8747091d 100644 --- a/src/types/ledger/inclusion_state.rs +++ b/src/types/ledger/inclusion_state.rs @@ -47,12 +47,12 @@ impl From for bee::LedgerInclusionStateDto { } #[cfg(feature = "inx")] -impl From for LedgerInclusionState { - fn from(value: inx::LedgerInclusionState) -> Self { +impl From for LedgerInclusionState { + fn from(value: bee_inx::LedgerInclusionState) -> Self { match value { - inx::LedgerInclusionState::Included => Self::Included, - inx::LedgerInclusionState::NoTransaction => Self::NoTransaction, - inx::LedgerInclusionState::Conflicting => Self::Conflicting, + bee_inx::LedgerInclusionState::Included => Self::Included, + bee_inx::LedgerInclusionState::NoTransaction => Self::NoTransaction, + bee_inx::LedgerInclusionState::Conflicting => Self::Conflicting, } } } diff --git a/src/types/ledger/output_metadata.rs b/src/types/ledger/output_metadata.rs index 880476e75..a0d077356 100644 --- a/src/types/ledger/output_metadata.rs +++ b/src/types/ledger/output_metadata.rs @@ -40,13 +40,14 @@ pub struct OutputWithMetadata { } #[cfg(feature = "inx")] -impl From for OutputWithMetadata { - fn from(value: inx::LedgerOutput) -> Self { - let output_id = OutputId::from(value.output_id); - Self { - output: Into::into(&value.output), +impl TryFrom for OutputWithMetadata { + type Error = bee_inx::Error; + + fn try_from(value: bee_inx::LedgerOutput) -> Result { + Ok(Self { + output: (&(value.output.inner()?)).into(), metadata: OutputMetadata { - output_id, + output_id: value.output_id.into(), block_id: value.block_id.into(), booked: MilestoneIndexTimestamp { milestone_index: value.milestone_index_booked.into(), @@ -54,14 +55,16 @@ impl From for OutputWithMetadata { }, spent_metadata: None, }, - } + }) } } #[cfg(feature = "inx")] -impl From for OutputWithMetadata { - fn from(value: inx::LedgerSpent) -> Self { - let mut delta = OutputWithMetadata::from(value.output); +impl TryFrom for OutputWithMetadata { + type Error = bee_inx::Error; + + fn try_from(value: bee_inx::LedgerSpent) -> Result { + let mut delta = OutputWithMetadata::try_from(value.output)?; delta.metadata.spent_metadata.replace(SpentMetadata { transaction_id: value.transaction_id_spent.into(), @@ -71,6 +74,13 @@ impl From for OutputWithMetadata { }, }); - delta + Ok(delta) } } + +/// The different number of bytes that are used for computing the rent cost. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RentStructureBytes { + pub num_key_bytes: u64, + pub num_data_bytes: u64, +} diff --git a/src/types/stardust/block/address/mod.rs b/src/types/stardust/block/address/mod.rs index 3d1aa2c1c..829dff3d8 100644 --- a/src/types/stardust/block/address/mod.rs +++ b/src/types/stardust/block/address/mod.rs @@ -74,17 +74,21 @@ pub(crate) mod test { #[test] fn test_address_bson() { - let address = Address::from(bee::Address::Ed25519(bee_test::rand::address::rand_ed25519_address())); + let address = Address::from(bee::Address::Ed25519( + bee_block_stardust::rand::address::rand_ed25519_address(), + )); let bson = to_bson(&address).unwrap(); assert_eq!(Bson::from(address), bson); assert_eq!(address, from_bson::
(bson).unwrap()); - let address = Address::from(bee::Address::Alias(bee_test::rand::address::rand_alias_address())); + let address = Address::from(bee::Address::Alias( + bee_block_stardust::rand::address::rand_alias_address(), + )); let bson = to_bson(&address).unwrap(); assert_eq!(Bson::from(address), bson); assert_eq!(address, from_bson::
(bson).unwrap()); - let address = Address::from(bee::Address::Nft(bee_test::rand::address::rand_nft_address())); + let address = Address::from(bee::Address::Nft(bee_block_stardust::rand::address::rand_nft_address())); let bson = to_bson(&address).unwrap(); assert_eq!(Bson::from(address), bson); assert_eq!(address, from_bson::
(bson).unwrap()); diff --git a/src/types/stardust/block/input.rs b/src/types/stardust/block/input.rs index a81ac801d..07fde1f17 100644 --- a/src/types/stardust/block/input.rs +++ b/src/types/stardust/block/input.rs @@ -53,12 +53,12 @@ pub(crate) mod test { } pub(crate) fn get_test_utxo_input() -> Input { - Input::Utxo(bee_test::rand::output::rand_output_id().into()) + Input::Utxo(bee_block_stardust::rand::output::rand_output_id().into()) } pub(crate) fn get_test_treasury_input() -> Input { Input::Treasury { - milestone_id: bee_test::rand::milestone::rand_milestone_id().into(), + milestone_id: bee_block_stardust::rand::milestone::rand_milestone_id().into(), } } } diff --git a/src/types/stardust/block/mod.rs b/src/types/stardust/block/mod.rs index 3c9388a1e..de60bf080 100644 --- a/src/types/stardust/block/mod.rs +++ b/src/types/stardust/block/mod.rs @@ -28,7 +28,7 @@ impl From for Block { fn from(value: bee::Block) -> Self { Self { protocol_version: value.protocol_version(), - parents: value.parents().iter().map(|id| BlockId::from(*id)).collect(), + parents: value.parents().iter().map(|&id| BlockId::from(id)).collect(), payload: value.payload().map(Into::into), nonce: value.nonce(), } @@ -70,7 +70,7 @@ mod tests { #[test] fn test_block_id_bson() { - let block_id = BlockId::from(bee_test::rand::block::rand_block_id()); + let block_id = BlockId::from(bee_block_stardust::rand::block::rand_block_id()); let bson = to_bson(&block_id).unwrap(); assert_eq!(Bson::from(block_id), bson); from_bson::(bson).unwrap(); @@ -93,7 +93,7 @@ mod tests { fn get_test_transaction_block() -> Block { Block::from( - bee::BlockBuilder::::new(bee_test::rand::parents::rand_parents()) + bee::BlockBuilder::::new(bee_block_stardust::rand::parents::rand_parents()) .with_nonce_provider(u64::MAX, 0.0) .with_payload(get_test_transaction_payload().try_into().unwrap()) .finish() @@ -103,7 +103,7 @@ mod tests { fn get_test_milestone_block() -> Block { Block::from( - bee::BlockBuilder::::new(bee_test::rand::parents::rand_parents()) + bee::BlockBuilder::::new(bee_block_stardust::rand::parents::rand_parents()) .with_nonce_provider(u64::MAX, 0.0) .with_payload(get_test_milestone_payload().try_into().unwrap()) .finish() @@ -113,7 +113,7 @@ mod tests { fn get_test_tagged_data_block() -> Block { Block::from( - bee::BlockBuilder::::new(bee_test::rand::parents::rand_parents()) + bee::BlockBuilder::::new(bee_block_stardust::rand::parents::rand_parents()) .with_nonce_provider(u64::MAX, 0.0) .with_payload(get_test_tagged_data_payload().try_into().unwrap()) .finish() diff --git a/src/types/stardust/block/output/alias.rs b/src/types/stardust/block/output/alias.rs index abd28039c..ed601ebdd 100644 --- a/src/types/stardust/block/output/alias.rs +++ b/src/types/stardust/block/output/alias.rs @@ -157,7 +157,7 @@ pub(crate) mod test { #[test] fn test_alias_id_bson() { - let alias_id = AliasId::from(bee_test::rand::output::rand_alias_id()); + let alias_id = AliasId::from(bee_block_stardust::rand::output::rand_alias_id()); let bson = to_bson(&alias_id).unwrap(); assert_eq!(Bson::from(alias_id), bson); assert_eq!(alias_id, from_bson::(bson).unwrap()); @@ -172,7 +172,7 @@ pub(crate) mod test { pub(crate) fn get_test_alias_output() -> AliasOutput { AliasOutput::from( - &bee::AliasOutput::build_with_amount(100, bee_test::rand::output::rand_alias_id()) + &bee::AliasOutput::build_with_amount(100, bee_block_stardust::rand::output::rand_alias_id()) .unwrap() .with_native_tokens(vec![get_test_native_token().try_into().unwrap()]) .with_state_index(0) @@ -183,13 +183,13 @@ pub(crate) mod test { rand_governor_address_unlock_condition().into(), ]) .with_features(vec![ - get_test_sender_block(bee_test::rand::address::rand_address().into()) + get_test_sender_block(bee_block_stardust::rand::address::rand_address().into()) .try_into() .unwrap(), get_test_metadata_block().try_into().unwrap(), ]) .with_immutable_features(vec![ - get_test_issuer_block(bee_test::rand::address::rand_address().into()) + get_test_issuer_block(bee_block_stardust::rand::address::rand_address().into()) .try_into() .unwrap(), get_test_metadata_block().try_into().unwrap(), diff --git a/src/types/stardust/block/output/basic.rs b/src/types/stardust/block/output/basic.rs index 48170a5bb..8f70a9d01 100644 --- a/src/types/stardust/block/output/basic.rs +++ b/src/types/stardust/block/output/basic.rs @@ -84,7 +84,7 @@ impl TryFrom for bee::BasicOutput { #[cfg(test)] pub(crate) mod test { - use bee_test::rand::output::unlock_condition::rand_address_unlock_condition; + use bee_block_stardust::rand::output::unlock_condition::rand_address_unlock_condition; use mongodb::bson::{from_bson, to_bson}; use super::*; @@ -116,7 +116,7 @@ pub(crate) mod test { rand_expiration_unlock_condition().into(), ]) .with_features(vec![ - get_test_sender_block(bee_test::rand::address::rand_address().into()) + get_test_sender_block(bee_block_stardust::rand::address::rand_address().into()) .try_into() .unwrap(), get_test_metadata_block().try_into().unwrap(), diff --git a/src/types/stardust/block/output/feature.rs b/src/types/stardust/block/output/feature.rs index 50125d390..7948e23f7 100644 --- a/src/types/stardust/block/output/feature.rs +++ b/src/types/stardust/block/output/feature.rs @@ -65,11 +65,11 @@ pub(crate) mod test { #[test] fn test_feature_bson() { - let block = get_test_sender_block(bee_test::rand::address::rand_address().into()); + let block = get_test_sender_block(bee_block_stardust::rand::address::rand_address().into()); let bson = to_bson(&block).unwrap(); assert_eq!(block, from_bson::(bson).unwrap()); - let block = get_test_issuer_block(bee_test::rand::address::rand_address().into()); + let block = get_test_issuer_block(bee_block_stardust::rand::address::rand_address().into()); let bson = to_bson(&block).unwrap(); assert_eq!(block, from_bson::(bson).unwrap()); diff --git a/src/types/stardust/block/output/foundry.rs b/src/types/stardust/block/output/foundry.rs index e3e7e3b42..102f0282f 100644 --- a/src/types/stardust/block/output/foundry.rs +++ b/src/types/stardust/block/output/foundry.rs @@ -135,7 +135,7 @@ pub(crate) mod test { FoundryOutput::from( &bee::FoundryOutput::build_with_amount( 100, - bee_test::rand::number::rand_number(), + bee_block_stardust::rand::number::rand_number(), bee::TokenScheme::Simple(bee::SimpleTokenScheme::new(250.into(), 200.into(), 300.into()).unwrap()), ) .unwrap() diff --git a/src/types/stardust/block/output/mod.rs b/src/types/stardust/block/output/mod.rs index e314bd184..13f5a2dd3 100644 --- a/src/types/stardust/block/output/mod.rs +++ b/src/types/stardust/block/output/mod.rs @@ -14,7 +14,7 @@ pub(crate) mod treasury; use std::str::FromStr; -use bee_block_stardust::output::{self as bee}; +use bee_block_stardust::output::{self as bee, Rent}; use mongodb::bson::{doc, Bson}; use serde::{Deserialize, Serialize}; @@ -28,7 +28,7 @@ pub use self::{ treasury::TreasuryOutput, }; use super::Address; -use crate::types::stardust::block::TransactionId; +use crate::types::{ledger::RentStructureBytes, stardust::block::TransactionId}; #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, derive_more::From)] pub struct OutputAmount(#[serde(with = "crate::types::util::stringify")] pub u64); @@ -149,6 +149,46 @@ impl Output { Self::Foundry(_) => true, } } + + pub fn rent_structure(&self) -> RentStructureBytes { + match self { + output @ (Self::Basic(_) | Self::Alias(_) | Self::Foundry(_) | Self::Nft(_)) => { + let bee_output = + bee::Output::try_from(output.clone()).expect("`Output` has to be convertible to `bee::Output`"); + + // The following computations of `data_bytes` and `key_bytes` makec use of the fact that the byte cost + // computation is a linear combination with respect to the type of the fields and their weight. + + let num_data_bytes = { + let config = bee::RentStructureBuilder::new() + .byte_cost(1) + .data_factor(1) + .key_factor(0) + .finish(); + bee_output.rent_cost(&config) + }; + + let num_key_bytes = { + let config = bee::RentStructureBuilder::new() + .byte_cost(1) + .data_factor(0) + .key_factor(1) + .finish(); + bee_output.rent_cost(&config) + }; + + RentStructureBytes { + num_data_bytes, + num_key_bytes, + } + } + // The treasury output does not have an associated byte cost. + Self::Treasury(_) => RentStructureBytes { + num_key_bytes: 0, + num_data_bytes: 0, + }, + } + } } impl From<&bee::Output> for Output { @@ -194,7 +234,7 @@ pub(crate) mod test { #[test] fn test_output_id_bson() { - let output_id = OutputId::from(bee_test::rand::output::rand_output_id()); + let output_id = OutputId::from(bee_block_stardust::rand::output::rand_output_id()); let bson = to_bson(&output_id).unwrap(); from_bson::(bson).unwrap(); } @@ -217,7 +257,9 @@ pub(crate) mod test { let bson = to_bson(&output).unwrap(); assert_eq!(output, from_bson::(bson).unwrap()); - let output = Output::from(&bee::Output::Treasury(bee_test::rand::output::rand_treasury_output())); + let output = Output::from(&bee::Output::Treasury( + bee_block_stardust::rand::output::rand_treasury_output(), + )); let bson = to_bson(&output).unwrap(); assert_eq!(output, from_bson::(bson).unwrap()); } diff --git a/src/types/stardust/block/output/native_token.rs b/src/types/stardust/block/output/native_token.rs index cc86c1091..f427f93b7 100644 --- a/src/types/stardust/block/output/native_token.rs +++ b/src/types/stardust/block/output/native_token.rs @@ -139,10 +139,12 @@ pub(crate) mod test { } pub(crate) fn rand_token_id() -> bee::TokenId { - bee_test::rand::bytes::rand_bytes_array().into() + bee_block_stardust::rand::bytes::rand_bytes_array().into() } pub(crate) fn get_test_native_token() -> NativeToken { - NativeToken::from(&bee::NativeToken::new(bee_test::rand::bytes::rand_bytes_array().into(), 100.into()).unwrap()) + NativeToken::from( + &bee::NativeToken::new(bee_block_stardust::rand::bytes::rand_bytes_array().into(), 100.into()).unwrap(), + ) } } diff --git a/src/types/stardust/block/output/nft.rs b/src/types/stardust/block/output/nft.rs index 685206481..cd2ce070f 100644 --- a/src/types/stardust/block/output/nft.rs +++ b/src/types/stardust/block/output/nft.rs @@ -140,7 +140,7 @@ impl TryFrom for bee::NftOutput { #[cfg(test)] pub(crate) mod test { - use bee_test::rand::output::unlock_condition::rand_address_unlock_condition; + use bee_block_stardust::rand::output::unlock_condition::rand_address_unlock_condition; use mongodb::bson::{from_bson, to_bson}; use super::*; @@ -169,7 +169,7 @@ pub(crate) mod test { } pub(crate) fn rand_nft_id() -> bee::NftId { - bee_test::rand::bytes::rand_bytes_array().into() + bee_block_stardust::rand::bytes::rand_bytes_array().into() } pub(crate) fn get_test_nft_output() -> NftOutput { @@ -184,14 +184,14 @@ pub(crate) mod test { rand_expiration_unlock_condition().into(), ]) .with_features(vec![ - get_test_sender_block(bee_test::rand::address::rand_address().into()) + get_test_sender_block(bee_block_stardust::rand::address::rand_address().into()) .try_into() .unwrap(), get_test_metadata_block().try_into().unwrap(), get_test_tag_block().try_into().unwrap(), ]) .with_immutable_features(vec![ - get_test_issuer_block(bee_test::rand::address::rand_address().into()) + get_test_issuer_block(bee_block_stardust::rand::address::rand_address().into()) .try_into() .unwrap(), get_test_metadata_block().try_into().unwrap(), diff --git a/src/types/stardust/block/output/treasury.rs b/src/types/stardust/block/output/treasury.rs index 311bc21aa..270a3ea7c 100644 --- a/src/types/stardust/block/output/treasury.rs +++ b/src/types/stardust/block/output/treasury.rs @@ -35,7 +35,7 @@ pub(crate) mod test { #[test] fn test_treasury_output_bson() { - let output = TreasuryOutput::from(&bee_test::rand::output::rand_treasury_output()); + let output = TreasuryOutput::from(&bee_block_stardust::rand::output::rand_treasury_output()); let bson = to_bson(&output).unwrap(); assert_eq!(output, from_bson::(bson).unwrap()); } diff --git a/src/types/stardust/block/output/unlock_condition/mod.rs b/src/types/stardust/block/output/unlock_condition/mod.rs index 1397d9639..e6cfafcb9 100644 --- a/src/types/stardust/block/output/unlock_condition/mod.rs +++ b/src/types/stardust/block/output/unlock_condition/mod.rs @@ -22,12 +22,14 @@ pub(crate) mod test { use std::fmt::Debug; - use bee_block_stardust::output::{unlock_condition as bee, Output}; - use bee_test::rand::{ - address::{rand_address, rand_alias_address}, - milestone::rand_milestone_index, - number::{rand_number, rand_number_range}, - output::{rand_alias_id, unlock_condition::*}, + use bee_block_stardust::{ + output::{unlock_condition as bee, Output}, + rand::{ + address::{rand_address, rand_alias_address}, + milestone::rand_milestone_index, + number::{rand_number, rand_number_range}, + output::{rand_alias_id, unlock_condition::*}, + }, }; use mongodb::bson::{from_bson, to_bson}; use serde::{de::DeserializeOwned, Serialize}; diff --git a/src/types/stardust/block/payload/milestone/mod.rs b/src/types/stardust/block/payload/milestone/mod.rs index 33caa0e29..6d3d24de0 100644 --- a/src/types/stardust/block/payload/milestone/mod.rs +++ b/src/types/stardust/block/payload/milestone/mod.rs @@ -76,7 +76,7 @@ impl From<&bee::MilestoneEssence> for MilestoneEssence { index: value.index().0.into(), timestamp: value.timestamp(), previous_milestone_id: (*value.previous_milestone_id()).into(), - parents: value.parents().iter().map(|id| BlockId::from(*id)).collect(), + parents: value.parents().iter().map(|&id| BlockId::from(id)).collect(), inclusion_merkle_root: **value.inclusion_merkle_root(), applied_merkle_root: **value.applied_merkle_root(), metadata: value.metadata().to_vec(), @@ -234,7 +234,7 @@ pub(crate) mod test { #[test] fn test_milestone_id_bson() { - let milestone_id = MilestoneId::from(bee_test::rand::milestone::rand_milestone_id()); + let milestone_id = MilestoneId::from(bee_block_stardust::rand::milestone::rand_milestone_id()); let bson = to_bson(&milestone_id).unwrap(); assert_eq!(Bson::from(milestone_id), bson); assert_eq!(milestone_id, from_bson::(bson).unwrap()); @@ -251,7 +251,7 @@ pub(crate) mod test { MigratedFundsEntry::from( &bee::option::MigratedFundsEntry::new( bee::option::TailTransactionHash::new(TAIL_TRANSACTION_HASH1).unwrap(), - bee_block_stardust::address::Address::Ed25519(bee_test::rand::address::rand_ed25519_address()), + bee_block_stardust::address::Address::Ed25519(bee_block_stardust::rand::address::rand_ed25519_address()), 2000000, ) .unwrap(), @@ -262,7 +262,7 @@ pub(crate) mod test { MigratedFundsEntry::from( &bee::option::MigratedFundsEntry::new( bee::option::TailTransactionHash::new(TAIL_TRANSACTION_HASH2).unwrap(), - bee_block_stardust::address::Address::Alias(bee_test::rand::address::rand_alias_address()), + bee_block_stardust::address::Address::Alias(bee_block_stardust::rand::address::rand_alias_address()), 2000000, ) .unwrap(), @@ -273,7 +273,7 @@ pub(crate) mod test { MigratedFundsEntry::from( &bee::option::MigratedFundsEntry::new( bee::option::TailTransactionHash::new(TAIL_TRANSACTION_HASH3).unwrap(), - bee_block_stardust::address::Address::Nft(bee_test::rand::address::rand_nft_address()), + bee_block_stardust::address::Address::Nft(bee_block_stardust::rand::address::rand_nft_address()), 2000000, ) .unwrap(), @@ -285,10 +285,10 @@ pub(crate) mod test { &bee::MilestoneEssence::new( 1.into(), 12345, - bee_test::rand::milestone::rand_milestone_id(), - bee_test::rand::parents::rand_parents(), - bee_test::rand::milestone::rand_merkle_root(), - bee_test::rand::milestone::rand_merkle_root(), + bee_block_stardust::rand::milestone::rand_milestone_id(), + bee_block_stardust::rand::parents::rand_parents(), + bee_block_stardust::rand::milestone::rand_merkle_root(), + bee_block_stardust::rand::milestone::rand_merkle_root(), "Foo".as_bytes().to_vec(), bee::MilestoneOptions::new(vec![bee::option::MilestoneOption::Receipt( bee::option::ReceiptMilestoneOption::new( @@ -300,8 +300,8 @@ pub(crate) mod test { get_test_nft_migrated_funds_entry().try_into().unwrap(), ], TreasuryTransactionPayload::new( - bee_test::rand::input::rand_treasury_input(), - bee_test::rand::output::rand_treasury_output(), + bee_block_stardust::rand::input::rand_treasury_input(), + bee_block_stardust::rand::output::rand_treasury_output(), ) .unwrap(), ) diff --git a/src/types/stardust/block/payload/tagged_data.rs b/src/types/stardust/block/payload/tagged_data.rs index a9869e602..d6c14bfcc 100644 --- a/src/types/stardust/block/payload/tagged_data.rs +++ b/src/types/stardust/block/payload/tagged_data.rs @@ -43,6 +43,6 @@ pub(crate) mod test { } pub(crate) fn get_test_tagged_data_payload() -> TaggedDataPayload { - Into::into(&bee_test::rand::payload::rand_tagged_data_payload()) + Into::into(&bee_block_stardust::rand::payload::rand_tagged_data_payload()) } } diff --git a/src/types/stardust/block/payload/transaction.rs b/src/types/stardust/block/payload/transaction.rs index 872d68eed..5c5940807 100644 --- a/src/types/stardust/block/payload/transaction.rs +++ b/src/types/stardust/block/payload/transaction.rs @@ -178,7 +178,7 @@ pub(crate) mod test { #[test] fn test_transaction_id_bson() { - let transaction_id = TransactionId::from(bee_test::rand::transaction::rand_transaction_id()); + let transaction_id = TransactionId::from(bee_block_stardust::rand::transaction::rand_transaction_id()); let bson = to_bson(&transaction_id).unwrap(); assert_eq!(Bson::from(transaction_id), bson); assert_eq!(transaction_id, from_bson::(bson).unwrap()); diff --git a/src/types/stardust/block/payload/treasury_transaction.rs b/src/types/stardust/block/payload/treasury_transaction.rs index d4fb248ef..97d225e54 100644 --- a/src/types/stardust/block/payload/treasury_transaction.rs +++ b/src/types/stardust/block/payload/treasury_transaction.rs @@ -49,8 +49,8 @@ pub(crate) mod test { pub(crate) fn get_test_treasury_transaction_payload() -> TreasuryTransactionPayload { TreasuryTransactionPayload::from( &bee::TreasuryTransactionPayload::new( - bee_test::rand::input::rand_treasury_input(), - bee_test::rand::output::rand_treasury_output(), + bee_block_stardust::rand::input::rand_treasury_input(), + bee_block_stardust::rand::output::rand_treasury_output(), ) .unwrap(), ) diff --git a/src/types/stardust/block/signature.rs b/src/types/stardust/block/signature.rs index c44b41662..9c0d7f8c0 100644 --- a/src/types/stardust/block/signature.rs +++ b/src/types/stardust/block/signature.rs @@ -58,8 +58,8 @@ pub(crate) mod test { pub(crate) fn get_test_signature() -> Signature { Signature::from(&bee::Signature::Ed25519(bee::Ed25519Signature::new( - bee_test::rand::bytes::rand_bytes_array(), - bee_test::rand::bytes::rand_bytes_array(), + bee_block_stardust::rand::bytes::rand_bytes_array(), + bee_block_stardust::rand::bytes::rand_bytes_array(), ))) } } diff --git a/src/types/tangle/mod.rs b/src/types/tangle/mod.rs index 88e4dea9d..2a3e6c325 100644 --- a/src/types/tangle/mod.rs +++ b/src/types/tangle/mod.rs @@ -2,5 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 mod milestone_index; +mod protocol; -pub use milestone_index::MilestoneIndex; +pub use self::{ + milestone_index::MilestoneIndex, + protocol::{ProtocolInfo, ProtocolParameters}, +}; diff --git a/src/types/tangle/protocol.rs b/src/types/tangle/protocol.rs new file mode 100644 index 000000000..b1f3a11ec --- /dev/null +++ b/src/types/tangle/protocol.rs @@ -0,0 +1,59 @@ +// Copyright 2022 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use bee_block_stardust as bee; +use serde::{Deserialize, Serialize}; + +use super::MilestoneIndex; + +/// Parameters relevant to byte cost calculations. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RentStructure { + pub v_byte_cost: u32, + pub v_byte_factor_data: u8, + pub v_byte_factor_key: u8, +} + +impl From<&bee::output::RentStructure> for RentStructure { + fn from(value: &bee::output::RentStructure) -> Self { + Self { + v_byte_cost: value.v_byte_cost, + v_byte_factor_data: value.v_byte_factor_data, + v_byte_factor_key: value.v_byte_factor_key, + } + } +} + +/// Protocol parameters. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct ProtocolParameters { + pub version: u8, + pub network_name: String, + pub bech32_hrp: String, + pub min_pow_score: u32, + pub below_max_depth: u8, + pub rent_structure: RentStructure, + #[serde(with = "crate::types::util::stringify")] + pub token_supply: u64, +} + +impl From for ProtocolParameters { + fn from(value: bee::protocol::ProtocolParameters) -> Self { + Self { + version: value.version(), + network_name: value.network_name().into(), + bech32_hrp: value.bech32_hrp().into(), + min_pow_score: value.min_pow_score(), + below_max_depth: value.below_max_depth(), + rent_structure: value.rent_structure().into(), + token_supply: value.token_supply(), + } + } +} + +/// Provides the information about the protocol at a given [`MilestoneIndex`]. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct ProtocolInfo { + pub parameters: ProtocolParameters, + pub tangle_index: MilestoneIndex, +} diff --git a/tests/block.rs b/tests/block.rs index 6e70c4645..7afaf5d5c 100644 --- a/tests/block.rs +++ b/tests/block.rs @@ -1,7 +1,7 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use bee_test::rand::block::{rand_block, rand_block_id}; +use bee_block_stardust::rand::block::{rand_block, rand_block_id}; use chronicle::{ db::{MongoDb, MongoDbConfig}, types::{