Skip to content

Commit

Permalink
Merge branch 'development' into st-val-merge2
Browse files Browse the repository at this point in the history
  • Loading branch information
aviator-app[bot] authored Jul 4, 2022
2 parents bca7c45 + a8ba89f commit 81fc119
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
38 changes: 37 additions & 1 deletion base_layer/core/src/validation/dan_validators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ mod helpers;
mod error;
pub use error::DanLayerValidationError;

use crate::transactions::transaction_components::TransactionOutput;

#[cfg(test)]
mod test_helpers;

Expand Down Expand Up @@ -80,10 +82,44 @@ impl<B: BlockchainBackend> MempoolTransactionValidation for TxDanLayerValidator<
validate_update_proposal_acceptance(&self.db, output)?
},
OutputType::ContractAmendment => validate_amendment(&self.db, output)?,
_ => continue,
_ => validate_no_sidechain_features(output)?,
}
}

Ok(())
}
}

fn validate_no_sidechain_features(output: &TransactionOutput) -> Result<(), ValidationError> {
match output.features.sidechain_features {
Some(ref features) => Err(ValidationError::NonContractOutputContainsSidechainFeatures {
output_type: output.features.output_type,
contract_id: features.contract_id,
}),
None => Ok(()),
}
}

#[cfg(test)]
mod tests {
use tari_common_types::types::FixedHash;

use super::*;
use crate::transactions::{
test_helpers::{create_unblinded_coinbase, TestParams},
transaction_components::SideChainFeatures,
CryptoFactories,
};

#[test]
fn it_rejects_standard_output_type_with_sidechain_features() {
let mut utxo = create_unblinded_coinbase(&TestParams::new(), 1);
utxo.features.sidechain_features = Some(SideChainFeatures::builder(FixedHash::default()).finish());
let output = utxo.as_transaction_output(&CryptoFactories::default()).unwrap();
let err = validate_no_sidechain_features(&output).unwrap_err();
assert!(matches!(
err,
ValidationError::NonContractOutputContainsSidechainFeatures { .. }
))
}
}
11 changes: 9 additions & 2 deletions base_layer/core/src/validation/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use tari_common_types::types::HashOutput;
use tari_common_types::types::{FixedHash, HashOutput};
use thiserror::Error;
use tokio::task;

Expand All @@ -29,7 +29,7 @@ use crate::{
chain_storage::ChainStorageError,
covenants::CovenantError,
proof_of_work::{monero_rx::MergeMineError, PowError},
transactions::transaction_components::TransactionError,
transactions::transaction_components::{OutputType, TransactionError},
validation::dan_validators::DanLayerValidationError,
};

Expand Down Expand Up @@ -119,6 +119,13 @@ pub enum ValidationError {
ErroneousCoinbaseOutput,
#[error("Digital Asset Network Error: {0}")]
DanLayerError(#[from] DanLayerValidationError),
#[error(
"Output was flagged as a {output_type} but contained sidechain feature data with contract_id {contract_id}"
)]
NonContractOutputContainsSidechainFeatures {
output_type: OutputType,
contract_id: FixedHash,
},
}

// ChainStorageError has a ValidationError variant, so to prevent a cyclic dependency we use a string representation in
Expand Down

0 comments on commit 81fc119

Please sign in to comment.