Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(avalanche-types): bump up rpcchainvm protocol version to 32 #157

Merged
merged 10 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make it compile
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Feb 22, 2024
commit 6604781dd9a61c130975fe902405b206a3622dcf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use crate::{
proto::pb::{
self,
appsender::{
SendAppGossipMsg, SendAppGossipSpecificMsg, SendAppRequestMsg, SendAppResponseMsg,
SendCrossChainAppRequestMsg, SendCrossChainAppResponseMsg,
SendAppErrorMsg, SendAppGossipMsg, SendAppGossipSpecificMsg, SendAppRequestMsg,
SendAppResponseMsg, SendCrossChainAppErrorMsg, SendCrossChainAppRequestMsg,
SendCrossChainAppResponseMsg,
},
google::protobuf::Empty,
},
Expand Down Expand Up @@ -81,6 +82,13 @@ impl pb::appsender::app_sender_server::AppSender for Server {
Ok(Response::new(Empty {}))
}

async fn send_app_error(
&self,
_request: Request<SendAppErrorMsg>,
) -> Result<Response<Empty>, Status> {
unimplemented!("not implemented")
}

async fn send_app_gossip(
&self,
request: Request<SendAppGossipMsg>,
Expand Down Expand Up @@ -172,4 +180,11 @@ impl pb::appsender::app_sender_server::AppSender for Server {

Ok(Response::new(Empty {}))
}

async fn send_cross_chain_app_error(
&self,
_request: Request<SendCrossChainAppErrorMsg>,
) -> Result<Response<Empty>, Status> {
unimplemented!("not implemented")
}
}
92 changes: 20 additions & 72 deletions crates/avalanche-types/src/subnet/rpc/vm/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,27 @@ where
validator_state: ValidatorStateClient::new(client_conn.clone()),
});

let mut versioned_dbs = Vec::with_capacity(req.db_servers.len());
for db_server in req.db_servers.iter() {
let semver = db_server.version.trim_start_matches('v');
let version =
Version::parse(semver).map_err(|e| tonic::Status::unknown(e.to_string()))?;
let server_addr = db_server.server_addr.as_str();

// Create a client connection with the server address
let client_conn = utils::grpc::default_client(server_addr)?
.connect()
.await
.map_err(|e| {
tonic::Status::unknown(format!(
"failed to create client conn from: {server_addr}: {e}",
))
})?;
let mut versioned_dbs = Vec::new();

let vdb = versioned_database::VersionedDatabase::new(
corruptabledb::Database::new_boxed(DatabaseClient::new_boxed(client_conn)),
version,
);
versioned_dbs.push(vdb);
}
// TODO: is this correct?
let version = Version::parse("1.0.0").map_err(|e| tonic::Status::unknown(e.to_string()))?;
let server_addr = req.db_server_addr.as_str();

// Create a client connection with the server address
let client_conn = utils::grpc::default_client(server_addr)?
.connect()
.await
.map_err(|e| {
tonic::Status::unknown(format!(
"failed to create client conn from: {server_addr}: {e}",
))
})?;

let vdb = versioned_database::VersionedDatabase::new(
corruptabledb::Database::new_boxed(DatabaseClient::new_boxed(client_conn.clone())),
version,
);
versioned_dbs.push(vdb);

let (tx_engine, mut rx_engine): (mpsc::Sender<Message>, mpsc::Receiver<Message>) =
mpsc::channel(100);
Expand Down Expand Up @@ -284,56 +282,6 @@ where
}))
}

/// Creates the HTTP handlers for custom VM network calls.
///
/// This creates and exposes handlers that the outside world can use to communicate
/// with a static reference to the VM. Each handler has the path:
/// `\[Address of node]/ext/VM/[VM ID]/[extension\]`
///
/// Returns a mapping from \[extension\]s to HTTP handlers.
///
/// Each extension can specify how locking is managed for convenience.
///
/// For example, it might make sense to have an extension for creating
/// genesis bytes this VM can interpret.
async fn create_static_handlers(
&self,
_req: Request<Empty>,
) -> std::result::Result<Response<vm::CreateStaticHandlersResponse>, tonic::Status> {
log::debug!("create_static_handlers called");

// get handlers from underlying vm
let mut inner_vm = self.vm.write().await;
let handlers = inner_vm.create_static_handlers().await.map_err(|e| {
tonic::Status::unknown(format!("failed to create static handlers: {e}"))
})?;

// create and start gRPC server serving HTTP service for each handler
let mut resp_handlers: Vec<vm::Handler> = Vec::with_capacity(handlers.keys().len());
for (prefix, http_handler) in handlers {
let server_addr = utils::new_socket_addr();
let server = grpc::Server::new(server_addr, self.stop_ch.subscribe());

server
.serve(pb::http::http_server::HttpServer::new(HttpServer::new(
http_handler.handler,
)))
.map_err(|e| {
tonic::Status::unknown(format!("failed to create http service: {e}"))
})?;

let resp_handler = vm::Handler {
prefix,
server_addr: server_addr.to_string(),
};
resp_handlers.push(resp_handler);
}

Ok(Response::new(vm::CreateStaticHandlersResponse {
handlers: resp_handlers,
}))
}

async fn build_block(
&self,
_req: Request<vm::BuildBlockRequest>,
Expand Down
Loading