Skip to content

Commit

Permalink
feat(applying): add cert and native script validation for ShelleyMA (#…
Browse files Browse the repository at this point in the history
…510)

BREAKING CHANGE: the `validate` fn signature has changed to support these changes

---------

Co-authored-by: Ale Gadea <ale.gadea@txpipe.io>
  • Loading branch information
sterraf and alegadea authored Sep 23, 2024
1 parent 1bec8be commit 07b7451
Show file tree
Hide file tree
Showing 15 changed files with 1,881 additions and 134 deletions.
56 changes: 47 additions & 9 deletions pallas-applying/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,78 @@ pub mod utils;
use alonzo::validate_alonzo_tx;
use babbage::validate_babbage_tx;
use byron::validate_byron_tx;
use pallas_primitives::alonzo::TransactionIndex;
use pallas_traverse::{Era, MultiEraTx};
use shelley_ma::validate_shelley_ma_tx;

pub use utils::{
Environment, MultiEraProtocolParameters, UTxOs,
ValidationError::{TxAndProtParamsDiffer, UnknownProtParams},
CertState, Environment, MultiEraProtocolParameters, UTxOs,
ValidationError::{
EnvMissingAccountState, PParamsByronDoesntNeedAccountState, TxAndProtParamsDiffer,
UnknownProtParams,
},
ValidationResult,
};

pub fn validate(metx: &MultiEraTx, utxos: &UTxOs, env: &Environment) -> ValidationResult {
match env.prot_params() {
MultiEraProtocolParameters::Byron(bpp) => match metx {
/// Ledger sequence rule: LEDGERS
pub fn validate_txs(
metxs: &[MultiEraTx],
env: &Environment,
utxos: &UTxOs,
cert_state: &mut CertState,
) -> ValidationResult {
let mut delta_state: CertState = cert_state.clone();
for (txix, metx) in metxs.iter().enumerate() {
validate_tx(
&metx,
txix.try_into().unwrap(),
env,
utxos,
&mut delta_state,
)?;
}
*cert_state = delta_state;
Ok(())
}

/// Ledger inference rule: LEDGER
pub fn validate_tx(
metx: &MultiEraTx,
txix: TransactionIndex,
env: &Environment,
utxos: &UTxOs,
cert_state: &mut CertState,
) -> ValidationResult {
let pp_acnt = (env.prot_params(), env.acnt());
match pp_acnt {
(MultiEraProtocolParameters::Byron(bpp), None) => match metx {
MultiEraTx::Byron(mtxp) => validate_byron_tx(mtxp, utxos, bpp, env.prot_magic()),
_ => Err(TxAndProtParamsDiffer),
},
MultiEraProtocolParameters::Shelley(spp) => match metx {
(MultiEraProtocolParameters::Byron(_), Some(_)) => Err(PParamsByronDoesntNeedAccountState),
(MultiEraProtocolParameters::Shelley(spp), Some(acnt)) => match metx {
MultiEraTx::AlonzoCompatible(mtx, Era::Shelley)
| MultiEraTx::AlonzoCompatible(mtx, Era::Allegra)
| MultiEraTx::AlonzoCompatible(mtx, Era::Mary) => validate_shelley_ma_tx(
mtx,
txix,
utxos,
cert_state,
spp,
&acnt,
env.block_slot(),
env.network_id(),
&metx.era(),
),
_ => Err(TxAndProtParamsDiffer),
},
MultiEraProtocolParameters::Alonzo(app) => match metx {
(MultiEraProtocolParameters::Alonzo(app), _) => match metx {
MultiEraTx::AlonzoCompatible(mtx, Era::Alonzo) => {
validate_alonzo_tx(mtx, utxos, app, env.block_slot(), env.network_id())
}
_ => Err(TxAndProtParamsDiffer),
},
MultiEraProtocolParameters::Babbage(bpp) => match metx {
(MultiEraProtocolParameters::Babbage(bpp), _) => match metx {
MultiEraTx::Babbage(mtx) => validate_babbage_tx(
mtx,
utxos,
Expand All @@ -54,8 +91,9 @@ pub fn validate(metx: &MultiEraTx, utxos: &UTxOs, env: &Environment) -> Validati
),
_ => Err(TxAndProtParamsDiffer),
},
MultiEraProtocolParameters::Conway(_) => {
(MultiEraProtocolParameters::Conway(_), _) => {
todo!("conway phase-1 validation not yet implemented");
}
(_, None) => Err(EnvMissingAccountState),
}
}
Loading

0 comments on commit 07b7451

Please sign in to comment.