diff --git a/Cargo.toml b/Cargo.toml index 6733ab65d..63dda172c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ members = [ "cardano-legacy-address", "sparse-array", "typed-bytes", + "chain-watch", ] [profile.bench] diff --git a/chain-watch/Cargo.toml b/chain-watch/Cargo.toml new file mode 100644 index 000000000..7c713c21d --- /dev/null +++ b/chain-watch/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "chain-watch" +version = "0.1.0" +authors = ["Enzo Cioppettini "] +edition = "2018" + +[dependencies] +prost = "0.7" + +[dependencies.tonic] +version = "0.4" +default-features = false +features = ["codegen", "prost"] + +[build-dependencies.tonic-build] +version = "0.4" +default-features = false +features = ["prost"] + +[features] +default = ["tonic/transport", "tonic-build/transport"] \ No newline at end of file diff --git a/chain-watch/build.rs b/chain-watch/build.rs new file mode 100644 index 000000000..98b73b44f --- /dev/null +++ b/chain-watch/build.rs @@ -0,0 +1,3 @@ +fn main() { + tonic_build::compile_protos("proto/watch.proto").unwrap(); +} diff --git a/chain-watch/proto/watch.proto b/chain-watch/proto/watch.proto new file mode 100644 index 000000000..8561bc230 --- /dev/null +++ b/chain-watch/proto/watch.proto @@ -0,0 +1,60 @@ +syntax = "proto3"; + +package iohk.chain.watch; + + +message Block { + bytes content = 1; +} + +message BlockSubscriptionRequest {} + +message TipSubscriptionRequest {} + +message MempoolSubscriptionRequest {} + +message SyncMultiverseRequest { + // send blocks with this chain_length or greater + uint32 from = 1; +} + +message BlockId { + bytes content = 1; +} + +message MempoolEvent { + bytes fragment_id = 1; + oneof event { + MempoolFragmentInserted inserted = 2; + MempoolFragmentRejected rejected = 3; + MempoolFragmentInABlock in_a_block = 4; + }; +} + + +message MempoolFragmentInserted {} + +message MempoolFragmentRejected { + string reason = 1; +} + +message MempoolFragmentInABlock { + BlockId block = 1; +} + + +service SubscriptionService { + // get a stream of blocks succesfully processed by the node, this means they + // are already validated. + // the parent of a block will always be streamed before the block itself. + rpc BlockSubscription(BlockSubscriptionRequest) returns (stream Block); + + // get tip updates + rpc TipSubscription(TipSubscriptionRequest) returns (stream BlockId); + + rpc MempoolSubscription(MempoolSubscriptionRequest) returns (stream MempoolEvent); + + // fetch all blocks from the given initial chainlength to the tip, from all + // possible branches and in increasing order + rpc SyncMultiverse(SyncMultiverseRequest) returns (stream Block); +} \ No newline at end of file diff --git a/chain-watch/src/lib.rs b/chain-watch/src/lib.rs new file mode 100644 index 000000000..3ea3a24cb --- /dev/null +++ b/chain-watch/src/lib.rs @@ -0,0 +1 @@ +tonic::include_proto!("iohk.chain.watch");