diff --git a/Cargo.lock b/Cargo.lock index b51cf14da..c0077d29a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1453,9 +1453,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.5.4" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82033247fd8e890df8f740e407ad4d038debb9eb1f40533fffb32e7d17dc6f7" +checksum = "b8ee0c1824c4dea5b5f81736aff91bae041d2c07ee1192bec91054e10e3e601e" dependencies = [ "arrayref", "arrayvec 0.7.6", @@ -2351,9 +2351,9 @@ dependencies = [ [[package]] name = "const-hex" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0121754e84117e65f9d90648ee6aa4882a6e63110307ab73967a4c5e7e69e586" +checksum = "487981fa1af147182687064d0a2c336586d337a606595ced9ffb0c685c250c73" dependencies = [ "cfg-if", "cpufeatures", @@ -2458,9 +2458,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" dependencies = [ "libc", ] @@ -3669,21 +3669,22 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.130" +version = "1.0.131" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c042a0ba58aaff55299632834d1ea53ceff73d62373f62c9ae60890ad1b942" +checksum = "2568d7d2cfc051e43414fe1ef80c712cbcd60c3624d1ad1cb4b2572324d0a5d9" dependencies = [ "cc", "cxxbridge-flags", "cxxbridge-macro", + "foldhash", "link-cplusplus", ] [[package]] name = "cxx-build" -version = "1.0.130" +version = "1.0.131" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45dc1c88d0fdac57518a9b1f6c4f4fb2aca8f3c30c0d03d7d8518b47ca0bcea6" +checksum = "1674a8b80cdcce32512a75975d85d569b160f612ee1d31645bc46771f7c220a1" dependencies = [ "cc", "codespan-reporting", @@ -3695,15 +3696,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.130" +version = "1.0.131" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa7ed7d30b289e2592cc55bc2ccd89803a63c913e008e6eb59f06cddf45bb52f" +checksum = "0c710c27f23b7fa00c23aaee9e6fd3e79a6dffc5f5c6217487ec5213f51296b7" [[package]] name = "cxxbridge-macro" -version = "1.0.130" +version = "1.0.131" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8c465d22de46b851c04630a5fc749a26005b263632ed2e0d9cc81518ead78d" +checksum = "0aa53ef9fc54b986272efe83e257bbb417d1c3ceab1b732411d8c634fda572be" dependencies = [ "proc-macro2", "quote", @@ -4455,7 +4456,7 @@ checksum = "3a82608ee96ce76aeab659e9b8d3c2b787bffd223199af88c674923d861ada10" dependencies = [ "execute-command-macro", "execute-command-tokens", - "generic-array 1.1.0", + "generic-array 1.1.1", ] [[package]] @@ -5614,9 +5615,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96512db27971c2c3eece70a1e106fbe6c87760234e31e8f7e5634912fe52794a" +checksum = "2cb8bc4c28d15ade99c7e90b219f30da4be5c88e586277e8cbe886beeb868ab2" dependencies = [ "typenum", ] @@ -5842,9 +5843,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.1" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ "allocator-api2", "equivalent", @@ -6140,7 +6141,7 @@ dependencies = [ "hyper 1.5.1", "hyper-util", "log", - "rustls 0.23.17", + "rustls 0.23.18", "rustls-pki-types", "tokio", "tokio-rustls 0.26.0", @@ -6479,13 +6480,13 @@ dependencies = [ [[package]] name = "impl-trait-for-tuples" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.89", ] [[package]] @@ -6525,7 +6526,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.1", + "hashbrown 0.15.2", ] [[package]] @@ -6718,9 +6719,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "540654e97a3f4470a492cd30ff187bc95d89557a903a2bbf112e2fae98104ef2" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "jni" @@ -6812,7 +6813,7 @@ dependencies = [ "http 1.1.0", "jsonrpsee-core", "pin-project", - "rustls 0.23.17", + "rustls 0.23.18", "rustls-pki-types", "rustls-platform-verifier", "soketto 0.8.0", @@ -6864,7 +6865,7 @@ dependencies = [ "hyper-util", "jsonrpsee-core", "jsonrpsee-types", - "rustls 0.23.17", + "rustls 0.23.18", "rustls-platform-verifier", "serde", "serde_json", @@ -7157,9 +7158,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.164" +version = "0.2.166" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" +checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36" [[package]] name = "libloading" @@ -7763,9 +7764,9 @@ dependencies = [ [[package]] name = "litemap" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" [[package]] name = "litep2p" @@ -7859,7 +7860,7 @@ version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown 0.15.1", + "hashbrown 0.15.2", ] [[package]] @@ -7898,7 +7899,7 @@ dependencies = [ "cid 0.11.1", "futures", "hex", - "primitives-proofs", + "primitives", "serde", "serde_json", "storagext", @@ -10470,8 +10471,7 @@ dependencies = [ "pallet-proofs", "pallet-storage-provider", "parity-scale-codec", - "primitives-commitment", - "primitives-proofs", + "primitives", "scale-info", "sp-arithmetic 26.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", "sp-core 34.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", @@ -11030,14 +11030,13 @@ dependencies = [ "frame-benchmarking 38.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", "frame-support 38.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", "frame-system 38.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", - "generic-array 1.1.0", + "generic-array 1.1.1", "hex", "log", "num-bigint", "parity-scale-codec", "polka-storage-proofs", - "primitives-commitment", - "primitives-proofs", + "primitives", "rand", "rand_chacha", "rand_xorshift", @@ -11090,7 +11089,7 @@ dependencies = [ "log", "pallet-insecure-randomness-collective-flip 26.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", "parity-scale-codec", - "primitives-proofs", + "primitives", "scale-info", "sp-core 34.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", "sp-io 38.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", @@ -11730,8 +11729,7 @@ dependencies = [ "pallet-proofs", "pallet-randomness", "parity-scale-codec", - "primitives-commitment", - "primitives-proofs", + "primitives", "rstest", "scale-info", "sp-arithmetic 26.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", @@ -12327,7 +12325,7 @@ checksum = "4e69bf016dc406eff7d53a7d3f7cf1c2e72c82b9088aac1118591e36dd2cd3e9" dependencies = [ "bitcoin_hashes 0.13.0", "rand", - "rand_core 0.5.1", + "rand_core 0.6.4", "serde", "unicode-normalization", ] @@ -12519,9 +12517,9 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pathdiff" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c5ce1153ab5b689d0c074c4e7fc613e942dfb7dd9eea5ab202d2ad91fe361" +checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" [[package]] name = "pbkdf2" @@ -12802,8 +12800,7 @@ dependencies = [ "filecoin-proofs", "pairing", "parity-scale-codec", - "primitives-commitment", - "primitives-proofs", + "primitives", "rand", "rand_xorshift", "rstest", @@ -12828,8 +12825,7 @@ dependencies = [ "parity-scale-codec", "polka-storage-proofs", "polka-storage-provider-common", - "primitives-commitment", - "primitives-proofs", + "primitives", "sc-cli", "serde", "serde_json", @@ -12852,8 +12848,7 @@ dependencies = [ "fr32", "jsonrpsee", "polka-storage-proofs", - "primitives-commitment", - "primitives-proofs", + "primitives", "serde", "serde_json", "storage-proofs-core", @@ -12878,8 +12873,7 @@ dependencies = [ "parity-scale-codec", "polka-storage-proofs", "polka-storage-provider-common", - "primitives-commitment", - "primitives-proofs", + "primitives", "rand", "rocksdb", "sc-cli", @@ -12943,7 +12937,7 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain-primitives 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", "polkadot-runtime-common 17.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", - "primitives-proofs", + "primitives", "scale-info", "smallvec", "sp-api 34.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", @@ -14758,9 +14752,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" +checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" [[package]] name = "positioned-io" @@ -14886,33 +14880,21 @@ dependencies = [ ] [[package]] -name = "primitives-commitment" +name = "primitives" version = "0.1.0" dependencies = [ "cid 0.11.1", + "clap", "filecoin-proofs", "parity-scale-codec", - "primitives-proofs", "rand", - "scale-info", - "sealed", - "serde", - "sha2 0.10.8", - "thiserror 2.0.3", -] - -[[package]] -name = "primitives-proofs" -version = "0.1.0" -dependencies = [ - "cid 0.11.1", - "clap", - "parity-scale-codec", "scale-decode", "scale-encode", "scale-info", + "sealed", "serde", "serde_json", + "sha2 0.10.8", "sp-api 34.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", "sp-core 34.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", "sp-runtime 39.0.1", @@ -15025,9 +15007,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.91" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "307e3004becf10f5a6e0d59d20f3cd28231b0e0827a96cd3e0ce6d14bc1e4bb3" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -16097,9 +16079,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.17" +version = "0.23.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e" +checksum = "9c9cc1d47e243d655ace55ed38201c19ae02c148ae56412ab8750e8f0166ab7f" dependencies = [ "log", "once_cell", @@ -16170,13 +16152,13 @@ dependencies = [ "jni", "log", "once_cell", - "rustls 0.23.17", + "rustls 0.23.18", "rustls-native-certs 0.7.3", "rustls-platform-verifier-android", "rustls-webpki 0.102.8", "security-framework", "security-framework-sys", - "webpki-roots 0.26.6", + "webpki-roots 0.26.7", "winapi 0.3.9", ] @@ -20972,7 +20954,7 @@ dependencies = [ "hex", "itertools 0.13.0", "parity-scale-codec", - "primitives-proofs", + "primitives", "serde", "serde_json", "sha2 0.10.8", @@ -20995,7 +20977,7 @@ dependencies = [ "frame-support 38.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409-2)", "hex", "parity-scale-codec", - "primitives-proofs", + "primitives", "serde", "serde_json", "storagext", @@ -21864,7 +21846,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.17", + "rustls 0.23.18", "rustls-pki-types", "tokio", ] @@ -22078,9 +22060,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", @@ -22089,9 +22071,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" dependencies = [ "once_cell", "valuable", @@ -22491,9 +22473,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.3" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", "idna 1.0.3", @@ -23086,9 +23068,9 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" [[package]] name = "webpki-roots" -version = "0.26.6" +version = "0.26.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +checksum = "5d642ff16b7e79272ae451b7322067cdc17cadf68c23264be9d94a32319efe7e" dependencies = [ "rustls-pki-types", ] @@ -23816,9 +23798,9 @@ dependencies = [ [[package]] name = "yoke" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" dependencies = [ "serde", "stable_deref_trait", @@ -23828,9 +23810,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", @@ -23861,18 +23843,18 @@ dependencies = [ [[package]] name = "zerofrom" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" dependencies = [ "zerofrom-derive", ] [[package]] name = "zerofrom-derive" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", @@ -23924,9 +23906,9 @@ dependencies = [ [[package]] name = "zombienet-configuration" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d7a8cc4f8e8bb3f40757b62d3b054da5c95f43321c775eb321edc89d431583e" +checksum = "3de034c8aeb865b528ec76da9c26e91acec88b31709b75c053ffd50999a70443" dependencies = [ "anyhow", "lazy_static", @@ -23944,9 +23926,9 @@ dependencies = [ [[package]] name = "zombienet-orchestrator" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d32fa87851f41443a78971bd7110274f9a66d139ac834de159adc08f90cf8e3" +checksum = "d5ee915b0c296af3591c7e80ce80beab963f9fec12ddd7dca5b818bdc8ad7304" dependencies = [ "anyhow", "async-trait", @@ -23977,9 +23959,9 @@ dependencies = [ [[package]] name = "zombienet-prom-metrics-parser" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9acb9c94bc7c2c83f8eb8e26ed403f757af1632f22b89394d8876412ede990ca" +checksum = "049d19866bac35574ccc7e6558f2ca2b802a4d7325e48978d55e7337e9cece20" dependencies = [ "pest", "pest_derive", @@ -23988,9 +23970,9 @@ dependencies = [ [[package]] name = "zombienet-provider" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc8f3f71d4d974fc4a2262fa9293c2eedc423540378bd7c1dc1b66cc95d1d1af" +checksum = "f5890668321c0f4c324830e5c47925d82458e484213caa57798ffd350d35f007" dependencies = [ "anyhow", "async-trait", @@ -24019,9 +24001,9 @@ dependencies = [ [[package]] name = "zombienet-sdk" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dbfddce7a6100cdc930b93301f1b6381e6577ecc013d6802258ea6902a2bebd" +checksum = "e713dd9911efe9238e0e1c30dec12884052da456d105014b5de2a5e914350476" dependencies = [ "async-trait", "futures", @@ -24036,9 +24018,9 @@ dependencies = [ [[package]] name = "zombienet-support" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d20567c52b4fd46b600cda254dedb6a6dc30cabf512de91e4f6f78f0f7f4644b" +checksum = "ba603a3cda55bef37fe4a9036521f7e4345726190aa54f4fa0ca7df77d2f7c39" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index c380d7e96..bbfc695ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,9 +7,6 @@ repository = "https://github.com/eigerco/polka-storage" [workspace] members = [ - "cli/polka-storage-provider/client", - "cli/polka-storage-provider/common", - "cli/polka-storage-provider/server", "lib/polka-storage-proofs", "maat", "mater/cli", @@ -20,9 +17,11 @@ members = [ "pallets/proofs", "pallets/randomness", "pallets/storage-provider", - "primitives/commitment", - "primitives/proofs", + "primitives", "runtime", + "storage-provider/client", + "storage-provider/common", + "storage-provider/server", "storage/polka-index", "storagext/cli", "storagext/lib", @@ -93,7 +92,7 @@ rand_chacha = { version = "0.3.1", default-features = false } rand_xorshift = "0.3" rocksdb = { version = "0.21" } scale-info = { version = "2.11.1", default-features = false } -sealed = "0.6.0" +sealed = { version = "0.6.0", default-features = false } serde = { version = "1.0.197", default-features = false } serde-big-array = { version = "0.3.2" } serde_derive = { version = "1.0.117" } @@ -137,10 +136,9 @@ pallet-proofs = { path = "pallets/proofs", default-features = false } pallet-randomness = { path = "pallets/randomness", default-features = false } pallet-storage-provider = { path = "pallets/storage-provider", default-features = false } polka-storage-proofs = { path = "lib/polka-storage-proofs", default-features = false } -polka-storage-provider-common = { path = "cli/polka-storage-provider/common" } +polka-storage-provider-common = { path = "storage-provider/common" } polka-storage-runtime = { path = "runtime" } -primitives-commitment = { path = "primitives/commitment" } -primitives-proofs = { path = "primitives/proofs", default-features = false } +primitives = { path = "primitives", default-features = false } storagext = { path = "storagext/lib" } # FileCoin proofs @@ -214,7 +212,6 @@ frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-s frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409-2", default-features = false } # FRAME Pallets -# TODO(#457,@cernicc,17/10/2024): Switch to BABE pallet-aura = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409-2", default-features = false } pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409-2", default-features = false } pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409-2", default-features = false } diff --git a/lib/polka-storage-proofs/Cargo.toml b/lib/polka-storage-proofs/Cargo.toml index 35ac36c7d..66d7d6ee3 100644 --- a/lib/polka-storage-proofs/Cargo.toml +++ b/lib/polka-storage-proofs/Cargo.toml @@ -11,8 +11,7 @@ version = "0.1.0" # Permanently used crates. bls12_381 = { workspace = true } pairing = { workspace = true } -primitives-commitment = { workspace = true } -primitives-proofs = { workspace = true } +primitives = { workspace = true } rand_xorshift = { workspace = true } # Crates are only imported on feature 'std'. @@ -53,8 +52,7 @@ std = [ "dep:storage-proofs-porep", "dep:storage-proofs-post", "dep:thiserror", - "primitives-commitment/std", - "primitives-proofs/std", + "primitives/std", "rand/std", "scale-info?/std", ] diff --git a/lib/polka-storage-proofs/src/porep/mod.rs b/lib/polka-storage-proofs/src/porep/mod.rs index 828c4b2e8..ce251c8ed 100644 --- a/lib/polka-storage-proofs/src/porep/mod.rs +++ b/lib/polka-storage-proofs/src/porep/mod.rs @@ -6,7 +6,7 @@ pub mod sealer; use bellperson::groth16; use blstrs::Bls12; use filecoin_proofs::{DefaultPieceHasher, SectorShapeBase}; -use primitives_proofs::RegisteredSealProof; +use primitives::proofs::RegisteredSealProof; use rand::rngs::OsRng; use storage_proofs_core::{compound_proof::CompoundProof, proof::ProofScheme}; use storage_proofs_porep::stacked::StackedDrg; diff --git a/lib/polka-storage-proofs/src/porep/sealer.rs b/lib/polka-storage-proofs/src/porep/sealer.rs index 21e35bdf7..e6e11a1de 100644 --- a/lib/polka-storage-proofs/src/porep/sealer.rs +++ b/lib/polka-storage-proofs/src/porep/sealer.rs @@ -8,11 +8,14 @@ use filecoin_proofs::{ DefaultPieceHasher, PaddedBytesAmount, PoRepConfig, SealCommitPhase1Output, SealPreCommitOutput, SealPreCommitPhase1Output, SectorShapeBase, UnpaddedBytesAmount, }; -use primitives_commitment::{ - piece::{PaddedPieceSize, PieceInfo}, - CommD, CommP, CommR, Commitment, +use primitives::{ + commitment::{ + piece::{PaddedPieceSize, PieceInfo}, + CommD, CommP, CommR, Commitment, + }, + proofs::RegisteredSealProof, + sector::SectorNumber, }; -use primitives_proofs::{RegisteredSealProof, SectorNumber}; use storage_proofs_core::{compound_proof, compound_proof::CompoundProof}; use storage_proofs_porep::stacked::{self, StackedCompound, StackedDrg}; @@ -445,16 +448,15 @@ mod test { fn padding_for_sector(#[case] piece_sizes: Vec) { let sealer = Sealer::new(RegisteredSealProof::StackedDRG2KiBV1P1); - let piece_infos: Vec<(Cursor>, primitives_commitment::piece::PieceInfo)> = - piece_sizes - .into_iter() - .map(|size| { - let (piece_bytes, piece_info) = - piece_with_random_data(PaddedBytesAmount(size as u64)); + let piece_infos: Vec<(Cursor>, PieceInfo)> = piece_sizes + .into_iter() + .map(|size| { + let (piece_bytes, piece_info) = + piece_with_random_data(PaddedBytesAmount(size as u64)); - (Cursor::new(piece_bytes), piece_info) - }) - .collect(); + (Cursor::new(piece_bytes), piece_info) + }) + .collect(); // Create a file-like sector where non-occupied bytes are 0 let sector_size = sealer.porep_config.sector_size.0 as usize; @@ -474,9 +476,7 @@ mod test { } /// Generates a piece of `size` and a PieceInfo for it - fn piece_with_random_data( - size: PaddedBytesAmount, - ) -> (Vec, primitives_commitment::piece::PieceInfo) { + fn piece_with_random_data(size: PaddedBytesAmount) -> (Vec, PieceInfo) { let rng = &mut XorShiftRng::from_seed(filecoin_proofs::TEST_SEED); let piece_size: UnpaddedBytesAmount = size.into(); diff --git a/lib/polka-storage-proofs/src/post/mod.rs b/lib/polka-storage-proofs/src/post/mod.rs index b58d3a67b..f8ae45752 100644 --- a/lib/polka-storage-proofs/src/post/mod.rs +++ b/lib/polka-storage-proofs/src/post/mod.rs @@ -11,7 +11,7 @@ use filecoin_proofs::{ as_safe_commitment, parameters::window_post_setup_params, PoStType, PrivateReplicaInfo, SectorShapeBase, }; -use primitives_proofs::{RegisteredPoStProof, SectorNumber}; +use primitives::{proofs::RegisteredPoStProof, sector::SectorNumber}; use rand::rngs::OsRng; use storage_proofs_core::compound_proof::{self, CompoundProof}; use storage_proofs_post::fallback::{ diff --git a/maat/Cargo.toml b/maat/Cargo.toml index 7f62c68b6..f37fdd999 100644 --- a/maat/Cargo.toml +++ b/maat/Cargo.toml @@ -23,17 +23,16 @@ bs58.workspace = true cid.workspace = true futures.workspace = true hex = { workspace = true } +primitives = { workspace = true, features = ["serde"] } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["std"] } +storagext = { workspace = true } subxt = { workspace = true, features = ["substrate-compat"] } thiserror.workspace = true tokio = { workspace = true, features = ["full"] } tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } -primitives-proofs = { workspace = true, features = ["serde"] } -storagext = { workspace = true } - zombienet-configuration.workspace = true zombienet-sdk.workspace = true zombienet-support.workspace = true diff --git a/maat/tests/real_world.rs b/maat/tests/real_world.rs index 360a253bd..352a37bce 100644 --- a/maat/tests/real_world.rs +++ b/maat/tests/real_world.rs @@ -2,7 +2,7 @@ use std::collections::BTreeSet; use cid::Cid; use maat::*; -use primitives_proofs::SectorSize; +use primitives::sector::SectorSize; use storagext::{ clients::ProofsClientExt, runtime::runtime_types::{ @@ -38,7 +38,7 @@ where .register_storage_provider( charlie, peer_id.clone(), - primitives_proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1, + primitives::proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1, true, ) .await @@ -57,11 +57,11 @@ where assert_eq!(event.info.sector_size, SectorSize::_2KiB); assert_eq!( event.info.window_post_proof_type, - primitives_proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1 + primitives::proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1 ); assert_eq!( event.info.window_post_partition_sectors, - primitives_proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1 + primitives::proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1 .window_post_partitions_sector() ); } @@ -227,7 +227,7 @@ where Cid::try_from("bagboea4b5abcaqolcsygu5o756srf7l4pzzagml5r3wa3o6ahoo5vixummsev6rf").unwrap(); let sectors_pre_commit_info = vec![SectorPreCommitInfo { - seal_proof: primitives_proofs::RegisteredSealProof::StackedDRG2KiBV1P1, + seal_proof: primitives::proofs::RegisteredSealProof::StackedDRG2KiBV1P1, sector_number: 1.into(), sealed_cid, deal_ids: vec![0], @@ -330,7 +330,7 @@ where proof: storagext::runtime::runtime_types::pallet_storage_provider::proofs::PoStProof { post_proof: - primitives_proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1, + primitives::proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1, proof_bytes: "beef".to_string().into_bounded_byte_vec(), }, }, diff --git a/pallets/market/Cargo.toml b/pallets/market/Cargo.toml index e17fdaf8c..0dc9afff1 100644 --- a/pallets/market/Cargo.toml +++ b/pallets/market/Cargo.toml @@ -21,8 +21,7 @@ codec = { workspace = true, default-features = false, features = ["derive"] } hex = { workspace = true, default-features = false, features = ["alloc"] } log = { workspace = true } multihash-codetable = { workspace = true, features = ["blake2b"] } -primitives-commitment = { workspace = true } -primitives-proofs = { workspace = true, default-features = false } +primitives = { workspace = true } scale-info = { workspace = true, default-features = false, features = ["derive"] } thiserror = { workspace = true, default-features = false } @@ -60,7 +59,7 @@ std = [ "frame-system/std", "hex/std", "pallet-balances/std", - "primitives-proofs/std", + "primitives/std", "scale-info/std", "sp-core/std", "sp-io/std", diff --git a/pallets/market/src/error.rs b/pallets/market/src/error.rs index 1085455db..fdcbbebe4 100644 --- a/pallets/market/src/error.rs +++ b/pallets/market/src/error.rs @@ -1,5 +1,5 @@ use codec::{Decode, Encode}; -use primitives_commitment::{piece::PaddedPieceSizeError, CommitmentError}; +use primitives::commitment::{piece::PaddedPieceSizeError, CommitmentError}; use scale_info::TypeInfo; // Clone and PartialEq required because of the BoundedVec<(DealId, DealSettlementError)> diff --git a/pallets/market/src/lib.rs b/pallets/market/src/lib.rs index b9496c4a8..b1c9c6405 100644 --- a/pallets/market/src/lib.rs +++ b/pallets/market/src/lib.rs @@ -38,14 +38,16 @@ pub mod pallet { PalletId, }; use frame_system::{pallet_prelude::*, Config as SystemConfig, Pallet as System}; - use primitives_commitment::{ - commd::compute_unsealed_sector_commitment, - piece::{PaddedPieceSize, PieceInfo}, - CommP, Commitment, CommitmentError, - }; - use primitives_proofs::{ - ActiveDeal, ActiveSector, DealId, Market, RegisteredSealProof, SectorDeal, SectorNumber, - SectorSize, StorageProviderValidation, MAX_DEALS_PER_SECTOR, MAX_SECTORS_PER_CALL, + use primitives::{ + commitment::{ + commd::compute_unsealed_sector_commitment, + piece::{PaddedPieceSize, PieceInfo}, + CommP, Commitment, CommitmentError, + }, + pallets::{ActiveDeal, ActiveSector, Market, SectorDeal, StorageProviderValidation}, + proofs::RegisteredSealProof, + sector::{SectorNumber, SectorSize}, + DealId, MAX_DEALS_PER_SECTOR, MAX_SECTORS_PER_CALL, }; use scale_info::TypeInfo; use sp_arithmetic::traits::BaseArithmetic; diff --git a/pallets/market/src/mock.rs b/pallets/market/src/mock.rs index 9928e722e..d93b11e9d 100644 --- a/pallets/market/src/mock.rs +++ b/pallets/market/src/mock.rs @@ -6,7 +6,7 @@ use frame_support::{ PalletId, }; use frame_system::{self as system, pallet_prelude::BlockNumberFor}; -use primitives_proofs::{Randomness, RegisteredPoStProof}; +use primitives::{pallets::Randomness, proofs::RegisteredPoStProof}; use sp_core::Pair; use sp_runtime::{ traits::{ConstU32, ConstU64, IdentifyAccount, IdentityLookup, Verify}, diff --git a/pallets/market/src/test.rs b/pallets/market/src/test.rs index a47f45e23..d8be52648 100644 --- a/pallets/market/src/test.rs +++ b/pallets/market/src/test.rs @@ -8,10 +8,12 @@ use frame_support::{ traits::Currency, BoundedVec, }; -use primitives_commitment::{CommP, Commitment}; -use primitives_proofs::{ - ActiveDeal, ActiveSector, DealId, Market as MarketTrait, RegisteredSealProof, SectorDeal, - SectorNumber, MAX_DEALS_PER_SECTOR, +use primitives::{ + commitment::{CommP, Commitment}, + pallets::{ActiveDeal, ActiveSector, Market as MarketTrait, SectorDeal}, + proofs::RegisteredSealProof, + sector::SectorNumber, + DealId, MAX_DEALS_PER_SECTOR, }; use sp_core::H256; use sp_runtime::AccountId32; diff --git a/pallets/proofs/Cargo.toml b/pallets/proofs/Cargo.toml index 37a72cb3b..21b273ad2 100644 --- a/pallets/proofs/Cargo.toml +++ b/pallets/proofs/Cargo.toml @@ -27,8 +27,7 @@ frame-system.workspace = true log = { workspace = true } num-bigint = { workspace = true } polka-storage-proofs = { workspace = true, features = ["substrate"] } -primitives-commitment = { workspace = true } -primitives-proofs = { workspace = true } +primitives = { workspace = true } rand = { workspace = true, features = ["alloc"] } rand_chacha = { workspace = true } scale-info = { features = ["derive"], workspace = true } @@ -63,6 +62,7 @@ std = [ "frame-support/std", "frame-system/std", "polka-storage-proofs/std", + "primitives/std", "scale-info/std", "sp-runtime/std", "sp-std/std", diff --git a/pallets/proofs/src/lib.rs b/pallets/proofs/src/lib.rs index d7b67de73..ffbc9f11d 100644 --- a/pallets/proofs/src/lib.rs +++ b/pallets/proofs/src/lib.rs @@ -26,10 +26,12 @@ pub mod pallet { use frame_support::{pallet_prelude::*, sp_runtime::BoundedBTreeMap}; use frame_system::pallet_prelude::*; - use primitives_proofs::{ - ProofVerification, ProverId, PublicReplicaInfo, RawCommitment, RegisteredPoStProof, - RegisteredSealProof, SectorNumber, Ticket, MAX_POST_PROOF_BYTES, MAX_SEAL_PROOF_BYTES, - MAX_SECTORS_PER_PROOF, + use primitives::{ + commitment::RawCommitment, + pallets::ProofVerification, + proofs::{ProverId, PublicReplicaInfo, RegisteredPoStProof, RegisteredSealProof, Ticket}, + sector::SectorNumber, + MAX_POST_PROOF_BYTES, MAX_SEAL_PROOF_BYTES, MAX_SECTORS_PER_PROOF, }; use crate::{ diff --git a/pallets/proofs/src/porep/config.rs b/pallets/proofs/src/porep/config.rs index 57a59a26c..1bb57014c 100644 --- a/pallets/proofs/src/porep/config.rs +++ b/pallets/proofs/src/porep/config.rs @@ -1,6 +1,6 @@ use bls12_381::Scalar as Fr; use num_bigint::BigUint; -use primitives_proofs::RegisteredSealProof; +use primitives::proofs::RegisteredSealProof; use sha2::{Digest, Sha256}; use crate::Vec; diff --git a/pallets/proofs/src/porep/mod.rs b/pallets/proofs/src/porep/mod.rs index dbf425f30..ab4c1afee 100644 --- a/pallets/proofs/src/porep/mod.rs +++ b/pallets/proofs/src/porep/mod.rs @@ -1,7 +1,11 @@ mod config; use config::{Config, PoRepID}; -use primitives_proofs::{ProverId, RawCommitment, RegisteredSealProof, SectorNumber, Ticket}; +use primitives::{ + commitment::RawCommitment, + proofs::{ProverId, RegisteredSealProof, Ticket}, + sector::SectorNumber, +}; use sha2::{Digest, Sha256}; use crate::{ @@ -248,7 +252,7 @@ fn generate_inclusion_input(challenge: usize) -> Fr { #[cfg(test)] mod tests { - use primitives_proofs::{RegisteredSealProof, SectorNumber}; + use primitives::{proofs::RegisteredSealProof, sector::SectorNumber}; use super::{ProofScheme, PublicInputs, Tau}; diff --git a/pallets/proofs/src/post/config.rs b/pallets/proofs/src/post/config.rs index 5e082336c..e61e09c84 100644 --- a/pallets/proofs/src/post/config.rs +++ b/pallets/proofs/src/post/config.rs @@ -1,4 +1,4 @@ -use primitives_proofs::RegisteredPoStProof; +use primitives::proofs::RegisteredPoStProof; pub struct Config { /// Size of the sector in bytes. diff --git a/pallets/proofs/src/post/mod.rs b/pallets/proofs/src/post/mod.rs index 99b274ab4..22107ebb3 100644 --- a/pallets/proofs/src/post/mod.rs +++ b/pallets/proofs/src/post/mod.rs @@ -3,10 +3,11 @@ mod config; use config::Config; use frame_support::{pallet_prelude::*, sp_runtime::BoundedBTreeMap}; use polka_storage_proofs::get_partitions_for_window_post; -use primitives_commitment::NODE_SIZE; -use primitives_proofs::{ - PublicReplicaInfo, RawCommitment, RegisteredPoStProof, SectorNumber, Ticket, - MAX_SECTORS_PER_PROOF, +use primitives::{ + commitment::RawCommitment, + proofs::{PublicReplicaInfo, RegisteredPoStProof, Ticket}, + sector::SectorNumber, + MAX_SECTORS_PER_PROOF, NODE_SIZE, }; use sha2::{Digest, Sha256}; diff --git a/pallets/proofs/src/tests/porep.rs b/pallets/proofs/src/tests/porep.rs index dddb512ec..9353c07d7 100644 --- a/pallets/proofs/src/tests/porep.rs +++ b/pallets/proofs/src/tests/porep.rs @@ -2,8 +2,11 @@ use codec::{Decode, Encode}; use frame_support::{assert_noop, assert_ok}; use hex::FromHex; use polka_storage_proofs::{Bls12, VerifyingKey}; -use primitives_proofs::{ - ProofVerification, ProverId, RawCommitment, RegisteredSealProof, SectorNumber, Ticket, +use primitives::{ + commitment::RawCommitment, + pallets::ProofVerification, + proofs::{ProverId, RegisteredSealProof, Ticket}, + sector::SectorNumber, }; use rand::SeedableRng; use rand_xorshift::XorShiftRng; diff --git a/pallets/proofs/src/tests/post.rs b/pallets/proofs/src/tests/post.rs index 5e160e1ce..9d10095cf 100644 --- a/pallets/proofs/src/tests/post.rs +++ b/pallets/proofs/src/tests/post.rs @@ -2,8 +2,11 @@ use codec::{Decode, Encode}; use frame_support::{assert_noop, assert_ok}; use hex::FromHex; use polka_storage_proofs::{Bls12, VerifyingKey}; -use primitives_proofs::{ - ProofVerification, PublicReplicaInfo, RawCommitment, RegisteredPoStProof, SectorNumber, Ticket, +use primitives::{ + commitment::RawCommitment, + pallets::ProofVerification, + proofs::{PublicReplicaInfo, RegisteredPoStProof, Ticket}, + sector::SectorNumber, }; use rand::SeedableRng; use rand_xorshift::XorShiftRng; diff --git a/pallets/randomness/Cargo.toml b/pallets/randomness/Cargo.toml index 66e9a4320..db96c5585 100644 --- a/pallets/randomness/Cargo.toml +++ b/pallets/randomness/Cargo.toml @@ -22,7 +22,7 @@ frame-support.workspace = true frame-system.workspace = true log = { workspace = true } pallet-insecure-randomness-collective-flip = { workspace = true, default-features = false } -primitives-proofs = { workspace = true } +primitives = { workspace = true } scale-info = { features = ["derive"], workspace = true } sp-core = { workspace = true, default-features = false } sp-runtime.workspace = true @@ -38,5 +38,5 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] -std = ["codec/std", "frame-benchmarking?/std", "frame-support/std", "frame-system/std", "scale-info/std", "sp-runtime/std"] +std = ["codec/std", "frame-benchmarking?/std", "frame-support/std", "frame-system/std", "primitives/std", "scale-info/std", "sp-runtime/std"] try-runtime = ["frame-support/try-runtime", "frame-system/try-runtime", "sp-runtime/try-runtime"] diff --git a/pallets/randomness/src/lib.rs b/pallets/randomness/src/lib.rs index cc02fff7d..b81a26133 100644 --- a/pallets/randomness/src/lib.rs +++ b/pallets/randomness/src/lib.rs @@ -18,7 +18,7 @@ pub mod pallet { use frame_support::{pallet_prelude::*, traits::Randomness as SubstrateRandomness}; use frame_system::pallet_prelude::*; - use primitives_proofs::Randomness; + use primitives::pallets::Randomness; use sp_runtime::{traits::Zero, Saturating}; pub const LOG_TARGET: &'static str = "runtime::randomness"; diff --git a/pallets/randomness/src/tests.rs b/pallets/randomness/src/tests.rs index 94519deaf..dbb6d4eb5 100644 --- a/pallets/randomness/src/tests.rs +++ b/pallets/randomness/src/tests.rs @@ -1,5 +1,5 @@ use frame_support::{assert_err, assert_ok}; -use primitives_proofs::Randomness; +use primitives::pallets::Randomness; use crate::{ mock::{new_test_ext, run_to_block, BlockNumber, RandomnessModule, SeedAgeLimit, Test}, diff --git a/pallets/storage-provider/Cargo.toml b/pallets/storage-provider/Cargo.toml index e55088d8a..56dea3bff 100644 --- a/pallets/storage-provider/Cargo.toml +++ b/pallets/storage-provider/Cargo.toml @@ -22,8 +22,7 @@ log = { workspace = true, features = ["kv"] } pallet-insecure-randomness-collective-flip = { workspace = true, default-features = false } pallet-proofs = { workspace = true, default-features = false } pallet-randomness = { workspace = true, default-features = false } -primitives-commitment = { workspace = true } -primitives-proofs = { workspace = true, default-features = false } +primitives = { workspace = true, default-features = false } scale-info = { workspace = true, default-features = false, features = ["derive"] } sp-arithmetic = { workspace = true, default-features = false } sp-core = { workspace = true, default-features = false } @@ -57,7 +56,7 @@ std = [ "frame-support/std", "frame-system/std", "pallet-balances/std", - "primitives-proofs/std", + "primitives/std", "scale-info/std", "sp-core/std", "sp-io/std", diff --git a/pallets/storage-provider/src/deadline.rs b/pallets/storage-provider/src/deadline.rs index ffb51e9c5..bff55ad58 100644 --- a/pallets/storage-provider/src/deadline.rs +++ b/pallets/storage-provider/src/deadline.rs @@ -4,7 +4,7 @@ use alloc::{collections::BTreeSet, vec::Vec}; use codec::{Decode, Encode}; use frame_support::{pallet_prelude::*, sp_runtime::BoundedBTreeMap}; -use primitives_proofs::SectorNumber; +use primitives::sector::SectorNumber; use scale_info::{prelude::cmp, TypeInfo}; use crate::{ @@ -791,7 +791,7 @@ mod tests { use alloc::collections::{BTreeMap, BTreeSet}; use frame_support::{pallet_prelude::*, sp_runtime::BoundedBTreeSet}; - use primitives_proofs::{SectorNumber, MAX_SECTORS, MAX_TERMINATIONS_PER_CALL}; + use primitives::{sector::SectorNumber, MAX_SECTORS, MAX_TERMINATIONS_PER_CALL}; use rstest::rstest; use crate::{ diff --git a/pallets/storage-provider/src/deadline/assignment.rs b/pallets/storage-provider/src/deadline/assignment.rs index 768f88460..614b68954 100644 --- a/pallets/storage-provider/src/deadline/assignment.rs +++ b/pallets/storage-provider/src/deadline/assignment.rs @@ -228,7 +228,7 @@ where #[cfg(test)] mod tests { use frame_support::BoundedVec; - use primitives_proofs::{RegisteredSealProof, SectorNumber}; + use primitives::{proofs::RegisteredSealProof, sector::SectorNumber}; use crate::{ deadline::{assign_deadlines, Deadline}, diff --git a/pallets/storage-provider/src/expiration_queue.rs b/pallets/storage-provider/src/expiration_queue.rs index f2b7b8c4d..4b2a100bf 100644 --- a/pallets/storage-provider/src/expiration_queue.rs +++ b/pallets/storage-provider/src/expiration_queue.rs @@ -6,7 +6,7 @@ use alloc::{ use core::ops::Not; use codec::{Decode, Encode}; -use primitives_proofs::SectorNumber; +use primitives::sector::SectorNumber; use scale_info::TypeInfo; use sp_core::{ConstU32, RuntimeDebug}; use sp_runtime::{BoundedBTreeMap, BoundedBTreeSet}; @@ -549,7 +549,7 @@ struct SectorExpirationSet { mod tests { extern crate alloc; - use primitives_proofs::{SectorNumber, MAX_SECTORS}; + use primitives::{sector::SectorNumber, MAX_SECTORS}; use crate::{expiration_queue::ExpirationQueue, sector::SectorOnChainInfo, tests::sector_set}; diff --git a/pallets/storage-provider/src/fault.rs b/pallets/storage-provider/src/fault.rs index fabad8fb1..8ccaff859 100644 --- a/pallets/storage-provider/src/fault.rs +++ b/pallets/storage-provider/src/fault.rs @@ -1,5 +1,5 @@ use frame_support::{pallet_prelude::*, sp_runtime::BoundedBTreeSet}; -use primitives_proofs::{SectorNumber, MAX_TERMINATIONS_PER_CALL}; +use primitives::{sector::SectorNumber, MAX_TERMINATIONS_PER_CALL}; use crate::{pallet::DECLARATIONS_MAX, partition::PartitionNumber}; diff --git a/pallets/storage-provider/src/lib.rs b/pallets/storage-provider/src/lib.rs index 783cc8a05..f749f0ec6 100644 --- a/pallets/storage-provider/src/lib.rs +++ b/pallets/storage-provider/src/lib.rs @@ -55,12 +55,15 @@ pub mod pallet { pallet_prelude::{BlockNumberFor, *}, Config as SystemConfig, }; - use primitives_commitment::{CommD, CommR, Commitment}; - use primitives_proofs::{ - derive_prover_id, + use primitives::{ + commitment::{CommD, CommR, Commitment}, + pallets::{ + CurrentDeadline, Market, ProofVerification, Randomness, StorageProviderValidation, + }, + proofs::{derive_prover_id, PublicReplicaInfo, RegisteredPoStProof}, randomness::{draw_randomness, DomainSeparationTag}, - Market, ProofVerification, PublicReplicaInfo, Randomness, RegisteredPoStProof, - SectorNumber, StorageProviderValidation, MAX_SEAL_PROOF_BYTES, MAX_SECTORS_PER_CALL, + sector::SectorNumber, + MAX_SEAL_PROOF_BYTES, MAX_SECTORS_PER_CALL, }; use scale_info::TypeInfo; use sp_arithmetic::traits::Zero; @@ -690,8 +693,7 @@ pub mod pallet { ); ensure!( - windowed_post.proof.proof_bytes.len() - <= primitives_proofs::MAX_POST_PROOF_BYTES as usize, + windowed_post.proof.proof_bytes.len() <= primitives::MAX_POST_PROOF_BYTES as usize, { log::error!("submit_window_post: invalid proof size"); Error::::PoStProofInvalid @@ -1073,7 +1075,7 @@ pub mod pallet { /// conversion between BlockNumbers fails, but technically should not ever happen. pub fn current_deadline( storage_provider: &T::AccountId, - ) -> Option>> { + ) -> Option>> { let sp = StorageProviders::::try_get(storage_provider).ok()?; let current_block = >::block_number(); @@ -1088,7 +1090,7 @@ pub mod pallet { ) .ok()?; - Some(primitives_proofs::CurrentDeadline { + Some(CurrentDeadline { deadline_index: deadline.idx, open: deadline.is_open(), challenge_block: deadline.challenge, diff --git a/pallets/storage-provider/src/partition.rs b/pallets/storage-provider/src/partition.rs index 9e7dfc939..853716cf7 100644 --- a/pallets/storage-provider/src/partition.rs +++ b/pallets/storage-provider/src/partition.rs @@ -8,7 +8,7 @@ use core::ops::AddAssign; use codec::{Decode, Encode}; use frame_support::{pallet_prelude::*, sp_runtime::BoundedBTreeSet}; -use primitives_proofs::SectorNumber; +use primitives::sector::SectorNumber; use scale_info::TypeInfo; use crate::{ diff --git a/pallets/storage-provider/src/proofs.rs b/pallets/storage-provider/src/proofs.rs index 931a9091a..22108cacd 100644 --- a/pallets/storage-provider/src/proofs.rs +++ b/pallets/storage-provider/src/proofs.rs @@ -3,7 +3,7 @@ use frame_support::{ pallet_prelude::{ConstU32, RuntimeDebug}, sp_runtime::BoundedVec, }; -use primitives_proofs::{RegisteredPoStProof, MAX_POST_PROOF_BYTES}; +use primitives::{proofs::RegisteredPoStProof, MAX_POST_PROOF_BYTES}; use scale_info::TypeInfo; use sp_core::blake2_64; diff --git a/pallets/storage-provider/src/sector.rs b/pallets/storage-provider/src/sector.rs index f8206cac2..8bf94ee25 100644 --- a/pallets/storage-provider/src/sector.rs +++ b/pallets/storage-provider/src/sector.rs @@ -1,8 +1,8 @@ use codec::{Decode, Encode}; use frame_support::{pallet_prelude::*, BoundedVec}; -use primitives_proofs::{ - DealId, RegisteredSealProof, SectorDeal, SectorNumber, CID_SIZE_IN_BYTES, MAX_DEALS_PER_SECTOR, - MAX_SEAL_PROOF_BYTES, MAX_TERMINATIONS_PER_CALL, +use primitives::{ + pallets::SectorDeal, proofs::RegisteredSealProof, sector::SectorNumber, DealId, + CID_SIZE_IN_BYTES, MAX_DEALS_PER_SECTOR, MAX_SEAL_PROOF_BYTES, MAX_TERMINATIONS_PER_CALL, }; use scale_info::TypeInfo; diff --git a/pallets/storage-provider/src/sector_map.rs b/pallets/storage-provider/src/sector_map.rs index acb7b1414..a75a4ba87 100644 --- a/pallets/storage-provider/src/sector_map.rs +++ b/pallets/storage-provider/src/sector_map.rs @@ -3,7 +3,7 @@ //! The [`DeadlineMap`] structure contains a `BTreeMap` that map a `PartitionMap` to a deadline. use codec::{Decode, Encode}; use frame_support::{pallet_prelude::*, sp_runtime::BoundedBTreeMap}; -use primitives_proofs::{SectorNumber, MAX_TERMINATIONS_PER_CALL}; +use primitives::{sector::SectorNumber, MAX_TERMINATIONS_PER_CALL}; use scale_info::TypeInfo; use crate::{error::GeneralPalletError, partition::PartitionNumber, sector::MAX_SECTORS}; diff --git a/pallets/storage-provider/src/storage_provider.rs b/pallets/storage-provider/src/storage_provider.rs index 183e883c0..2579b5ddc 100644 --- a/pallets/storage-provider/src/storage_provider.rs +++ b/pallets/storage-provider/src/storage_provider.rs @@ -7,7 +7,10 @@ use frame_support::{ pallet_prelude::{ConstU32, RuntimeDebug}, sp_runtime::{BoundedBTreeMap, BoundedVec}, }; -use primitives_proofs::{RegisteredPoStProof, SectorNumber, SectorSize}; +use primitives::{ + proofs::RegisteredPoStProof, + sector::{SectorNumber, SectorSize}, +}; use scale_info::TypeInfo; use sp_arithmetic::{traits::BaseArithmetic, ArithmeticError}; diff --git a/pallets/storage-provider/src/tests/declare_faults.rs b/pallets/storage-provider/src/tests/declare_faults.rs index 886b39ce0..173b2db48 100644 --- a/pallets/storage-provider/src/tests/declare_faults.rs +++ b/pallets/storage-provider/src/tests/declare_faults.rs @@ -1,5 +1,5 @@ use frame_support::{assert_err, assert_noop, assert_ok, pallet_prelude::*}; -use primitives_proofs::SectorNumber; +use primitives::sector::SectorNumber; use rstest::rstest; use sp_core::bounded_vec; use sp_runtime::{traits::BlockNumberProvider, BoundedVec}; diff --git a/pallets/storage-provider/src/tests/expiration_queue.rs b/pallets/storage-provider/src/tests/expiration_queue.rs index 9fa6ac3ba..c71f438ca 100644 --- a/pallets/storage-provider/src/tests/expiration_queue.rs +++ b/pallets/storage-provider/src/tests/expiration_queue.rs @@ -1,7 +1,7 @@ extern crate alloc; use alloc::collections::{BTreeMap, BTreeSet}; -use primitives_proofs::{RegisteredSealProof, SectorNumber}; +use primitives::{proofs::RegisteredSealProof, sector::SectorNumber}; use sp_runtime::{BoundedBTreeMap, BoundedBTreeSet}; use super::BlockNumber; diff --git a/pallets/storage-provider/src/tests/mod.rs b/pallets/storage-provider/src/tests/mod.rs index 4e566b19d..ef04b59c7 100644 --- a/pallets/storage-provider/src/tests/mod.rs +++ b/pallets/storage-provider/src/tests/mod.rs @@ -14,11 +14,13 @@ use frame_support::{ }; use frame_system::pallet_prelude::BlockNumberFor; use pallet_market::{BalanceOf, ClientDealProposal, DealProposal, DealState}; -use primitives_commitment::{CommP, Commitment}; -use primitives_proofs::{ - DealId, ProofVerification, PublicReplicaInfo, Randomness, RegisteredPoStProof, - RegisteredSealProof, SectorNumber, CID_SIZE_IN_BYTES, MAX_DEALS_PER_SECTOR, - MAX_POST_PROOF_BYTES, MAX_SEAL_PROOF_BYTES, MAX_SECTORS_PER_PROOF, MAX_TERMINATIONS_PER_CALL, +use primitives::{ + commitment::{CommP, Commitment, RawCommitment}, + pallets::{ProofVerification, Randomness}, + proofs::{ProverId, PublicReplicaInfo, RegisteredPoStProof, RegisteredSealProof, Ticket}, + sector::SectorNumber, + DealId, CID_SIZE_IN_BYTES, MAX_DEALS_PER_SECTOR, MAX_POST_PROOF_BYTES, MAX_SEAL_PROOF_BYTES, + MAX_SECTORS_PER_PROOF, MAX_TERMINATIONS_PER_CALL, }; use sp_core::{bounded_vec, Pair}; use sp_runtime::{ @@ -86,13 +88,13 @@ pub const INVALID_PROOF: [u8; 2] = [0xd, 0xe]; pub struct DummyProofsVerification; impl ProofVerification for DummyProofsVerification { fn verify_porep( - _prover_id: primitives_proofs::ProverId, + _prover_id: ProverId, _seal_proof: RegisteredSealProof, - _comm_r: primitives_proofs::RawCommitment, - _comm_d: primitives_proofs::RawCommitment, + _comm_r: RawCommitment, + _comm_d: RawCommitment, _sector: SectorNumber, - _ticket: primitives_proofs::Ticket, - _seed: primitives_proofs::Ticket, + _ticket: Ticket, + _seed: Ticket, _proof: BoundedVec>, ) -> sp_runtime::DispatchResult { Ok(()) @@ -100,7 +102,7 @@ impl ProofVerification for DummyProofsVerification { fn verify_post( _post_type: RegisteredPoStProof, - _randomness: primitives_proofs::Ticket, + _randomness: Ticket, _replicas: BoundedBTreeMap< SectorNumber, PublicReplicaInfo, diff --git a/pallets/storage-provider/src/tests/post_hook.rs b/pallets/storage-provider/src/tests/post_hook.rs index b300b7af6..5250a316a 100644 --- a/pallets/storage-provider/src/tests/post_hook.rs +++ b/pallets/storage-provider/src/tests/post_hook.rs @@ -1,5 +1,5 @@ use frame_support::{assert_ok, pallet_prelude::Get}; -use primitives_proofs::{DealId, SectorNumber}; +use primitives::{sector::SectorNumber, DealId}; use sp_core::bounded_vec; use sp_runtime::{BoundedBTreeMap, BoundedBTreeSet}; diff --git a/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs b/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs index e5e0d1e74..5f10f1b57 100644 --- a/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs +++ b/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs @@ -1,4 +1,4 @@ -use primitives_proofs::SectorNumber; +use primitives::sector::SectorNumber; use sp_core::bounded_vec; use sp_runtime::{BoundedBTreeMap, BoundedBTreeSet}; diff --git a/pallets/storage-provider/src/tests/pre_commit_sectors.rs b/pallets/storage-provider/src/tests/pre_commit_sectors.rs index 43dbffaee..94860a625 100644 --- a/pallets/storage-provider/src/tests/pre_commit_sectors.rs +++ b/pallets/storage-provider/src/tests/pre_commit_sectors.rs @@ -1,6 +1,6 @@ use frame_support::{assert_noop, assert_ok, pallet_prelude::*}; use frame_system::pallet_prelude::BlockNumberFor; -use primitives_proofs::MAX_SECTORS_PER_CALL; +use primitives::MAX_SECTORS_PER_CALL; use sp_core::bounded_vec; use sp_runtime::{BoundedVec, DispatchError}; diff --git a/pallets/storage-provider/src/tests/prove_commit_sectors.rs b/pallets/storage-provider/src/tests/prove_commit_sectors.rs index a95ade776..234bee3f9 100644 --- a/pallets/storage-provider/src/tests/prove_commit_sectors.rs +++ b/pallets/storage-provider/src/tests/prove_commit_sectors.rs @@ -1,6 +1,6 @@ use frame_support::{assert_noop, assert_ok, pallet_prelude::*}; use frame_system::pallet_prelude::BlockNumberFor; -use primitives_proofs::MAX_SECTORS_PER_CALL; +use primitives::MAX_SECTORS_PER_CALL; use sp_core::bounded_vec; use super::{new_test_ext, MaxProveCommitDuration}; diff --git a/pallets/storage-provider/src/tests/storage_provider_registration.rs b/pallets/storage-provider/src/tests/storage_provider_registration.rs index a8c5be613..4b0aee422 100644 --- a/pallets/storage-provider/src/tests/storage_provider_registration.rs +++ b/pallets/storage-provider/src/tests/storage_provider_registration.rs @@ -1,5 +1,5 @@ use frame_support::{assert_noop, assert_ok}; -use primitives_proofs::RegisteredPoStProof; +use primitives::proofs::RegisteredPoStProof; use sp_runtime::{BoundedVec, DispatchError}; use super::new_test_ext; diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml new file mode 100644 index 000000000..b5012ecab --- /dev/null +++ b/primitives/Cargo.toml @@ -0,0 +1,51 @@ +[package] +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license-file.workspace = true +name = "primitives" +repository.workspace = true +version = "0.1.0" + +[dependencies] +cid = { workspace = true } +clap = { workspace = true, features = ["derive"], optional = true } +codec = { workspace = true, features = ["derive"] } +filecoin-proofs = { workspace = true, optional = true } +scale-decode = { workspace = true, features = ["derive"] } +scale-encode = { workspace = true, features = ["derive"] } +scale-info = { workspace = true, features = ["derive"] } +sealed = { workspace = true } +serde = { workspace = true, optional = true, features = ["derive"] } +sha2 = { workspace = true } +sp-api = { workspace = true } +sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } +thiserror = { workspace = true } + +[dev-dependencies] +rand = { workspace = true, default-features = true } +serde_json = { workspace = true, default-features = true } + +[lints] +workspace = true + +[features] +clap = ["dep:clap", "std"] +default = [] +serde = ["dep:serde"] +std = [ + "cid/scale-codec", + "cid/std", + "codec/std", + "dep:filecoin-proofs", + "scale-info/std", + "serde/std", + "sha2/std", + "sp-api/std", + "sp-core/std", + "sp-runtime/std", + "sp-std/std", + "thiserror/std", +] diff --git a/primitives/commitment/Cargo.toml b/primitives/commitment/Cargo.toml deleted file mode 100644 index 675a57a6a..000000000 --- a/primitives/commitment/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -authors.workspace = true -edition.workspace = true -homepage.workspace = true -license-file.workspace = true -name = "primitives-commitment" -repository.workspace = true -version = "0.1.0" - -[features] -serde = ["dep:serde"] -std = ["dep:filecoin-proofs"] - -[dependencies] -cid.workspace = true -codec = { workspace = true, default-features = false, features = ["derive"] } -filecoin-proofs = { optional = true, workspace = true } -primitives-proofs.workspace = true -scale-info = { workspace = true, default-features = false, features = ["derive"] } -sealed.workspace = true -serde = { workspace = true, features = ["derive"], optional = true } -sha2.workspace = true -thiserror.workspace = true - -[dev-dependencies] -rand = { workspace = true, features = ["std", "std_rng"] } - -[lints] -workspace = true diff --git a/primitives/proofs/Cargo.toml b/primitives/proofs/Cargo.toml deleted file mode 100644 index 9a29c2962..000000000 --- a/primitives/proofs/Cargo.toml +++ /dev/null @@ -1,35 +0,0 @@ -[package] -authors.workspace = true -edition.workspace = true -homepage.workspace = true -license-file.workspace = true -name = "primitives-proofs" -repository.workspace = true -version = "0.1.0" - -[dependencies] -cid = { workspace = true, default-features = false, features = ["alloc"] } -codec = { workspace = true, default-features = false, features = ["derive"] } -scale-decode = { workspace = true, default-features = false, features = ["derive"] } -scale-encode = { workspace = true, default-features = false, features = ["derive"] } -scale-info = { workspace = true, default-features = false, features = ["derive"] } - -sp-api = { workspace = true, default-features = false } -sp-core = { workspace = true, default-features = false } -sp-runtime = { workspace = true, default-features = false } -sp-std = { workspace = true, default-features = false } -thiserror = { workspace = true, default-features = false } - -clap = { workspace = true, features = ["derive"], optional = true } -serde = { workspace = true, features = ["derive"], optional = true } - -[dev-dependencies] -serde_json = { workspace = true, default-features = true } - -[lints] -workspace = true - -[features] -clap = ["dep:clap", "std"] -default = ["std"] -std = ["cid/scale-codec", "codec/std", "scale-info/std", "sp-api/std", "sp-core/std", "sp-runtime/std", "sp-std/std"] diff --git a/primitives/proofs/src/lib.rs b/primitives/proofs/src/lib.rs deleted file mode 100644 index b9af60136..000000000 --- a/primitives/proofs/src/lib.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -pub mod randomness; -mod traits; -mod types; - -use codec::{Codec, Decode, Encode}; -use scale_info::TypeInfo; -pub use traits::*; -pub use types::*; - -/// Derives a unique prover ID for a given account. -/// -/// The function takes an `AccountId` and generates a 32-byte array that serves -/// as a unique identifier for the prover associated with that account. The -/// prover ID is derived using the Blake2 hash of the encoded account ID. -pub fn derive_prover_id(account_id: AccountId) -> [u8; 32] -where - AccountId: Encode, -{ - let encoded = account_id.encode(); - let mut encoded = sp_core::blake2_256(&encoded); - // Necessary to be valid bls12 381 element. - encoded[31] &= 0x3f; - encoded -} - -/// Current deadline in a proving period of a Storage Provider. -#[derive(Encode, Decode, TypeInfo)] -pub struct CurrentDeadline { - /// Index of a deadline. - /// - /// If there are 10 deadlines if the proving period, values will be [0, 9]. - /// After proving period rolls over, it'll start from 0 again. - pub deadline_index: u64, - /// Whether the deadline is open. - /// Only is false when `current_block < sp.proving_period_start`. - pub open: bool, - /// [`pallet_storage_provider::DeadlineInfo::challenge`]. - /// - /// Block at which the randomness should be fetched to generate/verify Post. - pub challenge_block: BlockNumber, - /// Block at which the deadline opens. - pub start: BlockNumber, -} - -sp_api::decl_runtime_apis! { - pub trait StorageProviderApi where AccountId: Codec - { - /// Gets the current deadline of the storage provider. - /// - /// If there is no Storage Provider of given AccountId returns [`Option::None`]. - /// May exceptionally return [`Option::None`] when - /// conversion between BlockNumbers fails, but technically should not ever happen. - fn current_deadline(storage_provider: AccountId) -> Option< - CurrentDeadline< - <::Header as sp_runtime::traits::Header>::Number - > - >; - } -} diff --git a/primitives/commitment/src/commd.rs b/primitives/src/commitment/commd.rs similarity index 98% rename from primitives/commitment/src/commd.rs rename to primitives/src/commitment/commd.rs index 410dfe48a..a0f62cba7 100644 --- a/primitives/commitment/src/commd.rs +++ b/primitives/src/commitment/commd.rs @@ -2,13 +2,13 @@ extern crate alloc; use alloc::vec::Vec; use core::{fmt::write, ops::Deref}; -use primitives_proofs::SectorSize; use sha2::{Digest, Sha256}; -use crate::{ +use super::{ piece::{PaddedPieceSize, PieceInfo, UnpaddedPieceSize}, - CommD, CommP, Commitment, NODE_SIZE, + CommD, CommP, Commitment, }; +use crate::{sector::SectorSize, NODE_SIZE}; // Ensure that the pieces are correct sizes fn ensure_piece_sizes( @@ -249,9 +249,9 @@ mod tests { use core::str::FromStr; use cid::Cid; - use primitives_proofs::SectorSize; use super::*; + use crate::sector::SectorSize; #[test] fn test_compute_comm_d_empty() { diff --git a/primitives/commitment/src/lib.rs b/primitives/src/commitment/mod.rs similarity index 93% rename from primitives/commitment/src/lib.rs rename to primitives/src/commitment/mod.rs index 096c32fb6..c4b7b01bc 100644 --- a/primitives/commitment/src/lib.rs +++ b/primitives/src/commitment/mod.rs @@ -1,5 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] // no_std by default, requires "std" for std-support - pub mod commd; pub mod piece; mod zero; @@ -8,14 +6,11 @@ use core::{fmt::Display, marker::PhantomData}; use cid::{multihash::Multihash, Cid}; use codec::{Decode, Encode}; -use primitives_proofs::RegisteredSealProof; +use piece::PaddedPieceSize; use scale_info::TypeInfo; use sealed::sealed; -use crate::piece::PaddedPieceSize; - -/// Merkle tree node size in bytes. -pub const NODE_SIZE: usize = 32; +use crate::proofs::RegisteredSealProof; /// Filecoin piece or sector data commitment merkle node/root (CommP & CommD) /// @@ -39,6 +34,9 @@ pub const SHA2_256_TRUNC254_PADDED: u64 = 0x1012; /// https://github.com/multiformats/multicodec/blob/badcfe56bb7e0bbb06b60d57565186cd6be1f932/table.csv#L537 pub const POSEIDON_BLS12_381_A1_FC1: u64 = 0xb401; +/// Byte representation of a raw commitment. +pub type RawCommitment = [u8; 32]; + #[sealed] pub trait CommitmentKind { /// Returns the [Multicodec](https://github.com/multiformats/multicodec/blob/master/table.csv) code for the commitment kind. @@ -115,7 +113,7 @@ pub struct Commitment where Kind: CommitmentKind, { - raw: [u8; 32], + raw: RawCommitment, kind: PhantomData, } @@ -153,7 +151,7 @@ where } /// Returns the raw commitment bytes. - pub fn raw(&self) -> [u8; 32] { + pub fn raw(&self) -> RawCommitment { self.raw } @@ -187,11 +185,11 @@ where } } -impl From<[u8; 32]> for Commitment +impl From for Commitment where Kind: CommitmentKind, { - fn from(value: [u8; 32]) -> Self { + fn from(value: RawCommitment) -> Self { Self { raw: value, kind: PhantomData, @@ -224,18 +222,19 @@ mod tests { use cid::{multihash::Multihash, Cid}; - use crate::{ + use super::RawCommitment; + use crate::commitment::{ CommD, CommP, CommR, Commitment, FIL_COMMITMENT_SEALED, FIL_COMMITMENT_UNSEALED, POSEIDON_BLS12_381_A1_FC1, SHA2_256_TRUNC254_PADDED, }; - fn rand_comm() -> [u8; 32] { + fn rand_raw_comm() -> RawCommitment { rand::random::<[u8; 32]>() } #[test] fn comm_d_to_cid() { - let raw = rand_comm(); + let raw = rand_raw_comm(); let cid = Commitment::::from(raw).cid(); assert_eq!(cid.codec(), FIL_COMMITMENT_UNSEALED); @@ -245,7 +244,7 @@ mod tests { #[test] fn cid_to_comm_d() { - let raw = rand_comm(); + let raw = rand_raw_comm(); // Correct hash format let mh = Multihash::wrap(SHA2_256_TRUNC254_PADDED, &raw).unwrap(); @@ -267,7 +266,7 @@ mod tests { #[test] fn comm_r_to_cid() { - let comm = rand_comm(); + let comm = rand_raw_comm(); let cid = Commitment::::from(comm).cid(); assert_eq!(cid.codec(), FIL_COMMITMENT_SEALED); @@ -277,7 +276,7 @@ mod tests { #[test] fn cid_to_comm_r() { - let comm = rand_comm(); + let comm = rand_raw_comm(); // Correct hash format let mh = Multihash::wrap(POSEIDON_BLS12_381_A1_FC1, &comm).unwrap(); @@ -299,7 +298,7 @@ mod tests { #[test] fn symmetric_conversion() { - let raw = rand_comm(); + let raw = rand_raw_comm(); // piece let cid = Commitment::::from(raw).cid(); diff --git a/primitives/commitment/src/piece.rs b/primitives/src/commitment/piece.rs similarity index 99% rename from primitives/commitment/src/piece.rs rename to primitives/src/commitment/piece.rs index f4c9b4a95..76b21fee1 100644 --- a/primitives/commitment/src/piece.rs +++ b/primitives/src/commitment/piece.rs @@ -3,7 +3,8 @@ use core::ops::{Add, AddAssign, Deref}; use codec::{Decode, Encode}; use scale_info::TypeInfo; -use crate::{CommP, Commitment, NODE_SIZE}; +use super::{CommP, Commitment}; +use crate::NODE_SIZE; /// Piece info contains piece commitment and piece size. #[cfg_attr(feature = "serde", derive(::serde::Deserialize, ::serde::Serialize))] diff --git a/primitives/commitment/src/zero.rs b/primitives/src/commitment/zero.rs similarity index 99% rename from primitives/commitment/src/zero.rs rename to primitives/src/commitment/zero.rs index f145c06ec..2be322c44 100644 --- a/primitives/commitment/src/zero.rs +++ b/primitives/src/commitment/zero.rs @@ -1,4 +1,4 @@ -use crate::piece::PaddedPieceSize; +use super::piece::PaddedPieceSize; /// Can't generate for: 1, 2, 4, 8, 16, 32, 64 bytes const SKIP: u32 = 7; diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs new file mode 100644 index 000000000..aa5a97b91 --- /dev/null +++ b/primitives/src/lib.rs @@ -0,0 +1,61 @@ +#![cfg_attr(not(feature = "std"), no_std)] // no_std by default, requires "std" for std-support + +pub mod commitment; +pub mod pallets; +pub mod proofs; +pub mod randomness; +pub mod sector; + +pub type DealId = u64; + +/// Merkle tree node size in bytes. +pub const NODE_SIZE: usize = 32; + +/// Max number of sectors. +/// +pub const MAX_SECTORS: u32 = 32 << 20; + +/// Size of a CID with a 512-bit multihash — i.e. the size of CommR/CommD/CommP +pub const CID_SIZE_IN_BYTES: u32 = 64; + +/// Number of Sectors that can be provided in a single extrinsics call. +/// Required for BoundedVec. +/// It was selected arbitrarly, without precise calculations. +pub const MAX_SECTORS_PER_CALL: u32 = 32; + +/// Number of Deals that can be contained in a single sector. +/// Required for BoundedVec. +/// It was selected arbitrarly, without precise calculations. + +pub const MAX_DEALS_PER_SECTOR: u32 = 128; + +/// Flattened size of all active deals for all of the sectors. +/// Required for BoundedVec. +pub const MAX_DEALS_FOR_ALL_SECTORS: u32 = MAX_SECTORS_PER_CALL * MAX_DEALS_PER_SECTOR; + +/// The maximum number of terminations for a single extrinsic call. +pub const MAX_TERMINATIONS_PER_CALL: u32 = 32; // TODO(@jmg-duarte,25/07/2024): change for a better value + +/// The maximum amount of sectors allowed in proofs and replicas. +/// This value is the absolute max, when the sector size is 32 GiB. +/// Proofs and replicas are still dynamically checked for their size depending on the sector size. +/// +/// References: +/// * Filecoin docs about PoSt: +pub const MAX_SECTORS_PER_PROOF: u32 = 2349; + +/// The absolute maximum length, in bytes, a seal proof should be for the largest sector size. +/// NOTE: Taken the value from `StackedDRG32GiBV1`, +/// which is not the biggest seal proof type but we do not plan on supporting non-interactive proof types at this time. +/// +/// References: +/// * +pub const MAX_SEAL_PROOF_BYTES: u32 = 1_920; + +/// The fixed length, in bytes, of a PoSt proof. +/// This value is the same as `PROOF_BYTES` in the `polka-storage-proofs` library. +/// It is redefined to avoid import the whole library for 1 constant. +/// +/// References: +/// * +pub const MAX_POST_PROOF_BYTES: u32 = 192; diff --git a/primitives/proofs/src/traits.rs b/primitives/src/pallets.rs similarity index 65% rename from primitives/proofs/src/traits.rs rename to primitives/src/pallets.rs index 9f37a4a7f..6646a29ce 100644 --- a/primitives/proofs/src/traits.rs +++ b/primitives/src/pallets.rs @@ -1,54 +1,47 @@ -extern crate alloc; - use cid::Cid; -use sp_core::ConstU32; -use sp_runtime::{BoundedBTreeMap, BoundedVec, DispatchError, DispatchResult, RuntimeDebug}; - -use crate::types::{ - DealId, ProverId, RawCommitment, RegisteredPoStProof, RegisteredSealProof, SectorNumber, Ticket, +use codec::{Codec, Decode, Encode}; +use scale_info::TypeInfo; +use sp_core::{ConstU32, RuntimeDebug}; +use sp_runtime::{BoundedBTreeMap, BoundedVec, DispatchError, DispatchResult}; + +use crate::{ + commitment::RawCommitment, + proofs::{ProverId, PublicReplicaInfo, RegisteredPoStProof, RegisteredSealProof, Ticket}, + sector::SectorNumber, + DealId, MAX_DEALS_PER_SECTOR, MAX_POST_PROOF_BYTES, MAX_SEAL_PROOF_BYTES, MAX_SECTORS_PER_CALL, + MAX_SECTORS_PER_PROOF, }; -/// Size of a CID with a 512-bit multihash — i.e. the size of CommR/CommD/CommP -pub const CID_SIZE_IN_BYTES: u32 = 64; - -/// Number of Sectors that can be provided in a single extrinsics call. -/// Required for BoundedVec. -/// It was selected arbitrarly, without precise calculations. -pub const MAX_SECTORS_PER_CALL: u32 = 32; -/// Number of Deals that can be contained in a single sector. -/// Required for BoundedVec. -/// It was selected arbitrarly, without precise calculations. -pub const MAX_DEALS_PER_SECTOR: u32 = 128; -/// Flattened size of all active deals for all of the sectors. -/// Required for BoundedVec. -pub const MAX_DEALS_FOR_ALL_SECTORS: u32 = MAX_SECTORS_PER_CALL * MAX_DEALS_PER_SECTOR; - -/// The maximum number of terminations for a single extrinsic call. -pub const MAX_TERMINATIONS_PER_CALL: u32 = 32; // TODO(@jmg-duarte,25/07/2024): change for a better value +/// Represents functions that are provided by the Randomness Pallet +pub trait Randomness { + fn get_randomness(block_number: BlockNumber) -> Result<[u8; 32], DispatchError>; +} -/// The maximum amount of sectors allowed in proofs and replicas. -/// This value is the absolute max, when the sector size is 32 GiB. -/// Proofs and replicas are still dynamically checked for their size depending on the sector size. -/// -/// References: -/// * Filecoin docs about PoSt: -pub const MAX_SECTORS_PER_PROOF: u32 = 2349; +pub trait StorageProviderValidation { + /// Checks that the storage provider is registered. + fn is_registered_storage_provider(storage_provider: &AccountId) -> bool; +} -/// The absolute maximum length, in bytes, a seal proof should be for the largest sector size. -/// NOTE: Taken the value from `StackedDRG32GiBV1`, -/// which is not the biggest seal proof type but we do not plan on supporting non-interactive proof types at this time. -/// -/// References: -/// * -pub const MAX_SEAL_PROOF_BYTES: u32 = 1_920; +/// Entrypoint for proof verification implemented by Pallet Proofs. +pub trait ProofVerification { + fn verify_porep( + prover_id: ProverId, + seal_proof: RegisteredSealProof, + comm_r: RawCommitment, + comm_d: RawCommitment, + sector: SectorNumber, + ticket: Ticket, + seed: Ticket, + proof: BoundedVec>, + ) -> DispatchResult; -/// The fixed length, in bytes, of a PoSt proof. -/// This value is the same as `PROOF_BYTES` in the `polka-storage-proofs` library. -/// It is redefined to avoid import the whole library for 1 constant. -/// -/// References: -/// * -pub const MAX_POST_PROOF_BYTES: u32 = 192; + fn verify_post( + post_type: RegisteredPoStProof, + randomness: Ticket, + replicas: BoundedBTreeMap>, + proof: BoundedVec>, + ) -> DispatchResult; +} /// Represents functions that are provided by the Market Provider Pallet pub trait Market { @@ -85,45 +78,6 @@ pub trait Market { ) -> DispatchResult; } -pub trait StorageProviderValidation { - /// Checks that the storage provider is registered. - fn is_registered_storage_provider(storage_provider: &AccountId) -> bool; -} - -/// The minimal information required about a replica, in order to be able to verify -/// a PoSt over it. -#[derive(Clone, core::fmt::Debug, PartialEq, Eq)] -pub struct PublicReplicaInfo { - /// The replica commitment. - pub comm_r: RawCommitment, -} - -/// Entrypoint for proof verification implemented by Pallet Proofs. -pub trait ProofVerification { - fn verify_porep( - prover_id: ProverId, - seal_proof: RegisteredSealProof, - comm_r: RawCommitment, - comm_d: RawCommitment, - sector: SectorNumber, - ticket: Ticket, - seed: Ticket, - proof: BoundedVec>, - ) -> DispatchResult; - - fn verify_post( - post_type: RegisteredPoStProof, - randomness: Ticket, - replicas: BoundedBTreeMap>, - proof: BoundedVec>, - ) -> DispatchResult; -} - -/// Represents functions that are provided by the Randomness Pallet -pub trait Randomness { - fn get_randomness(block_number: BlockNumber) -> Result<[u8; 32], DispatchError>; -} - /// Binds given Sector with the Deals that it should contain /// It's used as a data transfer object for extrinsics `verify_deals_for_activation` /// as well as `activate deals`. @@ -164,3 +118,38 @@ pub struct ActiveDeal { /// Real size of the data pub piece_size: u64, } + +/// Current deadline in a proving period of a Storage Provider. +#[derive(Encode, Decode, TypeInfo)] +pub struct CurrentDeadline { + /// Index of a deadline. + /// + /// If there are 10 deadlines if the proving period, values will be [0, 9]. + /// After proving period rolls over, it'll start from 0 again. + pub deadline_index: u64, + /// Whether the deadline is open. + /// Only is false when `current_block < sp.proving_period_start`. + pub open: bool, + /// [`pallet_storage_provider::DeadlineInfo::challenge`]. + /// + /// Block at which the randomness should be fetched to generate/verify Post. + pub challenge_block: BlockNumber, + /// Block at which the deadline opens. + pub start: BlockNumber, +} + +sp_api::decl_runtime_apis! { + pub trait StorageProviderApi where AccountId: Codec + { + /// Gets the current deadline of the storage provider. + /// + /// If there is no Storage Provider of given AccountId returns [`Option::None`]. + /// May exceptionally return [`Option::None`] when + /// conversion between BlockNumbers fails, but technically should not ever happen. + fn current_deadline(storage_provider: AccountId) -> Option< + CurrentDeadline< + <::Header as sp_runtime::traits::Header>::Number + > + >; + } +} diff --git a/primitives/src/proofs.rs b/primitives/src/proofs.rs new file mode 100644 index 000000000..aebef7d55 --- /dev/null +++ b/primitives/src/proofs.rs @@ -0,0 +1,158 @@ +use codec::{Decode, Encode}; +use scale_decode::DecodeAsType; +use scale_encode::EncodeAsType; +use scale_info::TypeInfo; +use sp_core::blake2_256; + +use crate::{commitment::RawCommitment, sector::SectorSize}; + +/// Byte representation of the entity that was signing the proof. +/// It must match the ProverId used for Proving. +pub type ProverId = [u8; 32]; + +/// Byte representation of randomness seed, it's used for challenge generation. +pub type Ticket = [u8; 32]; + +/// Derives a unique prover ID for a given account. +/// +/// The function takes an `AccountId` and generates a 32-byte array that serves +/// as a unique identifier for the prover associated with that account. The +/// prover ID is derived using the Blake2 hash of the encoded account ID. +pub fn derive_prover_id(account_id: AccountId) -> [u8; 32] +where + AccountId: Encode, +{ + let encoded = account_id.encode(); + let mut encoded = blake2_256(&encoded); + + // Necessary to be a valid bls12 381 element. + encoded[31] &= 0x3f; + encoded +} + +/// The minimal information required about a replica, in order to be able to verify +/// a PoSt over it. +#[derive(Clone, core::fmt::Debug, PartialEq, Eq)] +pub struct PublicReplicaInfo { + /// The replica commitment. + pub comm_r: RawCommitment, +} + +#[allow(non_camel_case_types)] +#[derive( + Debug, Decode, Encode, DecodeAsType, EncodeAsType, TypeInfo, Eq, PartialEq, Clone, Copy, +)] +#[cfg_attr(feature = "clap", derive(::clap::ValueEnum))] +#[cfg_attr(feature = "serde", derive(::serde::Deserialize, ::serde::Serialize))] +#[codec(crate = ::codec)] +#[decode_as_type(crate_path = "::scale_decode")] +#[encode_as_type(crate_path = "::scale_encode")] +/// References: +/// * +pub enum RegisteredSealProof { + #[cfg_attr(feature = "clap", clap(name = "2KiB"))] + #[cfg_attr(feature = "serde", serde(alias = "2KiB"))] + StackedDRG2KiBV1P1, +} + +impl RegisteredSealProof { + pub fn sector_size(&self) -> SectorSize { + SectorSize::_2KiB + } + + /// Produces the windowed PoSt-specific RegisteredProof corresponding + /// to the receiving RegisteredProof. + pub fn registered_window_post_proof(&self) -> RegisteredPoStProof { + match self { + RegisteredSealProof::StackedDRG2KiBV1P1 => { + RegisteredPoStProof::StackedDRGWindow2KiBV1P1 + } + } + } + + /// Proof size in bytes for each SealProof type. + /// + /// Reference: + /// * + pub fn proof_size(self) -> usize { + match self { + RegisteredSealProof::StackedDRG2KiBV1P1 => 192, + } + } +} + +/// Proof of Spacetime type, indicating version and sector size of the proof. +#[derive( + Debug, Decode, Encode, DecodeAsType, EncodeAsType, TypeInfo, PartialEq, Eq, Clone, Copy, +)] +#[cfg_attr(feature = "clap", derive(::clap::ValueEnum))] +#[cfg_attr(feature = "serde", derive(::serde::Deserialize, ::serde::Serialize))] +#[codec(crate = ::codec)] +#[decode_as_type(crate_path = "::scale_decode")] +#[encode_as_type(crate_path = "::scale_encode")] +pub enum RegisteredPoStProof { + #[cfg_attr(feature = "clap", clap(name = "2KiB"))] + #[cfg_attr(feature = "serde", serde(alias = "2KiB"))] + StackedDRGWindow2KiBV1P1, +} + +impl RegisteredPoStProof { + /// Returns the sector size of the proof type, which is measured in bytes. + pub fn sector_size(&self) -> SectorSize { + match self { + RegisteredPoStProof::StackedDRGWindow2KiBV1P1 => SectorSize::_2KiB, + } + } + + /// Returns the partition size, in sectors, associated with a proof type. + /// The partition size is the number of sectors proven in a single PoSt proof. + pub fn window_post_partitions_sector(&self) -> u64 { + // Resolve to post proof and then compute size from that. + match self { + RegisteredPoStProof::StackedDRGWindow2KiBV1P1 => 2, + } + } + + /// Number of sectors challenged in a replica. + /// + /// References: + /// * + pub fn sector_count(&self) -> usize { + match self { + RegisteredPoStProof::StackedDRGWindow2KiBV1P1 => 2, + } + } +} + +// serde_json requires std, hence, to test the serialization, we need: +// * test (duh!) +// * serde — (duh!) +// * std — because of serde_json +#[cfg(all(test, feature = "std", feature = "serde"))] +mod serde_tests { + use super::{RegisteredPoStProof, RegisteredSealProof}; + + #[test] + fn ensure_serde_for_registered_seal_proof() { + assert_eq!( + serde_json::from_str::(r#""2KiB""#).unwrap(), + RegisteredSealProof::StackedDRG2KiBV1P1 + ); + assert_eq!( + serde_json::from_str::(r#""StackedDRG2KiBV1P1""#).unwrap(), + RegisteredSealProof::StackedDRG2KiBV1P1 + ); + } + + #[test] + fn ensure_serde_for_registered_post_proof() { + assert_eq!( + serde_json::from_str::(r#""2KiB""#).unwrap(), + RegisteredPoStProof::StackedDRGWindow2KiBV1P1 + ); + assert_eq!( + serde_json::from_str::(r#""StackedDRGWindow2KiBV1P1""#).unwrap(), + RegisteredPoStProof::StackedDRGWindow2KiBV1P1 + ); + } +} diff --git a/primitives/proofs/src/randomness.rs b/primitives/src/randomness.rs similarity index 97% rename from primitives/proofs/src/randomness.rs rename to primitives/src/randomness.rs index 3e4a08e5e..9cfb8e44c 100644 --- a/primitives/proofs/src/randomness.rs +++ b/primitives/src/randomness.rs @@ -56,7 +56,7 @@ pub fn draw_randomness( #[cfg(test)] mod tests { - use crate::randomness::{draw_randomness, DomainSeparationTag}; + use super::{draw_randomness, DomainSeparationTag}; #[test] fn draw_randomness_test() { diff --git a/primitives/proofs/src/types.rs b/primitives/src/sector.rs similarity index 54% rename from primitives/proofs/src/types.rs rename to primitives/src/sector.rs index b5cfa10c3..66d4bd7bc 100644 --- a/primitives/proofs/src/types.rs +++ b/primitives/src/sector.rs @@ -9,11 +9,7 @@ use scale_encode::EncodeAsType; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; -pub type DealId = u64; - -/// Max number of sectors. -/// -pub const MAX_SECTORS: u32 = 32 << 20; +use crate::MAX_SECTORS; /// SectorNumber is a unique identifier for a sector. #[derive( @@ -174,16 +170,6 @@ impl Display for SectorNumber { } } -/// Byte representation of the entity that was signing the proof. -/// It must match the ProverId used for Proving. -pub type ProverId = [u8; 32]; - -/// Byte representation of a commitment - CommR or CommD. -pub type RawCommitment = [u8; 32]; - -/// Byte representation of randomness seed, it's used for challenge generation. -pub type Ticket = [u8; 32]; - /// SectorSize indicates one of a set of possible sizes in the network. #[derive( Encode, Decode, DecodeAsType, EncodeAsType, TypeInfo, Clone, RuntimeDebug, PartialEq, Eq, Copy, @@ -228,122 +214,3 @@ impl core::fmt::Display for SectorSize { } } } - -#[allow(non_camel_case_types)] -#[derive( - Debug, Decode, Encode, DecodeAsType, EncodeAsType, TypeInfo, Eq, PartialEq, Clone, Copy, -)] -#[cfg_attr(feature = "clap", derive(::clap::ValueEnum))] -#[cfg_attr(feature = "serde", derive(::serde::Deserialize, ::serde::Serialize))] -#[codec(crate = ::codec)] -#[decode_as_type(crate_path = "::scale_decode")] -#[encode_as_type(crate_path = "::scale_encode")] -/// References: -/// * -pub enum RegisteredSealProof { - #[cfg_attr(feature = "clap", clap(name = "2KiB"))] - #[cfg_attr(feature = "serde", serde(alias = "2KiB"))] - StackedDRG2KiBV1P1, -} - -impl RegisteredSealProof { - pub fn sector_size(&self) -> SectorSize { - SectorSize::_2KiB - } - - /// Produces the windowed PoSt-specific RegisteredProof corresponding - /// to the receiving RegisteredProof. - pub fn registered_window_post_proof(&self) -> RegisteredPoStProof { - match self { - RegisteredSealProof::StackedDRG2KiBV1P1 => { - RegisteredPoStProof::StackedDRGWindow2KiBV1P1 - } - } - } - - /// Proof size in bytes for each SealProof type. - /// - /// Reference: - /// * - pub fn proof_size(self) -> usize { - match self { - RegisteredSealProof::StackedDRG2KiBV1P1 => 192, - } - } -} - -/// Proof of Spacetime type, indicating version and sector size of the proof. -#[derive( - Debug, Decode, Encode, DecodeAsType, EncodeAsType, TypeInfo, PartialEq, Eq, Clone, Copy, -)] -#[cfg_attr(feature = "clap", derive(::clap::ValueEnum))] -#[cfg_attr(feature = "serde", derive(::serde::Deserialize, ::serde::Serialize))] -#[codec(crate = ::codec)] -#[decode_as_type(crate_path = "::scale_decode")] -#[encode_as_type(crate_path = "::scale_encode")] -pub enum RegisteredPoStProof { - #[cfg_attr(feature = "clap", clap(name = "2KiB"))] - #[cfg_attr(feature = "serde", serde(alias = "2KiB"))] - StackedDRGWindow2KiBV1P1, -} - -impl RegisteredPoStProof { - /// Returns the sector size of the proof type, which is measured in bytes. - pub fn sector_size(&self) -> SectorSize { - match self { - RegisteredPoStProof::StackedDRGWindow2KiBV1P1 => SectorSize::_2KiB, - } - } - - /// Returns the partition size, in sectors, associated with a proof type. - /// The partition size is the number of sectors proven in a single PoSt proof. - pub fn window_post_partitions_sector(&self) -> u64 { - // Resolve to post proof and then compute size from that. - match self { - RegisteredPoStProof::StackedDRGWindow2KiBV1P1 => 2, - } - } - - /// Number of sectors challenged in a replica. - /// - /// References: - /// * - pub fn sector_count(&self) -> usize { - match self { - RegisteredPoStProof::StackedDRGWindow2KiBV1P1 => 2, - } - } -} - -// serde_json requires std, hence, to test the serialization, we need: -// * test (duh!) -// * serde — (duh!) -// * std — because of serde_json -#[cfg(all(test, feature = "std", feature = "serde"))] -mod serde_tests { - use crate::{RegisteredPoStProof, RegisteredSealProof}; - - #[test] - fn ensure_serde_for_registered_seal_proof() { - assert_eq!( - serde_json::from_str::(r#""2KiB""#).unwrap(), - RegisteredSealProof::StackedDRG2KiBV1P1 - ); - assert_eq!( - serde_json::from_str::(r#""StackedDRG2KiBV1P1""#).unwrap(), - RegisteredSealProof::StackedDRG2KiBV1P1 - ); - } - - #[test] - fn ensure_serde_for_registered_post_proof() { - assert_eq!( - serde_json::from_str::(r#""2KiB""#).unwrap(), - RegisteredPoStProof::StackedDRGWindow2KiBV1P1 - ); - assert_eq!( - serde_json::from_str::(r#""StackedDRGWindow2KiBV1P1""#).unwrap(), - RegisteredPoStProof::StackedDRGWindow2KiBV1P1 - ); - } -} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 709189fd7..364c34cb9 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -25,8 +25,7 @@ pallet-market = { workspace = true, default-features = false } pallet-proofs = { workspace = true, default-features = false } pallet-randomness = { workspace = true, default-features = false } pallet-storage-provider = { workspace = true, default-features = false } - -primitives-proofs = { workspace = true, default-features = false } +primitives = { workspace = true, default-features = false } codec = { workspace = true, default-features = false, features = ["chain-error", "derive"] } docify = { workspace = true } @@ -130,7 +129,7 @@ std = [ "parachains-common/std", "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", - "primitives-proofs/std", + "primitives/std", "scale-info/std", "sp-api/std", "sp-block-builder/std", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index d6fe82974..549c3c92a 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -412,8 +412,8 @@ impl Runtime { } impl_runtime_apis! { - impl primitives_proofs::StorageProviderApi for Runtime { - fn current_deadline(storage_provider: AccountId) -> Option> { + impl primitives::pallets::StorageProviderApi for Runtime { + fn current_deadline(storage_provider: AccountId) -> Option> { StorageProvider::current_deadline(&storage_provider) } } diff --git a/cli/polka-storage-provider/README.md b/storage-provider/README.md similarity index 100% rename from cli/polka-storage-provider/README.md rename to storage-provider/README.md diff --git a/cli/polka-storage-provider/client/Cargo.toml b/storage-provider/client/Cargo.toml similarity index 90% rename from cli/polka-storage-provider/client/Cargo.toml rename to storage-provider/client/Cargo.toml index 0a5657353..bc78d0d09 100644 --- a/cli/polka-storage-provider/client/Cargo.toml +++ b/storage-provider/client/Cargo.toml @@ -12,8 +12,7 @@ version = "0.1.0" mater = { workspace = true } polka-storage-proofs = { workspace = true, features = ["std", "substrate"] } polka-storage-provider-common = { workspace = true } -primitives-commitment = { workspace = true } -primitives-proofs = { workspace = true, features = ["clap", "std"] } +primitives = { workspace = true, features = ["clap", "std"] } storagext = { workspace = true, features = ["clap"] } async-trait = { workspace = true } diff --git a/cli/polka-storage-provider/client/src/commands/mod.rs b/storage-provider/client/src/commands/mod.rs similarity index 100% rename from cli/polka-storage-provider/client/src/commands/mod.rs rename to storage-provider/client/src/commands/mod.rs diff --git a/cli/polka-storage-provider/client/src/commands/proofs.rs b/storage-provider/client/src/commands/proofs.rs similarity index 99% rename from cli/polka-storage-provider/client/src/commands/proofs.rs rename to storage-provider/client/src/commands/proofs.rs index 61e4de364..24604c869 100644 --- a/cli/polka-storage-provider/client/src/commands/proofs.rs +++ b/storage-provider/client/src/commands/proofs.rs @@ -13,14 +13,14 @@ use polka_storage_proofs::{ ZeroPaddingReader, }; use polka_storage_provider_common::commp::{calculate_piece_commitment, CommPError}; -use primitives_commitment::{ - piece::{PaddedPieceSize, PieceInfo}, - Commitment, CommitmentError, -}; -use primitives_proofs::{ - derive_prover_id, +use primitives::{ + commitment::{ + piece::{PaddedPieceSize, PieceInfo}, + Commitment, CommitmentError, + }, + proofs::{derive_prover_id, RegisteredPoStProof, RegisteredSealProof}, randomness::{draw_randomness, DomainSeparationTag}, - RegisteredPoStProof, RegisteredSealProof, SectorNumber, + sector::SectorNumber, }; use storagext::multipair::{MultiPairArgs, MultiPairSigner}; use subxt::tx::Signer; diff --git a/cli/polka-storage-provider/client/src/commands/wallet.rs b/storage-provider/client/src/commands/wallet.rs similarity index 100% rename from cli/polka-storage-provider/client/src/commands/wallet.rs rename to storage-provider/client/src/commands/wallet.rs diff --git a/cli/polka-storage-provider/client/src/main.rs b/storage-provider/client/src/main.rs similarity index 100% rename from cli/polka-storage-provider/client/src/main.rs rename to storage-provider/client/src/main.rs diff --git a/cli/polka-storage-provider/client/src/rpc_client.rs b/storage-provider/client/src/rpc_client.rs similarity index 100% rename from cli/polka-storage-provider/client/src/rpc_client.rs rename to storage-provider/client/src/rpc_client.rs diff --git a/cli/polka-storage-provider/common/Cargo.toml b/storage-provider/common/Cargo.toml similarity index 90% rename from cli/polka-storage-provider/common/Cargo.toml rename to storage-provider/common/Cargo.toml index 5e840041b..a58df5507 100644 --- a/cli/polka-storage-provider/common/Cargo.toml +++ b/storage-provider/common/Cargo.toml @@ -9,8 +9,7 @@ version = "0.1.0" [dependencies] # "Homegrown" crates -primitives-commitment = { workspace = true } -primitives-proofs = { workspace = true } +primitives = { workspace = true } storagext = { workspace = true, features = ["clap"] } chrono = { workspace = true, features = ["serde"] } diff --git a/cli/polka-storage-provider/common/src/commp.rs b/storage-provider/common/src/commp.rs similarity index 94% rename from cli/polka-storage-provider/common/src/commp.rs rename to storage-provider/common/src/commp.rs index 7b9ed2e67..b201f773c 100644 --- a/cli/polka-storage-provider/common/src/commp.rs +++ b/storage-provider/common/src/commp.rs @@ -5,7 +5,10 @@ use filecoin_hashers::{ Domain, }; use fr32::Fr32Reader; -use primitives_commitment::{piece::PaddedPieceSize, CommP, Commitment, NODE_SIZE}; +use primitives::{ + commitment::{piece::PaddedPieceSize, CommP, Commitment}, + NODE_SIZE, +}; use storage_proofs_core::merkle::BinaryMerkleTree; use thiserror::Error; @@ -58,8 +61,7 @@ mod tests { use std::io::Cursor; use polka_storage_proofs::ZeroPaddingReader; - use primitives_commitment::piece::PaddedPieceSize; - use primitives_proofs::SectorSize; + use primitives::{commitment::piece::PaddedPieceSize, sector::SectorSize}; use super::calculate_piece_commitment; diff --git a/cli/polka-storage-provider/common/src/lib.rs b/storage-provider/common/src/lib.rs similarity index 100% rename from cli/polka-storage-provider/common/src/lib.rs rename to storage-provider/common/src/lib.rs diff --git a/cli/polka-storage-provider/common/src/rpc/error.rs b/storage-provider/common/src/rpc/error.rs similarity index 100% rename from cli/polka-storage-provider/common/src/rpc/error.rs rename to storage-provider/common/src/rpc/error.rs diff --git a/cli/polka-storage-provider/common/src/rpc/mod.rs b/storage-provider/common/src/rpc/mod.rs similarity index 98% rename from cli/polka-storage-provider/common/src/rpc/mod.rs rename to storage-provider/common/src/rpc/mod.rs index 005a32c48..2482a2e34 100644 --- a/cli/polka-storage-provider/common/src/rpc/mod.rs +++ b/storage-provider/common/src/rpc/mod.rs @@ -4,7 +4,7 @@ use std::fmt; use chrono::{DateTime, Utc}; use jsonrpsee::proc_macros::rpc; -use primitives_proofs::{RegisteredPoStProof, RegisteredSealProof}; +use primitives::proofs::{RegisteredPoStProof, RegisteredSealProof}; use serde::{Deserialize, Serialize}; use storagext::types::market::{ ClientDealProposal as SxtClientDealProposal, DealProposal as SxtDealProposal, diff --git a/cli/polka-storage-provider/server/Cargo.toml b/storage-provider/server/Cargo.toml similarity index 91% rename from cli/polka-storage-provider/server/Cargo.toml rename to storage-provider/server/Cargo.toml index c2f8acb16..23cdcf5d5 100644 --- a/cli/polka-storage-provider/server/Cargo.toml +++ b/storage-provider/server/Cargo.toml @@ -16,8 +16,7 @@ delia = [] mater = { workspace = true } polka-storage-proofs = { workspace = true, features = ["std", "substrate"] } polka-storage-provider-common = { workspace = true } -primitives-commitment = { workspace = true, features = ["serde", "std"] } -primitives-proofs = { workspace = true, features = ["clap"] } +primitives = { workspace = true, features = ["serde", "std"] } storagext = { workspace = true, features = ["clap"] } async-trait = { workspace = true } diff --git a/cli/polka-storage-provider/server/src/db.rs b/storage-provider/server/src/db.rs similarity index 99% rename from cli/polka-storage-provider/server/src/db.rs rename to storage-provider/server/src/db.rs index f0d8d1886..fb478013d 100644 --- a/cli/polka-storage-provider/server/src/db.rs +++ b/storage-provider/server/src/db.rs @@ -3,7 +3,7 @@ use std::{ sync::atomic::{AtomicU32, Ordering}, }; -use primitives_proofs::{SectorNumber, SectorNumberError}; +use primitives::sector::{SectorNumber, SectorNumberError}; use rocksdb::{ColumnFamily, ColumnFamilyDescriptor, Options as DBOptions, DB as RocksDB}; use serde::{de::DeserializeOwned, Serialize}; use storagext::types::market::{ConversionError, DealProposal}; diff --git a/cli/polka-storage-provider/server/src/main.rs b/storage-provider/server/src/main.rs similarity index 99% rename from cli/polka-storage-provider/server/src/main.rs rename to storage-provider/server/src/main.rs index 5ba405972..5d643c43c 100644 --- a/cli/polka-storage-provider/server/src/main.rs +++ b/storage-provider/server/src/main.rs @@ -13,7 +13,7 @@ use clap::Parser; use pipeline::types::PipelineMessage; use polka_storage_proofs::porep::{self, PoRepParameters}; use polka_storage_provider_common::rpc::ServerInfo; -use primitives_proofs::{RegisteredPoStProof, RegisteredSealProof}; +use primitives::proofs::{RegisteredPoStProof, RegisteredSealProof}; use rand::Rng; use storagext::{ multipair::{DebugPair, MultiPairSigner}, diff --git a/cli/polka-storage-provider/server/src/pipeline/mod.rs b/storage-provider/server/src/pipeline/mod.rs similarity index 99% rename from cli/polka-storage-provider/server/src/pipeline/mod.rs rename to storage-provider/server/src/pipeline/mod.rs index f3fb11ad3..50d34d3e7 100644 --- a/cli/polka-storage-provider/server/src/pipeline/mod.rs +++ b/storage-provider/server/src/pipeline/mod.rs @@ -7,11 +7,11 @@ use polka_storage_proofs::porep::{ PoRepError, PoRepParameters, }; use polka_storage_provider_common::rpc::ServerInfo; -use primitives_commitment::{CommD, CommP, CommR, Commitment}; -use primitives_proofs::{ - derive_prover_id, +use primitives::{ + commitment::{CommD, CommP, CommR, Commitment}, + proofs::derive_prover_id, randomness::{draw_randomness, DomainSeparationTag}, - SectorNumber, + sector::SectorNumber, }; use storagext::{ types::{ diff --git a/cli/polka-storage-provider/server/src/pipeline/types.rs b/storage-provider/server/src/pipeline/types.rs similarity index 98% rename from cli/polka-storage-provider/server/src/pipeline/types.rs rename to storage-provider/server/src/pipeline/types.rs index bbc08af70..62669cb0d 100644 --- a/cli/polka-storage-provider/server/src/pipeline/types.rs +++ b/storage-provider/server/src/pipeline/types.rs @@ -1,7 +1,10 @@ use std::path::PathBuf; -use primitives_commitment::{piece::PieceInfo, CommD, CommP, CommR, Commitment}; -use primitives_proofs::{DealId, SectorNumber}; +use primitives::{ + commitment::{piece::PieceInfo, CommD, CommP, CommR, Commitment}, + sector::SectorNumber, + DealId, +}; use serde::{Deserialize, Serialize}; use storagext::types::market::DealProposal; diff --git a/cli/polka-storage-provider/server/src/rpc.rs b/storage-provider/server/src/rpc.rs similarity index 99% rename from cli/polka-storage-provider/server/src/rpc.rs rename to storage-provider/server/src/rpc.rs index 4cd7873b3..75760e966 100644 --- a/cli/polka-storage-provider/server/src/rpc.rs +++ b/storage-provider/server/src/rpc.rs @@ -5,7 +5,7 @@ use jsonrpsee::server::Server; use polka_storage_provider_common::rpc::{ CidString, RpcError, ServerInfo, StorageProviderRpcServer, }; -use primitives_commitment::{CommP, Commitment, CommitmentKind}; +use primitives::commitment::{CommP, Commitment, CommitmentKind}; use storagext::{ types::market::{ClientDealProposal as SxtClientDealProposal, DealProposal as SxtDealProposal}, MarketClientExt, diff --git a/cli/polka-storage-provider/server/src/storage.rs b/storage-provider/server/src/storage.rs similarity index 99% rename from cli/polka-storage-provider/server/src/storage.rs rename to storage-provider/server/src/storage.rs index 958a7ec53..359b440f6 100644 --- a/cli/polka-storage-provider/server/src/storage.rs +++ b/storage-provider/server/src/storage.rs @@ -12,8 +12,7 @@ use futures::{TryFutureExt, TryStreamExt}; use mater::Cid; use polka_storage_proofs::ZeroPaddingReader; use polka_storage_provider_common::commp::{calculate_piece_commitment, CommPError}; -use primitives_commitment::piece::PaddedPieceSize; -use primitives_proofs::RegisteredPoStProof; +use primitives::{commitment::piece::PaddedPieceSize, proofs::RegisteredPoStProof}; use tokio::{ fs::{self, File}, io::{AsyncRead, BufWriter}, diff --git a/storagext/cli/Cargo.toml b/storagext/cli/Cargo.toml index 33b67ac78..1fffaab93 100644 --- a/storagext/cli/Cargo.toml +++ b/storagext/cli/Cargo.toml @@ -17,7 +17,7 @@ clap = { workspace = true, features = ["derive", "env"] } codec.workspace = true frame-support = { workspace = true, features = ["std"] } hex = { workspace = true, features = ["serde", "std"] } -primitives-proofs = { workspace = true } +primitives = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } subxt = { workspace = true, features = ["jsonrpsee", "substrate-compat"] } diff --git a/storagext/cli/src/cmd/market.rs b/storagext/cli/src/cmd/market.rs index 5c3aa8daf..15fa2cde0 100644 --- a/storagext/cli/src/cmd/market.rs +++ b/storagext/cli/src/cmd/market.rs @@ -2,7 +2,7 @@ use std::time::Duration; use anyhow::bail; use clap::{ArgGroup, Subcommand}; -use primitives_proofs::DealId; +use primitives::DealId; use storagext::{ deser::DeserializablePath, multipair::{DebugPair, MultiPairSigner}, diff --git a/storagext/cli/src/cmd/storage_provider.rs b/storagext/cli/src/cmd/storage_provider.rs index d9be9c171..25460bc27 100644 --- a/storagext/cli/src/cmd/storage_provider.rs +++ b/storagext/cli/src/cmd/storage_provider.rs @@ -1,7 +1,7 @@ use std::time::Duration; use clap::Subcommand; -use primitives_proofs::{RegisteredPoStProof, SectorNumber}; +use primitives::{proofs::RegisteredPoStProof, sector::SectorNumber}; use storagext::{ deser::DeserializablePath, multipair::MultiPairSigner, diff --git a/storagext/lib/Cargo.toml b/storagext/lib/Cargo.toml index fde9cea82..3f776749c 100644 --- a/storagext/lib/Cargo.toml +++ b/storagext/lib/Cargo.toml @@ -20,7 +20,7 @@ frame-support = { workspace = true, features = ["std"] } futures.workspace = true hex = { workspace = true, features = ["serde"] } itertools = { workspace = true } -primitives-proofs = { workspace = true, features = ["serde", "std"] } +primitives = { workspace = true, features = ["serde", "std"] } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } sha2 = { workspace = true } diff --git a/storagext/lib/artifacts/metadata.scale b/storagext/lib/artifacts/metadata.scale index b556254d4..31510857f 100644 Binary files a/storagext/lib/artifacts/metadata.scale and b/storagext/lib/artifacts/metadata.scale differ diff --git a/storagext/lib/src/clients/market.rs b/storagext/lib/src/clients/market.rs index 438dd1654..e65772e29 100644 --- a/storagext/lib/src/clients/market.rs +++ b/storagext/lib/src/clients/market.rs @@ -1,6 +1,6 @@ use std::future::Future; -use primitives_proofs::DealId; +use primitives::DealId; use subxt::{ext::sp_core::crypto::Ss58Codec, utils::Static}; use crate::{ diff --git a/storagext/lib/src/clients/storage_provider.rs b/storagext/lib/src/clients/storage_provider.rs index 9a3043e6e..af73cf289 100644 --- a/storagext/lib/src/clients/storage_provider.rs +++ b/storagext/lib/src/clients/storage_provider.rs @@ -1,6 +1,6 @@ use std::future::Future; -use primitives_proofs::RegisteredPoStProof; +use primitives::proofs::RegisteredPoStProof; use runtime::runtime_types::bounded_collections::bounded_vec::BoundedVec; use subxt::{ ext::{futures::TryStreamExt, sp_core::crypto::Ss58Codec}, @@ -16,7 +16,7 @@ use crate::{ pallet_storage_provider::{ proofs::SubmitWindowedPoStParams, storage_provider::StorageProviderState, }, - primitives_proofs::CurrentDeadline, + primitives::pallets::CurrentDeadline, }, storage_provider::calls::types::register_storage_provider::PeerId, }, diff --git a/storagext/lib/src/runtime/mod.rs b/storagext/lib/src/runtime/mod.rs index 37b5f46e2..802760421 100644 --- a/storagext/lib/src/runtime/mod.rs +++ b/storagext/lib/src/runtime/mod.rs @@ -17,20 +17,20 @@ pub mod display; with = "::subxt::utils::Static<::subxt::ext::sp_runtime::MultiSignature>" ), substitute_type( - path = "primitives_proofs::types::RegisteredSealProof", - with = "::primitives_proofs::RegisteredSealProof", + path = "primitives::proofs::types::RegisteredSealProof", + with = "::primitives::proofs::RegisteredSealProof", ), substitute_type( - path = "primitives_proofs::types::RegisteredPoStProof", - with = "::primitives_proofs::RegisteredPoStProof", + path = "primitives::proofs::types::RegisteredPoStProof", + with = "::primitives::proofs::RegisteredPoStProof", ), substitute_type( - path = "primitives_proofs::types::SectorSize", - with = "::primitives_proofs::SectorSize", + path = "primitives::sector::SectorSize", + with = "::primitives::sector::SectorSize", ), substitute_type( - path = "primitives_proofs::types::SectorNumber", - with = "::primitives_proofs::SectorNumber", + path = "primitives::sector::SectorNumber", + with = "::primitives::sector::SectorNumber", ), // impl Deserialize derive_for_type( diff --git a/storagext/lib/src/types/storage_provider.rs b/storagext/lib/src/types/storage_provider.rs index fc43534ab..4f6446265 100644 --- a/storagext/lib/src/types/storage_provider.rs +++ b/storagext/lib/src/types/storage_provider.rs @@ -6,7 +6,11 @@ use std::collections::BTreeSet; use cid::Cid; -use primitives_proofs::{DealId, RegisteredPoStProof, RegisteredSealProof, SectorNumber}; +use primitives::{ + proofs::{RegisteredPoStProof, RegisteredSealProof}, + sector::SectorNumber, + DealId, +}; use crate::{ runtime::{ @@ -313,7 +317,7 @@ mod tests { use std::{collections::BTreeSet, str::FromStr}; use cid::Cid; - use primitives_proofs::RegisteredPoStProof; + use primitives::proofs::RegisteredPoStProof; use crate::{ runtime::runtime_types::pallet_market::pallet::DealState as RuntimeDealState,