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 median #2049

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,8 @@ pub struct Mempool {
#[derive(Deserialize, Serialize, Default, Debug, Clone, PartialEq)]
#[serde(default)]
pub struct Tapi {
/// Oppose WIP0014
pub oppose_wip0014: bool,
/// Oppose WIP0016
pub oppose_wip0016: bool,
/// Oppose WIP0017
pub oppose_wip0017: bool,
}

fn to_partial_consensus_constants(c: &ConsensusConstants) -> PartialConsensusConstants {
Expand Down
10 changes: 4 additions & 6 deletions config/src/loaders/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,16 @@ enabled = false
// Check that the tapi table does not need to explicitly set all the new "oppose_wip" fields
// and they default to "false"
let empty_config = super::from_str("[tapi]").unwrap();
let config_oppose_0016 = super::from_str(
let config_oppose_0017 = super::from_str(
r"
[tapi]
oppose_wip0016 = true
oppose_wip0017 = true
",
)
.unwrap();

assert_eq!(empty_config.tapi, Tapi::default());
assert!(!empty_config.tapi.oppose_wip0014);
assert!(!empty_config.tapi.oppose_wip0016);
assert!(!config_oppose_0016.tapi.oppose_wip0014);
assert!(config_oppose_0016.tapi.oppose_wip0016);
assert!(!empty_config.tapi.oppose_wip0017);
assert!(config_oppose_0017.tapi.oppose_wip0017);
}
}
49 changes: 32 additions & 17 deletions data_structures/src/mainnet_validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ pub fn wip_info() -> HashMap<String, Epoch> {
active_wips.insert("WIP0008".to_string(), FIRST_HARD_FORK);
active_wips.insert("WIP0009-0011-0012".to_string(), SECOND_HARD_FORK);
active_wips.insert("THIRD_HARD_FORK".to_string(), THIRD_HARD_FORK);
active_wips.insert("WIP0014-0016".to_string(), 549141);

active_wips
}

/// Initial information about WIPs for Testnet and Development
fn test_wip_info() -> HashMap<String, Epoch> {
let mut active_wips = HashMap::<String, Epoch>::default();
active_wips.insert("WIP0008".to_string(), 0);
active_wips.insert("WIP0009-0011-0012".to_string(), 0);
active_wips.insert("THIRD_HARD_FORK".to_string(), 0);
active_wips.insert("WIP0014-0016".to_string(), 0);

active_wips
}
Expand Down Expand Up @@ -106,26 +118,24 @@ impl TapiEngine {
}

// Hardcoded information about WIPs in vote processing
let bit = 0;
let wip_0014 = BitVotesCounter {
let bit = 1;
let wip_0017 = BitVotesCounter {
votes: 0,
period: 26880,
wip: "WIP0014-0016".to_string(),
wip: "WIP0017".to_string(),
// Start voting at
// TODO: Choose a right date
// 13 July 2021 @ 9:00:00 UTC
init: 522240,
end: u32::MAX,
bit,
};
voting_wips[bit] = Some(wip_0014);
voting_wips[bit] = Some(wip_0017);
}
Environment::Testnet | Environment::Development => {
// In non-mainnet chains, all the WIPs that are active in mainnet are considered
// active since epoch 0. And there is no voting.
self.wip_activation.insert("WIP0008".to_string(), 0);
self.wip_activation
.insert("WIP0009-0011-0012".to_string(), 0);
self.wip_activation.insert("THIRD_HARD_FORK".to_string(), 0);
self.wip_activation = test_wip_info();
}
};

Expand Down Expand Up @@ -380,6 +390,10 @@ impl ActiveWips {
pub fn wip0016(&self) -> bool {
self.wip_active("WIP0014-0016")
}

pub fn wip0017(&self) -> bool {
self.wip_active("WIP0017")
}
}

#[cfg(test)]
Expand Down Expand Up @@ -644,24 +658,25 @@ mod tests {
let mut t = TapiEngine::default();

let (epoch, old_wips) = t.initialize_wip_information(Environment::Mainnet);
// The first block whose vote must be counted is the one from WIP0014
let init_epoch_wip0014 = 522240;
assert_eq!(epoch, init_epoch_wip0014);
// The first block whose vote must be counted is the one from WIP0017
// TODO: Update block number
let init_epoch_wip0017 = 522240;
assert_eq!(epoch, init_epoch_wip0017);
// The TapiEngine was just created, there list of old_wips must be empty
assert_eq!(old_wips, HashSet::new());
// The list of active WIPs only contains the first, second, and third hard forks
let mut hm = HashMap::new();
hm.insert("WIP0008".to_string(), FIRST_HARD_FORK);
hm.insert("WIP0009-0011-0012".to_string(), SECOND_HARD_FORK);
hm.insert("THIRD_HARD_FORK".to_string(), THIRD_HARD_FORK);
for (k, v) in wip_info() {
hm.insert(k, v);
}
assert_eq!(t.wip_activation, hm);

// Test initialize_wip_information with a non-empty TapiEngine
let (epoch, old_wips) = t.initialize_wip_information(Environment::Mainnet);
// WIP0014 is already included and it won't be updated
let name_wip0014 = "WIP0014-0016".to_string();
// WIP0017 is already included and it won't be updated
let name_wip0017 = "WIP0017".to_string();
let mut hs = HashSet::new();
hs.insert(name_wip0014);
hs.insert(name_wip0017);
assert_eq!(old_wips, hs);

// There is no new WIPs to update so we obtain the max value
Expand Down
19 changes: 11 additions & 8 deletions node/src/actors/chain_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2171,20 +2171,23 @@ impl ChainManager {

/// Return the value of the version field for a block in this epoch
fn tapi_signals_mask(&self, epoch: Epoch) -> u32 {
let Tapi {
oppose_wip0014,
oppose_wip0016,
} = &self.tapi;
let Tapi { oppose_wip0017 } = &self.tapi;

let mut v = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be v = 1, to keep bit 0 enabled?

if !oppose_wip0014
&& !oppose_wip0016
// Bit 0
// FIXME(#2051): Assess when remove achieved bit signaling
let bit = 0;
v |= 1 << bit;

// Bit 1
let bit = 1;
if !oppose_wip0017
&& self
.chain_state
.tapi_engine
.in_voting_range(epoch, "WIP0014-0016")
.in_voting_range(epoch, "WIP0017")
{
v |= 1 << 0;
v |= 1 << bit;
}

v
Expand Down
1 change: 1 addition & 0 deletions rad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if_rust_version = "1.0.0"
json = "0.12.1"
log = "0.4.8"
num_enum = "0.4.2"
ordered-float = "1.0"
rand = "0.7.3"
serde = "1.0.111"
serde_cbor = "0.11.1"
Expand Down
2 changes: 1 addition & 1 deletion rad/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub enum RadError {
ModeTie { values: RadonArray, max_count: u16 },
/// Tried to apply mod reducer on an empty array
#[fail(display = "Tried to apply mode reducer on an empty array")]
ModeEmpty,
EmptyArray,
/// The given arguments are not valid for the given operator
#[fail(
display = "Wrong `{}::{}()` arguments: `{:?}`",
Expand Down
2 changes: 1 addition & 1 deletion rad/src/filters/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod tests {
#[test]
fn test_filter_mode_empty() {
let input = vec![];
let expected = RadError::ModeEmpty;
let expected = RadError::EmptyArray;

let mut ctx = ReportContext {
stage: Stage::Tally(TallyMetaData::default()),
Expand Down
14 changes: 9 additions & 5 deletions rad/src/operators/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ pub fn count(input: &RadonArray) -> RadonInteger {
RadonInteger::from(input.value().len() as i128)
}

pub fn reduce(input: &RadonArray, args: &[Value]) -> Result<RadonTypes, RadError> {
pub fn reduce(
input: &RadonArray,
args: &[Value],
context: &mut ReportContext<RadonTypes>,
) -> Result<RadonTypes, RadError> {
let wrong_args = || RadError::WrongArguments {
input_type: RadonArray::radon_type_name(),
operator: "Reduce".to_string(),
Expand All @@ -39,7 +43,7 @@ pub fn reduce(input: &RadonArray, args: &[Value]) -> Result<RadonTypes, RadError
let reducer_integer = from_value::<u8>(arg).map_err(|_| wrong_args())?;
let reducer_code = RadonReducers::try_from(reducer_integer).map_err(|_| wrong_args())?;

reducers::reduce(input, reducer_code)
reducers::reduce(input, reducer_code, context)
}

pub fn get(input: &RadonArray, args: &[Value]) -> Result<RadonTypes, RadError> {
Expand Down Expand Up @@ -395,7 +399,7 @@ mod tests {
]);
let args = &[];

let result = reduce(input, args);
let result = reduce(input, args, &mut ReportContext::default());

assert_eq!(
&result.unwrap_err().to_string(),
Expand All @@ -411,7 +415,7 @@ mod tests {
]);
let args = &[Value::Text(String::from("wrong"))]; // This is RadonReducers::AverageMean

let result = reduce(input, args);
let result = reduce(input, args, &mut ReportContext::default());

assert_eq!(
&result.unwrap_err().to_string(),
Expand All @@ -427,7 +431,7 @@ mod tests {
]);
let args = &[Value::Integer(-1)]; // This doesn't match any reducer code in RadonReducers

let result = reduce(input, args);
let result = reduce(input, args, &mut ReportContext::default());

assert_eq!(
&result.unwrap_err().to_string(),
Expand Down
Loading