diff --git a/Cargo.lock b/Cargo.lock index b8c2ad9c7..ba84a1667 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -266,11 +266,11 @@ dependencies = [ [[package]] name = "anchor-client" -version = "0.30.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4adc1b211826d72036dc2fcb679a8ef7fe5b9afda376b0b26debe19e28de3ea" +checksum = "cb48c4a7911038da546dc752655a29fa49f6bd50ebc1edca218bac8da1012acd" dependencies = [ - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", "anyhow", "futures", "regex", @@ -475,17 +475,15 @@ dependencies = [ [[package]] name = "anchor-spl" -version = "0.30.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04bd077c34449319a1e4e0bc21cea572960c9ae0d0fefda0dd7c52fcc3c647a3" +checksum = "6c4fd6e43b2ca6220d2ef1641539e678bfc31b6cc393cf892b373b5997b6a39a" dependencies = [ - "anchor-lang 0.30.1", - "spl-associated-token-account 3.0.2", - "spl-pod 0.2.2", + "anchor-lang 0.29.0", + "solana-program", + "spl-associated-token-account 2.3.0", "spl-token 4.0.0", - "spl-token-2022 3.0.2", - "spl-token-group-interface 0.2.3", - "spl-token-metadata-interface 0.3.3", + "spl-token-2022 0.9.0", ] [[package]] @@ -1617,7 +1615,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "beacon" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=master#47598512b7d282c34b619adf140403feeb138e71" +source = "git+https://github.com/helium/proto?branch=master#ad18fa2ac0864a2ec0da1c362139778cfd512ce2" dependencies = [ "base64 0.21.7", "byteorder", @@ -2132,19 +2130,10 @@ dependencies = [ [[package]] name = "circuit-breaker" version = "0.1.0" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "circuit-breaker" -version = "0.1.0" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] @@ -2783,19 +2772,10 @@ dependencies = [ [[package]] name = "data-credits" version = "0.2.2" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "data-credits" -version = "0.2.2" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] @@ -3170,19 +3150,10 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "fanout" version = "0.1.0" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "fanout" -version = "0.1.0" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] @@ -3755,45 +3726,23 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "helium-anchor-gen" version = "0.1.0" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", - "circuit-breaker 0.1.0 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "data-credits 0.2.2 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "fanout 0.1.0 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "helium-entity-manager 0.2.11 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "helium-sub-daos 0.1.8 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "hexboosting 0.1.0 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "lazy-distributor 0.2.0 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "lazy-transactions 0.2.0 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "mobile-entity-manager 0.1.3 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "price-oracle 0.2.1 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "rewards-oracle 0.2.0 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "treasury-management 0.2.0 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", - "voter-stake-registry 0.3.3 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", -] - -[[package]] -name = "helium-anchor-gen" -version = "0.1.0" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", - "circuit-breaker 0.1.0 (git+https://github.com/helium/helium-anchor-gen.git)", - "data-credits 0.2.2 (git+https://github.com/helium/helium-anchor-gen.git)", - "fanout 0.1.0 (git+https://github.com/helium/helium-anchor-gen.git)", - "helium-entity-manager 0.2.11 (git+https://github.com/helium/helium-anchor-gen.git)", - "helium-sub-daos 0.1.8 (git+https://github.com/helium/helium-anchor-gen.git)", - "hexboosting 0.1.0 (git+https://github.com/helium/helium-anchor-gen.git)", - "lazy-distributor 0.2.0 (git+https://github.com/helium/helium-anchor-gen.git)", - "lazy-transactions 0.2.0 (git+https://github.com/helium/helium-anchor-gen.git)", - "mobile-entity-manager 0.1.3 (git+https://github.com/helium/helium-anchor-gen.git)", - "price-oracle 0.2.1 (git+https://github.com/helium/helium-anchor-gen.git)", - "rewards-oracle 0.2.0 (git+https://github.com/helium/helium-anchor-gen.git)", - "treasury-management 0.2.0 (git+https://github.com/helium/helium-anchor-gen.git)", - "voter-stake-registry 0.3.3 (git+https://github.com/helium/helium-anchor-gen.git)", + "anchor-lang 0.29.0", + "circuit-breaker", + "data-credits", + "fanout", + "helium-entity-manager", + "helium-sub-daos", + "hexboosting", + "lazy-distributor", + "lazy-transactions", + "mobile-entity-manager", + "price-oracle", + "rewards-oracle", + "treasury-management", + "voter-stake-registry", ] [[package]] @@ -3806,7 +3755,7 @@ dependencies = [ "bs58 0.5.0", "byteorder", "ed25519-compact", - "getrandom 0.1.16", + "getrandom 0.2.10", "k256", "lazy_static", "multihash", @@ -3824,25 +3773,16 @@ dependencies = [ [[package]] name = "helium-entity-manager" version = "0.2.11" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "helium-entity-manager" -version = "0.2.11" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] name = "helium-lib" version = "0.0.0" -source = "git+https://github.com/helium/helium-wallet-rs.git?branch=master#4acf688beac3c507c33843a745516839e1f814b2" +source = "git+https://github.com/helium/helium-wallet-rs.git?branch=master#6b8a6bbf343027087a401cd907c9f6c848991aac" dependencies = [ "anchor-client", "anchor-spl", @@ -3853,7 +3793,7 @@ dependencies = [ "chrono", "futures", "h3o", - "helium-anchor-gen 0.1.0 (git+https://github.com/helium/helium-anchor-gen.git?branch=main)", + "helium-anchor-gen", "helium-crypto", "helium-proto", "hex", @@ -3882,7 +3822,7 @@ dependencies = [ [[package]] name = "helium-proto" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=master#47598512b7d282c34b619adf140403feeb138e71" +source = "git+https://github.com/helium/proto?branch=master#ad18fa2ac0864a2ec0da1c362139778cfd512ce2" dependencies = [ "bytes", "prost", @@ -3898,19 +3838,10 @@ dependencies = [ [[package]] name = "helium-sub-daos" version = "0.1.8" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "helium-sub-daos" -version = "0.1.8" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] @@ -3961,19 +3892,10 @@ checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" [[package]] name = "hexboosting" version = "0.1.0" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "hexboosting" -version = "0.1.0" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] @@ -4781,37 +4703,19 @@ dependencies = [ [[package]] name = "lazy-distributor" version = "0.2.0" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "lazy-distributor" -version = "0.2.0" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "lazy-transactions" -version = "0.2.0" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] name = "lazy-transactions" version = "0.2.0" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] @@ -5184,19 +5088,10 @@ dependencies = [ [[package]] name = "mobile-entity-manager" version = "0.1.3" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "mobile-entity-manager" -version = "0.1.3" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] @@ -5626,7 +5521,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ - "proc-macro-crate 1.1.3", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", "syn 2.0.58", @@ -6023,7 +5918,7 @@ dependencies = [ "file-store", "futures", "futures-util", - "helium-anchor-gen 0.1.0 (git+https://github.com/helium/helium-anchor-gen.git)", + "helium-anchor-gen", "helium-lib", "helium-proto", "humantime-serde", @@ -6049,19 +5944,10 @@ dependencies = [ [[package]] name = "price-oracle" version = "0.2.1" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "price-oracle" -version = "0.2.1" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] @@ -6175,7 +6061,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80b776a1b2dc779f5ee0641f8ade0125bc1298dd41a9a0c16d8bd57b42d222b1" dependencies = [ "bytes", - "heck 0.4.0", + "heck 0.5.0", "itertools", "log", "multimap", @@ -6233,11 +6119,10 @@ dependencies = [ [[package]] name = "pyth-solana-receiver-sdk" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e6559643f0b377b6f293269251f6a804ae7332c37f7310371f50c833453cd0" +version = "0.3.1" +source = "git+https://github.com/madninja/pyth-crosschain.git?branch=madninja/cap_solana_dep#6576247294bde3ab7b62f7a2dfb4d4d48c401b35" dependencies = [ - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", "hex", "pythnet-sdk", "solana-program", @@ -6245,9 +6130,8 @@ dependencies = [ [[package]] name = "pythnet-sdk" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbbc0456f9f27c9ad16b6c3bf1b2a7fea61eebf900f4d024a0468b9a84fe0c1" +version = "2.3.0" +source = "git+https://github.com/madninja/pyth-crosschain.git?branch=madninja/cap_solana_dep#6576247294bde3ab7b62f7a2dfb4d4d48c401b35" dependencies = [ "anchor-lang 0.30.1", "bincode", @@ -6256,7 +6140,6 @@ dependencies = [ "byteorder", "fast-math", "hex", - "proc-macro2", "rustc_version 0.4.0", "serde", "sha3 0.10.6", @@ -6710,19 +6593,10 @@ dependencies = [ [[package]] name = "rewards-oracle" version = "0.2.0" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "rewards-oracle" -version = "0.2.0" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] @@ -7444,7 +7318,7 @@ dependencies = [ "clap 4.4.8", "file-store", "futures", - "helium-anchor-gen 0.1.0 (git+https://github.com/helium/helium-anchor-gen.git)", + "helium-anchor-gen", "helium-crypto", "itertools", "metrics", @@ -8435,6 +8309,20 @@ dependencies = [ "syn 2.0.58", ] +[[package]] +name = "spl-tlv-account-resolution" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "062e148d3eab7b165582757453632ffeef490c02c86a48bfdb4988f63eefb3b9" +dependencies = [ + "bytemuck", + "solana-program", + "spl-discriminator 0.1.1", + "spl-pod 0.1.1", + "spl-program-error 0.3.1", + "spl-type-length-value 0.3.1", +] + [[package]] name = "spl-tlv-account-resolution" version = "0.5.2" @@ -8493,6 +8381,28 @@ dependencies = [ "thiserror", ] +[[package]] +name = "spl-token-2022" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4abf34a65ba420584a0c35f3903f8d727d1f13ababbdc3f714c6b065a686e86" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "num_enum 0.7.2", + "solana-program", + "solana-zk-token-sdk", + "spl-memo", + "spl-pod 0.1.1", + "spl-token 4.0.0", + "spl-token-metadata-interface 0.2.0", + "spl-transfer-hook-interface 0.3.0", + "spl-type-length-value 0.3.1", + "thiserror", +] + [[package]] name = "spl-token-2022" version = "1.0.0" @@ -8595,6 +8505,22 @@ dependencies = [ "spl-type-length-value 0.4.3", ] +[[package]] +name = "spl-transfer-hook-interface" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "051d31803f873cabe71aec3c1b849f35248beae5d19a347d93a5c9cccc5d5a9b" +dependencies = [ + "arrayref", + "bytemuck", + "solana-program", + "spl-discriminator 0.1.1", + "spl-pod 0.1.1", + "spl-program-error 0.3.1", + "spl-tlv-account-resolution 0.4.0", + "spl-type-length-value 0.3.1", +] + [[package]] name = "spl-transfer-hook-interface" version = "0.4.1" @@ -9344,19 +9270,10 @@ dependencies = [ [[package]] name = "treasury-management" version = "0.2.0" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "treasury-management" -version = "0.2.0" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] @@ -9399,7 +9316,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", - "rand 0.7.3", + "rand 0.8.5", "static_assertions", ] @@ -9601,19 +9518,10 @@ dependencies = [ [[package]] name = "voter-stake-registry" version = "0.3.3" -source = "git+https://github.com/helium/helium-anchor-gen.git?branch=main#761b839a71cc6d2aecf4be994af9d8206aeae0e1" +source = "git+https://github.com/helium/helium-anchor-gen.git#a7e694d49245ca9830bcfef68cce34f230c91011" dependencies = [ "anchor-gen", - "anchor-lang 0.30.1", -] - -[[package]] -name = "voter-stake-registry" -version = "0.3.3" -source = "git+https://github.com/helium/helium-anchor-gen.git#761b839a71cc6d2aecf4be994af9d8206aeae0e1" -dependencies = [ - "anchor-gen", - "anchor-lang 0.30.1", + "anchor-lang 0.29.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a45355a99..9860df9a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ license = "Apache-2.0" edition = "2021" [workspace.dependencies] -anchor-client = { version = "0.30.0", features = ["async"] } +anchor-client = { version = "0.29.0", features = ["async"] } anyhow = { version = "1", features = ["backtrace"] } bs58 = { version = "0.4", features = ["check"] } thiserror = "1" diff --git a/mobile_config/src/client/gateway_client.rs b/mobile_config/src/client/gateway_client.rs index 69ab7f128..a1a4a381f 100644 --- a/mobile_config/src/client/gateway_client.rs +++ b/mobile_config/src/client/gateway_client.rs @@ -4,7 +4,10 @@ use file_store::traits::MsgVerify; use futures::stream::{self, StreamExt}; use helium_crypto::{Keypair, PublicKey, PublicKeyBinary, Sign}; use helium_proto::{ - services::{mobile_config, Channel}, + services::{ + mobile_config::{self, DeviceType}, + Channel, + }, Message, }; use retainer::Cache; @@ -50,7 +53,10 @@ pub trait GatewayInfoResolver: Clone + Send + Sync + 'static { address: &PublicKeyBinary, ) -> Result, Self::Error>; - async fn stream_gateways_info(&mut self) -> Result; + async fn stream_gateways_info( + &mut self, + device_types: &[DeviceType], + ) -> Result; } #[async_trait::async_trait] @@ -92,11 +98,15 @@ impl GatewayInfoResolver for GatewayClient { Ok(response) } + /// Returns all gateways if device_types is empty + /// Otherwise, only selected device_types async fn stream_gateways_info( &mut self, + device_types: &[DeviceType], ) -> Result { let mut req = mobile_config::GatewayInfoStreamReqV1 { batch_size: self.batch_size, + device_types: device_types.iter().map(|v| DeviceType::into(*v)).collect(), signer: self.signing_key.public_key().into(), signature: vec![], }; diff --git a/mobile_config/src/gateway_info.rs b/mobile_config/src/gateway_info.rs index a9ada7896..ada624a81 100644 --- a/mobile_config/src/gateway_info.rs +++ b/mobile_config/src/gateway_info.rs @@ -88,6 +88,16 @@ impl From for DeviceType { #[error("invalid device type string")] pub struct DeviceTypeParseError; +impl std::fmt::Display for DeviceType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + DeviceType::Cbrs => write!(f, "cbrs"), + DeviceType::WifiIndoor => write!(f, "wifiIndoor"), + DeviceType::WifiOutdoor => write!(f, "wifiOutdoor"), + DeviceType::WifiDataOnly => write!(f, "wifiDataOnly"), + } + } +} impl std::str::FromStr for DeviceType { type Err = DeviceTypeParseError; @@ -116,9 +126,11 @@ pub(crate) mod db { join key_to_assets kta on infos.asset = kta.asset "#; const BATCH_SQL_WHERE_SNIPPET: &str = " where kta.entity_key = any($1::bytea[]) "; + const DEVICE_TYPES_WHERE_SNIPPET: &str = " where device_type::text = any($1) "; lazy_static::lazy_static! { static ref BATCH_METADATA_SQL: String = format!("{GET_METADATA_SQL} {BATCH_SQL_WHERE_SNIPPET}"); + static ref DEVICE_TYPES_METADATA_SQL: String = format!("{GET_METADATA_SQL} {DEVICE_TYPES_WHERE_SNIPPET}"); } pub async fn get_info( @@ -153,11 +165,26 @@ pub(crate) mod db { pub fn all_info_stream<'a>( db: impl PgExecutor<'a> + 'a, + device_types: &'a [DeviceType], ) -> impl Stream + 'a { - sqlx::query_as::<_, GatewayInfo>(GET_METADATA_SQL) - .fetch(db) - .filter_map(|metadata| async move { metadata.ok() }) - .boxed() + match device_types.is_empty() { + true => sqlx::query_as::<_, GatewayInfo>(GET_METADATA_SQL) + .fetch(db) + .filter_map(|metadata| async move { metadata.ok() }) + .boxed(), + false => sqlx::query_as::<_, GatewayInfo>(&DEVICE_TYPES_METADATA_SQL) + .bind( + device_types + .iter() + // The device_types field has a jsonb type but is being used as a string, + // which forces us to add quotes. + .map(|v| format!("\"{}\"", v)) + .collect::>(), + ) + .fetch(db) + .filter_map(|metadata| async move { metadata.ok() }) + .boxed(), + } } impl sqlx::FromRow<'_, sqlx::postgres::PgRow> for GatewayInfo { diff --git a/mobile_config/src/gateway_service.rs b/mobile_config/src/gateway_service.rs index 048980d55..90f1a11f9 100644 --- a/mobile_config/src/gateway_service.rs +++ b/mobile_config/src/gateway_service.rs @@ -1,5 +1,5 @@ use crate::{ - gateway_info::{self, GatewayInfo}, + gateway_info::{self, DeviceType, GatewayInfo}, key_cache::KeyCache, telemetry, verify_public_key, GrpcResult, GrpcStreamResult, }; @@ -156,16 +156,21 @@ impl mobile_config::Gateway for GatewayService { let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; - tracing::debug!("fetching all gateways' info"); - let pool = self.metadata_pool.clone(); let signing_key = self.signing_key.clone(); let batch_size = request.batch_size; let (tx, rx) = tokio::sync::mpsc::channel(100); + let device_types: Vec = request.device_types().map(|v| v.into()).collect(); + + tracing::debug!( + "fetching all gateways' info. Device types: {:?} ", + device_types + ); + tokio::spawn(async move { - let stream = gateway_info::db::all_info_stream(&pool); + let stream = gateway_info::db::all_info_stream(&pool, &device_types); stream_multi_gateways_info(stream, tx.clone(), signing_key.clone(), batch_size).await }); diff --git a/mobile_config/tests/gateway_service.rs b/mobile_config/tests/gateway_service.rs index 8a818baad..c1eb71dd3 100644 --- a/mobile_config/tests/gateway_service.rs +++ b/mobile_config/tests/gateway_service.rs @@ -1,5 +1,9 @@ -use helium_crypto::{KeyTag, Keypair, PublicKey, Sign}; -use helium_proto::services::mobile_config::{self as proto, GatewayClient}; +use futures::stream::StreamExt; + +use helium_crypto::{KeyTag, Keypair, PublicKey, PublicKeyBinary, Sign}; +use helium_proto::services::mobile_config::{ + self as proto, DeviceType, GatewayClient, GatewayInfoStreamReqV1, GatewayInfoStreamResV1, +}; use mobile_config::{ gateway_service::GatewayService, key_cache::{CacheKeys, KeyCache}, @@ -78,10 +82,196 @@ async fn gateway_info_authorization_errors(pool: PgPool) -> anyhow::Result<()> { Ok(()) } +#[sqlx::test] +async fn gateway_stream_info_data_types(pool: PgPool) { + let admin_key = make_keypair(); + let server_key = make_keypair(); + let asset1_pubkey = make_keypair().public_key().clone(); + let asset1_hex_idx = 631711281837647359_i64; + let asset2_hex_idx = 631711286145955327_i64; + let asset3_hex_idx = 631711286145006591_i64; + let asset2_pubkey = make_keypair().public_key().clone(); + let asset3_pubkey = make_keypair().public_key().clone(); + + create_db_tables(&pool).await; + add_db_record( + &pool, + "asset1", + asset1_hex_idx, + "\"wifiIndoor\"", + asset1_pubkey.clone().into(), + ) + .await; + add_db_record( + &pool, + "asset2", + asset2_hex_idx, + "\"wifiDataOnly\"", + asset2_pubkey.clone().into(), + ) + .await; + add_db_record( + &pool, + "asset3", + asset3_hex_idx, + "\"wifiDataOnly\"", + asset3_pubkey.clone().into(), + ) + .await; + + let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let addr = listener.local_addr().unwrap(); + + // Start the gateway server + let keys = CacheKeys::from_iter([(admin_key.public_key().to_owned(), KeyRole::Administrator)]); + let (_key_cache_tx, key_cache) = KeyCache::new(keys); + let gws = GatewayService::new(key_cache, pool.clone(), server_key); + let _handle = tokio::spawn( + transport::Server::builder() + .add_service(proto::GatewayServer::new(gws)) + .serve_with_incoming(tokio_stream::wrappers::TcpListenerStream::new(listener)), + ); + let mut client = GatewayClient::connect(format!("http://{addr}")) + .await + .unwrap(); + + // Check wifi indoor + let req = make_gateway_stream_signed_req(&admin_key, &[DeviceType::WifiIndoor]); + let mut stream = client.info_stream(req).await.unwrap().into_inner(); + let res = stream.next().await.unwrap().unwrap(); + let gw_info = res.gateways.first().unwrap(); + let pub_key = PublicKey::from_bytes(gw_info.address.clone()).unwrap(); + assert_eq!(pub_key, asset1_pubkey.clone()); + assert_eq!( + DeviceType::try_from(gw_info.device_type).unwrap(), + DeviceType::WifiIndoor + ); + assert_eq!( + i64::from_str_radix(&gw_info.metadata.clone().unwrap().location, 16).unwrap(), + asset1_hex_idx + ); + assert!(stream.next().await.is_none()); + + // Check wifi data only + let req = make_gateway_stream_signed_req(&admin_key, &[DeviceType::WifiDataOnly]); + let stream = client.info_stream(req).await.unwrap().into_inner(); + + let resp = stream + .filter_map(|result| async { result.ok() }) + .collect::>() + .await; + let gateways = resp.first().unwrap().gateways.clone(); + assert_eq!(gateways.len(), 2); + let device_type = gateways.first().unwrap().device_type; + assert_eq!( + DeviceType::try_from(device_type).unwrap(), + DeviceType::WifiDataOnly + ); + let device_type = gateways.get(1).unwrap().device_type; + assert_eq!( + DeviceType::try_from(device_type).unwrap(), + DeviceType::WifiDataOnly + ); + + // Check all + let req = make_gateway_stream_signed_req(&admin_key, &[]); + let stream = client.info_stream(req).await.unwrap().into_inner(); + + let resp = stream + .filter_map(|result| async { result.ok() }) + .collect::>() + .await; + let gateways = resp.first().unwrap().gateways.clone(); + assert_eq!(gateways.len(), 3); +} + +async fn add_db_record( + pool: &PgPool, + asset: &str, + location: i64, + device_type: &str, + key: PublicKeyBinary, +) { + add_mobile_hotspot_infos(pool, asset, location, device_type).await; + add_asset_key(pool, asset, key).await; +} + +async fn add_mobile_hotspot_infos(pool: &PgPool, asset: &str, location: i64, device_type: &str) { + sqlx::query( + r#" + INSERT INTO +"mobile_hotspot_infos" ("asset", "location", "device_type") + VALUES +($1, $2, $3::jsonb); + "#, + ) + .bind(asset) + .bind(location) + .bind(device_type) + .execute(pool) + .await + .unwrap(); +} + +async fn add_asset_key(pool: &PgPool, asset: &str, key: PublicKeyBinary) { + let b58 = bs58::decode(key.to_string()).into_vec().unwrap(); + sqlx::query( + r#" + INSERT INTO + "key_to_assets" ("asset", "entity_key") + VALUES ($1, $2); + "#, + ) + .bind(asset) + .bind(b58) + .execute(pool) + .await + .unwrap(); +} + +async fn create_db_tables(pool: &PgPool) { + sqlx::query( + r#" + CREATE TABLE mobile_hotspot_infos ( + asset character varying(255) NULL, + location numeric NULL, + device_type jsonb NOT NULL + );"#, + ) + .execute(pool) + .await + .unwrap(); + + sqlx::query( + r#" + CREATE TABLE key_to_assets ( + asset character varying(255) NULL, + entity_key bytea NULL + );"#, + ) + .execute(pool) + .await + .unwrap(); +} fn make_keypair() -> Keypair { Keypair::generate(KeyTag::default(), &mut rand::rngs::OsRng) } +fn make_gateway_stream_signed_req( + signer: &Keypair, + device_types: &[DeviceType], +) -> proto::GatewayInfoStreamReqV1 { + let mut req = GatewayInfoStreamReqV1 { + batch_size: 10000, + signer: signer.public_key().to_vec(), + signature: vec![], + device_types: device_types.iter().map(|v| DeviceType::into(*v)).collect(), + }; + + req.signature = signer.sign(&req.encode_to_vec()).unwrap(); + req +} + fn make_signed_info_request(address: &PublicKey, signer: &Keypair) -> proto::GatewayInfoReqV1 { let mut req = proto::GatewayInfoReqV1 { address: address.to_vec(), diff --git a/mobile_verifier/tests/integrations/speedtests.rs b/mobile_verifier/tests/integrations/speedtests.rs index 38d2fe629..5c6e9b9e8 100644 --- a/mobile_verifier/tests/integrations/speedtests.rs +++ b/mobile_verifier/tests/integrations/speedtests.rs @@ -6,7 +6,9 @@ use file_store::{ FileInfo, }; use helium_crypto::PublicKeyBinary; -use helium_proto::services::poc_mobile::SpeedtestAvgValidity; +use helium_proto::services::{ + mobile_config::DeviceType as MobileDeviceType, poc_mobile::SpeedtestAvgValidity, +}; use mobile_config::{ client::gateway_client::GatewayInfoResolver, gateway_info::{DeviceType, GatewayInfo, GatewayInfoStream}, @@ -35,7 +37,10 @@ impl GatewayInfoResolver for MockGatewayInfoResolver { })) } - async fn stream_gateways_info(&mut self) -> Result { + async fn stream_gateways_info( + &mut self, + _device_types: &[MobileDeviceType], + ) -> Result { todo!() } }