Skip to content

Commit

Permalink
Merge branch 'main' into fix/immutable-secondary
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed May 8, 2024
2 parents cb4f71f + 954e99d commit 6370278
Show file tree
Hide file tree
Showing 98 changed files with 4,266 additions and 2,053 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
## [Unreleased]


<a name="v0.25.0"></a>
## [v0.25.0] - 2024-04-02
### Build
- **deps:** update utxorpc-spec requirement from 0.3.0 to 0.4.4 ([#425](https://github.com/txpipe/pallas/issues/425))

### Feat
- add Conway 2024-03 CDDL conformity ([#424](https://github.com/txpipe/pallas/issues/424))
- **applying:** add support for preview / preprod networks ([#422](https://github.com/txpipe/pallas/issues/422))

### Test
- **hardano:** fix failing tests on CI context ([#429](https://github.com/txpipe/pallas/issues/429))
- **hardano:** discover snapshots by inspecting test_data dir ([#428](https://github.com/txpipe/pallas/issues/428))


<a name="v0.24.0"></a>
## [v0.24.0] - 2024-03-09
### Build
Expand Down Expand Up @@ -1118,7 +1132,8 @@ handshake, chainsync, localstate and blockfetch mini-protocols changed the API s
- apply fmt to entire workspace


[Unreleased]: https://github.com/txpipe/pallas/compare/v0.24.0...HEAD
[Unreleased]: https://github.com/txpipe/pallas/compare/v0.25.0...HEAD
[v0.25.0]: https://github.com/txpipe/pallas/compare/v0.24.0...v0.25.0
[v0.24.0]: https://github.com/txpipe/pallas/compare/v0.23.0...v0.24.0
[v0.23.0]: https://github.com/txpipe/pallas/compare/v0.22.0...v0.23.0
[v0.22.0]: https://github.com/txpipe/pallas/compare/v0.21.0...v0.22.0
Expand Down
5 changes: 4 additions & 1 deletion examples/n2c-miniprotocols/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ async fn do_localstate_query(client: &mut NodeClient) {
let result = queries_v16::get_system_start(client).await.unwrap();
info!("result: {:?}", result);

let result = queries_v16::get_chain_block_no(client).await.unwrap();
info!("result: {:?}", result);

let era = queries_v16::get_current_era(client).await.unwrap();
info!("result: {:?}", era);

Expand Down Expand Up @@ -93,7 +96,7 @@ async fn do_chainsync(client: &mut NodeClient) {
info!("intersected point is {:?}", point);

loop {
let next = client.chainsync().request_next().await.unwrap();
let next = client.chainsync().request_or_await_next().await.unwrap();
match next {
chainsync::NextResponse::RollForward(h, _) => {
let block_number = MultiEraBlock::decode(&h).unwrap().number();
Expand Down
27 changes: 2 additions & 25 deletions examples/n2n-miniprotocols/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pallas::{
miniprotocols::{blockfetch, chainsync, keepalive, Point, MAINNET_MAGIC},
},
};
use std::time::Duration;

use thiserror::Error;
use tokio::time::Instant;

Expand Down Expand Up @@ -117,14 +117,6 @@ async fn do_chainsync(
}
}

async fn do_keepalive(mut keepalive_client: keepalive::Client) -> Result<(), Error> {
loop {
tokio::time::sleep(Duration::from_secs(20)).await;
keepalive_client.send_keepalive().await?;
tracing::info!("keepalive sent");
}
}

#[tokio::main]
async fn main() {
tracing::subscriber::set_global_default(
Expand All @@ -145,25 +137,10 @@ async fn main() {
plexer,
chainsync,
blockfetch,
keepalive,
..
} = peer;

let chainsync_handle = tokio::spawn(do_chainsync(chainsync, blockfetch));
let keepalive_handle = tokio::spawn(do_keepalive(keepalive));

// If any of these concurrent tasks exit or fail, the others are canceled.
let (chainsync_result, keepalive_result) =
tokio::try_join!(chainsync_handle, keepalive_handle)
.expect("error joining tokio threads");

if let Err(err) = chainsync_result {
tracing::error!("chainsync error: {:?}", err);
}

if let Err(err) = keepalive_result {
tracing::error!("keepalive error: {:?}", err);
}
do_chainsync(chainsync, blockfetch).await.unwrap();

plexer.abort().await;

Expand Down
8 changes: 4 additions & 4 deletions pallas-addresses/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pallas-addresses"
description = "Ergonomic library to work with different Cardano addresses"
version = "0.24.0"
version = "0.25.0"
edition = "2021"
repository = "https://github.com/txpipe/pallas"
homepage = "https://github.com/txpipe/pallas"
Expand All @@ -12,10 +12,10 @@ authors = ["Santiago Carmuega <santiago@carmuega.me>"]

[dependencies]
hex = "0.4.3"
pallas-crypto = { version = "=0.24.0", path = "../pallas-crypto" }
pallas-codec = { version = "=0.24.0", path = "../pallas-codec" }
pallas-crypto = { version = "=0.25.0", path = "../pallas-crypto" }
pallas-codec = { version = "=0.25.0", path = "../pallas-codec" }
base58 = "0.2.0"
bech32 = "0.9.1"
thiserror = "1.0.31"
crc = "3.0.1"
sha3 = "0.10.8"
cryptoxide = "0.4"
8 changes: 2 additions & 6 deletions pallas-addresses/src/byron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub struct AddressPayload {
pub addrtype: AddrType,
}

use sha3::{Digest, Sha3_256};
use cryptoxide::hashing::sha3_256;
impl AddressPayload {
pub fn hash_address_id(
addrtype: &AddrType,
Expand All @@ -227,11 +227,7 @@ impl AddressPayload {
let parts = (addrtype, spending_data, attributes);
let buf = minicbor::to_vec(parts).unwrap();

let mut sha = Sha3_256::new();
sha.update(buf);
let sha = sha.finalize();

pallas_crypto::hash::Hasher::<224>::hash(&sha)
pallas_crypto::hash::Hasher::<224>::hash(&sha3_256(&buf))
}

pub fn new(addrtype: AddrType, spending_data: SpendingData, attributes: AddrAttrs) -> Self {
Expand Down
12 changes: 6 additions & 6 deletions pallas-applying/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pallas-applying"
description = "Logic for validating and applying new blocks and txs to the chain state"
version = "0.24.0"
version = "0.25.0"
edition = "2021"
repository = "https://github.com/MaicoLeberle/pallas"
homepage = "https://github.com/MaicoLeberle/pallas"
Expand All @@ -13,11 +13,11 @@ authors = ["Maico Leberle <maico.leberle@gmail.com>"]
doctest = false

[dependencies]
pallas-addresses = { version = "=0.24.0", path = "../pallas-addresses" }
pallas-codec = { version = "=0.24.0", path = "../pallas-codec" }
pallas-crypto = { version = "=0.24.0", path = "../pallas-crypto" }
pallas-primitives = { version = "=0.24.0", path = "../pallas-primitives" }
pallas-traverse = { version = "=0.24.0", path = "../pallas-traverse" }
pallas-addresses = { version = "=0.25.0", path = "../pallas-addresses" }
pallas-codec = { version = "=0.25.0", path = "../pallas-codec" }
pallas-crypto = { version = "=0.25.0", path = "../pallas-crypto" }
pallas-primitives = { version = "=0.25.0", path = "../pallas-primitives" }
pallas-traverse = { version = "=0.25.0", path = "../pallas-traverse" }
rand = "0.8"
hex = "0.4"

Expand Down
6 changes: 5 additions & 1 deletion pallas-applying/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Pallas Applying

Crate for performing transaction validation according to the Cardano protocol.
Crate for performing transaction validation according to the Cardano protocol. Generally speaking, this crate is structured in multiple modules, each one handling a specific Cardano era. These eras are: Byron, ShelleyMA, Alonzo and Babbage.

Refer to *docs/<era>.md* to see the mathematical specifications regarding *<era>*.

Refer to *tests/README.md* for explanations regarding the test suite in any era.
29 changes: 15 additions & 14 deletions pallas-applying/src/alonzo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::utils::{
get_network_id_value, get_payment_part, get_shelley_address, get_val_size_in_words,
mk_alonzo_vk_wits_check_list, values_are_equal, verify_signature,
AlonzoError::*,
AlonzoProtParams, FeePolicy, UTxOs,
AlonzoProtParams, UTxOs,
ValidationError::{self, *},
ValidationResult,
};
Expand Down Expand Up @@ -36,7 +36,7 @@ pub fn validate_alonzo_tx(
network_id: &u8,
) -> ValidationResult {
let tx_body: &TransactionBody = &mtx.transaction_body;
let size: &u64 = &get_alonzo_comp_tx_size(tx_body).ok_or(Alonzo(UnknownTxSize))?;
let size: &u32 = &get_alonzo_comp_tx_size(tx_body).ok_or(Alonzo(UnknownTxSize))?;
check_ins_not_empty(tx_body)?;
check_ins_and_collateral_in_utxos(tx_body, utxos)?;
check_tx_validity_interval(tx_body, mtx, block_slot)?;
Expand Down Expand Up @@ -131,7 +131,7 @@ fn check_upper_bound(

fn check_fee(
tx_body: &TransactionBody,
size: &u64,
size: &u32,
mtx: &MintedTx,
utxos: &UTxOs,
prot_pps: &AlonzoProtParams,
Expand All @@ -147,11 +147,10 @@ fn check_fee(
// minimum fee.
fn check_min_fee(
tx_body: &TransactionBody,
size: &u64,
size: &u32,
prot_pps: &AlonzoProtParams,
) -> ValidationResult {
let fee_policy: &FeePolicy = &prot_pps.fee_policy;
if tx_body.fee < fee_policy.summand + fee_policy.multiplier * size {
if tx_body.fee < (prot_pps.minfee_b + prot_pps.minfee_a * size) as u64 {
return Err(Alonzo(FeeBelowMin));
}
Ok(())
Expand Down Expand Up @@ -185,7 +184,7 @@ fn check_collaterals_number(
collaterals: &[TransactionInput],
prot_pps: &AlonzoProtParams,
) -> ValidationResult {
let number_collateral: u64 = collaterals.len() as u64;
let number_collateral: u32 = collaterals.len() as u32;
if number_collateral == 0 {
Err(Alonzo(CollateralMissing))
} else if number_collateral > prot_pps.max_collateral_inputs {
Expand Down Expand Up @@ -222,7 +221,7 @@ fn check_collaterals_assets(
utxos: &UTxOs,
prot_pps: &AlonzoProtParams,
) -> ValidationResult {
let fee_percentage: u64 = tx_body.fee * prot_pps.collateral_percent;
let fee_percentage: u64 = tx_body.fee * prot_pps.collateral_percentage as u64;
match &tx_body.collateral {
Some(collaterals) => {
for collateral in collaterals {
Expand Down Expand Up @@ -317,7 +316,7 @@ fn compute_min_lovelace(output: &TransactionOutput, prot_pps: &AlonzoProtParams)
Some(_) => 37, // utxoEntrySizeWithoutVal (27) + dataHashSize (10)
None => 27, // utxoEntrySizeWithoutVal
};
prot_pps.coins_per_utxo_word * output_entry_size
prot_pps.ada_per_utxo_byte * output_entry_size
}

// The size of the value in each of the outputs should not be greater than the
Expand All @@ -327,7 +326,7 @@ fn check_output_val_size(
prot_pps: &AlonzoProtParams,
) -> ValidationResult {
for output in tx_body.outputs.iter() {
if get_val_size_in_words(&output.amount) > prot_pps.max_val_size {
if get_val_size_in_words(&output.amount) > prot_pps.max_value_size as u64 {
return Err(Alonzo(MaxValSizeExceeded));
}
}
Expand Down Expand Up @@ -364,8 +363,8 @@ fn check_tx_network_id(tx_body: &TransactionBody, network_id: &u8) -> Validation
}

// The transaction size does not exceed the protocol limit.
fn check_tx_size(size: &u64, prot_pps: &AlonzoProtParams) -> ValidationResult {
if *size > prot_pps.max_tx_size {
fn check_tx_size(size: &u32, prot_pps: &AlonzoProtParams) -> ValidationResult {
if *size > prot_pps.max_transaction_size {
return Err(Alonzo(MaxTxSizeExceeded));
}
Ok(())
Expand All @@ -384,7 +383,7 @@ fn check_tx_ex_units(mtx: &MintedTx, prot_pps: &AlonzoProtParams) -> ValidationR
mem += ex_units.mem;
steps += ex_units.steps;
}
if mem > prot_pps.max_tx_ex_mem || steps > prot_pps.max_tx_ex_steps {
if mem > prot_pps.max_tx_ex_units.mem || steps > prot_pps.max_tx_ex_units.steps {
return Err(Alonzo(TxExUnitsExceeded));
}
}
Expand Down Expand Up @@ -528,7 +527,7 @@ fn check_redeemers(
Some(redeemers) => redeemers
.iter()
.map(|x| RedeemerPointer {
tag: x.tag.clone(),
tag: x.tag,
index: x.index,
})
.collect(),
Expand Down Expand Up @@ -897,6 +896,8 @@ fn compute_script_integrity_hash(plutus_data: &[PlutusData], redeemer: &[Redeeme
}

fn cost_model_cbor() -> Vec<u8> {
// Mainnet, preprod and preview all have the same cost model during the Alonzo
// era.
hex::decode(
"a141005901d59f1a000302590001011a00060bc719026d00011a000249f01903e800011a000249f018201a0025cea81971f70419744d186419744d186419744d186419744d186419744d186419744d18641864186419744d18641a000249f018201a000249f018201a000249f018201a000249f01903e800011a000249f018201a000249f01903e800081a000242201a00067e2318760001011a000249f01903e800081a000249f01a0001b79818f7011a000249f0192710011a0002155e19052e011903e81a000249f01903e8011a000249f018201a000249f018201a000249f0182001011a000249f0011a000249f0041a000194af18f8011a000194af18f8011a0002377c190556011a0002bdea1901f1011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000242201a00067e23187600010119f04c192bd200011a000249f018201a000242201a00067e2318760001011a000242201a00067e2318760001011a0025cea81971f704001a000141bb041a000249f019138800011a000249f018201a000302590001011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a00330da70101ff"
).unwrap()
Expand Down

0 comments on commit 6370278

Please sign in to comment.