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

Feature/client versioning 1 #3960

Merged
merged 8 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions massa-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ massa_signature = { path = "../massa-signature" }
massa_time = { path = "../massa-time" }
massa_sdk = { path = "../massa-sdk" }
massa_wallet = { path = "../massa-wallet" }
massa_proto = { path = "../massa-proto" }

[dev-dependencies]
toml_edit = "0.19"
Expand Down
33 changes: 32 additions & 1 deletion massa-client/src/cmds.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 MASSA LABS <info@massa.net>

use crate::display::Output;
use crate::{client_warning, rpc_error};
use crate::{client_warning, grpc_error, rpc_error};
use anyhow::{anyhow, bail, Result};
use console::style;
use massa_api_exports::{
Expand All @@ -22,10 +22,12 @@ use massa_models::{
operation::{Operation, OperationId, OperationType},
slot::Slot,
};
use massa_proto::massa::api::v1 as grpc;
use massa_sdk::Client;
use massa_signature::KeyPair;
use massa_time::MassaTime;
use massa_wallet::Wallet;

use serde::Serialize;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt::Write as _;
Expand Down Expand Up @@ -769,6 +771,35 @@ impl Command {
Command::wallet_generate_secret_key => {
let wallet = wallet_opt.as_mut().unwrap();

// In order to generate a KeyPair we need to get the MIP statuses and use the latest
// active version
let req = grpc::GetMipStatusRequest { id: "".to_string() };
let versioning_status = match client.grpc.get_mip_status(req).await {
Ok(resp_) => {
let resp = resp_.into_inner();
resp.entry
}
Err(e) => {
// FIXME: Should we default to the last known version - default to 0?
grpc_error!(e)
}
};

// Note: unused for now as AddressFactory is not yet merged
let _address_version = versioning_status
.into_iter()
.rev()
.find_map(|entry| {
let state = grpc::ComponentStateId::from_i32(entry.state_id)
.unwrap_or(grpc::ComponentStateId::Error);
match state {
grpc::ComponentStateId::Active => Some(entry.state_id),
_ => None,
}
})
.unwrap_or(0);
println!("Should create address with version: {}", _address_version);

let key = KeyPair::generate();
let ad = wallet.add_keypairs(vec![key])?[0];
if json {
Expand Down
8 changes: 8 additions & 0 deletions massa-client/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ macro_rules! rpc_error {
};
}

#[macro_export]
/// bail a shinny RPC error
macro_rules! grpc_error {
($e:expr) => {
bail!("check if your node is running and grpc api enabled: {}", $e)
};
}

#[macro_export]
/// print a yellow warning
macro_rules! client_warning {
Expand Down
1 change: 1 addition & 0 deletions massa-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ massa_time = { path = "../massa-time" }
massa_wallet = { path = "../massa-wallet" }
massa_serialization = { path = "../massa-serialization" }
massa_proto = { path = "../massa-proto" }
massa_versioning_worker = { path = "../massa-versioning-worker" }

[dev-dependencies]
crossbeam = "0.8.2"
Expand Down
23 changes: 23 additions & 0 deletions massa-grpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,29 @@ pub(crate) fn get_largest_stakers(
})
}

// Get node version
pub(crate) fn get_mip_status(
grpc: &MassaGrpc,
request: tonic::Request<grpc::GetMipStatusRequest>,
) -> Result<grpc::GetMipStatusResponse, GrpcError> {
let mip_store_status_ = grpc.mip_store.get_mip_status();
let mip_store_status: Result<Vec<grpc::MipStatusEntry>, GrpcError> = mip_store_status_
.iter()
aoudiamoncef marked this conversation as resolved.
Show resolved Hide resolved
.map(|(mip_info, state_id_)| {
let state_id = grpc::ComponentStateId::from(state_id_);
Ok(grpc::MipStatusEntry {
mip_info: Some(grpc::MipInfo::from(mip_info)),
state_id: i32::from(state_id),
aoudiamoncef marked this conversation as resolved.
Show resolved Hide resolved
})
})
.collect();

Ok(grpc::GetMipStatusResponse {
id: request.into_inner().id,
entry: mip_store_status?,
})
}

/// Get next block best parents
pub(crate) fn get_next_block_best_parents(
grpc: &MassaGrpc,
Expand Down
10 changes: 9 additions & 1 deletion massa-grpc/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use massa_proto::massa::api::v1 as grpc;

use crate::api::{
get_blocks, get_blocks_by_slots, get_datastore_entries, get_largest_stakers,
get_blocks, get_blocks_by_slots, get_datastore_entries, get_largest_stakers, get_mip_status,
get_next_block_best_parents, get_operations, get_sc_execution_events, get_selector_draws,
get_transactions_throughput, get_version,
};
Expand Down Expand Up @@ -55,6 +55,14 @@ impl grpc::massa_service_server::MassaService for MassaGrpc {
Ok(tonic::Response::new(get_largest_stakers(self, request)?))
}

/// handler for get mip status (versioning)
async fn get_mip_status(
&self,
request: tonic::Request<grpc::GetMipStatusRequest>,
) -> Result<tonic::Response<grpc::GetMipStatusResponse>, tonic::Status> {
Ok(tonic::Response::new(get_mip_status(self, request)?))
}

/// handler for get next block best parents
async fn get_next_block_best_parents(
&self,
Expand Down
4 changes: 4 additions & 0 deletions massa-grpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use massa_proto::massa::api::v1::massa_service_server::MassaServiceServer;
use massa_proto::massa::api::v1::FILE_DESCRIPTOR_SET;
use massa_protocol_exports::ProtocolController;
use massa_storage::Storage;
use massa_versioning_worker::versioning::MipStore;

use tokio::sync::oneshot;
use tonic::{
codec::CompressionEncoding,
Expand Down Expand Up @@ -46,6 +48,8 @@ pub struct MassaGrpc {
pub grpc_config: GrpcConfig,
/// node version
pub version: massa_models::version::Version,
/// mip store
pub mip_store: MipStore,
}

impl MassaGrpc {
Expand Down
12 changes: 11 additions & 1 deletion massa-grpc/src/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ use massa_models::config::{
MAX_DENUNCIATIONS_PER_BLOCK_HEADER, MAX_ENDORSEMENTS_PER_MESSAGE, MAX_FUNCTION_NAME_LENGTH,
MAX_OPERATIONS_PER_BLOCK, MAX_OPERATIONS_PER_MESSAGE, MAX_OPERATION_DATASTORE_ENTRY_COUNT,
MAX_OPERATION_DATASTORE_KEY_LENGTH, MAX_OPERATION_DATASTORE_VALUE_LENGTH, MAX_PARAMETERS_SIZE,
PERIODS_PER_CYCLE, T0, THREAD_COUNT, VERSION,
MIP_STORE_STATS_BLOCK_CONSIDERED, MIP_STORE_STATS_COUNTERS_MAX, PERIODS_PER_CYCLE, T0,
THREAD_COUNT, VERSION,
};
use massa_pool_exports::test_exports::MockPoolController;
use massa_pool_exports::PoolChannels;
use massa_pos_exports::test_exports::MockSelectorController;
use massa_proto::massa::api::v1::massa_service_client::MassaServiceClient;
use massa_protocol_exports::MockProtocolController;
use massa_versioning_worker::versioning::{MipStatsConfig, MipStore};
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
path::PathBuf,
Expand Down Expand Up @@ -94,6 +96,13 @@ async fn test_start_grpc_server() {
client_certificate_authority_root_path: PathBuf::default(),
};

let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
counters_max: MIP_STORE_STATS_COUNTERS_MAX,
};

let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

let service = MassaGrpc {
consensus_controller: Box::new(consensus_controller),
consensus_channels,
Expand All @@ -112,6 +121,7 @@ async fn test_start_grpc_server() {
storage: shared_storage,
grpc_config: grpc_config.clone(),
version: *VERSION,
mip_store,
};

let stop_handle = service.serve(&grpc_config).await.unwrap();
Expand Down
1 change: 1 addition & 0 deletions massa-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ async fn launch(
storage: shared_storage.clone(),
grpc_config: grpc_config.clone(),
version: *VERSION,
mip_store,
};

// HACK maybe should remove timeout later
Expand Down
5 changes: 5 additions & 0 deletions massa-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ prost = "0.11.8"
prost-types = "0.11.8"
tonic = "0.9.1"

[build-dependencies]
aoudiamoncef marked this conversation as resolved.
Show resolved Hide resolved
glob = "0.3.1"
prost-build = "0.11.8"
tonic-build = "0.9.1"

[features]
build-tonic = []
2 changes: 1 addition & 1 deletion massa-proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod tonic {
.map_err(|e| format!("protobuf compilation error: {:?}", e))?;

// Generate documentation for the protobuf API
generate_doc(&protos).map_err(|e| format!("protobuf documentation error: {:?}", e))?;
// generate_doc(&protos).map_err(|e| format!("protobuf documentation error: {:?}", e))?;

// Return Ok if the build and documentation generation were successful
Ok(())
Expand Down
19 changes: 19 additions & 0 deletions massa-proto/proto/massa/api/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "google/api/annotations.proto";
import "google/rpc/status.proto";
import "operation.proto";
import "slot.proto";
import "versioning.proto";

option csharp_namespace = "Com.Massa.Api.V1";
option go_package = "github.com/massalabs/massa/api/v1;v1";
Expand Down Expand Up @@ -96,6 +97,11 @@ service MassaService {
option (google.api.http) = {get: "/v1/version"};
}

// Get
rpc GetMipStatus(GetMipStatusRequest) returns (GetMipStatusResponse) {
option (google.api.http) = {get: "/v1/mip_status"};
}

// ███████╗████████╗██████╗ ███████╗ █████╗ ███╗ ███╗
// ██╔════╝╚══██╔══╝██╔══██╗██╔════╝██╔══██╗████╗ ████║
// ███████╗ ██║ ██████╔╝█████╗ ███████║██╔████╔██║
Expand Down Expand Up @@ -414,6 +420,19 @@ message SelectorDraws {
repeated IndexedSlot next_endorsement_draws = 3;
}

message GetMipStatusRequest {
// Request id
string id = 1;
}

// GetMipStatusResponse holds response from GetMipStatus
message GetMipStatusResponse {
// Request id
string id = 1;
// MipInfo - status id entry
repeated MipStatusEntry entry = 2;
}

// GetTransactionsThroughputRequest holds request for GetTransactionsThroughput
message GetTransactionsThroughputRequest {
// Request id
Expand Down
48 changes: 48 additions & 0 deletions massa-proto/proto/massa/api/v1/versioning.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2023 MASSA LABS <info@massa.net>

syntax = "proto3";

package massa.api.v1;

option csharp_namespace = "Com.Massa.Api.V1";
option go_package = "github.com/massalabs/massa/api/v1;v1";
option java_multiple_files = true;
option java_package = "com.massa.api.v1";
option objc_class_prefix = "GRPC";
option php_namespace = "Com\\Massa\\Api\\V1";
option ruby_package = "Com::Massa::Api::V1";
option swift_prefix = "GRPC";

// Entry for GetMipStatusResponse
message MipStatusEntry {
// Mip info
MipInfo mip_info = 1;
// state id
ComponentStateId state_id = 2;
}

// Same as MipInfo struct in versioning package
message MipInfo {
string name = 1;
fixed32 version = 2;
fixed64 start = 3;
fixed64 timeout = 4;
fixed64 activation_delay = 5;
repeated MipComponentEntry components = 6;
}

message MipComponentEntry {
fixed32 kind = 1;
fixed32 version = 2;
}

// Same as ComponentStateId enum in versioning package
enum ComponentStateId {
aoudiamoncef marked this conversation as resolved.
Show resolved Hide resolved
COMPONENT_STATE_ID_UNSPECIFIED = 0;
COMPONENT_STATE_ID_ERROR = 1;
COMPONENT_STATE_ID_DEFINED = 2;
COMPONENT_STATE_ID_STARTED = 3;
COMPONENT_STATE_ID_LOCKEDIN = 4;
COMPONENT_STATE_ID_ACTIVE = 5;
COMPONENT_STATE_ID_FAILED = 6;
}
Binary file modified massa-proto/src/api.bin
Binary file not shown.
Loading