Skip to content
Snippets Groups Projects
Commit 8087b944 authored by Éloïs's avatar Éloïs
Browse files

[ref] blockchain & ws2p-v1: remove commented code

parent 495b4703
No related branches found
No related tags found
1 merge request!109Resolve "Fork resolution algorithm"
......@@ -588,10 +588,6 @@ mod tests {
),
(TreeNodeId(11), child_fork_blockstamp),
];
/*assert!(
(sheets[0] == expected_sheets[0] && sheets[1] == expected_sheets[1])
|| (sheets[0] == expected_sheets[1] && sheets[1] == expected_sheets[0])
);*/
assert!(rust_tests_tools::collections::slice_same_elems(
&expected_sheets,
&sheets
......
......@@ -97,90 +97,3 @@ pub fn insert_new_fork_block(forks_dbs: &ForksDBs, dal_block: DALBlock) -> Resul
Ok(false)
}
}
/*/// Write DALBlock in databases
pub fn write(
blockchain_db: &BinDB<LocalBlockchainV10Datas>,
forks_db: &BinDB<ForksV10Datas>,
forks_blocks_db: &BinDB<ForksBlocksV10Datas>,
dal_block: &DALBlock,
from_to_fork_id: Option<ForkId>,
sync: bool,
revert: bool,
) -> Result<(), DALError> {
if dal_block.fork_id.0 == 0 {
blockchain_db.write(|db| {
if revert {
db.remove(&dal_block.block.number);
} else {
db.insert(dal_block.block.number, dal_block.clone());
}
})?;
if from_to_fork_id.is_some() {
forks_blocks_db.write(|db| {
db.remove(&dal_block.block.blockstamp());
})?;
}
}
// Move block in a fork
if revert {
if let Some(to_fork_id) = from_to_fork_id {
forks_db.write(|db| {
let previous_blockstamp = dal_block.block.previous_blockstamp();
let mut fork_meta_datas = db.get(&to_fork_id).unwrap().clone();
fork_meta_datas.insert(
previous_blockstamp,
dal_block
.block
.hash
.expect("Try to get hash of a reduce block !"),
);
db.insert(to_fork_id, fork_meta_datas);
})?;
}
} else if let Some(from_fork_id) = from_to_fork_id {
// Remove block in fork origin
forks_db.write(|db| {
let mut fork_meta_datas = db
.get(&from_fork_id)
.expect("from_fork_id don(t exist !")
.clone();
let previous_blockstamp = dal_block.block.previous_blockstamp();
fork_meta_datas.remove(&previous_blockstamp);
db.insert(from_fork_id, fork_meta_datas);
if dal_block.fork_id.0 > 0 {
let mut fork_meta_datas = db.get(&dal_block.fork_id).unwrap().clone();
fork_meta_datas.insert(
previous_blockstamp,
dal_block
.block
.hash
.expect("Try to get hash of a reduce block !"),
);
db.insert(from_fork_id, fork_meta_datas);
}
})?;
}
if !sync {
let mut blockchain_meta_datas: HashMap<PreviousBlockstamp, BlockHash> = forks_db
.read(|db| db.get(&ForkId(0)).cloned())
.expect("Get blockchain meta datas : DALError")
.unwrap_or_else(HashMap::new);
let block_previous_hash = if dal_block.block.number.0 == 0 {
PreviousBlockstamp::default()
} else {
PreviousBlockstamp {
id: BlockId(dal_block.block.number.0 - 1),
hash: BlockHash(dal_block.block.previous_hash),
}
};
blockchain_meta_datas.insert(block_previous_hash, dal_block.block.hash.unwrap());
forks_db
.write(|db| {
db.insert(ForkId(0), blockchain_meta_datas);
})
.expect("Write blockchain meta datas : DALError");
}
Ok(())
}*/
......@@ -13,10 +13,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::constants::*;
use crate::*;
use dubp_documents::Blockstamp;
use duniter_network::*;
use dup_crypto::keys::*;
use durs_message::requests::BlockchainRequest;
use durs_message::*;
......@@ -151,44 +148,6 @@ impl WS2PModuleDatas {
}))
.expect("Fail to send network event to router !");
}
pub fn get_network_consensus(&self) -> Result<Blockstamp, NetworkConsensusError> {
let mut count_known_blockstamps = 0;
let mut farthest_blockstamp = Blockstamp::default();
let mut blockstamps_occurences: HashMap<Blockstamp, usize> =
HashMap::with_capacity(*WS2P_DEFAULT_OUTCOMING_QUOTA);
let mut dominant_blockstamp = Blockstamp::default();
let mut dominant_blockstamp_occurences = 0;
for (_ws2p_full_id, head) in self.heads_cache.clone() {
count_known_blockstamps += 1;
let blockstamps_occurences_copy = blockstamps_occurences.clone();
match blockstamps_occurences_copy.get(&head.blockstamp()) {
Some(occurences) => {
let occurences_mut = blockstamps_occurences
.get_mut(&head.blockstamp())
.expect("WS2P: Fail to get_mut blockstamps_occurences !");
*occurences_mut += 1;
if *occurences > dominant_blockstamp_occurences {
dominant_blockstamp_occurences = *occurences;
dominant_blockstamp = head.blockstamp();
}
}
None => {
blockstamps_occurences.insert(head.blockstamp(), 0);
}
}
if head.blockstamp().id.0 > farthest_blockstamp.id.0 {
farthest_blockstamp = head.blockstamp();
}
}
if count_known_blockstamps < 5 {
return Err(NetworkConsensusError::InsufficientData(
count_known_blockstamps,
));
} else if farthest_blockstamp == dominant_blockstamp {
return Ok(dominant_blockstamp);
}
Err(NetworkConsensusError::Fork())
}
fn count_established_connections(&self) -> usize {
let mut count_established_connections = 0;
for (_ws2p_full_id, (_ep, state)) in self.ws2p_endpoints.clone() {
......@@ -482,65 +441,6 @@ impl WS2PModuleDatas {
WS2PSignal::Empty
}
/*pub fn send_request_to_all_connections(
&mut self,
ws2p_request: &OldNetworkRequest,
) -> Result<(), SendRequestError> {
let mut count_successful_sending: usize = 0;
let mut errors: Vec<ws::Error> = Vec::new();
match *ws2p_request {
OldNetworkRequest::GetCurrent(req_full_id, _receiver) => {
for (ws2p_full_id, (_ep, state)) in self.ws2p_endpoints.clone() {
if let WS2PConnectionState::Established = state {
let ws2p_request = OldNetworkRequest::GetCurrent(
ModuleReqFullId(
req_full_id.0,
ModuleReqId(
(self.requests_awaiting_response.len()
+ count_successful_sending)
as u32,
),
),
ws2p_full_id,
);
match self.send_request_to_specific_node(&ws2p_full_id, &ws2p_request) {
Ok(_) => count_successful_sending += 1,
Err(e) => errors.push(e),
};
}
}
}
/* OldNetworkRequest::GetBlock(req_full_id, number) => {} */
OldNetworkRequest::GetBlocks(_req_full_id, _receiver, _count, _from_number) => {}
OldNetworkRequest::GetRequirementsPending(req_full_id, _receiver, min_cert) => {
for (ws2p_full_id, (_ep, state)) in self.ws2p_endpoints.clone() {
if let WS2PConnectionState::Established = state {
let ws2p_request = OldNetworkRequest::GetRequirementsPending(
ModuleReqFullId(
req_full_id.0,
ModuleReqId(self.requests_awaiting_response.len() as u32),
),
ws2p_full_id,
min_cert,
);
match self.send_request_to_specific_node(&ws2p_full_id, &ws2p_request) {
Ok(_) => count_successful_sending += 1,
Err(e) => errors.push(e),
};
}
}
}
_ => {
return Err(SendRequestError::RequestTypeMustNotBeTransmitted());
}
}
debug!("count_successful_sending = {}", count_successful_sending);
if !errors.is_empty() {
return Err(SendRequestError::WSError(count_successful_sending, errors));
}
Ok(())
}*/
pub fn send_request_to_specific_node(
&mut self,
receiver_ws2p_full_id: &NodeFullId,
......
......@@ -824,19 +824,6 @@ impl DursModule<DuRsConf, DursMsg> for WS2PModule {
connected_nodes.push(k);
}
}
// Print network consensus
match ws2p_module.get_network_consensus() {
Ok(consensus_blockstamp) => {
debug!(
"WS2PModule : get_network_consensus() = {:?}",
consensus_blockstamp
);
if current_blockstamp.id.0 < (consensus_blockstamp.id.0 + 2) {
warn!("We probably are in a fork branch !");
}
}
Err(e) => warn!("{:?}", e),
}
// Print current_blockstamp
info!(
"WS2PModule : current_blockstamp() = {:?}",
......@@ -859,27 +846,6 @@ impl DursModule<DuRsConf, DursMsg> for WS2PModule {
info!("Connected to know endpoints...");
ws2p_module.connect_to_know_endpoints();
}
/*// Request blocks from network
if SystemTime::now()
.duration_since(last_blocks_request)
.unwrap() > Duration::new(*BLOCKS_REQUEST_INTERVAL, 0)
&& SystemTime::now().duration_since(start_time).unwrap() > Duration::new(10, 0)
{
let mut request_blocks_from = current_blockstamp.id.0;
if request_blocks_from > 0 {
request_blocks_from += 1;
}
info!("get chunks from all connections...");
let module_id = WS2PModule::name();
let _blocks_request_result =
ws2p_module.send_request_to_all_connections(&OldNetworkRequest::GetBlocks(
ModuleReqFullId(module_id, ModuleReqId(0 as u32)),
NodeFullId::default(),
50,
request_blocks_from,
));
last_blocks_request = SystemTime::now();
}*/
// Request pending_identities from network
if SystemTime::now()
.duration_since(last_identities_request)
......@@ -901,15 +867,6 @@ impl DursModule<DuRsConf, DursMsg> for WS2PModule {
if let Some(&(ref ep, ref state)) =
ws2p_module.ws2p_endpoints.get(&ep_full_id)
{
/*let dal_endpoint = durs_blockchain_dal::endpoint::DALEndpoint::new(
state.clone() as u32,
ep.node_uuid().unwrap().0,
ep.pubkey(),
durs_blockchain_dal::endpoint::string_to_api(&ep.api().0).unwrap(),
1,
ep.to_string(),
received_time.duration_since(UNIX_EPOCH).unwrap(),
);*/
ws2p_db::write_endpoint(
&db,
&ep,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment