Skip to content

Commit

Permalink
Merge branch 'main' into filtered-delegations-rewards
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Carmuega <[email protected]>
  • Loading branch information
scarmuega authored Dec 12, 2024
2 parents dddcebb + 57157b6 commit 67d1b08
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 20 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<a name="unreleased"></a>
## [Unreleased]


<a name="v0.30.1"></a>
## [v0.30.1] - 2024-08-25
### Fix
Expand Down
15 changes: 14 additions & 1 deletion examples/n2c-miniprotocols/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ use pallas::{
facades::NodeClient,
miniprotocols::{
chainsync,
localstate::queries_v16::{self, Addr, Addrs, StakeAddr},
localstate::queries_v16::{self, Addr, Addrs, StakeAddr, TransactionInput},
Point, PRE_PRODUCTION_MAGIC,
},
},
crypto::hash::Hash,
};
use tracing::info;
use hex::FromHex;

This comment has been minimized.

Copy link
@sterraf

sterraf Dec 12, 2024

Contributor

I can clean this merge-introduced double import in the next PR


use hex::FromHex;

Expand All @@ -21,6 +23,17 @@ async fn do_localstate_query(client: &mut NodeClient) {

client.acquire(None).await.unwrap();

// Get UTxO from a (singleton) set of tx inputs.
let transaction_id = Hash::<32>::from(<[u8; 32]>::from_hex(
"15244950ed56a3af61a00f62584779fb53a9f3910468013a2b00b94b8bbc10e0"
).unwrap());
let tx_in = TransactionInput { transaction_id, index: 0 };
let mut txins = BTreeSet::new();
txins.insert(tx_in);

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ impl Encode<()> for BlockQuery {
e.array(1)?;
e.u16(14)?;
}
BlockQuery::GetUTxOByTxIn(_) => {
BlockQuery::GetUTxOByTxIn(txin) => {
e.array(2)?;
e.u16(15)?;
e.encode(2)?;
e.encode(txin)?;
}
BlockQuery::GetStakePools => {
e.array(1)?;
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<'b> Decode<'b, ()> for BlockQuery {
// 12 => Ok(Self::DebugNewEpochState),
13 => Ok(Self::DebugChainDepState),
14 => Ok(Self::GetRewardProvenance),
// 15 => Ok(Self::GetUTxOByTxIn(())),
15 => Ok(Self::GetUTxOByTxIn(d.decode()?)),
16 => Ok(Self::GetStakePools),
// 17 => Ok(Self::GetStakePoolParams(())),
18 => Ok(Self::GetRewardInfoPools),
Expand Down
32 changes: 31 additions & 1 deletion pallas-network/src/miniprotocols/localstate/queries_v16/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub enum BlockQuery {
DebugNewEpochState,
DebugChainDepState,
GetRewardProvenance,
GetUTxOByTxIn(AnyCbor),
GetUTxOByTxIn(TxIns),
GetStakePools,
GetStakePoolParams(AnyCbor),
GetRewardInfoPools,
Expand Down Expand Up @@ -260,9 +260,25 @@ pub struct UTxOByAddress {
pub utxo: KeyValuePairs<UTxO, TransactionOutput>,
}

pub type UTxOByTxin = UTxOByAddress;

// Bytes CDDL -> #6.121([ * #6.121([ *datum ]) ])
pub type Datum = (Era, TagWrap<Bytes, 24>);

// From `pallas-primitives`, with fewer `derive`s
#[derive(
Encode, Decode, Debug, PartialEq, Eq, PartialOrd, Ord, Clone,
)]
pub struct TransactionInput {
#[n(0)]
pub transaction_id: Hash<32>,

#[n(1)]
pub index: u64,
}

pub type TxIns = BTreeSet<TransactionInput>;

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum TransactionOutput {
Current(PostAlonsoTransactionOutput),
Expand Down Expand Up @@ -515,3 +531,17 @@ pub async fn get_filtered_delegations_rewards(

Ok(result)
}

/// Get a subset of the UTxO, filtered by transaction input.
pub async fn get_utxo_by_txin(
client: &mut Client,
era: u16,
txins: TxIns,
) -> Result<UTxOByTxin, ClientError> {
let query = BlockQuery::GetUTxOByTxIn(txins);
let query = LedgerQuery::BlockQuery(era, query);
let query = Request::LedgerQuery(query);
let result = client.query(query).await?;

Ok(result)
}
8 changes: 4 additions & 4 deletions pallas-network/tests/protocols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub async fn blockfetch_server_and_client_happy_path() {
client_bf.send_done().await.unwrap();
});

_ = tokio::join!(client, server);
tokio::try_join!(client, server).unwrap();
}

#[tokio::test]
Expand Down Expand Up @@ -457,7 +457,7 @@ pub async fn chainsync_server_and_client_happy_path_n2n() {
client_cs.send_done().await.unwrap();
});

_ = tokio::join!(client, server);
tokio::try_join!(client, server).unwrap();
}

#[cfg(unix)]
Expand Down Expand Up @@ -1159,7 +1159,7 @@ pub async fn local_state_query_server_and_client_happy_path() {
client.statequery().send_done().await.unwrap();
});

_ = tokio::join!(client, server);
tokio::try_join!(client, server).unwrap();
}

#[tokio::test]
Expand Down Expand Up @@ -1317,7 +1317,7 @@ pub async fn txsubmission_server_and_client_happy_path_n2n() {
assert_eq!(*client_txsub.state(), txsubmission::State::Done);
});

_ = tokio::join!(client, server);
tokio::try_join!(client, server).unwrap();
}

#[tokio::test]
Expand Down
1 change: 0 additions & 1 deletion pallas-txbuilder/src/conway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ impl BuildConway for StagingTransaction {
language_view,
};

dbg!(&dta);
dta.hash()
});

Expand Down
26 changes: 17 additions & 9 deletions pallas-txbuilder/src/transaction/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pallas_crypto::{
hash::{Hash, Hasher},
key::ed25519,
};
use pallas_primitives::{babbage, conway, Fragment, NonEmptySet};
use pallas_primitives::{conway, Fragment, NonEmptySet};
use pallas_wallet::PrivateKey;

use std::{collections::HashMap, ops::Deref};
Expand Down Expand Up @@ -644,7 +644,7 @@ impl BuiltTransaction {
.map(|x| x.to_vec())
.unwrap_or_default();

vkey_witnesses.push(babbage::VKeyWitness {
vkey_witnesses.push(conway::VKeyWitness {
vkey: Vec::from(pubkey.as_ref()).into(),
signature: Vec::from(signature.as_ref()).into(),
});
Expand Down Expand Up @@ -682,17 +682,21 @@ impl BuiltTransaction {
self.signatures = Some(new_sigs);

// TODO: chance for serialisation round trip issues?
let mut tx = babbage::Tx::decode_fragment(&self.tx_bytes.0)
let mut tx = conway::Tx::decode_fragment(&self.tx_bytes.0)
.map_err(|_| TxBuilderError::CorruptedTxBytes)?;

let mut vkey_witnesses = tx.transaction_witness_set.vkeywitness.unwrap_or_default();
let mut vkey_witnesses = tx
.transaction_witness_set
.vkeywitness
.map(|x| x.to_vec())
.unwrap_or_default();

vkey_witnesses.push(babbage::VKeyWitness {
vkey_witnesses.push(conway::VKeyWitness {
vkey: Vec::from(pub_key.as_ref()).into(),
signature: Vec::from(signature.as_ref()).into(),
});

tx.transaction_witness_set.vkeywitness = Some(vkey_witnesses);
tx.transaction_witness_set.vkeywitness = Some(NonEmptySet::from_vec(vkey_witnesses).unwrap());

self.tx_bytes = tx.encode_fragment().unwrap().into();
}
Expand All @@ -719,14 +723,18 @@ impl BuiltTransaction {
self.signatures = Some(new_sigs);

// TODO: chance for serialisation round trip issues?
let mut tx = babbage::Tx::decode_fragment(&self.tx_bytes.0)
let mut tx = conway::Tx::decode_fragment(&self.tx_bytes.0)
.map_err(|_| TxBuilderError::CorruptedTxBytes)?;

let mut vkey_witnesses = tx.transaction_witness_set.vkeywitness.unwrap_or_default();
let mut vkey_witnesses = tx
.transaction_witness_set
.vkeywitness
.map(|x| x.to_vec())
.unwrap_or_default();

vkey_witnesses.retain(|x| *x.vkey != pk.0.to_vec());

tx.transaction_witness_set.vkeywitness = Some(vkey_witnesses);
tx.transaction_witness_set.vkeywitness = Some(NonEmptySet::from_vec(vkey_witnesses).unwrap());

self.tx_bytes = tx.encode_fragment().unwrap().into();
}
Expand Down
30 changes: 30 additions & 0 deletions pallas-utxorpc/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ impl<C: LedgerContext> Mapper<C> {
max_value_size: params.max_value_size.into(),
collateral_percentage: params.collateral_percentage.into(),
max_collateral_inputs: params.max_collateral_inputs.into(),
prices: Some(u5c::ExPrices {
steps: Some(u5c::RationalNumber {
numerator: params.execution_costs.step_price.numerator as i32,
denominator: params.execution_costs.step_price.denominator as u32,
}),
memory: Some(u5c::RationalNumber {
numerator: params.execution_costs.mem_price.numerator as i32,
denominator: params.execution_costs.mem_price.denominator as u32,
}),
}),
max_execution_units_per_transaction: Some(u5c::ExUnits {
memory: params.max_tx_ex_units.mem,
steps: params.max_tx_ex_units.steps,
Expand Down Expand Up @@ -117,6 +127,16 @@ impl<C: LedgerContext> Mapper<C> {
max_value_size: params.max_value_size.into(),
collateral_percentage: params.collateral_percentage.into(),
max_collateral_inputs: params.max_collateral_inputs.into(),
prices: Some(u5c::ExPrices {
steps: Some(u5c::RationalNumber {
numerator: params.execution_costs.step_price.numerator as i32,
denominator: params.execution_costs.step_price.denominator as u32,
}),
memory: Some(u5c::RationalNumber {
numerator: params.execution_costs.mem_price.numerator as i32,
denominator: params.execution_costs.mem_price.denominator as u32,
}),
}),
max_execution_units_per_transaction: Some(u5c::ExUnits {
memory: params.max_tx_ex_units.mem,
steps: params.max_tx_ex_units.steps,
Expand Down Expand Up @@ -177,6 +197,16 @@ impl<C: LedgerContext> Mapper<C> {
max_value_size: params.max_value_size.into(),
collateral_percentage: params.collateral_percentage.into(),
max_collateral_inputs: params.max_collateral_inputs.into(),
prices: Some(u5c::ExPrices {
steps: Some(u5c::RationalNumber {
numerator: params.execution_costs.step_price.numerator as i32,
denominator: params.execution_costs.step_price.denominator as u32,
}),
memory: Some(u5c::RationalNumber {
numerator: params.execution_costs.mem_price.numerator as i32,
denominator: params.execution_costs.mem_price.denominator as u32,
}),
}),
max_execution_units_per_transaction: Some(u5c::ExUnits {
memory: params.max_tx_ex_units.mem,
steps: params.max_tx_ex_units.steps,
Expand Down

0 comments on commit 67d1b08

Please sign in to comment.