-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Expose endpoint to control streams (#430)
This PR exposes a gRPC endpoint for the Block Streamer service to provide control over individual Block Streams. There are currently 3 methods: start/stop/list. The functionality across these methods is quite basic, I didn't want to spend too much time fleshing them out as I'm still not certain on how exactly they will be used. I expect them to Change once the Control Plane starts using them.
- Loading branch information
1 parent
1303013
commit 9c5ee15
Showing
14 changed files
with
721 additions
and
57 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
tonic_build::compile_protos("proto/block_streamer.proto")?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use tonic::Request; | ||
|
||
use block_streamer::block_streamer_client::BlockStreamerClient; | ||
use block_streamer::{start_stream_request::Rule, ActionAnyRule, ListStreamsRequest, Status}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut client = BlockStreamerClient::connect("http://[::1]:10000").await?; | ||
|
||
let response = client | ||
.list_streams(Request::new(ListStreamsRequest {})) | ||
.await?; | ||
|
||
println!("RESPONSE = {:#?}", response); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use tonic::Request; | ||
|
||
use block_streamer::block_streamer_client::BlockStreamerClient; | ||
use block_streamer::{start_stream_request::Rule, ActionAnyRule, StartStreamRequest, Status}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut client = BlockStreamerClient::connect("http://[::1]:10000").await?; | ||
|
||
let response = client | ||
.start_stream(Request::new(StartStreamRequest { | ||
start_block_height: 106700000, | ||
account_id: "morgs.near".to_string(), | ||
function_name: "test".to_string(), | ||
rule: Some(Rule::ActionAnyRule(ActionAnyRule { | ||
affected_account_id: "social.near".to_string(), | ||
status: Status::Success.into(), | ||
})), | ||
})) | ||
.await?; | ||
|
||
println!("RESPONSE = {:?}", response); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use tonic::Request; | ||
|
||
use block_streamer::block_streamer_client::BlockStreamerClient; | ||
use block_streamer::StopStreamRequest; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut client = BlockStreamerClient::connect("http://[::1]:10000").await?; | ||
|
||
let response = client | ||
.stop_stream(Request::new(StopStreamRequest { | ||
// ID for indexer morgs.near/test | ||
stream_id: "16210176318434468568".to_string(), | ||
})) | ||
.await?; | ||
|
||
println!("RESPONSE = {:?}", response); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
syntax = "proto3"; | ||
|
||
package blockstreamer; | ||
|
||
// The BlockStreamer service provides RPCs to manage BlockStream instances. | ||
service BlockStreamer { | ||
// Starts a new BlockStream process. | ||
rpc StartStream (StartStreamRequest) returns (StartStreamResponse); | ||
|
||
// Stops an existing BlockStream process. | ||
rpc StopStream (StopStreamRequest) returns (StopStreamResponse); | ||
|
||
// Lists all current BlockStream processes. | ||
rpc ListStreams (ListStreamsRequest) returns (ListStreamsResponse); | ||
} | ||
|
||
// Request message for starting a BlockStream. | ||
message StartStreamRequest { | ||
// Which block height to start from. | ||
uint64 start_block_height = 1; | ||
// The account ID which the indexer is defined under | ||
string account_id = 2; | ||
// The name of the indexer | ||
string function_name = 3; | ||
// The filter rule to apply to incoming blocks | ||
oneof rule { | ||
ActionAnyRule action_any_rule = 4; | ||
ActionFunctionCallRule action_function_call_rule = 5; | ||
} | ||
} | ||
|
||
// Match any action against the specified account | ||
message ActionAnyRule { | ||
// The account ID pattern to match against | ||
string affected_account_id = 1; | ||
// The status of the action to match against | ||
Status status = 2; | ||
} | ||
|
||
// Match a specific function call against the specified account | ||
message ActionFunctionCallRule { | ||
// The account ID pattern to match against | ||
string affected_account_id = 1; | ||
// The function name to match against | ||
string function_name = 2; | ||
// The status of the action to match against | ||
Status status = 3; | ||
} | ||
|
||
enum Status { | ||
STATUS_UNSPECIFIED = 0; | ||
STATUS_SUCCESS = 1; | ||
STATUS_FAILURE = 2; | ||
STATUS_ANY = 3; | ||
} | ||
|
||
// Response message for starting a BlockStream. | ||
message StartStreamResponse { | ||
// ID or handle of the started BlockStream. | ||
string stream_id = 1; | ||
} | ||
|
||
// Request message for stopping a BlockStream. | ||
message StopStreamRequest { | ||
// ID or handle of the BlockStream to stop. | ||
string stream_id = 1; | ||
} | ||
|
||
// Response message for stopping a BlockStream. | ||
message StopStreamResponse { | ||
// Confirmation message or status. | ||
string status = 1; | ||
} | ||
|
||
// Request message for listing BlockStreams. | ||
message ListStreamsRequest { | ||
// Optional filters or parameters for listing streams. | ||
} | ||
|
||
// Response message for listing BlockStreams. | ||
message ListStreamsResponse { | ||
// List of active BlockStreams. | ||
repeated StreamInfo streams = 1; | ||
} | ||
|
||
// Information about a single BlockStream instance. | ||
message StreamInfo { | ||
string stream_id = 1; | ||
int64 start_block_height = 2; | ||
string indexer_name = 3; | ||
string chain_id = 4; | ||
string status = 5; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod blockstreamer { | ||
tonic::include_proto!("blockstreamer"); | ||
} | ||
|
||
pub use blockstreamer::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.