Skip to content

Commit

Permalink
Merge #3163
Browse files Browse the repository at this point in the history
3163: Prepare testnet 16 r=AurelienFT a=Eitu33

* [x] document all added functions
* [x] try in sandbox / simulation / labnet
* [x] unit tests on the added & changed features
  * [x] make tests compile
  * [x] make tests pass 
* [x] add logs allowing easy debugging in case the changes caused problems
* [x] if the API has changed, update the API specification

This PR contains the following ones : 
- #3147 
- #3165
- #3180 
- #3183 
- #3167
- #3185
- #3158
- #3186
- #3187
- #3164
- #3150 
- #3188 
- #3189
- #3190
- #3170 
- #3194 

Co-authored-by: Thomas Plisson <thomas.plisson@epitech.eu>
Co-authored-by: Eitu33 <89928840+Eitu33@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 31, 2022
2 parents 1863a53 + 4a25c64 commit 59e9ff9
Show file tree
Hide file tree
Showing 117 changed files with 5,719 additions and 2,417 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ jobs:
with:
command: fmt
args: --all -- --check
- uses: actions-rs/cargo@v1
with:
command: install
args: cargo-spellcheck
- uses: actions-rs/cargo@v1
with:
command: spellcheck
args: -m 1

check:
if: github.ref != 'refs/heads/staging'
Expand Down Expand Up @@ -119,6 +111,8 @@ jobs:
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: -- -A clippy::uninlined-format-args


# Full cross-platform tests required by bors to merge on main branch
full:
Expand Down Expand Up @@ -210,3 +204,14 @@ jobs:
with:
branch: gh-pages
folder: target/doc

unit_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: "recursive"
- name: setup_tests
shell: bash
run: |
cargo install cargo-script && cargo script tools/setup_test.rs && git diff --no-ext-diff --quiet
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ docs/_build
massa.iml
ledger
docs/venv
# tools
massa_unit_tests_*.tar.gz
extract_massa_unit_tests_src_*
19 changes: 16 additions & 3 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"massa-cipher",
"massa-consensus-exports",
"massa-consensus-worker",
"massa-executed-ops",
"massa-execution-exports",
"massa-execution-worker",
"massa-factory-exports",
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mass adoption.
[![Bors enabled](https://bors.tech/images/badge_small.svg)](https://app.bors.tech/repositories/39543)
[![Coverage Status](https://coveralls.io/repos/github/massalabs/massa/badge.svg?branch=main)](https://coveralls.io/github/massalabs/massa?branch=main)
[![Docs](https://img.shields.io/static/v1?label=docs&message=massa&color=blue)](https://massalabs.github.io/massa/massa_node/)
[![OpenRPC Playground](https://img.shields.io/static/v1?label=openrpc-playground&message=massa&color=blue)](https://playground.open-rpc.org/?schemaUrl=https://raw.githubusercontent.com/massalabs/massa-docs/main/technical-doc/openrpc.json&uiSchema\[appBar\]\[ui:input\]=false&uiSchema\[appBar\]\[ui:inputPlaceholder\]=Enter+Massa+JSON-RPC+server+URL&uiSchema\[appBar\]\[ui:logoUrl\]=https://massa.net/favicons/favicon.ico&uiSchema\[appBar\]\[ui:splitView\]=false&uiSchema\[appBar\]\[ui:darkMode\]=false&uiSchema\[appBar\]\[ui:title\]=Massa&uiSchema\[appBar\]\[ui:examplesDropdown\]=false&uiSchema\[methods\]\[ui:defaultExpanded\]=false&uiSchema\[methods\]\[ui:methodPlugins\]=false&uiSchema\[params\]\[ui:defaultExpanded\]=false)
[![OpenRPC Playground](https://img.shields.io/static/v1?label=explore-openrpc-specification&message=massa&color=blue)](https://playground.open-rpc.org/?schemaUrl=https://test.massa.net/api/v2&uiSchema\[appBar\]\[ui:input\]=false&uiSchema\[appBar\]\[ui:inputPlaceholder\]=Enter+Massa+JSON-RPC+server+URL&uiSchema\[appBar\]\[ui:logoUrl\]=https://massa.net/favicons/favicon.ico&uiSchema\[appBar\]\[ui:splitView\]=false&uiSchema\[appBar\]\[ui:darkMode\]=false&uiSchema\[appBar\]\[ui:title\]=Massa&uiSchema\[appBar\]\[ui:examplesDropdown\]=false&uiSchema\[methods\]\[ui:defaultExpanded\]=false&uiSchema\[methods\]\[ui:methodPlugins\]=true&uiSchema\[params\]\[ui:defaultExpanded\]=false)
[![Open in Gitpod](https://shields.io/badge/Gitpod-contribute-brightgreen?logo=gitpod&style=flat)](https://gitpod.io/#https://github.com/massalabs/massa)

## Introduction
Expand All @@ -25,6 +25,9 @@ An easy-to-read blog post introduction with videos is written
We are now releasing the **Massa testnet** in this GitHub repository,
with its explorer available at <https://massa.net/testnet>.

You can interact with Massa JSON-RPC public API on [OpenRPC Playground](https://playground.open-rpc.org/?schemaUrl=https://test.massa.net/api/v2&uiSchema\[appBar\]\[ui:input\]=false&uiSchema\[appBar\]\[ui:inputPlaceholder\]=Enter+Massa+JSON-RPC+server+URL&uiSchema\[appBar\]\[ui:logoUrl\]=https://massa.net/favicons/favicon.ico&uiSchema\[appBar\]\[ui:splitView\]=false&uiSchema\[appBar\]\[ui:darkMode\]=false&uiSchema\[appBar\]\[ui:title\]=Massa&uiSchema\[appBar\]\[ui:examplesDropdown\]=false&uiSchema\[methods\]\[ui:defaultExpanded\]=false&uiSchema\[methods\]\[ui:methodPlugins\]=true&uiSchema\[params\]\[ui:defaultExpanded\]=false)which is an equivalent of SwaggerUI for OpenAPI specifications.


## Testnet Incentives

As decentralization is our core value, we would like to help you start
Expand Down
5 changes: 4 additions & 1 deletion massa-api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

use jsonrpc_core::serde::Deserialize;
use std::net::SocketAddr;
use std::path::PathBuf;

/// API settings.
/// the API settings
#[derive(Debug, Deserialize, Clone, Copy)]
#[derive(Debug, Deserialize, Clone)]
pub struct APIConfig {
/// when looking for next draw we want to look at max `draw_lookahead_period_count`
pub draw_lookahead_period_count: u64,
Expand All @@ -15,6 +16,8 @@ pub struct APIConfig {
pub bind_public: SocketAddr,
/// max argument count
pub max_arguments: u64,
/// openrpc specification path
pub openrpc_spec_path: PathBuf,
/// max datastore value length
pub max_datastore_value_length: u64,
/// max op datastore entry
Expand Down
56 changes: 39 additions & 17 deletions massa-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,66 @@ use thiserror::Error;
#[non_exhaustive]
#[derive(Display, Error, Debug)]
pub enum ApiError {
/// too many arguments error: {0}
TooManyArguments(String),
/// send channel error: {0}
/// Send channel error: {0}
SendChannelError(String),
/// receive channel error: {0}
/// Receive channel error: {0}
ReceiveChannelError(String),
/// `massa_hash` error: {0}
MassaHashError(#[from] MassaHashError),
/// consensus error: {0}
/// Consensus error: {0}
ConsensusError(#[from] Box<ConsensusError>),
/// execution error: {0}
/// Execution error: {0}
ExecutionError(#[from] ExecutionError),
/// network error: {0}
/// Network error: {0}
NetworkError(#[from] NetworkError),
/// protocol error: {0}
/// Protocol error: {0}
ProtocolError(#[from] ProtocolError),
/// models error: {0}
/// Models error: {0}
ModelsError(#[from] ModelsError),
/// time error: {0}
/// Time error: {0}
TimeError(#[from] TimeError),
/// wallet error: {0}
/// Wallet error: {0}
WalletError(#[from] WalletError),
/// not found
/// Not found
NotFound,
/// inconsistency: {0}
/// Inconsistency error: {0}
InconsistencyError(String),
/// missing command sender {0}
/// Missing command sender: {0}
MissingCommandSender(String),
/// missing configuration {0}
/// Missing configuration: {0}
MissingConfig(String),
/// the wrong API (either Public or Private) was called
/// The wrong API (either Public or Private) was called
WrongAPI,
/// Bad request: {0}
BadRequest(String),
/// Internal server error: {0}
InternalServerError(String),
}

impl From<ApiError> for jsonrpc_core::Error {
fn from(err: ApiError) -> Self {
// JSON-RPC Server errors codes must be between -32099 to -32000
let code = match err {
ApiError::BadRequest(_) => -32000,
ApiError::InternalServerError(_) => -32001,
ApiError::NotFound => -32004,
ApiError::SendChannelError(_) => -32006,
ApiError::ReceiveChannelError(_) => -32007,
ApiError::MassaHashError(_) => -32008,
ApiError::ConsensusError(_) => -32009,
ApiError::ExecutionError(_) => -32010,
ApiError::NetworkError(_) => -32011,
ApiError::ProtocolError(_) => -32012,
ApiError::ModelsError(_) => -32013,
ApiError::TimeError(_) => -32014,
ApiError::WalletError(_) => -32015,
ApiError::InconsistencyError(_) => -32016,
ApiError::MissingCommandSender(_) => -32017,
ApiError::MissingConfig(_) => -32018,
ApiError::WrongAPI => -32019,
};
jsonrpc_core::Error {
code: jsonrpc_core::ErrorCode::ServerError(500),
code: jsonrpc_core::ErrorCode::ServerError(code),
message: err.to_string(),
data: None,
}
Expand Down
11 changes: 7 additions & 4 deletions massa-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![warn(unused_crate_dependencies)]
use crate::error::ApiError::WrongAPI;
use error::ApiError;
use jsonrpc_core::{BoxFuture, IoHandler, Value};
use jsonrpc_core::{serde_json, BoxFuture, IoHandler, Value};
use jsonrpc_derive::rpc;
use jsonrpc_http_server::{CloseHandle, ServerBuilder};
use massa_consensus_exports::{ConsensusCommandSender, ConsensusConfig};
Expand Down Expand Up @@ -33,7 +33,6 @@ use massa_network_exports::{NetworkCommandSender, NetworkConfig};
use massa_pool_exports::PoolController;
use massa_pos_exports::SelectorController;
use massa_protocol_exports::ProtocolCommandSender;
use massa_signature::KeyPair;
use massa_storage::Storage;
use massa_wallet::Wallet;
use parking_lot::RwLock;
Expand Down Expand Up @@ -159,10 +158,10 @@ pub trait Endpoints {
#[rpc(name = "node_sign_message")]
fn node_sign_message(&self, _: Vec<u8>) -> BoxFuture<Result<PubkeySig, ApiError>>;

/// Add a vector of new keys for the node to use to stake.
/// Add a vector of new secret(private) keys for the node to use to stake.
/// No confirmation to expect.
#[rpc(name = "add_staking_secret_keys")]
fn add_staking_secret_keys(&self, _: Vec<KeyPair>) -> BoxFuture<Result<(), ApiError>>;
fn add_staking_secret_keys(&self, _: Vec<String>) -> BoxFuture<Result<(), ApiError>>;

/// Execute bytecode in read-only mode.
#[rpc(name = "execute_read_only_bytecode")]
Expand Down Expand Up @@ -289,6 +288,10 @@ pub trait Endpoints {
&self,
_: EventFilter,
) -> BoxFuture<Result<Vec<SCOutputEvent>, ApiError>>;

/// Get OpenRPC specification.
#[rpc(name = "rpc.discover")]
fn get_openrpc_spec(&self) -> BoxFuture<Result<Value, ApiError>>;
}

fn wrong_api<T>() -> BoxFuture<Result<T, ApiError>> {
Expand Down
18 changes: 15 additions & 3 deletions massa-api/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::config::APIConfig;
use crate::error::ApiError;
use crate::{Endpoints, Private, RpcServer, StopHandle, API};
use crate::{Endpoints, Private, RpcServer, StopHandle, Value, API};

use jsonrpc_core::BoxFuture;
use jsonrpc_http_server::tokio::sync::mpsc;
Expand Down Expand Up @@ -33,6 +33,7 @@ use massa_wallet::Wallet;

use parking_lot::RwLock;
use std::net::{IpAddr, SocketAddr};
use std::str::FromStr;
use std::sync::Arc;

impl API<Private> {
Expand Down Expand Up @@ -86,11 +87,18 @@ impl Endpoints for API<Private> {
Box::pin(closure())
}

fn add_staking_secret_keys(&self, keys: Vec<KeyPair>) -> BoxFuture<Result<(), ApiError>> {
fn add_staking_secret_keys(&self, secret_keys: Vec<String>) -> BoxFuture<Result<(), ApiError>> {
let keypairs = match secret_keys.iter().map(|x| KeyPair::from_str(x)).collect() {
Ok(keypairs) => keypairs,
Err(e) => {
let closure = async move || Err(ApiError::BadRequest(e.to_string()));
return Box::pin(closure());
}
};
let node_wallet = self.0.node_wallet.clone();
let closure = async move || {
let mut w_wallet = node_wallet.write();
w_wallet.add_keypairs(keys)?;
w_wallet.add_keypairs(keypairs)?;
Ok(())
};
Box::pin(closure())
Expand Down Expand Up @@ -227,4 +235,8 @@ impl Endpoints for API<Private> {
let closure = async move || Ok(network_command_sender.remove_from_whitelist(ips).await?);
Box::pin(closure())
}

fn get_openrpc_spec(&self) -> BoxFuture<Result<Value, ApiError>> {
crate::wrong_api::<Value>()
}
}
Loading

0 comments on commit 59e9ff9

Please sign in to comment.