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

Include xor versioning #4090

Merged
merged 27 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1ad955b
feat(channel) : impl send_deadline on sender and recv_deadline / recv…
modship Jun 13, 2023
214a16e
update block graph counter
modship Jun 13, 2023
ae041f0
Add debug logs.
AurelienFT Jun 14, 2023
05c83e3
fix compil
AurelienFT Jun 14, 2023
a1792de
Add more logs
AurelienFT Jun 14, 2023
f8c281d
Try to fix caches
AurelienFT Jun 14, 2023
caf4e30
Add print block prod
AurelienFT Jun 14, 2023
243a919
Fix logs
AurelienFT Jun 14, 2023
0c11482
Add more debug on op pool
AurelienFT Jun 14, 2023
ac556dd
fix print
AurelienFT Jun 14, 2023
c9fc187
Add logs on iterating.
AurelienFT Jun 14, 2023
090dd48
adapt logs
AurelienFT Jun 14, 2023
46795f9
Add more debug print around versioning update
AurelienFT Jun 14, 2023
34d423f
Add more debug ops.
AurelienFT Jun 14, 2023
c67d948
Add logs in finalize.
AurelienFT Jun 14, 2023
29ffba4
Add logs massa db
AurelienFT Jun 14, 2023
2008760
Add get_hash_kind_version in final state
sydhds Jun 15, 2023
b368beb
Propagated the only_use_xor bool
Leo-Besancon Jun 15, 2023
64a37a9
Merge branch 'include_xor_versioning' of https://github.com/massalabs…
Leo-Besancon Jun 15, 2023
965a61c
Compute xor
Leo-Besancon Jun 15, 2023
eba864c
Fix lsm_tree init
Leo-Besancon Jun 15, 2023
6f61d6b
Remove debug print
AurelienFT Jun 15, 2023
22559f9
Merge branch 'main' into include_xor_versioning
AurelienFT Jun 15, 2023
d92081e
update peernet
AurelienFT Jun 15, 2023
d55a0d9
Use slot ts for Versioning check
sydhds Jun 15, 2023
68c30ab
Merge branch 'main' into include_xor_versioning
AurelienFT Jun 15, 2023
8975bfd
Fix clippy
AurelienFT Jun 15, 2023
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
4 changes: 2 additions & 2 deletions massa-async-pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ impl AsyncPool {
/// Resets the pool to its initial state
///
/// USED ONLY FOR BOOTSTRAP
pub fn reset(&mut self) {
pub fn reset(&mut self, only_use_xor: bool) {
self.db
.write()
.delete_prefix(ASYNC_POOL_PREFIX, STATE_CF, None);
.delete_prefix(ASYNC_POOL_PREFIX, STATE_CF, None, only_use_xor);
self.recompute_message_info_cache();
}

Expand Down
14 changes: 9 additions & 5 deletions massa-bootstrap/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,13 @@ pub fn get_state(
{
let mut final_state_guard = final_state.write();

let only_use_xor = final_state_guard.get_only_use_xor(&Slot::new(0, 31));

if !bootstrap_config.keep_ledger {
// load ledger from initial ledger file
final_state_guard
.ledger
.load_initial_ledger()
.load_initial_ledger(only_use_xor)
.map_err(|err| {
BootstrapError::GeneralError(format!(
"could not load initial ledger: {}",
Expand All @@ -439,10 +441,12 @@ pub fn get_state(
);

// TODO: should receive ver batch here?
final_state_guard
.db
.write()
.write_batch(batch, Default::default(), Some(slot));
final_state_guard.db.write().write_batch(
batch,
Default::default(),
Some(slot),
only_use_xor,
);
}
return Ok(GlobalBootstrapState::new(final_state));
}
Expand Down
8 changes: 4 additions & 4 deletions massa-bootstrap/src/tests/scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,13 @@ fn test_bootstrap_server() {
final_write
.db
.write()
.write_batch(batch, Default::default(), Some(next));
.write_batch(batch, Default::default(), Some(next), false);

let final_state_hash = final_write.db.read().get_db_hash();
let cycle = next.get_cycle(final_state_local_config.periods_per_cycle.clone());
final_write
.pos_state
.feed_cycle_state_hash(cycle, final_state_hash);
.feed_cycle_state_hash(cycle, final_state_hash, false);

current_slot = next;
}
Expand Down Expand Up @@ -462,13 +462,13 @@ fn test_bootstrap_server() {
final_write
.db
.write()
.write_batch(batch, Default::default(), Some(next));
.write_batch(batch, Default::default(), Some(next), false);

let final_state_hash = final_write.db.read().get_db_hash();
let cycle = next.get_cycle(final_state_local_config.periods_per_cycle.clone());
final_write
.pos_state
.feed_cycle_state_hash(cycle, final_state_hash);
.feed_cycle_state_hash(cycle, final_state_hash, false);

let mut list_changes_write = list_changes_clone.write();
list_changes_write.push((next, changes));
Expand Down
15 changes: 10 additions & 5 deletions massa-bootstrap/src/tests/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,18 @@ fn get_random_pos_state(r_limit: u64, mut pos: PoSFinalState) -> PoSFinalState {

pos.create_initial_cycle(&mut batch);

pos.db.write().write_batch(batch, Default::default(), None);
pos.db
.write()
.write_batch(batch, Default::default(), None, false);

let mut batch = DBBatch::new();

pos.apply_changes_to_batch(changes, Slot::new(0, 0), false, &mut batch)
.expect("Critical: Error while applying changes to pos_state");

pos.db.write().write_batch(batch, Default::default(), None);
pos.db
.write()
.write_batch(batch, Default::default(), None, false);

pos
}
Expand Down Expand Up @@ -230,7 +234,8 @@ pub fn get_random_executed_ops(
let mut executed_ops = ExecutedOps::new(config.clone(), db.clone());
let mut batch = DBBatch::new();
executed_ops.apply_changes_to_batch(get_random_executed_ops_changes(10), slot, &mut batch);
db.write().write_batch(batch, Default::default(), None);
db.write()
.write_batch(batch, Default::default(), None, false);
executed_ops
}

Expand Down Expand Up @@ -264,7 +269,7 @@ pub fn get_random_executed_de(
executed_de
.db
.write()
.write_batch(batch, Default::default(), None);
.write_batch(batch, Default::default(), None, false);

executed_de
}
Expand Down Expand Up @@ -318,7 +323,7 @@ pub fn get_random_final_state_bootstrap(
async_pool
.db
.write()
.write_batch(batch, versioning_batch, None);
.write_batch(batch, versioning_batch, None, false);

let executed_ops = get_random_executed_ops(
r_limit,
Expand Down
35 changes: 34 additions & 1 deletion massa-channel/src/receiver.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{
ops::{Deref, DerefMut},
sync::Arc,
time::{Duration, Instant},
};

use crossbeam::channel::{Receiver, RecvError, TryRecvError};
use crossbeam::channel::{Receiver, RecvError, RecvTimeoutError, TryRecvError};
use prometheus::{Counter, Gauge};

#[derive(Clone)]
Expand Down Expand Up @@ -63,6 +64,38 @@ impl<T> MassaReceiver<T> {
}
}

pub fn recv_deadline(&self, deadline: Instant) -> Result<T, RecvTimeoutError> {
match self.receiver.recv_deadline(deadline) {
Ok(msg) => {
self.inc_metrics();

Ok(msg)
}
Err(e) => {
let _ = prometheus::unregister(Box::new(self.actual_len.clone()));
let _ = prometheus::unregister(Box::new(self.received.clone()));

Err(e)
}
}
}

pub fn recv_timeout(&self, timeout: Duration) -> Result<T, RecvTimeoutError> {
match self.receiver.recv_timeout(timeout) {
Ok(msg) => {
self.inc_metrics();

Ok(msg)
}
Err(e) => {
let _ = prometheus::unregister(Box::new(self.actual_len.clone()));
let _ = prometheus::unregister(Box::new(self.received.clone()));

Err(e)
}
}
}

pub fn recv(&self) -> Result<T, RecvError> {
match self.receiver.recv() {
Ok(msg) => {
Expand Down
15 changes: 14 additions & 1 deletion massa-channel/src/sender.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{ops::Deref, time::Duration};
use std::{
ops::Deref,
time::{Duration, Instant},
};

use crossbeam::channel::{SendError, SendTimeoutError, Sender, TrySendError};
use prometheus::Gauge;
Expand Down Expand Up @@ -34,6 +37,16 @@ impl<T> MassaSender<T> {
}
}

pub fn send_deadline(&self, msg: T, deadline: Instant) -> Result<(), SendTimeoutError<T>> {
match self.sender.send_deadline(msg, deadline) {
Ok(()) => {
self.actual_len.inc();
Ok(())
}
Err(e) => Err(e),
}
}

pub fn try_send(&self, msg: T) -> Result<(), TrySendError<T>> {
match self.sender.try_send(msg) {
Ok(()) => {
Expand Down
28 changes: 15 additions & 13 deletions massa-consensus-worker/src/state/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,19 +330,6 @@ impl ConsensusState {
"block_id": add_block_id
});

{
// set metrics
let add_slot_timestamp = timeslots::get_block_slot_timestamp(
self.config.thread_count,
self.config.t0,
self.config.genesis_timestamp,
add_block_slot,
)?;
let now = MassaTime::now()?;
let diff = now.saturating_sub(add_slot_timestamp);
self.massa_metrics.set_block_graph_diff_ms(diff.to_millis());
}

// Ensure block parents are claimed by the block's storage.
// Note that operations and endorsements should already be there (claimed in Protocol).
storage.claim_block_refs(&parents_hash_period.iter().map(|(p_id, _)| *p_id).collect());
Expand Down Expand Up @@ -498,6 +485,21 @@ impl ConsensusState {
self.mark_final_blocks(&add_block_id, final_blocks)?;

massa_trace!("consensus.block_graph.add_block_to_graph.end", {});

{
// set metrics
let add_slot_timestamp = timeslots::get_block_slot_timestamp(
self.config.thread_count,
self.config.t0,
self.config.genesis_timestamp,
add_block_slot,
)?;
let now = MassaTime::now()?;
let diff = now.saturating_sub(add_slot_timestamp);
self.massa_metrics.inc_block_graph_counter();
self.massa_metrics.inc_block_graph_ms(diff.to_millis());
}

Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions massa-db/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub const STATE_CF: &str = "state";
pub const VERSIONING_CF: &str = "versioning";

pub const STATE_HASH_KEY: &[u8; 1] = b"h";
pub const STATE_HASH_XOR_KEY: &[u8; 1] = b"x";
pub const STATE_HASH_KEY_IS_XOR_KEY: &[u8; 6] = b"is_xor";
pub const STATE_HASH_INITIAL_BYTES: &[u8; 32] = &[0; HASH_SIZE_BYTES];
pub const CHANGE_ID_KEY: &[u8; 1] = b"c";

Expand Down
Loading