forked from massalabs/massa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage: move store to after protocol check
- Loading branch information
Showing
16 changed files
with
82 additions
and
216 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
// Copyright (c) 2022 MASSA LABS <[email protected]> | ||
|
||
use massa_models::{ | ||
constants::CHANNEL_SIZE, signed::Signable, storage::Storage, Block, BlockHeader, BlockId, | ||
SerializeCompact, SignedHeader, | ||
constants::CHANNEL_SIZE, signed::Signable, storage::Storage, Block, BlockId, SerializeCompact, | ||
SignedHeader, | ||
}; | ||
use massa_protocol_exports::{ | ||
ProtocolCommand, ProtocolCommandSender, ProtocolEvent, ProtocolEventReceiver, | ||
|
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
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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
// Copyright (c) 2022 MASSA LABS <[email protected]> | ||
|
||
use massa_models::SerializeCompact; | ||
use massa_models::{constants::CHANNEL_SIZE, node::NodeId}; | ||
use massa_models::{ | ||
storage::Storage, Block, BlockId, SignedEndorsement, SignedHeader, SignedOperation, | ||
}; | ||
use massa_models::{Block, BlockId, SignedEndorsement, SignedHeader, SignedOperation}; | ||
use massa_network_exports::{ | ||
NetworkCommand, NetworkCommandSender, NetworkEvent, NetworkEventReceiver, | ||
}; | ||
|
@@ -72,19 +69,12 @@ impl MockNetworkController { | |
.expect("Couldn't send header to protocol."); | ||
} | ||
|
||
pub async fn send_block( | ||
&mut self, | ||
source_node_id: NodeId, | ||
block_id: BlockId, | ||
block_and_storage: Option<(Block, Storage)>, | ||
) { | ||
if let Some((block, storage)) = block_and_storage { | ||
storage.store_block(block_id, block.clone(), block.to_bytes_compact().unwrap()); | ||
} | ||
pub async fn send_block(&mut self, source_node_id: NodeId, block: Block, serialized: Vec<u8>) { | ||
self.network_event_tx | ||
.send(NetworkEvent::ReceivedBlock { | ||
node: source_node_id, | ||
block_id, | ||
block, | ||
serialized, | ||
}) | ||
.await | ||
.expect("Couldn't send block to protocol."); | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Copyright (c) 2022 MASSA LABS <[email protected]> | ||
|
||
use super::tools::{protocol_test, protocol_test_with_storage}; | ||
use super::tools::protocol_test; | ||
use massa_models::prehash::Set; | ||
use massa_models::signed::Signable; | ||
use massa_models::BlockId; | ||
|
@@ -16,14 +16,13 @@ async fn test_without_a_priori() { | |
// start | ||
let protocol_settings = &tools::PROTOCOL_SETTINGS; | ||
|
||
protocol_test_with_storage( | ||
protocol_test( | ||
protocol_settings, | ||
async move |mut network_controller, | ||
protocol_event_receiver, | ||
mut protocol_command_sender, | ||
protocol_manager, | ||
protocol_pool_event_receiver, | ||
storage| { | ||
protocol_pool_event_receiver| { | ||
let node_a = tools::create_and_connect_nodes(1, &mut network_controller) | ||
.await | ||
.pop() | ||
|
@@ -57,7 +56,7 @@ async fn test_without_a_priori() { | |
|
||
// node B replied with the block | ||
network_controller | ||
.send_block(node_b.id, hash_1, Some((block, storage))) | ||
.send_block(node_b.id, block, Default::default()) | ||
.await; | ||
|
||
// 7. Make sure protocol did not send additional ask for block commands. | ||
|
@@ -91,14 +90,13 @@ async fn test_without_a_priori() { | |
async fn test_someone_knows_it() { | ||
// start | ||
let protocol_settings = &tools::PROTOCOL_SETTINGS; | ||
protocol_test_with_storage( | ||
protocol_test( | ||
protocol_settings, | ||
async move |mut network_controller, | ||
mut protocol_event_receiver, | ||
mut protocol_command_sender, | ||
protocol_manager, | ||
protocol_pool_event_receiver, | ||
storage| { | ||
protocol_pool_event_receiver| { | ||
let node_a = tools::create_and_connect_nodes(1, &mut network_controller) | ||
.await | ||
.pop() | ||
|
@@ -140,7 +138,7 @@ async fn test_someone_knows_it() { | |
|
||
// node C replied with the block | ||
network_controller | ||
.send_block(node_c.id, hash_1, Some((block, storage))) | ||
.send_block(node_c.id, block, Default::default()) | ||
.await; | ||
|
||
// 7. Make sure protocol did not send additional ask for block commands. | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Copyright (c) 2022 MASSA LABS <[email protected]> | ||
|
||
use super::tools::{protocol_test, protocol_test_with_storage}; | ||
use super::tools::protocol_test; | ||
use massa_models::prehash::{Map, Set}; | ||
use massa_models::signed::Signable; | ||
use massa_models::{BlockId, Slot}; | ||
|
@@ -15,14 +15,13 @@ use std::time::Duration; | |
#[serial] | ||
async fn test_protocol_bans_node_sending_block_with_invalid_signature() { | ||
let protocol_settings = &tools::PROTOCOL_SETTINGS; | ||
protocol_test_with_storage( | ||
protocol_test( | ||
protocol_settings, | ||
async move |mut network_controller, | ||
mut protocol_event_receiver, | ||
protocol_command_sender, | ||
protocol_manager, | ||
protocol_pool_event_receiver, | ||
storage| { | ||
protocol_pool_event_receiver| { | ||
// Create 1 node. | ||
let mut nodes = tools::create_and_connect_nodes(1, &mut network_controller).await; | ||
|
||
|
@@ -36,15 +35,7 @@ async fn test_protocol_bans_node_sending_block_with_invalid_signature() { | |
|
||
// 3. Send block to protocol. | ||
network_controller | ||
.send_block( | ||
creator_node.id, | ||
block | ||
.header | ||
.content | ||
.compute_id() | ||
.expect("Fail to compute block id"), | ||
Some((block, storage)), | ||
) | ||
.send_block(creator_node.id, block, Default::default()) | ||
.await; | ||
|
||
// The node is banned. | ||
|
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.