Skip to content

Commit

Permalink
Network Sustainability Mechanism - ZIP 234 and 235 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mariopil committed Oct 18, 2024
1 parent 76a5494 commit ce2eedd
Show file tree
Hide file tree
Showing 40 changed files with 982 additions and 576 deletions.
3 changes: 2 additions & 1 deletion zebra-chain/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ use crate::{
};

mod commitment;
mod error;
mod hash;
mod header;
mod height;
mod serialize;

pub mod error;
pub mod genesis;
pub mod merkle;
pub mod subsidy;

#[cfg(any(test, feature = "proptest-impl"))]
pub mod arbitrary;
Expand Down
15 changes: 14 additions & 1 deletion zebra-chain/src/block/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

use thiserror::Error;

use crate::error::SubsidyError;

#[cfg(any(test, feature = "proptest-impl"))]
use proptest_derive::Arbitrary;

#[derive(Clone, Error, Debug, PartialEq, Eq)]
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
#[allow(missing_docs)]
#[derive(Error, Debug, PartialEq, Eq)]
pub enum BlockError {
#[error("block has no transactions")]
NoTransactions,

#[error("transaction has wrong consensus branch id for block network upgrade")]
WrongTransactionConsensusBranchId,

#[error("block failed subsidy validation")]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
Subsidy(#[from] SubsidyError),
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::collections::HashMap;

use zebra_chain::{
use crate::{
amount::{Amount, Error, NonNegative},
block::Height,
parameters::{subsidy::*, Network, NetworkUpgrade::*},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
//! Tests for funding streams.

use color_eyre::Report;
use zebra_chain::parameters::{
subsidy::FundingStreamReceiver,
testnet::{
self, ConfiguredActivationHeights, ConfiguredFundingStreamRecipient,
ConfiguredFundingStreams,

use crate::{
block::subsidy::general::block_subsidy_pre_nsm,
parameters::{
subsidy::FundingStreamReceiver,
testnet::{
self, ConfiguredActivationHeights, ConfiguredFundingStreamRecipient,
ConfiguredFundingStreams,
},
NetworkKind,
},
NetworkKind,
};

use crate::block::subsidy::general::block_subsidy;

use super::*;

/// Check mainnet funding stream values are correct for the entire period.
Expand All @@ -26,7 +28,7 @@ fn test_funding_stream_values() -> Result<(), Report> {
assert!(funding_stream_values(
canopy_height_minus1,
network,
block_subsidy(canopy_height_minus1, network)?
block_subsidy_pre_nsm(canopy_height_minus1, network)?
)?
.is_empty());

Expand All @@ -50,7 +52,7 @@ fn test_funding_stream_values() -> Result<(), Report> {
funding_stream_values(
canopy_height,
network,
block_subsidy(canopy_height, network)?
block_subsidy_pre_nsm(canopy_height, network)?
)
.unwrap(),
hash_map
Expand All @@ -60,7 +62,7 @@ fn test_funding_stream_values() -> Result<(), Report> {
funding_stream_values(
canopy_height_plus1,
network,
block_subsidy(canopy_height_plus1, network)?
block_subsidy_pre_nsm(canopy_height_plus1, network)?
)
.unwrap(),
hash_map
Expand All @@ -70,7 +72,7 @@ fn test_funding_stream_values() -> Result<(), Report> {
funding_stream_values(
canopy_height_plus2,
network,
block_subsidy(canopy_height_plus2, network)?
block_subsidy_pre_nsm(canopy_height_plus2, network)?
)
.unwrap(),
hash_map
Expand All @@ -82,11 +84,11 @@ fn test_funding_stream_values() -> Result<(), Report> {
let last = (end - 1).unwrap();

assert_eq!(
funding_stream_values(last, network, block_subsidy(last, network)?).unwrap(),
funding_stream_values(last, network, block_subsidy_pre_nsm(last, network)?).unwrap(),
hash_map
);

assert!(funding_stream_values(end, network, block_subsidy(end, network)?)?.is_empty());
assert!(funding_stream_values(end, network, block_subsidy_pre_nsm(end, network)?)?.is_empty());

// TODO: Replace this with Mainnet once there's an NU6 activation height defined for Mainnet
let network = testnet::Parameters::build()
Expand Down Expand Up @@ -137,7 +139,8 @@ fn test_funding_stream_values() -> Result<(), Report> {
Height(nu6_height.0 + 1),
] {
assert_eq!(
funding_stream_values(height, &network, block_subsidy(height, &network)?).unwrap(),
funding_stream_values(height, &network, block_subsidy_pre_nsm(height, &network)?)
.unwrap(),
hash_map
);
}
Expand Down Expand Up @@ -191,7 +194,8 @@ fn test_funding_stream_values() -> Result<(), Report> {
Height(nu6_height.0 + 1),
] {
assert_eq!(
funding_stream_values(height, &network, block_subsidy(height, &network)?).unwrap(),
funding_stream_values(height, &network, block_subsidy_pre_nsm(height, &network)?)
.unwrap(),
hash_map
);
}
Expand Down
Loading

0 comments on commit ce2eedd

Please sign in to comment.