From 97635a7cf68ca356a0fa7d72a48001ab2f695d0f Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 22 Jul 2024 10:34:37 +0100 Subject: [PATCH] Block timestamps now in chronicle application events Timestamps now provide an ordering for terms, this allows incremental arrow use Signed-off-by: Ryan --- Cargo.lock | 332 ++++++++-------- Cargo.toml | 4 +- crates/api/Cargo.toml | 1 - crates/api/src/api.rs | 7 +- crates/api/src/error.rs | 7 - crates/chronicle-arrow/src/lib.rs | 360 +++++++++--------- crates/chronicle-arrow/src/query/activity.rs | 16 +- crates/chronicle-arrow/src/query/agent.rs | 8 +- crates/chronicle-arrow/src/query/entity.rs | 9 +- crates/chronicle-persistence/src/lib.rs | 119 ++++-- crates/chronicle-persistence/src/query.rs | 31 +- crates/chronicle-persistence/src/queryable.rs | 11 +- crates/chronicle-persistence/src/schema.rs | 31 +- crates/chronicle-telemetry/src/telemetry.rs | 2 +- .../chronicle-test-infrastructure/Cargo.toml | 1 + .../src/substitutes/mockchain.rs | 8 + .../src/substitutes/mod.rs | 24 +- .../src/substitutes/stubstrate.rs | 9 +- crates/common/src/identity.rs | 2 +- crates/opactl/Cargo.toml | 2 + crates/opactl/src/test/mockchain.rs | 8 + crates/pallet-chronicle/Cargo.toml | 1 + crates/pallet-chronicle/src/lib.rs | 20 +- crates/pallet-chronicle/src/mock.rs | 8 + crates/pallet-chronicle/src/tests.rs | 2 + crates/pallet-chronicle/src/weights.rs | 7 +- .../src/subxt_client.rs | 11 +- diesel.toml | 4 +- 28 files changed, 592 insertions(+), 453 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71419f8f7..a96675bfd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,13 +244,12 @@ dependencies = [ "metrics", "metrics-exporter-prometheus", "opa", - "opentelemetry 0.22.0", + "opentelemetry 0.23.0", "parking_lot 0.12.3", "poem", "protocol-substrate", "protocol-substrate-chronicle", "protocol-substrate-opa", - "r2d2", "reqwest", "rust-embed", "serde", @@ -300,7 +299,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -952,9 +951,9 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8828ec6e544c02b0d6691d21ed9f9218d0384a82542855073c2a3f58304aaf0" +checksum = "d7ebdfa2ebdab6b1760375fa7d6f382b9f486eac35fc994625a00e89280bdbb7" dependencies = [ "async-task", "concurrent-queue", @@ -976,9 +975,9 @@ dependencies = [ [[package]] name = "async-graphql" -version = "7.0.6" +version = "7.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf338d20ba5bab309f55ce8df95d65ee19446f7737f06f4a64593ab2c6b546ad" +checksum = "2b76aba2f176af685c2229633881a3adeae51f87ae1811781e73910b7001c93e" dependencies = [ "async-graphql-derive", "async-graphql-parser", @@ -999,7 +998,7 @@ dependencies = [ "multer", "num-traits", "once_cell", - "opentelemetry 0.22.0", + "opentelemetry 0.23.0", "pin-project-lite 0.2.14", "regex", "serde", @@ -1013,9 +1012,9 @@ dependencies = [ [[package]] name = "async-graphql-derive" -version = "7.0.6" +version = "7.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc51fd6b7102acda72bc94e8ae1543844d5688ff394a6cf7c21f2a07fe2d64e4" +checksum = "72e2e26a6b44bc61df3ca8546402cf9204c28e30c06084cc8e75cd5e34d4f150" dependencies = [ "Inflector", "async-graphql-parser", @@ -1024,15 +1023,15 @@ dependencies = [ "proc-macro2", "quote", "strum 0.26.3", - "syn 2.0.70", + "syn 2.0.71", "thiserror", ] [[package]] name = "async-graphql-parser" -version = "7.0.6" +version = "7.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75361eefd64e39f89bead4cb45fddbaf60ddb0e7b15fb7c852b6088bcd63071f" +checksum = "f801451484b4977d6fe67b29030f81353cabdcbb754e5a064f39493582dac0cf" dependencies = [ "async-graphql-value", "pest", @@ -1042,9 +1041,9 @@ dependencies = [ [[package]] name = "async-graphql-poem" -version = "7.0.6" +version = "7.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "072888eb96e1dc0398d8e163015c3c24323a94e71b65757af4ddc07beb38df18" +checksum = "6fead92136d9c0c68b6da5ea16962604163b1f4d59750ec7b36155ca9ff105d3" dependencies = [ "async-graphql", "futures-util", @@ -1059,9 +1058,9 @@ dependencies = [ [[package]] name = "async-graphql-value" -version = "7.0.6" +version = "7.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1f665d2d52b41c4ed1f01c43f3ef27a2fe0af2452ed5c8bc7ac9b1a8719afaa" +checksum = "69117c43c01d81a69890a9f5dd6235f2f027ca8d1ec62d6d3c5e01ca0edb4f2b" dependencies = [ "bytes", "indexmap 2.2.6", @@ -1132,9 +1131,9 @@ dependencies = [ [[package]] name = "async-signal" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "794f185324c2f00e771cd9f1ae8b5ac68be2ca7abb129a87afd6e86d228bc54d" +checksum = "dfb3634b73397aa844481f814fad23bbf07fdb0eabec10f2eb95e58944b1ec32" dependencies = [ "async-io", "async-lock", @@ -1178,7 +1177,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1195,7 +1194,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1413,7 +1412,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1541,9 +1540,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.5.1" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" +checksum = "e9ec96fe9a81b5e365f9db71fe00edc4fe4ca2cc7dcb7861f0603012a7caa210" dependencies = [ "arrayref", "arrayvec 0.7.4", @@ -1681,7 +1680,7 @@ checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1692,9 +1691,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" dependencies = [ "serde", ] @@ -1804,13 +1803,12 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.0" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaff6f8ce506b9773fa786672d63fc7a191ffea1be33f72bbd4aeacefca9ffc8" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" dependencies = [ "jobserver", "libc", - "once_cell", ] [[package]] @@ -1925,7 +1923,7 @@ dependencies = [ "libc", "mockito", "opa", - "opentelemetry 0.22.0", + "opentelemetry 0.23.0", "percent-encoding", "protocol-abstract", "protocol-substrate", @@ -2138,6 +2136,7 @@ dependencies = [ "insta", "lazy_static", "pallet-chronicle", + "pallet-timestamp", "parity-scale-codec", "portpicker", "protocol-abstract", @@ -2352,7 +2351,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2999,7 +2998,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3032,7 +3031,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3049,7 +3048,7 @@ checksum = "4b2c1c1776b986979be68bb2285da855f8d8a35851a769fca8740df7c3d07877" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3121,7 +3120,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3154,7 +3153,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core 0.20.10", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3295,7 +3294,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3306,7 +3305,7 @@ checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3350,7 +3349,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3393,7 +3392,7 @@ dependencies = [ "diesel_table_macro_syntax", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3413,7 +3412,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" dependencies = [ - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3521,7 +3520,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3567,9 +3566,9 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.70", + "syn 2.0.71", "termcolor", - "toml 0.8.14", + "toml 0.8.15", "walkdir", ] @@ -3903,7 +3902,7 @@ dependencies = [ "prettyplease 0.2.20", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -4346,7 +4345,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing 0.0.0", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -4358,7 +4357,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -4368,7 +4367,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0 dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -4522,7 +4521,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -5096,9 +5095,9 @@ dependencies = [ [[package]] name = "http-body" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", "http 1.1.0", @@ -5113,7 +5112,7 @@ dependencies = [ "bytes", "futures-util", "http 1.1.0", - "http-body 1.0.0", + "http-body 1.0.1", "pin-project-lite 0.2.14", ] @@ -5176,7 +5175,7 @@ dependencies = [ "futures-util", "h2 0.4.5", "http 1.1.0", - "http-body 1.0.0", + "http-body 1.0.1", "httparse", "httpdate", "itoa", @@ -5271,7 +5270,7 @@ dependencies = [ "futures-channel", "futures-util", "http 1.1.0", - "http-body 1.0.0", + "http-body 1.0.1", "hyper 1.4.1", "pin-project-lite 0.2.14", "socket2 0.5.7", @@ -5933,7 +5932,7 @@ dependencies = [ "futures-timer", "futures-util", "http 1.1.0", - "http-body 1.0.0", + "http-body 1.0.1", "http-body-util", "jsonrpsee-types 0.23.2", "pin-project", @@ -5974,7 +5973,7 @@ checksum = "2d90064e04fb9d7282b1c71044ea94d0bbc6eff5621c66f1a0bce9e9de7cf3ac" dependencies = [ "async-trait", "base64 0.22.1", - "http-body 1.0.0", + "http-body 1.0.1", "hyper 1.4.1", "hyper-rustls 0.27.2", "hyper-util", @@ -6001,7 +6000,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -6982,7 +6981,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -6996,7 +6995,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -7007,7 +7006,7 @@ checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -7018,7 +7017,7 @@ checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -7453,7 +7452,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -7937,6 +7936,7 @@ dependencies = [ "k256 0.11.6", "lazy_static", "pallet-opa", + "pallet-timestamp", "parity-scale-codec", "portpicker", "protocol-abstract", @@ -7998,7 +7998,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -8021,9 +8021,9 @@ dependencies = [ [[package]] name = "opentelemetry" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900d57987be3f2aeb70d385fff9b27fb74c5723cc9a52d904d4f9c807a0667bf" +checksum = "1b69a91d4893e713e06f724597ad630f1fa76057a5e1026c0ca67054a9032a76" dependencies = [ "futures-core", "futures-sink", @@ -8031,14 +8031,13 @@ dependencies = [ "once_cell", "pin-project-lite 0.2.14", "thiserror", - "urlencoding", ] [[package]] name = "opentelemetry" -version = "0.23.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b69a91d4893e713e06f724597ad630f1fa76057a5e1026c0ca67054a9032a76" +checksum = "4c365a63eec4f55b7efeceb724f1336f26a9cf3427b70e59e2cd2a5b947fba96" dependencies = [ "futures-core", "futures-sink", @@ -8073,14 +8072,14 @@ dependencies = [ [[package]] name = "opentelemetry-http" -version = "0.11.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7690dc77bf776713848c4faa6501157469017eaf332baccd4eb1cea928743d94" +checksum = "ad31e9de44ee3538fb9d64fe3376c1362f406162434609e79aea2a41a0af78ab" dependencies = [ "async-trait", "bytes", - "http 0.2.12", - "opentelemetry 0.22.0", + "http 1.1.0", + "opentelemetry 0.24.0", ] [[package]] @@ -8115,15 +8114,15 @@ dependencies = [ [[package]] name = "opentelemetry-semantic-conventions" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9ab5bd6c42fb9349dcf28af2ba9a0667f697f9bdcca045d39f2cec5543e2910" +checksum = "1869fb4bb9b35c5ba8a1e40c9b128a7b4c010d07091e864a29da19e4fe2ca4d7" [[package]] name = "opentelemetry-semantic-conventions" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1869fb4bb9b35c5ba8a1e40c9b128a7b4c010d07091e864a29da19e4fe2ca4d7" +checksum = "1cefe0543875379e47eb5f1e68ff83f45cc41366a92dfd0d073d513bf68e9a05" [[package]] name = "opentelemetry-stdout" @@ -8240,6 +8239,7 @@ dependencies = [ "frame-system", "macro-attr-2018", "newtype-derive-2018", + "pallet-timestamp", "parity-scale-codec", "scale-info", "serde", @@ -8498,7 +8498,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.2", + "redox_syscall 0.5.3", "smallvec", "windows-targets 0.52.6", ] @@ -8621,7 +8621,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -8738,7 +8738,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -8826,9 +8826,9 @@ dependencies = [ [[package]] name = "poem" -version = "3.0.1" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88b6912ed1e8833d7c22c9c986c517f4518d7d37e3c04566d917c789aaea591" +checksum = "14c2c9ce82b482f5d7b0db655b104fc80fc0d7de9fc099e9f4a40a96faaef6f1" dependencies = [ "base64 0.22.1", "bytes", @@ -8840,9 +8840,9 @@ dependencies = [ "hyper-util", "mime", "nix 0.28.0", - "opentelemetry 0.22.0", + "opentelemetry 0.24.0", "opentelemetry-http", - "opentelemetry-semantic-conventions 0.14.0", + "opentelemetry-semantic-conventions 0.16.0", "parking_lot 0.12.3", "percent-encoding", "pin-project-lite 0.2.14", @@ -8864,14 +8864,14 @@ dependencies = [ [[package]] name = "poem-derive" -version = "3.0.0" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2b961d58a6c53380c20236394381d9292fda03577f902b158f1638932964dcf" +checksum = "adec62bf9b9483848bc0b46c7911a23a47885b83c20ac9a71d700e349e172aaa" dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -8938,7 +8938,7 @@ dependencies = [ "polkavm-common 0.8.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -8950,7 +8950,7 @@ dependencies = [ "polkavm-common 0.9.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -8960,7 +8960,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15e85319a0d5129dc9f021c62607e0804f5fb777a05cdda44d750ac0732def66" dependencies = [ "polkavm-derive-impl 0.8.0", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -8970,7 +8970,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl 0.9.0", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -9164,7 +9164,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -9245,7 +9245,7 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -9291,7 +9291,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -9379,7 +9379,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -9497,9 +9497,9 @@ dependencies = [ [[package]] name = "psl" -version = "2.1.50" +version = "2.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20f2890e9f6f068d927643e8d547931b537f21fd298e197c4837f1265b11e560" +checksum = "9175d202d68cb9075415cd2d00062282941010af4174edb7a82d20514b89bc36" dependencies = [ "psl-types", ] @@ -9734,9 +9734,9 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "11.0.2" +version = "11.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e29830cbb1290e404f24c73af91c5d8d631ce7e128691e9477556b540cd01ecd" +checksum = "cb9ee317cfe3fbd54b36a511efc1edd42e216903c9cd575e686dd68a2ba90d8d" dependencies = [ "bitflags 2.6.0", ] @@ -9829,9 +9829,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ "bitflags 2.6.0", ] @@ -9864,7 +9864,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -10200,7 +10200,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.70", + "syn 2.0.71", "walkdir", ] @@ -10641,7 +10641,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -11474,7 +11474,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -11695,7 +11695,7 @@ dependencies = [ "proc-macro2", "quote", "scale-info", - "syn 2.0.70", + "syn 2.0.71", "thiserror", ] @@ -11880,9 +11880,9 @@ dependencies = [ [[package]] name = "secret-vault" -version = "1.12.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae81887a0ca28d659f809b8927c0fefe763d18c3035a14f9eec1813d7b07830" +checksum = "7a536ac6442e012bdb882ad2a35e3b7cc2ec2d9f5d44953d5cd07ff88be8696e" dependencies = [ "async-trait", "cargo-husky", @@ -11898,9 +11898,9 @@ dependencies = [ [[package]] name = "secret-vault-value" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5f8cfb86d2019f64a4cfb49e499f401f406fbec946c1ffeea9d0504284347de" +checksum = "bc32a777b53b3433b974c9c26b6d502a50037f8da94e46cb8ce2ced2cfdfaea0" dependencies = [ "hex", "zeroize", @@ -11908,9 +11908,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ "bitflags 2.6.0", "core-foundation", @@ -11922,9 +11922,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" dependencies = [ "core-foundation-sys", "libc", @@ -11996,7 +11996,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -12496,7 +12496,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -12780,7 +12780,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#6dd777ffe62cff936e04a76134ccf07de9dee429" +source = "git+https://github.com/paritytech/polkadot-sdk#f8f70b37562e3519401f8c1fada9a2c55589e0c6" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -12831,7 +12831,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0 dependencies = [ "quote", "sp-crypto-hashing 0.0.0", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -12851,7 +12851,7 @@ checksum = "48d09fa0a5f7299fb81ee25ae3853d26200f7a348148aed6de76be905c007dbe" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -12861,17 +12861,17 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0 dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#6dd777ffe62cff936e04a76134ccf07de9dee429" +source = "git+https://github.com/paritytech/polkadot-sdk#f8f70b37562e3519401f8c1fada9a2c55589e0c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -12888,7 +12888,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#6dd777ffe62cff936e04a76134ccf07de9dee429" +source = "git+https://github.com/paritytech/polkadot-sdk#f8f70b37562e3519401f8c1fada9a2c55589e0c6" dependencies = [ "environmental", "parity-scale-codec", @@ -13162,7 +13162,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#6dd777ffe62cff936e04a76134ccf07de9dee429" +source = "git+https://github.com/paritytech/polkadot-sdk#f8f70b37562e3519401f8c1fada9a2c55589e0c6" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -13208,20 +13208,20 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#6dd777ffe62cff936e04a76134ccf07de9dee429" +source = "git+https://github.com/paritytech/polkadot-sdk#f8f70b37562e3519401f8c1fada9a2c55589e0c6" dependencies = [ "Inflector", "expander", "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -13235,7 +13235,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -13349,7 +13349,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0 [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#6dd777ffe62cff936e04a76134ccf07de9dee429" +source = "git+https://github.com/paritytech/polkadot-sdk#f8f70b37562e3519401f8c1fada9a2c55589e0c6" [[package]] name = "sp-storage" @@ -13367,7 +13367,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#6dd777ffe62cff936e04a76134ccf07de9dee429" +source = "git+https://github.com/paritytech/polkadot-sdk#f8f70b37562e3519401f8c1fada9a2c55589e0c6" dependencies = [ "impl-serde", "parity-scale-codec", @@ -13431,7 +13431,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#6dd777ffe62cff936e04a76134ccf07de9dee429" +source = "git+https://github.com/paritytech/polkadot-sdk#f8f70b37562e3519401f8c1fada9a2c55589e0c6" dependencies = [ "parity-scale-codec", "tracing", @@ -13537,7 +13537,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -13570,7 +13570,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#6dd777ffe62cff936e04a76134ccf07de9dee429" +source = "git+https://github.com/paritytech/polkadot-sdk#f8f70b37562e3519401f8c1fada9a2c55589e0c6" dependencies = [ "impl-trait-for-tuples", "log", @@ -13824,7 +13824,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -13935,7 +13935,7 @@ dependencies = [ "sp-maybe-compressed-blob", "strum 0.24.1", "tempfile", - "toml 0.8.14", + "toml 0.8.15", "walkdir", "wasm-opt", ] @@ -13955,7 +13955,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "subxt" version = "0.37.0" -source = "git+https://github.com/paritytech/subxt#f9d6f84bdd58e5e9ab0464e2052c8ed6a62b16ec" +source = "git+https://github.com/paritytech/subxt#f359119da26aa427ee8b3bfa5fd41d9b580eade0" dependencies = [ "async-trait", "derive-where", @@ -13990,7 +13990,7 @@ dependencies = [ [[package]] name = "subxt-codegen" version = "0.37.0" -source = "git+https://github.com/paritytech/subxt#f9d6f84bdd58e5e9ab0464e2052c8ed6a62b16ec" +source = "git+https://github.com/paritytech/subxt#f359119da26aa427ee8b3bfa5fd41d9b580eade0" dependencies = [ "frame-metadata 16.0.0", "heck 0.5.0", @@ -14002,7 +14002,7 @@ dependencies = [ "scale-info", "scale-typegen", "subxt-metadata", - "syn 2.0.70", + "syn 2.0.71", "thiserror", "tokio", ] @@ -14010,7 +14010,7 @@ dependencies = [ [[package]] name = "subxt-core" version = "0.37.0" -source = "git+https://github.com/paritytech/subxt#f9d6f84bdd58e5e9ab0464e2052c8ed6a62b16ec" +source = "git+https://github.com/paritytech/subxt#f359119da26aa427ee8b3bfa5fd41d9b580eade0" dependencies = [ "base58", "blake2 0.10.6", @@ -14039,7 +14039,7 @@ dependencies = [ [[package]] name = "subxt-lightclient" version = "0.37.0" -source = "git+https://github.com/paritytech/subxt#f9d6f84bdd58e5e9ab0464e2052c8ed6a62b16ec" +source = "git+https://github.com/paritytech/subxt#f359119da26aa427ee8b3bfa5fd41d9b580eade0" dependencies = [ "futures", "futures-util", @@ -14055,7 +14055,7 @@ dependencies = [ [[package]] name = "subxt-macro" version = "0.37.0" -source = "git+https://github.com/paritytech/subxt#f9d6f84bdd58e5e9ab0464e2052c8ed6a62b16ec" +source = "git+https://github.com/paritytech/subxt#f359119da26aa427ee8b3bfa5fd41d9b580eade0" dependencies = [ "darling 0.20.10", "parity-scale-codec", @@ -14063,13 +14063,13 @@ dependencies = [ "quote", "scale-typegen", "subxt-codegen", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] name = "subxt-metadata" version = "0.37.0" -source = "git+https://github.com/paritytech/subxt#f9d6f84bdd58e5e9ab0464e2052c8ed6a62b16ec" +source = "git+https://github.com/paritytech/subxt#f359119da26aa427ee8b3bfa5fd41d9b580eade0" dependencies = [ "frame-metadata 16.0.0", "hashbrown 0.14.5", @@ -14091,9 +14091,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.70" +version = "2.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" +checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" dependencies = [ "proc-macro2", "quote", @@ -14253,22 +14253,22 @@ checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -14393,9 +14393,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.38.0" +version = "1.38.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "eb2caba9f80616f438e09748d5acda951967e1ea58508ef53d9c6402485a46df" dependencies = [ "backtrace", "bytes", @@ -14429,7 +14429,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -14572,14 +14572,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.14" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" +checksum = "ac2caab0bf757388c6c0ae23b3293fdb463fee59434529014f85e3263b995c28" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.15", + "toml_edit 0.22.16", ] [[package]] @@ -14617,9 +14617,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.15" +version = "0.22.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59a3a72298453f564e2b111fa896f8d07fabb36f51f06d7e875fc5e0b5a3ef1" +checksum = "278f3d518e152219c994ce877758516bca5e118eaed6996192a774fb9fbf0788" dependencies = [ "indexmap 2.2.6", "serde", @@ -14756,7 +14756,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -15184,12 +15184,6 @@ dependencies = [ "serde", ] -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - [[package]] name = "user-error" version = "1.2.8" @@ -15396,7 +15390,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", "wasm-bindgen-shared", ] @@ -15430,7 +15424,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -16254,7 +16248,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -16274,7 +16268,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c7e24ff28..af8a06aaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ members = [ Inflector = "0.11.4" anyhow = { version = "^1", features = ["backtrace"] } assert_fs = "1.0" -async-graphql = "^7" +async-graphql = "7.0.7" async-graphql-poem = "^7" async-signals = "^0.4" async-stream = "^0.3.3" @@ -101,7 +101,7 @@ mockito = "1.1" newtype-derive-2018 = "0.2.1" oauth2 = "4.4" opa = { git = "https://github.com/chronicleworks/opa-rs", rev = "9fa2fbce" } -opentelemetry = { version = "0.22" } +opentelemetry = { version = "0.23" } owo-colors = "3.5.0" parking_lot = "0.12.0" percent-encoding = "2.1.0" diff --git a/crates/api/Cargo.toml b/crates/api/Cargo.toml index 869f78a32..1e4f7e5d2 100644 --- a/crates/api/Cargo.toml +++ b/crates/api/Cargo.toml @@ -63,7 +63,6 @@ common = { path = "../common", features = [ protocol-substrate = { path = "../protocol-substrate" } protocol-substrate-chronicle = { path = "../protocol-substrate-chronicle" } protocol-substrate-opa = { path = "../protocol-substrate-opa" } -r2d2 = { version = "^0.8.1" } [dev-dependencies] diff --git a/crates/api/src/api.rs b/crates/api/src/api.rs index d71f9eb5b..43db56f75 100644 --- a/crates/api/src/api.rs +++ b/crates/api/src/api.rs @@ -263,12 +263,12 @@ where // Successfully committed to ledger, so apply // to db and broadcast notification to // subscription subscribers - Some((ChronicleEvent::Committed{ref diff, ref identity, ..},tx,block_id,_position,_span )) => { + Some((ChronicleEvent::Committed{ref diff, ref identity, timestamp, .. },tx,block_id,_position,_span )) => { debug!(diff = ?diff.summarize()); trace!(delta = %serde_json::to_string_pretty(&diff.to_json().compact().await.unwrap()).unwrap()); - api.sync( diff.clone().into(), &block_id,tx ) + api.sync( diff.clone().into(), &block_id,tx , timestamp) .instrument(info_span!("incoming_confirmation", offset = ?block_id, tx = %tx)) .await .map_err(|e| { @@ -1297,10 +1297,11 @@ where prov: Box, block_id: &BlockId, tx_id: ChronicleTransactionId, + block_time: u64, ) -> Result { trace!(prov = ?prov); let block_id = *block_id; - self.store.apply_prov(&prov).await?; + self.store.apply_prov(&prov, block_time, block_id).await?; self.store.set_last_block_id(&block_id, tx_id).await?; Ok(ApiResponse::Unit) } diff --git a/crates/api/src/error.rs b/crates/api/src/error.rs index 95051eaae..635e9249c 100644 --- a/crates/api/src/error.rs +++ b/crates/api/src/error.rs @@ -70,13 +70,6 @@ pub enum ApiError { AddrParseError, ), - #[error("Connection pool: {0}")] - ConnectionPool( - #[from] - #[source] - r2d2::Error, - ), - #[error("IO error: {0}")] InputOutput( #[from] diff --git a/crates/chronicle-arrow/src/lib.rs b/crates/chronicle-arrow/src/lib.rs index dd4a8221a..d98a5e7f8 100644 --- a/crates/chronicle-arrow/src/lib.rs +++ b/crates/chronicle-arrow/src/lib.rs @@ -1320,22 +1320,22 @@ roles: { "ended": String("2022-01-02T00:00:00Z"), "generated": Array [ - String("entity-0"), - String("entity-1"), + String("entity-7"), + String("entity-8"), ], - "id": String("ItemManufacturedActivity-0"), + "id": String("ItemManufacturedActivity-7"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "started": String("2022-01-01T00:00:00Z"), "used": Array [ - String("entity-0"), - String("entity-1"), + String("entity-7"), + String("entity-8"), ], "was_associated_with": Array [ Object { "delegated": Array [], "responsible": Object { - "agent": String("agent-0"), + "agent": String("agent-7"), "role": String("ROLE_TYPE"), }, }, @@ -1345,22 +1345,22 @@ roles: { "ended": String("2022-01-02T00:00:00Z"), "generated": Array [ - String("entity-1"), - String("entity-2"), + String("entity-6"), + String("entity-7"), ], - "id": String("ItemManufacturedActivity-1"), + "id": String("ItemManufacturedActivity-6"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "started": String("2022-01-01T00:00:00Z"), "used": Array [ - String("entity-1"), - String("entity-2"), + String("entity-6"), + String("entity-7"), ], "was_associated_with": Array [ Object { "delegated": Array [], "responsible": Object { - "agent": String("agent-1"), + "agent": String("agent-6"), "role": String("ROLE_TYPE"), }, }, @@ -1370,22 +1370,22 @@ roles: { "ended": String("2022-01-02T00:00:00Z"), "generated": Array [ - String("entity-2"), - String("entity-3"), + String("entity-5"), + String("entity-6"), ], - "id": String("ItemManufacturedActivity-2"), + "id": String("ItemManufacturedActivity-5"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "started": String("2022-01-01T00:00:00Z"), "used": Array [ - String("entity-2"), - String("entity-3"), + String("entity-5"), + String("entity-6"), ], "was_associated_with": Array [ Object { "delegated": Array [], "responsible": Object { - "agent": String("agent-2"), + "agent": String("agent-5"), "role": String("ROLE_TYPE"), }, }, @@ -1395,22 +1395,22 @@ roles: { "ended": String("2022-01-02T00:00:00Z"), "generated": Array [ - String("entity-3"), String("entity-4"), + String("entity-5"), ], - "id": String("ItemManufacturedActivity-3"), + "id": String("ItemManufacturedActivity-4"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "started": String("2022-01-01T00:00:00Z"), "used": Array [ - String("entity-3"), String("entity-4"), + String("entity-5"), ], "was_associated_with": Array [ Object { "delegated": Array [], "responsible": Object { - "agent": String("agent-3"), + "agent": String("agent-4"), "role": String("ROLE_TYPE"), }, }, @@ -1420,22 +1420,22 @@ roles: { "ended": String("2022-01-02T00:00:00Z"), "generated": Array [ + String("entity-3"), String("entity-4"), - String("entity-5"), ], - "id": String("ItemManufacturedActivity-4"), + "id": String("ItemManufacturedActivity-3"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "started": String("2022-01-01T00:00:00Z"), "used": Array [ + String("entity-3"), String("entity-4"), - String("entity-5"), ], "was_associated_with": Array [ Object { "delegated": Array [], "responsible": Object { - "agent": String("agent-4"), + "agent": String("agent-3"), "role": String("ROLE_TYPE"), }, }, @@ -1445,22 +1445,22 @@ roles: { "ended": String("2022-01-02T00:00:00Z"), "generated": Array [ - String("entity-5"), - String("entity-6"), + String("entity-2"), + String("entity-3"), ], - "id": String("ItemManufacturedActivity-5"), + "id": String("ItemManufacturedActivity-2"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "started": String("2022-01-01T00:00:00Z"), "used": Array [ - String("entity-5"), - String("entity-6"), + String("entity-2"), + String("entity-3"), ], "was_associated_with": Array [ Object { "delegated": Array [], "responsible": Object { - "agent": String("agent-5"), + "agent": String("agent-2"), "role": String("ROLE_TYPE"), }, }, @@ -1470,22 +1470,22 @@ roles: { "ended": String("2022-01-02T00:00:00Z"), "generated": Array [ - String("entity-6"), - String("entity-7"), + String("entity-1"), + String("entity-2"), ], - "id": String("ItemManufacturedActivity-6"), + "id": String("ItemManufacturedActivity-1"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "started": String("2022-01-01T00:00:00Z"), "used": Array [ - String("entity-6"), - String("entity-7"), + String("entity-1"), + String("entity-2"), ], "was_associated_with": Array [ Object { "delegated": Array [], "responsible": Object { - "agent": String("agent-6"), + "agent": String("agent-1"), "role": String("ROLE_TYPE"), }, }, @@ -1495,22 +1495,22 @@ roles: { "ended": String("2022-01-02T00:00:00Z"), "generated": Array [ - String("entity-7"), - String("entity-8"), + String("entity-0"), + String("entity-1"), ], - "id": String("ItemManufacturedActivity-7"), + "id": String("ItemManufacturedActivity-0"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "started": String("2022-01-01T00:00:00Z"), "used": Array [ - String("entity-7"), - String("entity-8"), + String("entity-0"), + String("entity-1"), ], "was_associated_with": Array [ Object { "delegated": Array [], "responsible": Object { - "agent": String("agent-7"), + "agent": String("agent-0"), "role": String("ROLE_TYPE"), }, }, @@ -1522,17 +1522,17 @@ roles: { "acted_on_behalf_of": Array [ Object { - "activity": String("activity-0"), - "agent": String("agent-0"), + "activity": String("activity-7"), + "agent": String("agent-7"), "role": String("DELEGATED_CERTIFIER"), }, ], - "id": String("ContractorAgent-0"), + "id": String("ContractorAgent-7"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "entity": String("entity-0"), + "entity": String("entity-7"), "role": String("UNSPECIFIED_INTERACTION"), }, ], @@ -1540,17 +1540,17 @@ roles: { "acted_on_behalf_of": Array [ Object { - "activity": String("activity-1"), - "agent": String("agent-1"), + "activity": String("activity-6"), + "agent": String("agent-6"), "role": String("DELEGATED_CERTIFIER"), }, ], - "id": String("ContractorAgent-1"), + "id": String("ContractorAgent-6"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "entity": String("entity-1"), + "entity": String("entity-6"), "role": String("UNSPECIFIED_INTERACTION"), }, ], @@ -1558,17 +1558,17 @@ roles: { "acted_on_behalf_of": Array [ Object { - "activity": String("activity-2"), - "agent": String("agent-2"), + "activity": String("activity-5"), + "agent": String("agent-5"), "role": String("DELEGATED_CERTIFIER"), }, ], - "id": String("ContractorAgent-2"), + "id": String("ContractorAgent-5"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "entity": String("entity-2"), + "entity": String("entity-5"), "role": String("UNSPECIFIED_INTERACTION"), }, ], @@ -1576,17 +1576,17 @@ roles: { "acted_on_behalf_of": Array [ Object { - "activity": String("activity-3"), - "agent": String("agent-3"), + "activity": String("activity-4"), + "agent": String("agent-4"), "role": String("DELEGATED_CERTIFIER"), }, ], - "id": String("ContractorAgent-3"), + "id": String("ContractorAgent-4"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "entity": String("entity-3"), + "entity": String("entity-4"), "role": String("UNSPECIFIED_INTERACTION"), }, ], @@ -1594,17 +1594,17 @@ roles: { "acted_on_behalf_of": Array [ Object { - "activity": String("activity-4"), - "agent": String("agent-4"), + "activity": String("activity-3"), + "agent": String("agent-3"), "role": String("DELEGATED_CERTIFIER"), }, ], - "id": String("ContractorAgent-4"), + "id": String("ContractorAgent-3"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "entity": String("entity-4"), + "entity": String("entity-3"), "role": String("UNSPECIFIED_INTERACTION"), }, ], @@ -1612,17 +1612,17 @@ roles: { "acted_on_behalf_of": Array [ Object { - "activity": String("activity-5"), - "agent": String("agent-5"), + "activity": String("activity-2"), + "agent": String("agent-2"), "role": String("DELEGATED_CERTIFIER"), }, ], - "id": String("ContractorAgent-5"), + "id": String("ContractorAgent-2"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "entity": String("entity-5"), + "entity": String("entity-2"), "role": String("UNSPECIFIED_INTERACTION"), }, ], @@ -1630,17 +1630,17 @@ roles: { "acted_on_behalf_of": Array [ Object { - "activity": String("activity-6"), - "agent": String("agent-6"), + "activity": String("activity-1"), + "agent": String("agent-1"), "role": String("DELEGATED_CERTIFIER"), }, ], - "id": String("ContractorAgent-6"), + "id": String("ContractorAgent-1"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "entity": String("entity-6"), + "entity": String("entity-1"), "role": String("UNSPECIFIED_INTERACTION"), }, ], @@ -1648,17 +1648,17 @@ roles: { "acted_on_behalf_of": Array [ Object { - "activity": String("activity-7"), - "agent": String("agent-7"), + "activity": String("activity-0"), + "agent": String("agent-0"), "role": String("DELEGATED_CERTIFIER"), }, ], - "id": String("ContractorAgent-7"), + "id": String("ContractorAgent-0"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "entity": String("entity-7"), + "entity": String("entity-0"), "role": String("UNSPECIFIED_INTERACTION"), }, ], @@ -1669,39 +1669,43 @@ roles: "certIDAttribute": String("certIDAttribute-value"), "had_primary_source": Array [ Object { - "activity": String("activity-ps-0"), - "source": String("CertificateEntity-0"), + "activity": String("activity-ps-7"), + "source": String("CertificateEntity-7"), }, ], - "id": String("CertificateEntity-0"), + "id": String("CertificateEntity-7"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "agent": String("agent-0"), + "agent": String("agent-7"), "role": String("CERTIFIER"), }, + Object { + "agent": String("agent-7"), + "role": String("MANUFACTURER"), + }, ], "was_derived_from": Array [ Object { - "activity": String("activity-d-0"), - "source": String("CertificateEntity-0"), + "activity": String("activity-d-7"), + "source": String("CertificateEntity-7"), }, ], "was_generated_by": Array [ - String("activity-0"), - String("activity-1"), + String("activity-7"), + String("activity-8"), ], "was_quoted_from": Array [ Object { - "activity": String("activity-q-0"), - "source": String("CertificateEntity-0"), + "activity": String("activity-q-7"), + "source": String("CertificateEntity-7"), }, ], "was_revision_of": Array [ Object { - "activity": String("activity-r-0"), - "source": String("CertificateEntity-0"), + "activity": String("activity-r-7"), + "source": String("CertificateEntity-7"), }, ], }, @@ -1709,43 +1713,43 @@ roles: "certIDAttribute": String("certIDAttribute-value"), "had_primary_source": Array [ Object { - "activity": String("activity-ps-1"), - "source": String("CertificateEntity-1"), + "activity": String("activity-ps-6"), + "source": String("CertificateEntity-6"), }, ], - "id": String("CertificateEntity-1"), + "id": String("CertificateEntity-6"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "agent": String("agent-1"), + "agent": String("agent-6"), "role": String("CERTIFIER"), }, Object { - "agent": String("agent-1"), + "agent": String("agent-6"), "role": String("MANUFACTURER"), }, ], "was_derived_from": Array [ Object { - "activity": String("activity-d-1"), - "source": String("CertificateEntity-1"), + "activity": String("activity-d-6"), + "source": String("CertificateEntity-6"), }, ], "was_generated_by": Array [ - String("activity-1"), - String("activity-2"), + String("activity-6"), + String("activity-7"), ], "was_quoted_from": Array [ Object { - "activity": String("activity-q-1"), - "source": String("CertificateEntity-1"), + "activity": String("activity-q-6"), + "source": String("CertificateEntity-6"), }, ], "was_revision_of": Array [ Object { - "activity": String("activity-r-1"), - "source": String("CertificateEntity-1"), + "activity": String("activity-r-6"), + "source": String("CertificateEntity-6"), }, ], }, @@ -1753,43 +1757,43 @@ roles: "certIDAttribute": String("certIDAttribute-value"), "had_primary_source": Array [ Object { - "activity": String("activity-ps-2"), - "source": String("CertificateEntity-2"), + "activity": String("activity-ps-5"), + "source": String("CertificateEntity-5"), }, ], - "id": String("CertificateEntity-2"), + "id": String("CertificateEntity-5"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "agent": String("agent-2"), + "agent": String("agent-5"), "role": String("CERTIFIER"), }, Object { - "agent": String("agent-2"), + "agent": String("agent-5"), "role": String("MANUFACTURER"), }, ], "was_derived_from": Array [ Object { - "activity": String("activity-d-2"), - "source": String("CertificateEntity-2"), + "activity": String("activity-d-5"), + "source": String("CertificateEntity-5"), }, ], "was_generated_by": Array [ - String("activity-2"), - String("activity-3"), + String("activity-5"), + String("activity-6"), ], "was_quoted_from": Array [ Object { - "activity": String("activity-q-2"), - "source": String("CertificateEntity-2"), + "activity": String("activity-q-5"), + "source": String("CertificateEntity-5"), }, ], "was_revision_of": Array [ Object { - "activity": String("activity-r-2"), - "source": String("CertificateEntity-2"), + "activity": String("activity-r-5"), + "source": String("CertificateEntity-5"), }, ], }, @@ -1797,43 +1801,43 @@ roles: "certIDAttribute": String("certIDAttribute-value"), "had_primary_source": Array [ Object { - "activity": String("activity-ps-3"), - "source": String("CertificateEntity-3"), + "activity": String("activity-ps-4"), + "source": String("CertificateEntity-4"), }, ], - "id": String("CertificateEntity-3"), + "id": String("CertificateEntity-4"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "agent": String("agent-3"), + "agent": String("agent-4"), "role": String("CERTIFIER"), }, Object { - "agent": String("agent-3"), + "agent": String("agent-4"), "role": String("MANUFACTURER"), }, ], "was_derived_from": Array [ Object { - "activity": String("activity-d-3"), - "source": String("CertificateEntity-3"), + "activity": String("activity-d-4"), + "source": String("CertificateEntity-4"), }, ], "was_generated_by": Array [ - String("activity-3"), String("activity-4"), + String("activity-5"), ], "was_quoted_from": Array [ Object { - "activity": String("activity-q-3"), - "source": String("CertificateEntity-3"), + "activity": String("activity-q-4"), + "source": String("CertificateEntity-4"), }, ], "was_revision_of": Array [ Object { - "activity": String("activity-r-3"), - "source": String("CertificateEntity-3"), + "activity": String("activity-r-4"), + "source": String("CertificateEntity-4"), }, ], }, @@ -1841,43 +1845,43 @@ roles: "certIDAttribute": String("certIDAttribute-value"), "had_primary_source": Array [ Object { - "activity": String("activity-ps-4"), - "source": String("CertificateEntity-4"), + "activity": String("activity-ps-3"), + "source": String("CertificateEntity-3"), }, ], - "id": String("CertificateEntity-4"), + "id": String("CertificateEntity-3"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "agent": String("agent-4"), + "agent": String("agent-3"), "role": String("CERTIFIER"), }, Object { - "agent": String("agent-4"), + "agent": String("agent-3"), "role": String("MANUFACTURER"), }, ], "was_derived_from": Array [ Object { - "activity": String("activity-d-4"), - "source": String("CertificateEntity-4"), + "activity": String("activity-d-3"), + "source": String("CertificateEntity-3"), }, ], "was_generated_by": Array [ + String("activity-3"), String("activity-4"), - String("activity-5"), ], "was_quoted_from": Array [ Object { - "activity": String("activity-q-4"), - "source": String("CertificateEntity-4"), + "activity": String("activity-q-3"), + "source": String("CertificateEntity-3"), }, ], "was_revision_of": Array [ Object { - "activity": String("activity-r-4"), - "source": String("CertificateEntity-4"), + "activity": String("activity-r-3"), + "source": String("CertificateEntity-3"), }, ], }, @@ -1885,43 +1889,43 @@ roles: "certIDAttribute": String("certIDAttribute-value"), "had_primary_source": Array [ Object { - "activity": String("activity-ps-5"), - "source": String("CertificateEntity-5"), + "activity": String("activity-ps-2"), + "source": String("CertificateEntity-2"), }, ], - "id": String("CertificateEntity-5"), + "id": String("CertificateEntity-2"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "agent": String("agent-5"), + "agent": String("agent-2"), "role": String("CERTIFIER"), }, Object { - "agent": String("agent-5"), + "agent": String("agent-2"), "role": String("MANUFACTURER"), }, ], "was_derived_from": Array [ Object { - "activity": String("activity-d-5"), - "source": String("CertificateEntity-5"), + "activity": String("activity-d-2"), + "source": String("CertificateEntity-2"), }, ], "was_generated_by": Array [ - String("activity-5"), - String("activity-6"), + String("activity-2"), + String("activity-3"), ], "was_quoted_from": Array [ Object { - "activity": String("activity-q-5"), - "source": String("CertificateEntity-5"), + "activity": String("activity-q-2"), + "source": String("CertificateEntity-2"), }, ], "was_revision_of": Array [ Object { - "activity": String("activity-r-5"), - "source": String("CertificateEntity-5"), + "activity": String("activity-r-2"), + "source": String("CertificateEntity-2"), }, ], }, @@ -1929,43 +1933,43 @@ roles: "certIDAttribute": String("certIDAttribute-value"), "had_primary_source": Array [ Object { - "activity": String("activity-ps-6"), - "source": String("CertificateEntity-6"), + "activity": String("activity-ps-1"), + "source": String("CertificateEntity-1"), }, ], - "id": String("CertificateEntity-6"), + "id": String("CertificateEntity-1"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "agent": String("agent-6"), + "agent": String("agent-1"), "role": String("CERTIFIER"), }, Object { - "agent": String("agent-6"), + "agent": String("agent-1"), "role": String("MANUFACTURER"), }, ], "was_derived_from": Array [ Object { - "activity": String("activity-d-6"), - "source": String("CertificateEntity-6"), + "activity": String("activity-d-1"), + "source": String("CertificateEntity-1"), }, ], "was_generated_by": Array [ - String("activity-6"), - String("activity-7"), + String("activity-1"), + String("activity-2"), ], "was_quoted_from": Array [ Object { - "activity": String("activity-q-6"), - "source": String("CertificateEntity-6"), + "activity": String("activity-q-1"), + "source": String("CertificateEntity-1"), }, ], "was_revision_of": Array [ Object { - "activity": String("activity-r-6"), - "source": String("CertificateEntity-6"), + "activity": String("activity-r-1"), + "source": String("CertificateEntity-1"), }, ], }, @@ -1973,43 +1977,39 @@ roles: "certIDAttribute": String("certIDAttribute-value"), "had_primary_source": Array [ Object { - "activity": String("activity-ps-7"), - "source": String("CertificateEntity-7"), + "activity": String("activity-ps-0"), + "source": String("CertificateEntity-0"), }, ], - "id": String("CertificateEntity-7"), + "id": String("CertificateEntity-0"), "namespace_name": String("default"), "namespace_uuid": String("00000000-0000-0000-0000-000000000000"), "was_attributed_to": Array [ Object { - "agent": String("agent-7"), + "agent": String("agent-0"), "role": String("CERTIFIER"), }, - Object { - "agent": String("agent-7"), - "role": String("MANUFACTURER"), - }, ], "was_derived_from": Array [ Object { - "activity": String("activity-d-7"), - "source": String("CertificateEntity-7"), + "activity": String("activity-d-0"), + "source": String("CertificateEntity-0"), }, ], "was_generated_by": Array [ - String("activity-7"), - String("activity-8"), + String("activity-0"), + String("activity-1"), ], "was_quoted_from": Array [ Object { - "activity": String("activity-q-7"), - "source": String("CertificateEntity-7"), + "activity": String("activity-q-0"), + "source": String("CertificateEntity-0"), }, ], "was_revision_of": Array [ Object { - "activity": String("activity-r-7"), - "source": String("CertificateEntity-7"), + "activity": String("activity-r-0"), + "source": String("CertificateEntity-0"), }, ], }, diff --git a/crates/chronicle-arrow/src/query/activity.rs b/crates/chronicle-arrow/src/query/activity.rs index b8a2a0700..740d0e65d 100644 --- a/crates/chronicle-arrow/src/query/activity.rs +++ b/crates/chronicle-arrow/src/query/activity.rs @@ -14,8 +14,8 @@ use uuid::Uuid; use chronicle_persistence::{ query::{Activity, Association, Delegation, Generation, Namespace, Usage, WasInformedBy}, schema::{ - activity, agent, association, delegation, entity, generation, namespace, usage, - wasinformedby, + activity, activity_block_info, agent, association, delegation, entity, generation, + namespace, usage, wasinformedby, }, }; use common::{ @@ -294,8 +294,12 @@ pub async fn load_activities_by_type( Some(typ_value) => activity::table .inner_join(namespace::table.on(activity::namespace_id.eq(namespace::id))) + .inner_join( + activity_block_info::table + .on(activity::id.eq(activity_block_info::activity_id)), + ) .filter(activity::domaintype.eq(typ_value.external_id_part())) - .order(activity::id) + .order(activity_block_info::block_time) .select((Activity::as_select(), Namespace::as_select())) .offset(position as i64) .limit(max_records as i64) @@ -304,8 +308,12 @@ pub async fn load_activities_by_type( None => activity::table .inner_join(namespace::table.on(activity::namespace_id.eq(namespace::id))) + .inner_join( + activity_block_info::table + .on(activity::id.eq(activity_block_info::activity_id)), + ) .filter(activity::domaintype.is_null()) - .order(activity::id) + .order(activity_block_info::block_time) .select((Activity::as_select(), Namespace::as_select())) .offset(position as i64) .limit(max_records as i64) diff --git a/crates/chronicle-arrow/src/query/agent.rs b/crates/chronicle-arrow/src/query/agent.rs index ec05151db..8bf066935 100644 --- a/crates/chronicle-arrow/src/query/agent.rs +++ b/crates/chronicle-arrow/src/query/agent.rs @@ -11,7 +11,7 @@ use uuid::Uuid; use chronicle_persistence::{ query::{Agent, Attribution, Delegation, Namespace}, - schema::{activity, agent, attribution, delegation, entity, namespace}, + schema::{activity, agent, agent_block_info, attribution, delegation, entity, namespace}, }; use common::{ attributes::Attributes, @@ -297,8 +297,9 @@ pub async fn load_agents_by_type( Some(typ_value) => agent::table .inner_join(namespace::table.on(agent::namespace_id.eq(namespace::id))) + .inner_join(agent_block_info::table.on(agent::id.eq(agent_block_info::agent_id))) .filter(agent::domaintype.eq(typ_value.external_id_part())) - .order(agent::id) + .order(agent_block_info::block_time.desc()) .select((Agent::as_select(), Namespace::as_select())) .offset(position as i64) .limit(max_records as i64) @@ -307,8 +308,9 @@ pub async fn load_agents_by_type( None => agent::table .inner_join(namespace::table.on(agent::namespace_id.eq(namespace::id))) + .inner_join(agent_block_info::table.on(agent::id.eq(agent_block_info::agent_id))) .filter(agent::domaintype.is_null()) - .order(agent::id) + .order(agent_block_info::block_time.desc()) .select((Agent::as_select(), Namespace::as_select())) .offset(position as i64) .limit(max_records as i64) diff --git a/crates/chronicle-arrow/src/query/entity.rs b/crates/chronicle-arrow/src/query/entity.rs index 5e4a56f6c..8bd647e88 100644 --- a/crates/chronicle-arrow/src/query/entity.rs +++ b/crates/chronicle-arrow/src/query/entity.rs @@ -12,7 +12,8 @@ use uuid::Uuid; use chronicle_persistence::{ query::{Attribution, Derivation, Entity, Generation, Namespace}, schema::{ - activity, agent, attribution, derivation, entity, entity_attribute, generation, namespace, + activity, agent, attribution, derivation, entity, entity_attribute, entity_block_info, + generation, namespace, }, }; use common::{ @@ -348,8 +349,9 @@ pub async fn load_entities_by_type( let entities_and_namespaces: Vec<(Entity, Namespace)> = if let Some(typ_value) = typ { entity::table .inner_join(namespace::table.on(entity::namespace_id.eq(namespace::id))) + .inner_join(entity_block_info::table.on(entity::id.eq(entity_block_info::entity_id))) .filter(entity::domaintype.eq(typ_value.external_id_part())) - .order(entity::id) + .order(entity_block_info::block_time.desc()) .select((Entity::as_select(), Namespace::as_select())) .offset(position as i64) .limit(max_records as i64) @@ -358,8 +360,9 @@ pub async fn load_entities_by_type( } else { entity::table .inner_join(namespace::table.on(entity::namespace_id.eq(namespace::id))) + .inner_join(entity_block_info::table.on(entity::id.eq(entity_block_info::entity_id))) .filter(entity::domaintype.is_null()) - .order(entity::id) + .order(entity_block_info::block_time.desc()) .select((Entity::as_select(), Namespace::as_select())) .offset(position as i64) .limit(max_records as i64) diff --git a/crates/chronicle-persistence/src/lib.rs b/crates/chronicle-persistence/src/lib.rs index 5579d2981..1d51588c8 100644 --- a/crates/chronicle-persistence/src/lib.rs +++ b/crates/chronicle-persistence/src/lib.rs @@ -1,6 +1,6 @@ use std::{str::FromStr, time::Duration}; -use chrono::{TimeZone, Utc}; +use chrono::{DateTime, NaiveDateTime, TimeZone, Utc}; use common::{ attributes::Attribute, prov::{ @@ -211,12 +211,12 @@ impl Store { Ok(schema::agent::table .filter(dsl::external_id.eq(external_id).and(dsl::namespace_id.eq(nsid))) - .first::(connection) + .select(query::Agent::as_select()) + .limit(1) + .first(connection) .await?) } - /// Apply an activity to persistent storage, name + namespace are a key, so we update times + - /// domaintype on conflict #[instrument(level = "trace", skip(self, connection), ret(Debug))] async fn apply_activity( &self, @@ -224,6 +224,8 @@ impl Store { Activity { ref external_id, namespace_id, started, ended, domaintype_id, attributes, .. }: &Activity, + block_time: u64, + block_hash: &BlockId, ) -> Result<(), StoreError> { use schema::activity as dsl; let (_, nsid) = self @@ -269,6 +271,23 @@ impl Store { .activity_by_activity_external_id_and_namespace(connection, external_id, namespace_id) .await?; + diesel::insert_into(schema::activity_block_info::table) + .values(( + schema::activity_block_info::activity_id.eq(id), + schema::activity_block_info::block_time + .eq(NaiveDateTime::from_timestamp_millis(block_time as i64)), + schema::activity_block_info::block_hash.eq(Some(block_hash.to_string())), + )) + .on_conflict(schema::activity_block_info::activity_id) + .do_update() + .set(( + schema::activity_block_info::block_time + .eq(NaiveDateTime::from_timestamp_millis(block_time as i64)), + schema::activity_block_info::block_hash.eq(Some(block_hash.to_string())), + )) + .execute(connection) + .await?; + diesel::insert_into(schema::activity_attribute::table) .values( attributes @@ -287,14 +306,13 @@ impl Store { Ok(()) } - /// Apply an agent to persistent storage, external_id + namespace are a key, so we update - /// publickey + domaintype on conflict current is a special case, only relevant to local CLI - /// context. A possibly improved design would be to store this in another table given its scope #[instrument(level = "trace", skip(self, connection), ret(Debug))] async fn apply_agent( &self, connection: &mut AsyncPgConnection, Agent { ref external_id, namespaceid, domaintypeid, attributes, .. }: &Agent, + block_time: u64, + block_hash: &BlockId, ) -> Result<(), StoreError> { use schema::agent::dsl; let (_, nsid) = self @@ -315,7 +333,6 @@ impl Store { .values(( dsl::external_id.eq(external_id), dsl::namespace_id.eq(nsid), - dsl::current.eq(0), dsl::domaintype.eq(domaintypeid.as_ref().map(|x| x.external_id_part())), )) .on_conflict((dsl::namespace_id, dsl::external_id)) @@ -328,6 +345,23 @@ impl Store { .agent_by_agent_external_id_and_namespace(connection, external_id, namespaceid) .await?; + diesel::insert_into(schema::agent_block_info::table) + .values(( + schema::agent_block_info::agent_id.eq(id), + schema::agent_block_info::block_time + .eq(NaiveDateTime::from_timestamp_millis(block_time as i64)), + schema::agent_block_info::block_hash.eq(Some(block_hash.to_string())), + )) + .on_conflict(schema::agent_block_info::agent_id) + .do_update() + .set(( + schema::agent_block_info::block_time + .eq(NaiveDateTime::from_timestamp_millis(block_time as i64)), + schema::agent_block_info::block_hash.eq(Some(block_hash.to_string())), + )) + .execute(connection) + .await?; + diesel::insert_into(schema::agent_attribute::table) .values( attributes @@ -351,6 +385,8 @@ impl Store { &self, connection: &mut AsyncPgConnection, Entity { namespace_id, external_id, domaintypeid, attributes, .. }: &Entity, + block_time: u64, + block_hash: &BlockId, ) -> Result<(), StoreError> { use schema::entity::dsl; let (_, nsid) = self @@ -383,6 +419,23 @@ impl Store { .entity_by_entity_external_id_and_namespace(connection, external_id, namespace_id) .await?; + diesel::insert_into(schema::entity_block_info::table) + .values(( + schema::entity_block_info::entity_id.eq(id), + schema::entity_block_info::block_time + .eq(NaiveDateTime::from_timestamp_millis(block_time as i64)), + schema::entity_block_info::block_hash.eq(Some(block_hash.to_string())), + )) + .on_conflict(schema::entity_block_info::entity_id) + .do_update() + .set(( + schema::entity_block_info::block_time + .eq(NaiveDateTime::from_timestamp_millis(block_time as i64)), + schema::entity_block_info::block_hash.eq(Some(block_hash.to_string())), + )) + .execute(connection) + .await?; + diesel::insert_into(schema::entity_attribute::table) .values( attributes @@ -405,18 +458,20 @@ impl Store { &self, connection: &mut AsyncPgConnection, model: &ProvModel, + timestamp: u64, + block_hash: BlockId, ) -> Result<(), StoreError> { for (_, ns) in model.namespaces.iter() { self.apply_namespace(connection, ns).await? } for (_, agent) in model.agents.iter() { - self.apply_agent(connection, agent).await? + self.apply_agent(connection, agent, timestamp, &block_hash).await? } for (_, activity) in model.activities.iter() { - self.apply_activity(connection, activity).await? + self.apply_activity(connection, activity, timestamp, &block_hash).await? } for (_, entity) in model.entities.iter() { - self.apply_entity(connection, entity).await? + self.apply_entity(connection, entity, timestamp, &block_hash).await? } for ((namespaceid, _), association) in model.association.iter() { @@ -486,11 +541,16 @@ impl Store { Ok(()) } - pub async fn apply_prov(&self, prov: &ProvModel) -> Result<(), StoreError> { + pub async fn apply_prov( + &self, + prov: &ProvModel, + block_time: u64, + block_hash: BlockId, + ) -> Result<(), StoreError> { self.connection() .await? .build_transaction() - .run(|connection| Box::pin(self.apply_model(connection, prov))) + .run(|connection| Box::pin(self.apply_model(connection, prov, block_time, block_hash))) .await?; Ok(()) @@ -1210,32 +1270,6 @@ impl Store { Ok(()) } - #[instrument(skip_all)] - pub async fn apply_use_agent( - &self, - connection: &mut AsyncPgConnection, - external_id: &ExternalId, - namespace: &ExternalId, - ) -> Result<(), StoreError> { - let (_, nsid) = self.namespace_by_external_id(connection, namespace).await?; - use schema::agent::dsl; - - diesel::update(schema::agent::table.filter(dsl::current.ne(0))) - .set(dsl::current.eq(0)) - .execute(connection) - .await?; - - diesel::update( - schema::agent::table - .filter(dsl::external_id.eq(external_id).and(dsl::namespace_id.eq(nsid))), - ) - .set(dsl::current.eq(1)) - .execute(connection) - .await?; - - Ok(()) - } - #[instrument(skip_all)] pub async fn prov_model_for_agent_id( &self, @@ -1272,6 +1306,7 @@ impl Store { .filter(schema::agent::external_id.eq(id.external_id_part())) .filter(schema::namespace::external_id.eq(ns)) .select(query::Agent::as_select()) + .limit(1) .first(connection) .await .optional()? @@ -1295,6 +1330,7 @@ impl Store { .filter(schema::activity::external_id.eq(id.external_id_part())) .filter(schema::namespace::external_id.eq(ns)) .select(query::Activity::as_select()) + .limit(1) .first(connection) .await?; @@ -1319,6 +1355,7 @@ impl Store { .filter(schema::activity::external_id.eq(id.external_id_part())) .filter(schema::namespace::external_id.eq(ns)) .select(query::Activity::as_select()) + .limit(1) .first(connection) .await .optional()? @@ -1342,6 +1379,7 @@ impl Store { .filter(schema::entity::external_id.eq(id.external_id_part())) .filter(schema::namespace::external_id.eq(ns)) .select(query::Entity::as_select()) + .limit(1) .first(connection) .await?; @@ -1366,6 +1404,7 @@ impl Store { .filter(schema::entity::external_id.eq(id.external_id_part())) .filter(schema::namespace::external_id.eq(ns)) .select(query::Entity::as_select()) + .limit(1) .first(connection) .await .optional()? @@ -1391,6 +1430,7 @@ impl Store { .filter(schema::entity::external_id.eq(id.external_id_part())) .filter(schema::namespace::external_id.eq(ns)) .select(query::Entity::as_select()) + .limit(1) .first(connection) .await .optional()? @@ -1400,6 +1440,7 @@ impl Store { .filter(schema::activity::external_id.eq(id.external_id_part())) .filter(schema::namespace::external_id.eq(ns)) .select(query::Activity::as_select()) + .limit(1) .first(connection) .await .optional()? diff --git a/crates/chronicle-persistence/src/query.rs b/crates/chronicle-persistence/src/query.rs index 5b5de60ea..bf4b36627 100644 --- a/crates/chronicle-persistence/src/query.rs +++ b/crates/chronicle-persistence/src/query.rs @@ -75,10 +75,19 @@ pub struct Agent { pub external_id: String, pub namespace_id: i32, pub domaintype: Option, - pub current: i32, pub identity_id: Option, } +#[derive(Queryable, Selectable, Identifiable)] +#[diesel(table_name = crate::schema::agent_block_info)] +#[diesel(belongs_to(Agent, foreign_key = agent_id))] +#[diesel(primary_key(agent_id))] +pub struct AgentBlockInfo { + pub agent_id: i32, + pub block_time: Option, + pub block_hash: Option, +} + #[derive(Debug, Queryable, Selectable, Identifiable, PartialEq)] #[diesel(belongs_to(Usage))] #[diesel(belongs_to(Generation))] @@ -92,6 +101,15 @@ pub struct Activity { pub ended: Option, } +#[derive(Queryable, Selectable, Identifiable)] +#[diesel(table_name = crate::schema::activity_block_info)] +#[diesel(belongs_to(Activity, foreign_key = activity_id))] +#[diesel(primary_key(activity_id))] +pub struct ActivityBlockInfo { + pub activity_id: i32, + pub block_time: Option, + pub block_hash: Option, +} #[derive(Debug, Queryable, Identifiable, Associations, Selectable)] #[diesel(belongs_to(Generation, foreign_key = id))] #[diesel(belongs_to(Usage, foreign_key = id))] @@ -105,6 +123,16 @@ pub struct Entity { pub domaintype: Option, } +#[derive(Queryable, Selectable, Identifiable)] +#[diesel(table_name = crate::schema::entity_block_info)] +#[diesel(belongs_to(Entity, foreign_key = entity_id))] +#[diesel(primary_key(entity_id))] +pub struct EntityBlockInfo { + pub entity_id: i32, + pub block_time: Option, + pub block_hash: Option, +} + #[derive(Debug, Queryable, Selectable, Identifiable, Associations, PartialEq)] #[diesel(table_name = wasinformedby)] #[diesel(primary_key(activity_id, informing_activity_id))] @@ -185,6 +213,5 @@ pub struct Derivation { pub struct NewAgent<'a> { pub external_id: &'a str, pub namespace_id: i32, - pub current: i32, pub domaintype: Option<&'a str>, } diff --git a/crates/chronicle-persistence/src/queryable.rs b/crates/chronicle-persistence/src/queryable.rs index a86fdc871..25b0d20f9 100644 --- a/crates/chronicle-persistence/src/queryable.rs +++ b/crates/chronicle-persistence/src/queryable.rs @@ -9,10 +9,8 @@ pub struct Agent { pub external_id: String, pub namespace_id: i32, pub domaintype: Option, - pub current: i32, pub identity_id: Option, } - #[derive(Default, Queryable, Selectable, SimpleObject)] #[diesel(table_name = crate::schema::activity)] pub struct Activity { @@ -23,7 +21,6 @@ pub struct Activity { pub started: Option, pub ended: Option, } - #[derive(Queryable, Selectable, SimpleObject)] #[diesel(table_name = crate::schema::entity)] pub struct Entity { @@ -33,6 +30,14 @@ pub struct Entity { pub domaintype: Option, } +#[derive(Queryable, Selectable, SimpleObject)] +#[diesel(table_name = crate::schema::entity_block_info)] +pub struct EntityBlockInfo { + pub entity_id: i32, + pub block_time: Option, + pub block_hash: Option, +} + #[derive(Default, Queryable)] pub struct Namespace { _id: i32, diff --git a/crates/chronicle-persistence/src/schema.rs b/crates/chronicle-persistence/src/schema.rs index 388e8ca4b..229059e45 100644 --- a/crates/chronicle-persistence/src/schema.rs +++ b/crates/chronicle-persistence/src/schema.rs @@ -19,13 +19,20 @@ diesel::table! { } } +diesel::table! { + activity_block_info (activity_id) { + activity_id -> Int4, + block_time -> Nullable, + block_hash -> Nullable, + } +} + diesel::table! { agent (id) { id -> Int4, external_id -> Text, namespace_id -> Int4, domaintype -> Nullable, - current -> Int4, identity_id -> Nullable, } } @@ -38,6 +45,14 @@ diesel::table! { } } +diesel::table! { + agent_block_info (agent_id) { + agent_id -> Int4, + block_time -> Nullable, + block_hash -> Nullable, + } +} + diesel::table! { association (agent_id, activity_id, role) { agent_id -> Int4, @@ -89,6 +104,14 @@ diesel::table! { } } +diesel::table! { + entity_block_info (entity_id) { + entity_id -> Int4, + block_time -> Nullable, + block_hash -> Nullable, + } +} + diesel::table! { generation (activity_id, generated_entity_id) { activity_id -> Int4, @@ -143,9 +166,11 @@ diesel::table! { diesel::joinable!(activity -> namespace (namespace_id)); diesel::joinable!(activity_attribute -> activity (activity_id)); +diesel::joinable!(activity_block_info -> activity (activity_id)); diesel::joinable!(agent -> identity (identity_id)); diesel::joinable!(agent -> namespace (namespace_id)); diesel::joinable!(agent_attribute -> agent (agent_id)); +diesel::joinable!(agent_block_info -> agent (agent_id)); diesel::joinable!(association -> activity (activity_id)); diesel::joinable!(association -> agent (agent_id)); diesel::joinable!(attribution -> agent (agent_id)); @@ -154,6 +179,7 @@ diesel::joinable!(delegation -> activity (activity_id)); diesel::joinable!(derivation -> activity (activity_id)); diesel::joinable!(entity -> namespace (namespace_id)); diesel::joinable!(entity_attribute -> entity (entity_id)); +diesel::joinable!(entity_block_info -> entity (entity_id)); diesel::joinable!(generation -> activity (activity_id)); diesel::joinable!(generation -> entity (generated_entity_id)); diesel::joinable!(hadidentity -> agent (agent_id)); @@ -165,14 +191,17 @@ diesel::joinable!(usage -> entity (entity_id)); diesel::allow_tables_to_appear_in_same_query!( activity, activity_attribute, + activity_block_info, agent, agent_attribute, + agent_block_info, association, attribution, delegation, derivation, entity, entity_attribute, + entity_block_info, generation, hadidentity, identity, diff --git a/crates/chronicle-telemetry/src/telemetry.rs b/crates/chronicle-telemetry/src/telemetry.rs index 8d1f098f5..35b6bd029 100644 --- a/crates/chronicle-telemetry/src/telemetry.rs +++ b/crates/chronicle-telemetry/src/telemetry.rs @@ -1,9 +1,9 @@ use opentelemetry::{global, logs::LogError, metrics::MetricsError, trace::TraceError}; use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; use opentelemetry_sdk::{runtime, trace as sdktrace}; +use std::sync::atomic::{AtomicBool, Ordering}; use tracing_opentelemetry::{MetricsLayer, OpenTelemetryLayer}; use tracing_subscriber::{fmt::format::FmtSpan, prelude::*, EnvFilter}; -use std::sync::atomic::{AtomicBool, Ordering}; // Global state to ensure telemetry is only initialized once static TELEMETRY_INITIALIZED: AtomicBool = AtomicBool::new(false); diff --git a/crates/chronicle-test-infrastructure/Cargo.toml b/crates/chronicle-test-infrastructure/Cargo.toml index f5e6fb3e9..ac3440393 100644 --- a/crates/chronicle-test-infrastructure/Cargo.toml +++ b/crates/chronicle-test-infrastructure/Cargo.toml @@ -33,6 +33,7 @@ pallet-chronicle = { path = "../pallet-chronicle" } parity-scale-codec = { version = "3.6", default-features = false, features = [ "derive", ] } +pallet-timestamp = { git = 'https://github.com/paritytech/polkadot-sdk.git', tag = 'polkadot-v1.9.0', default-features = false } portpicker = { workspace = true } protocol-abstract = { path = "../protocol-abstract" } protocol-substrate = { path = "../protocol-substrate" } diff --git a/crates/chronicle-test-infrastructure/src/substitutes/mockchain.rs b/crates/chronicle-test-infrastructure/src/substitutes/mockchain.rs index b02ac9221..ab3d416a4 100644 --- a/crates/chronicle-test-infrastructure/src/substitutes/mockchain.rs +++ b/crates/chronicle-test-infrastructure/src/substitutes/mockchain.rs @@ -13,6 +13,7 @@ frame_support::construct_runtime!( { System: frame_system, ChronicleModule: pallet_chronicle, + Timestamp: pallet_timestamp } ); @@ -48,6 +49,13 @@ impl frame_system::Config for Test { type Version = (); } +impl pallet_timestamp::Config for Test { + type MinimumPeriod = ConstU64<1>; + type Moment = u64; + type OnTimestampSet = (); + type WeightInfo = (); +} + impl pallet_chronicle::Config for Test { type OperationSubmission = protocol_substrate_chronicle::common::ledger::OperationSubmission; type RuntimeEvent = RuntimeEvent; diff --git a/crates/chronicle-test-infrastructure/src/substitutes/mod.rs b/crates/chronicle-test-infrastructure/src/substitutes/mod.rs index 83d183f1c..08ee6507a 100644 --- a/crates/chronicle-test-infrastructure/src/substitutes/mod.rs +++ b/crates/chronicle-test-infrastructure/src/substitutes/mod.rs @@ -67,34 +67,22 @@ impl<'a> TemporaryDatabase<'a> { } pub fn is_running_in_container() -> bool { - Path::new("/.dockerenv").exists() + Path::new("/.dockerenv").exists() } impl<'a> Default for TemporaryDatabase<'a> { fn default() -> Self { let container = CLIENT.run(Postgres::default()); - let port = if is_running_in_container() { - 5432 - } else { - - container.get_host_port_ipv4(5432) - }; + let port = + if is_running_in_container() { 5432 } else { container.get_host_port_ipv4(5432) }; - let ip = if is_running_in_container() { + let ip = if is_running_in_container() { container.get_bridge_ip_address().to_string() - } else { - "127.0.0.1".to_owned() + "127.0.0.1".to_owned() }; - Self { - db_uri: format!( - "postgresql://postgres@{}:{}/", - ip, - port - ), - container, - } + Self { db_uri: format!("postgresql://postgres@{}:{}/", ip, port), container } } } diff --git a/crates/chronicle-test-infrastructure/src/substitutes/stubstrate.rs b/crates/chronicle-test-infrastructure/src/substitutes/stubstrate.rs index db051beda..beda8f77e 100644 --- a/crates/chronicle-test-infrastructure/src/substitutes/stubstrate.rs +++ b/crates/chronicle-test-infrastructure/src/substitutes/stubstrate.rs @@ -113,8 +113,13 @@ impl LedgerWriter for Stubstrate { let opa_event = match ev { RuntimeEvent::ChronicleModule(event) => match event { - Event::::Applied(diff, identity, correlation_id) => - Some(ChronicleEvent::Committed { diff, identity, correlation_id }), + Event::::Applied(diff, identity, correlation_id, timestamp) => + Some(ChronicleEvent::Committed { + diff, + identity, + correlation_id, + timestamp, + }), Event::::Contradiction(contradiction, identity, correlation_id) => Some(ChronicleEvent::Contradicted { contradiction, diff --git a/crates/common/src/identity.rs b/crates/common/src/identity.rs index d4c3953fc..9297ce1c6 100644 --- a/crates/common/src/identity.rs +++ b/crates/common/src/identity.rs @@ -382,7 +382,7 @@ mod tests { "resource": "users", "action": "read" }); - let state = json!([{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]); + let state = json!([{"id": 1u8, "name": "Alice"}, {"id": 2u8, "name": "Bob"}]); let context = OpaData::graphql(&identity, &operation, &state); let json = serde_json::to_string(&context).unwrap(); diff --git a/crates/opactl/Cargo.toml b/crates/opactl/Cargo.toml index b11233478..0f2f57e5f 100644 --- a/crates/opactl/Cargo.toml +++ b/crates/opactl/Cargo.toml @@ -40,6 +40,8 @@ frame-system = { git = 'https://github.com/paritytech/polkadot-sdk.git', tag = ' hex = { workspace = true } insta = { workspace = true, features = ["yaml"] } pallet-opa = { path = "../pallet-opa", features = ["std"] } +pallet-timestamp = { git = 'https://github.com/paritytech/polkadot-sdk.git', tag = 'polkadot-v1.9.0', default-features = false } + parity-scale-codec = { version = "3.6", default-features = false, features = [ "derive", ] } diff --git a/crates/opactl/src/test/mockchain.rs b/crates/opactl/src/test/mockchain.rs index f7f9f17f2..645bac632 100644 --- a/crates/opactl/src/test/mockchain.rs +++ b/crates/opactl/src/test/mockchain.rs @@ -13,6 +13,7 @@ frame_support::construct_runtime!( { System: frame_system, OpaModule: pallet_opa, + Timestamp: pallet_timestamp } ); @@ -48,6 +49,13 @@ impl frame_system::Config for Test { type Version = (); } +impl pallet_timestamp::Config for Test { + type MinimumPeriod = ConstU64<1>; + type OnTimestampSet = (); + type WeightInfo = (); + type Moment = u64; +} + impl pallet_opa::Config for Test { type OpaSubmission = common::opa::codec::OpaSubmissionV1; type RuntimeEvent = RuntimeEvent; diff --git a/crates/pallet-chronicle/Cargo.toml b/crates/pallet-chronicle/Cargo.toml index 7bd782d82..191dc3314 100644 --- a/crates/pallet-chronicle/Cargo.toml +++ b/crates/pallet-chronicle/Cargo.toml @@ -17,6 +17,7 @@ frame-system = { git = 'https://github.com/paritytech/polkadot-sdk.git', tag = ' sp-core = { git = 'https://github.com/paritytech/polkadot-sdk.git', tag = 'polkadot-v1.9.0', default-features = false } sp-std = { git = 'https://github.com/paritytech/polkadot-sdk.git', tag = 'polkadot-v1.9.0', default-features = false } sp-runtime = { git = 'https://github.com/paritytech/polkadot-sdk.git', tag = 'polkadot-v1.9.0', default-features = false } +pallet-timestamp = { git = 'https://github.com/paritytech/polkadot-sdk.git', tag = 'polkadot-v1.9.0', default-features = false } macro-attr-2018 = { workspace = true } newtype-derive-2018 = { workspace = true } parity-scale-codec = { version = "3.6", default-features = false, features = [ diff --git a/crates/pallet-chronicle/src/lib.rs b/crates/pallet-chronicle/src/lib.rs index e5c626114..c737afd55 100644 --- a/crates/pallet-chronicle/src/lib.rs +++ b/crates/pallet-chronicle/src/lib.rs @@ -25,6 +25,8 @@ pub mod chronicle_core { pub use weights::*; +use pallet_timestamp::{self as timestamp}; + // A configuration type for opa settings, serializable to JSON etc #[derive(frame_support::Serialize, frame_support::Deserialize)] pub struct OpaConfiguration { @@ -46,7 +48,7 @@ pub mod pallet { /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] - pub trait Config: frame_system::Config { + pub trait Config: frame_system::Config + timestamp::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// Type representing the weight of this pallet @@ -100,7 +102,12 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub (super) fn deposit_event)] pub enum Event { - Applied(common::prov::ProvModel, common::identity::SignedIdentity, [u8; 32]), + Applied( + common::prov::ProvModel, + common::identity::SignedIdentity, + [u8; 32], + ::Moment, + ), Contradiction(common::prov::Contradiction, common::identity::SignedIdentity, [u8; 32]), } @@ -157,7 +164,7 @@ pub mod pallet { // contradiction #[pallet::call_index(0)] #[pallet::weight({ - let weight = T::WeightInfo::operation_weight(& operations.items); + let weight = ::WeightInfo::operation_weight(& operations.items); let dispatch_class = DispatchClass::Normal; let pays_fee = Pays::No; (weight, dispatch_class, pays_fee) @@ -220,17 +227,18 @@ pub mod pallet { for common::ledger::StateOutput { address, data } in dirty { delta.combine(&data); - // Update storage. Provenance::::set(&address, Some(data)); } - // Emit an event. + let now = >::get(); + Self::deposit_event(Event::Applied( delta, (*operations.identity).clone(), operations.correlation_id, + now, )); - // Return a successful DispatchResultWithPostInfo + Ok(()) } } diff --git a/crates/pallet-chronicle/src/mock.rs b/crates/pallet-chronicle/src/mock.rs index f03eb5fb2..e931db80a 100644 --- a/crates/pallet-chronicle/src/mock.rs +++ b/crates/pallet-chronicle/src/mock.rs @@ -15,6 +15,7 @@ frame_support::construct_runtime!( { System: frame_system, ChronicleModule: crate, + Timestamp: pallet_timestamp } ); @@ -56,6 +57,13 @@ impl pallet_template::Config for Test { type WeightInfo = (); } +impl pallet_timestamp::Config for Test { + type MinimumPeriod = ConstU64<1>; + type Moment = u64; + type OnTimestampSet = (); + type WeightInfo = (); +} + // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { frame_system::GenesisConfig::::default().build_storage().unwrap().into() diff --git a/crates/pallet-chronicle/src/tests.rs b/crates/pallet-chronicle/src/tests.rs index 9d688dd96..64faedb1d 100644 --- a/crates/pallet-chronicle/src/tests.rs +++ b/crates/pallet-chronicle/src/tests.rs @@ -23,6 +23,7 @@ fn it_works_for_default_value() { common::prov::ProvModel::default(), common::identity::SignedIdentity::new_no_identity(), op.correlation_id, + 0, ) .into(), ); @@ -54,6 +55,7 @@ fn single_operation() { delta_model, common::identity::SignedIdentity::new_no_identity(), sub.correlation_id, + 0, ) .into(), ); diff --git a/crates/pallet-chronicle/src/weights.rs b/crates/pallet-chronicle/src/weights.rs index 7a7cb971b..d3fb27034 100644 --- a/crates/pallet-chronicle/src/weights.rs +++ b/crates/pallet-chronicle/src/weights.rs @@ -57,10 +57,13 @@ impl WeightInfo for SubstrateWeight { /// Calculates the weight of processing a vector of Chronicle operations. /// Assumes a worst-case scenario where each operation requires one read and one write, - /// plus a base execution time. + /// plus a base execution time and the overhead of reading the current timestamp. fn operation_weight(ops: &[ChronicleOperation]) -> Weight { let reads_writes = ops.len() as u64 * (T::DbWeight::get().reads(1) + T::DbWeight::get().writes(1)); - Weight::from_parts(9_000_000, 0).saturating_add(reads_writes) + let timestamp_weight = T::DbWeight::get().reads(1); + Weight::from_parts(9_000_000, 0) + .saturating_add(reads_writes) + .saturating_add(timestamp_weight) } } diff --git a/crates/protocol-substrate-chronicle/src/subxt_client.rs b/crates/protocol-substrate-chronicle/src/subxt_client.rs index 3c79ac1d4..7f1c77d8c 100644 --- a/crates/protocol-substrate-chronicle/src/subxt_client.rs +++ b/crates/protocol-substrate-chronicle/src/subxt_client.rs @@ -29,6 +29,7 @@ pub enum ChronicleEvent { diff: common::prov::ProvModel, identity: SignedIdentity, correlation_id: [u8; 32], + timestamp: u64, }, Contradicted { contradiction: common::prov::Contradiction, @@ -48,8 +49,9 @@ impl ChronicleEvent { diff: common::prov::ProvModel, identity: SignedIdentity, correlation_id: [u8; 32], + timestamp: u64, ) -> Self { - ChronicleEvent::Committed { diff, identity, correlation_id } + ChronicleEvent::Committed { diff, identity, correlation_id, timestamp } } pub fn new_contradicted( @@ -67,12 +69,13 @@ fn extract_event( where C: subxt::Config, { - type Applied = (common::prov::ProvModel, common::identity::SignedIdentity, [u8; 32]); + type Applied = (common::prov::ProvModel, common::identity::SignedIdentity, [u8; 32], u64); type Contradicted = (common::prov::Contradiction, common::identity::SignedIdentity, [u8; 32]); match (event.pallet_name(), event.variant_name(), event.field_bytes()) { ("Chronicle", "Applied", mut event_bytes) => match Applied::decode(&mut event_bytes) { - Ok((prov_model, identity, correlation_id)) => - Ok(Some(ChronicleEvent::new_committed(prov_model, identity, correlation_id))), + Ok((prov_model, identity, correlation_id, timestamp)) => Ok(Some( + ChronicleEvent::new_committed(prov_model, identity, correlation_id, timestamp), + )), Err(e) => { tracing::error!("Failed to decode ProvModel: {}", e); Err(e.into()) diff --git a/diesel.toml b/diesel.toml index 35a12ff0d..ccbc3b575 100644 --- a/diesel.toml +++ b/diesel.toml @@ -2,7 +2,7 @@ # see https://diesel.rs/guides/configuring-diesel-cli [print_schema] -file = "src/schema.rs" +file = "crates/chronicle-persistence/src/schema.rs" [migrations_directory] -dir = "migrations" +dir = "crates/chronicle-persistence/migrations"