Skip to content

Commit

Permalink
feat: apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
lrubiorod committed Sep 17, 2021
1 parent 1ad2cb1 commit 2ca0fe9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
23 changes: 13 additions & 10 deletions data_structures/src/data_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,9 @@ impl DataRequestPool {
self.data_request_pool.get(dr_pointer).map(|dr_state| {
let mut reveals: Vec<&RevealTransaction> = dr_state.info.reveals.values().collect();
if active_wips.wip0019() {
// As specified in (7) in WIP-0019
reveals.sort_unstable_by_key(|reveal| {
let mut bytes_to_hash = vec![];
bytes_to_hash.extend(reveal.body.pkh.hash);
bytes_to_hash.extend(dr_pointer.as_ref());

calculate_sha256(bytes_to_hash.as_ref()).0
concatenate_and_hash(&reveal.body.pkh.hash, dr_pointer.as_ref())
});
} else {
reveals.sort_unstable_by_key(|reveal| reveal.body.pkh);
Expand Down Expand Up @@ -100,12 +97,9 @@ impl DataRequestPool {
dr_state.info.reveals.values().cloned().collect();

if active_wips.wip0019() {
// As specified in (7) in WIP-0019
reveals.sort_unstable_by_key(|reveal| {
let mut bytes_to_hash = vec![];
bytes_to_hash.extend(reveal.body.pkh.hash);
bytes_to_hash.extend(dr_pointer.as_ref());

calculate_sha256(bytes_to_hash.as_ref()).0
concatenate_and_hash(&reveal.body.pkh.hash, dr_pointer.as_ref())
});
} else {
reveals.sort_unstable_by_key(|reveal| reveal.body.pkh);
Expand Down Expand Up @@ -424,6 +418,15 @@ impl DataRequestPool {
}
}

/// Concatenate 2 bytes sequences and hash
fn concatenate_and_hash(a: &[u8], b: &[u8]) -> [u8; 32] {
let mut bytes_to_hash = vec![];
bytes_to_hash.extend(a);
bytes_to_hash.extend(b);

calculate_sha256(bytes_to_hash.as_ref()).0
}

/// Return the change that should be returned to the creator of the data request if
/// some witness fails to commit, fails to reveal, or reports a value out of consensus.
/// If the change is 0, the change `ValueTransferOutput` should not be created
Expand Down
8 changes: 5 additions & 3 deletions data_structures/src/mainnet_validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ pub fn current_active_wips() -> ActiveWips {
/// Auxiliary function that returns the current active wips and the WIPs in voting process as actived
/// It is only used for testing
pub fn all_wips_active() -> ActiveWips {
let mut h = current_active_wips();
h.active_wips.insert("WIP0017-0018-0019".to_string(), 0);
let mut active_wips = current_active_wips();
active_wips
.active_wips
.insert("WIP0017-0018-0019".to_string(), 0);

h
active_wips
}

impl TapiEngine {
Expand Down
8 changes: 4 additions & 4 deletions node/src/actors/chain_manager/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,26 +1277,26 @@ impl Handler<BuildDrt> for ChainManager {
block_epoch: self.current_epoch.unwrap(),
};

let mut dro = msg.dro;
let mut dr_output = msg.dro;
// TODO: Remove after WIP-0019 activation
// Before wip-0019 activation, RadType::HttpGet enum is serialized with a 0.
// With the new update, position 0 is RadType::Unknown, so to keep backward compatibility,
// we need to convert HttpGet retrievals to Unknown.
if !active_wips.wip0019() {
for retrieval in &mut dro.data_request.retrieve {
for retrieval in &mut dr_output.data_request.retrieve {
if retrieval.kind == RADType::HttpGet {
retrieval.kind = RADType::Unknown;
}
}
}

if let Err(e) = validate_rad_request(&dro.data_request, &active_wips) {
if let Err(e) = validate_rad_request(&dr_output.data_request, &active_wips) {
return Box::pin(actix::fut::err(e));
}
let timestamp = u64::try_from(get_timestamp()).unwrap();
let max_dr_weight = self.consensus_constants().max_dr_weight;
match transaction_factory::build_drt(
dro,
dr_output,
msg.fee,
&mut self.chain_state.own_utxos,
self.own_pkh.unwrap(),
Expand Down
3 changes: 3 additions & 0 deletions node/src/actors/chain_manager/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ impl ChainManager {
active_wips: self.chain_state.tapi_engine.wip_activation.clone(),
block_epoch: current_epoch,
};

// TODO: Remove after WIP-0019 activation
// It is only used to include the active_wips in the extra validation of the rad_requests
let active_wips = Arc::new(active_wips);
let active_wips2 = active_wips.clone();

Expand Down

0 comments on commit 2ca0fe9

Please sign in to comment.