Skip to content

Commit

Permalink
refactor: move current_active_wips and all_wips_active to mainnet_val…
Browse files Browse the repository at this point in the history
…idations
  • Loading branch information
lrubiorod committed Sep 17, 2021
1 parent 0efa2a1 commit 1ad2cb1
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 35 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion bridges/centralized-ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ witnet_data_structures = { path = "../../data_structures" }
witnet_config = { path = "../../config" }
witnet_net = { path = "../../net" }
witnet_node = { path = "../../node" }
witnet_rad = { path = "../../rad" }
witnet_util = { path = "../../util" }
witnet_validations = { path = "../../validations" }
2 changes: 1 addition & 1 deletion bridges/centralized-ethereum/src/actors/dr_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use serde_json::json;
use std::{fmt, time::Duration};
use witnet_data_structures::{
chain::{DataRequestOutput, Hash},
mainnet_validations::current_active_wips,
proto::ProtobufConvert,
radon_error::RadonErrors,
};
use witnet_net::client::tcp::{jsonrpc, JsonRpcClient};
use witnet_rad::current_active_wips;
use witnet_util::timestamp::get_timestamp;
use witnet_validations::validations::{validate_data_request_output, validate_rad_request};

Expand Down
1 change: 0 additions & 1 deletion bridges/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ tokio-core = "0.1.17"
web3 = "0.10.0"
witnet_data_structures = { path = "../../data_structures" }
witnet_crypto = { path = "../../crypto" }
witnet_rad = { path = "../../rad" }
witnet_util = { path = "../../util" }
witnet_validations = { path = "../../validations" }
2 changes: 1 addition & 1 deletion bridges/ethereum/src/actors/claim_and_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use web3::{contract, futures::Future, types::U256};
use witnet_crypto::hash::{calculate_sha256, Sha256};
use witnet_data_structures::{
chain::{DataRequestOutput, Hashable, KeyedSignature},
mainnet_validations::current_active_wips,
proto::ProtobufConvert,
};
use witnet_rad::current_active_wips;
use witnet_util::timestamp::get_local_timestamp;
use witnet_validations::validations::validate_rad_request;

Expand Down
18 changes: 18 additions & 0 deletions data_structures/src/mainnet_validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ fn test_wip_info() -> HashMap<String, Epoch> {
active_wips
}

/// Auxiliary function that returns the current active wips for using in RADON
/// It is only used for testing or for external libraries, so we set epoch to MAX
pub fn current_active_wips() -> ActiveWips {
ActiveWips {
active_wips: wip_info(),
block_epoch: u32::MAX,
}
}

/// 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);

h
}

impl TapiEngine {
pub fn update_bit_counter(
&mut self,
Expand Down
5 changes: 3 additions & 2 deletions node/src/actors/chain_manager/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,14 +1015,15 @@ mod tests {
};

use witnet_crypto::signature::{sign, verify};
use witnet_data_structures::{chain::*, transaction::*, vrf::VrfCtx};
use witnet_data_structures::{
chain::*, mainnet_validations::current_active_wips, transaction::*, vrf::VrfCtx,
};
use witnet_protected::Protected;
use witnet_validations::validations::validate_block_signature;

use crate::actors::chain_manager::verify_signatures;

use super::*;
use witnet_rad::current_active_wips;

const INITIAL_BLOCK_REWARD: u64 = 250 * 1_000_000_000;
const HALVING_PERIOD: u32 = 3_500_000;
Expand Down
6 changes: 4 additions & 2 deletions node/src/actors/chain_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ use witnet_data_structures::{
},
data_request::DataRequestPool,
get_environment,
mainnet_validations::{after_second_hard_fork, in_emergency_period, ActiveWips},
mainnet_validations::{
after_second_hard_fork, current_active_wips, in_emergency_period, ActiveWips,
},
radon_report::{RadonReport, ReportContext},
superblock::{ARSIdentities, AddSuperBlockVote, SuperBlockConsensus},
transaction::{TallyTransaction, Transaction},
Expand All @@ -65,7 +67,7 @@ use witnet_data_structures::{
vrf::VrfCtx,
};

use witnet_rad::{current_active_wips, types::RadonTypes};
use witnet_rad::types::RadonTypes;
use witnet_util::timestamp::seconds_to_human_string;
use witnet_validations::validations::{
compare_block_candidates, validate_block, validate_block_transactions,
Expand Down
2 changes: 1 addition & 1 deletion node/src/actors/inventory_manager/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ mod tests {
TransactionsPool, ValueTransferOutput,
},
data_request::DataRequestPool,
mainnet_validations::current_active_wips,
transaction::{Transaction, VTTransaction, VTTransactionBody},
utxo_pool::UnspentOutputsPool,
vrf::BlockEligibilityClaim,
};
use witnet_rad::current_active_wips;

const INITIAL_BLOCK_REWARD: u64 = 250 * 1_000_000_000;
const HALVING_PERIOD: u32 = 3_500_000;
Expand Down
3 changes: 1 addition & 2 deletions node/tests/data_request_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use std::{

use serde::{Deserialize, Serialize};

use witnet_data_structures::chain::DataRequestOutput;
use witnet_data_structures::{chain::DataRequestOutput, mainnet_validations::all_wips_active};
use witnet_node::actors::messages::BuildDrt;
use witnet_rad::{
all_wips_active,
script::RadonScriptExecutionSettings,
types::{
bytes::RadonBytes, float::RadonFloat, integer::RadonInteger, string::RadonString,
Expand Down
20 changes: 1 addition & 19 deletions rad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
};
use witnet_data_structures::{
chain::{RADAggregate, RADRequest, RADRetrieve, RADTally, RADType},
mainnet_validations::{wip_info, ActiveWips},
mainnet_validations::{current_active_wips, ActiveWips},
radon_report::{RadonReport, ReportContext, RetrievalMetadata, Stage, TallyMetaData},
};

Expand All @@ -42,24 +42,6 @@ pub struct RADRequestExecutionReport {
pub tally: RadonReport<RadonTypes>,
}

/// Auxiliary function that returns the current active wips for using in RADON
/// It is only used for testing or for external libraries, so we set epoch to MAX
pub fn current_active_wips() -> ActiveWips {
ActiveWips {
active_wips: wip_info(),
block_epoch: u32::MAX,
}
}

/// 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);

h
}

/// Executes a data request locally.
/// The `inputs_injection` allows for disabling the actual retrieval of the data sources and
/// the provided strings will be fed to the retrieval scripts instead. It is therefore expected that
Expand Down
3 changes: 2 additions & 1 deletion src/cli/node/json_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use witnet_data_structures::{
KeyedSignature, NodeStats, OutputPointer, PublicKey, PublicKeyHash, StateMachine,
SupplyInfo, SyncStatus, ValueTransferOutput,
},
mainnet_validations::current_active_wips,
proto::ProtobufConvert,
transaction::Transaction,
transaction_factory::NodeBalance,
Expand All @@ -38,7 +39,7 @@ use witnet_node::actors::{
},
messages::{BuildVtt, GetReputationResult, SignalingInfo},
};
use witnet_rad::{current_active_wips, types::RadonTypes};
use witnet_rad::types::RadonTypes;
use witnet_util::{credentials::create_credentials_file, timestamp::pretty_print};
use witnet_validations::validations::{validate_data_request_output, validate_rad_request, Wit};

Expand Down
2 changes: 1 addition & 1 deletion validations/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ use witnet_data_structures::{
};
use witnet_protected::Protected;
use witnet_rad::{
all_wips_active, current_active_wips,
error::RadError,
filters::RadonFilters,
reducers::RadonReducers,
types::{bytes::RadonBytes, integer::RadonInteger, RadonTypes},
};

use crate::validations::*;
use witnet_data_structures::mainnet_validations::{all_wips_active, current_active_wips};

mod compare_block_candidates;
mod randpoe;
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/actors/app/handlers/create_data_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use crate::{
};
use witnet_data_structures::{
chain::{DataRequestOutput, Hashable},
mainnet_validations::current_active_wips,
proto::ProtobufConvert,
transaction::Transaction,
transaction_factory::FeeType,
};
use witnet_rad::current_active_wips;

#[derive(Debug, Deserialize)]
pub struct CreateDataReqRequest {
Expand Down

0 comments on commit 1ad2cb1

Please sign in to comment.