Skip to content

Commit

Permalink
Feature/chainid (massalabs#4588)
Browse files Browse the repository at this point in the history
* Add initial chain id impl

* Add chain id to jsonrpc, grpc public & grpc private api

* Add massa-client features sandbox

* Add chain id SC unit test

* Fix unit test + add dummy gas costs

* Update massa-proto-rs dependency

* Update massa-sc-runtime dependency

* Add unit test allowing easy update of massa docs

* Use chain id through config instead of constants directly

* Use chain id everywhere (round 1) (massalabs#4863)

* Use chain id everywhere (round 1)

* Use chain id in massa client

---------

Co-authored-by: sydhds <[email protected]>

* Remove confusing chain id

* Fix some unit tests

* Test 27 6 wip (massalabs#4582)

* Update addresses and public keys

* Add more info to double staking protection"s panic message

* fmt

* update version and genesis

* Update version and CI

* Update Cargo.lock

* add community charter

* Add serde json tests (massalabs#4579)

* chore: typo fix (massalabs#4589)

* Update to wasmer 4.2.4 (massalabs#4581)

Co-authored-by: sydhds <[email protected]>

* typo fix

* typo fix

* typo fix

* typo fix

* typo fix

---------

Co-authored-by: Sydhds <[email protected]>
Co-authored-by: sydhds <[email protected]>

* ci: add checksum + tested with ACT (massalabs#4590)

* Upgrade-to-latest-toolchain (massalabs#4585)

Co-authored-by: Leo-Besancon <[email protected]>

* Update massa-sc-runtime

Signed-off-by: Jean-François <[email protected]>

* Cargo update

* Remove compatibility layer in tracing (massalabs#4535)

* Add deferred_credits initial file for test

* Update Genesis and CI

* Push back Genesis

* Same

---------

Signed-off-by: Jean-François <[email protected]>
Co-authored-by: Damir Vodenicarevic <[email protected]>
Co-authored-by: Moncef AOUDIA <[email protected]>
Co-authored-by: Ursulafe <[email protected]>
Co-authored-by: Sydhds <[email protected]>
Co-authored-by: sydhds <[email protected]>
Co-authored-by: Jean-François <[email protected]>

* Add initial chain id impl

* Use chain id everywhere (round 1) (massalabs#4863)

* Use chain id everywhere (round 1)

* Use chain id in massa client

---------

Co-authored-by: sydhds <[email protected]>

* Fix unit tests (final round)

* Minor fix

* Revert some nasty insert from bad rebase

* Auto gen chain id from VERSION

* Cargo clippy && fmt && doc pass

* Update massa-sc-runtime dependency

---------

Signed-off-by: Jean-François <[email protected]>
Co-authored-by: sydhds <[email protected]>
Co-authored-by: Leo-Besancon <[email protected]>
Co-authored-by: Damir Vodenicarevic <[email protected]>
Co-authored-by: Moncef AOUDIA <[email protected]>
Co-authored-by: Ursulafe <[email protected]>
Co-authored-by: Jean-François <[email protected]>
  • Loading branch information
7 people authored Dec 22, 2023
1 parent 3d8703c commit 949a022
Show file tree
Hide file tree
Showing 75 changed files with 712 additions and 256 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ massa_versioning = { path = "./massa-versioning" }
massa_wallet = { path = "./massa-wallet" }

# Massa projects dependencies
massa-proto-rs = { git = "https://github.com/massalabs/massa-proto-rs", "rev" = "30b91d705b704287662b0e42457ece442005fa46" }
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", "rev" = "0bef3a9c0013e61b0c2b18105238649ac74007c9" }
massa-proto-rs = { git = "https://github.com/massalabs/massa-proto-rs", "rev" = "84678fb77cf6d06d85d55e2c20502908ff292e61" }
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", "rev" = "d1dce679951ce1d1dad0471b2ac6b8ef12b44e9d" }
peernet = { git = "https://github.com/massalabs/PeerNet", "branch" = "main" }

# Common dependencies
Expand Down
2 changes: 2 additions & 0 deletions massa-api-exports/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ pub struct APIConfig {
pub keypair: KeyPair,
/// last_start_period value, used to know if we are during a restart or not
pub last_start_period: u64,
/// chain id
pub chain_id: u64,
}
2 changes: 2 additions & 0 deletions massa-api-exports/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub struct NodeStatus {
pub execution_stats: ExecutionStats,
/// compact configuration
pub config: CompactConfig,
/// chain id
pub chain_id: u64,
}

impl std::fmt::Display for NodeStatus {
Expand Down
26 changes: 17 additions & 9 deletions massa-api/src/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ impl MassaRpcServer for API<Public> {
pool_stats,
config,
current_cycle,
chain_id: self.0.api_settings.chain_id,
})
}

Expand Down Expand Up @@ -1139,14 +1140,17 @@ fn check_input_operation(
api_cfg: &APIConfig,
last_slot: Option<Slot>,
) -> RpcResult<SecureShareOperation> {
let operation_deserializer = SecureShareDeserializer::new(OperationDeserializer::new(
api_cfg.max_datastore_value_length,
api_cfg.max_function_name_length,
api_cfg.max_parameter_size,
api_cfg.max_op_datastore_entry_count,
api_cfg.max_op_datastore_key_length,
api_cfg.max_op_datastore_value_length,
));
let operation_deserializer = SecureShareDeserializer::new(
OperationDeserializer::new(
api_cfg.max_datastore_value_length,
api_cfg.max_function_name_length,
api_cfg.max_parameter_size,
api_cfg.max_op_datastore_entry_count,
api_cfg.max_op_datastore_key_length,
api_cfg.max_op_datastore_value_length,
),
api_cfg.chain_id,
);

let mut op_serialized = Vec::new();
op_serialized.extend(op_input.signature.to_bytes());
Expand Down Expand Up @@ -1178,7 +1182,11 @@ fn check_input_operation(
};
if let Some(slot) = last_slot {
if op.content.expire_period < slot.period {
return Err(ApiError::InconsistencyError("Operation expire_period is lower than the current period of this node. Your operation will never be included in a block.".into()).into());
return Err(
ApiError::InconsistencyError(
"Operation expire_period is lower than the current period of this node. Your operation will never be included in a block.".into()
).into()
);
}
}
if rest.is_empty() {
Expand Down
4 changes: 4 additions & 0 deletions massa-api/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{collections::HashMap, net::SocketAddr};
use massa_api_exports::config::APIConfig;
use massa_consensus_exports::{ConsensusBroadcasts, MockConsensusController};
use massa_execution_exports::{GasCosts, MockExecutionController};
use massa_models::config::CHAINID;
use massa_models::{
config::{
BASE_OPERATION_GAS_COST, ENDORSEMENT_COUNT, GENESIS_TIMESTAMP, MAX_DATASTORE_VALUE_LENGTH,
Expand Down Expand Up @@ -65,6 +66,7 @@ pub(crate) fn get_apiv2_server(addr: &SocketAddr) -> (API<ApiV2>, APIConfig) {
t0: T0,
periods_per_cycle: PERIODS_PER_CYCLE,
last_start_period: 0,
chain_id: *CHAINID,
};

// let shared_storage: massa_storage::Storage = massa_storage::Storage::create_root();
Expand Down Expand Up @@ -138,6 +140,7 @@ pub(crate) fn start_public_api(addr: SocketAddr) -> (API<Public>, APIConfig) {
t0: T0,
periods_per_cycle: PERIODS_PER_CYCLE,
last_start_period: 0,
chain_id: *CHAINID,
};

let shared_storage: massa_storage::Storage = massa_storage::Storage::create_root();
Expand Down Expand Up @@ -249,6 +252,7 @@ pub(crate) fn start_public_api(addr: SocketAddr) -> (API<Public>, APIConfig) {
try_connection_timer_same_peer: MassaTime::from_millis(1000),
test_oldest_peer_cooldown: MassaTime::from_millis(720000),
rate_limit: 1024 * 1024 * 2,
chain_id: *CHAINID,
},
*VERSION,
NodeId::new(keypair.get_public_key()),
Expand Down
2 changes: 2 additions & 0 deletions massa-api/src/tests/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ async fn get_status() {
assert_eq!(response.network_stats.in_connection_count, 10);
assert_eq!(response.network_stats.out_connection_count, 5);
assert_eq!(response.config.thread_count, 32);
// Chain id == 77 for Node in sandbox mode otherwise it is always greater
assert!(response.chain_id > 77);

api_public_handle.stop().await;
}
Expand Down
5 changes: 4 additions & 1 deletion massa-bootstrap/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ impl Deserializer<BootstrapServerMessage> for BootstrapServerMessageDeserializer
/// use massa_time::MassaTime;
/// use massa_models::version::Version;
/// use std::str::FromStr;
/// use massa_models::config::CHAINID;
///
/// let message_serializer = BootstrapServerMessageSerializer::new();
/// let args = BootstrapServerMessageDeserializerArgs {
Expand All @@ -423,7 +424,9 @@ impl Deserializer<BootstrapServerMessage> for BootstrapServerMessageDeserializer
/// max_rolls_length: 1000, max_production_stats_length: 1000, max_credits_length: 1000,
/// max_executed_ops_length: 1000, max_ops_changes_length: 1000,
/// mip_store_stats_block_considered: 100,
/// max_denunciations_per_block_header: 128, max_denunciation_changes_length: 1000,};
/// max_denunciations_per_block_header: 128, max_denunciation_changes_length: 1000,
/// chain_id: *CHAINID
/// };
/// let message_deserializer = BootstrapServerMessageDeserializer::new(args);
/// let bootstrap_server_message = BootstrapServerMessage::BootstrapTime {
/// server_time: MassaTime::from_millis(0),
Expand Down
5 changes: 5 additions & 0 deletions massa-bootstrap/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ pub struct BootstrapConfig {
pub max_denunciations_per_block_header: u32,
/// max executed denunciations changes
pub max_denunciation_changes_length: u64,
/// chain id
pub chain_id: u64,
}

/// Bootstrap server binding
Expand Down Expand Up @@ -169,6 +171,7 @@ pub struct BootstrapClientConfig {
pub mip_store_stats_block_considered: usize,
pub max_denunciations_per_block_header: u32,
pub max_denunciation_changes_length: u64,
pub chain_id: u64,
}

/// Bootstrap Message der args
Expand Down Expand Up @@ -198,6 +201,7 @@ pub struct BootstrapServerMessageDeserializerArgs {
pub mip_store_stats_block_considered: usize,
pub max_denunciations_per_block_header: u32,
pub max_denunciation_changes_length: u64,
pub chain_id: u64,
}

// TODO: add a proc macro for this case
Expand All @@ -210,6 +214,7 @@ impl From<&BootstrapServerMessageDeserializerArgs> for BlockDeserializerArgs {
endorsement_count: value.endorsement_count,
max_denunciations_per_block_header: value.max_denunciations_per_block_header,
last_start_period: None,
chain_id: value.chain_id,
}
}
}
3 changes: 2 additions & 1 deletion massa-bootstrap/src/tests/binders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use massa_db_exports::{MassaDBConfig, MassaDBController};
use massa_db_worker::MassaDB;
use massa_final_state::FinalStateConfig;
use massa_models::config::{
BOOTSTRAP_RANDOMNESS_SIZE_BYTES, CONSENSUS_BOOTSTRAP_PART_SIZE, ENDORSEMENT_COUNT,
BOOTSTRAP_RANDOMNESS_SIZE_BYTES, CHAINID, CONSENSUS_BOOTSTRAP_PART_SIZE, ENDORSEMENT_COUNT,
MAX_ADVERTISE_LENGTH, MAX_BOOTSTRAP_BLOCKS, MAX_BOOTSTRAP_ERROR_LENGTH,
MAX_BOOTSTRAP_FINAL_STATE_PARTS_SIZE, MAX_BOOTSTRAP_VERSIONING_ELEMENTS_SIZE,
MAX_DATASTORE_ENTRY_COUNT, MAX_DATASTORE_KEY_LENGTH, MAX_DATASTORE_VALUE_LENGTH,
Expand Down Expand Up @@ -83,6 +83,7 @@ impl BootstrapClientBinder {
mip_store_stats_block_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
max_denunciations_per_block_header: MAX_DENUNCIATIONS_PER_BLOCK_HEADER,
max_denunciation_changes_length: MAX_DENUNCIATION_CHANGES_LENGTH,
chain_id: *CHAINID,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions massa-bootstrap/src/tests/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{net::SocketAddr, path::PathBuf};

use massa_models::config::CHAINID;
use massa_models::{
config::{
BOOTSTRAP_RANDOMNESS_SIZE_BYTES, CONSENSUS_BOOTSTRAP_PART_SIZE, ENDORSEMENT_COUNT,
Expand Down Expand Up @@ -78,6 +79,7 @@ impl Default for BootstrapConfig {
mip_store_stats_block_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
max_denunciations_per_block_header: MAX_DENUNCIATIONS_PER_BLOCK_HEADER,
max_denunciation_changes_length: MAX_DENUNCIATION_CHANGES_LENGTH,
chain_id: *CHAINID,
}
}
}
2 changes: 2 additions & 0 deletions massa-bootstrap/src/tests/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fn test_serialize_bootstrap_server_message() {
mip_store_stats_block_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
max_denunciations_per_block_header: MAX_DENUNCIATIONS_PER_BLOCK_HEADER,
max_denunciation_changes_length: MAX_DENUNCIATION_CHANGES_LENGTH,
chain_id: *CHAINID,
};

parametric_test(
Expand Down Expand Up @@ -170,6 +171,7 @@ fn test_serialize_error_cases_servermsg() {
mip_store_stats_block_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
max_denunciations_per_block_header: MAX_DENUNCIATIONS_PER_BLOCK_HEADER,
max_denunciation_changes_length: MAX_DENUNCIATION_CHANGES_LENGTH,
chain_id: *CHAINID,
};

let mut rng = rand::thread_rng();
Expand Down
15 changes: 8 additions & 7 deletions massa-bootstrap/src/tests/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use massa_ledger_exports::{LedgerEntry, SetUpdateOrDelete};
use massa_ledger_worker::test_exports::create_final_ledger;
use massa_models::bytecode::Bytecode;
use massa_models::config::{
BOOTSTRAP_RANDOMNESS_SIZE_BYTES, CONSENSUS_BOOTSTRAP_PART_SIZE, ENDORSEMENT_COUNT,
BOOTSTRAP_RANDOMNESS_SIZE_BYTES, CHAINID, CONSENSUS_BOOTSTRAP_PART_SIZE, ENDORSEMENT_COUNT,
MAX_ADVERTISE_LENGTH, MAX_BOOTSTRAP_BLOCKS, MAX_BOOTSTRAP_ERROR_LENGTH,
MAX_BOOTSTRAP_FINAL_STATE_PARTS_SIZE, MAX_BOOTSTRAP_VERSIONING_ELEMENTS_SIZE,
MAX_CONSENSUS_BLOCKS_IDS, MAX_DATASTORE_ENTRY_COUNT, MAX_DATASTORE_KEY_LENGTH,
Expand Down Expand Up @@ -384,13 +384,14 @@ pub fn get_bootstrap_config(bootstrap_public_key: NodeId) -> BootstrapConfig {
mip_store_stats_block_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
max_denunciations_per_block_header: MAX_DENUNCIATIONS_PER_BLOCK_HEADER,
max_denunciation_changes_length: MAX_DENUNCIATION_CHANGES_LENGTH,
chain_id: *CHAINID,
}
}

fn gen_export_active_blocks<R: Rng>(rng: &mut R) -> ExportActiveBlock {
let keypair = KeyPair::generate(0).unwrap();
let block = gen_random_block(&keypair, rng)
.new_verifiable(BlockSerializer::new(), &keypair)
.new_verifiable(BlockSerializer::new(), &keypair, *CHAINID)
.unwrap();
let parents = (0..32)
.map(|_| (gen_random_block_id(rng), rng.gen()))
Expand Down Expand Up @@ -512,7 +513,7 @@ fn gen_random_block<R: Rng>(keypair: &KeyPair, rng: &mut R) -> Block {
};

let endorsement = endorsement
.new_verifiable(EndorsementSerializer::new(), keypair)
.new_verifiable(EndorsementSerializer::new(), keypair, *CHAINID)
.unwrap();
endorsements.push(endorsement);
}
Expand All @@ -531,7 +532,7 @@ fn gen_random_block<R: Rng>(keypair: &KeyPair, rng: &mut R) -> Block {
endorsements,
denunciations,
}
.new_verifiable(BlockHeaderSerializer::new(), keypair)
.new_verifiable(BlockHeaderSerializer::new(), keypair, *CHAINID)
.unwrap();
let mut operations = vec![];
for _ in 0..rng.gen_range(0..MAX_OPERATIONS_PER_BLOCK) {
Expand Down Expand Up @@ -889,7 +890,7 @@ impl BootstrapServerMessage {
};

let endorsement = endorsement
.new_verifiable(EndorsementSerializer::new(), &keypair)
.new_verifiable(EndorsementSerializer::new(), &keypair, *CHAINID)
.unwrap();
endorsements.push(endorsement);
}
Expand Down Expand Up @@ -929,7 +930,7 @@ impl BootstrapServerMessage {
endorsements: endorsements.clone(),
denunciations,
}
.new_verifiable(BlockHeaderSerializer::new(), &keypair)
.new_verifiable(BlockHeaderSerializer::new(), &keypair, *CHAINID)
.unwrap();

let block = Block {
Expand All @@ -944,7 +945,7 @@ impl BootstrapServerMessage {
.collect(),
is_final: false,
block: block
.new_verifiable(BlockSerializer::new(), &keypair)
.new_verifiable(BlockSerializer::new(), &keypair, *CHAINID)
.unwrap(),
};
for _ in 0..block_nb {
Expand Down
2 changes: 2 additions & 0 deletions massa-client/base_config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ private_port = 33034
public_port = 33035
grpc_public_port = 33037
grpc_private_port = 33038
# Chain id for SecureNet, please update to match the target node chain id
chain_id = 77

[client]
# maximum size in bytes of a request. Defaults to 50MB
Expand Down
3 changes: 3 additions & 0 deletions massa-client/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ impl Output for NodeStatus {
)
}
}

println!();
println!("Chain id: {}", self.chain_id);
}
}

Expand Down
10 changes: 9 additions & 1 deletion massa-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ struct Args {
/// Port to listen on (Massa GRPC Private API).
#[arg(long)]
grpc_private_port: Option<u16>,
/// Chain id
#[arg(long)]
chain_id: Option<u64>,
/// Address to listen on
#[arg(long)]
ip: Option<IpAddr>,
Expand Down Expand Up @@ -136,6 +139,10 @@ async fn run(args: Args) -> Result<()> {
Some(grpc_port) => grpc_port,
None => settings.default_node.grpc_private_port,
};
let chain_id = match args.chain_id {
Some(chain_id) => chain_id,
None => settings.default_node.chain_id,
};

// Setup panic handlers,
// and when a panic occurs,
Expand All @@ -154,6 +161,7 @@ async fn run(args: Args) -> Result<()> {
private_port,
grpc_port,
grpc_priv_port,
chain_id,
&http_config,
)
.await?;
Expand All @@ -172,7 +180,7 @@ async fn run(args: Args) -> Result<()> {
_ => ask_password(&args.wallet),
};

let wallet = Wallet::new(args.wallet, password)?;
let wallet = Wallet::new(args.wallet, password, chain_id)?;
Some(wallet)
}
false => None,
Expand Down
6 changes: 5 additions & 1 deletion massa-client/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ pub(crate) async fn run(
_ => ask_password(wallet_path),
};

let wallet = match Wallet::new(wallet_path.to_path_buf(), password) {
let wallet = match Wallet::new(
wallet_path.to_path_buf(),
password,
client.chain_id,
) {
Ok(wallet) => wallet,
Err(e) => {
println!("Could not open wallet: {}", e);
Expand Down
1 change: 1 addition & 0 deletions massa-client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct DefaultNode {
pub public_port: u16,
pub grpc_public_port: u16,
pub grpc_private_port: u16,
pub chain_id: u64,
}

/// Client settings
Expand Down
3 changes: 2 additions & 1 deletion massa-consensus-exports/src/bootstrapable_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ impl Deserializer<BootstrapableGraph> for BootstrapableGraphDeserializer {
/// use massa_hash::Hash;
/// use massa_models::{prehash::PreHashMap, block_id::BlockId, config::THREAD_COUNT};
/// use massa_models::block::BlockDeserializerArgs;
/// use massa_models::config::CHAINID;
/// let mut bootstrapable_graph = BootstrapableGraph {
/// final_blocks: Vec::new(),
/// };
/// let mut buffer = Vec::new();
/// BootstrapableGraphSerializer::new().serialize(&bootstrapable_graph, &mut buffer).unwrap();
/// let args = BlockDeserializerArgs {
/// thread_count: 32,max_operations_per_block: 16,endorsement_count: 10,max_denunciations_per_block_header: 128,last_start_period: Some(0),};
/// thread_count: 32,max_operations_per_block: 16,endorsement_count: 10,max_denunciations_per_block_header: 128,last_start_period: Some(0),chain_id: *CHAINID};
/// let (rest, bootstrapable_graph_deserialized) = BootstrapableGraphDeserializer::new(args, 10).deserialize::<DeserializeError>(&buffer).unwrap();
/// let mut buffer2 = Vec::new();
/// BootstrapableGraphSerializer::new().serialize(&bootstrapable_graph_deserialized, &mut buffer2).unwrap();
Expand Down
Loading

0 comments on commit 949a022

Please sign in to comment.