From c3f3377e8a3d4d6ce166cee8168f5d02ad39754a Mon Sep 17 00:00:00 2001 From: sofia-bobbiesi Date: Fri, 5 Sep 2025 16:01:00 -0300 Subject: [PATCH 1/5] fix(compiler): include tip_slot in Compiler configuration --- crates/trp/src/compiler.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/trp/src/compiler.rs b/crates/trp/src/compiler.rs index aaed6fbf2..7eb85a834 100644 --- a/crates/trp/src/compiler.rs +++ b/crates/trp/src/compiler.rs @@ -94,12 +94,14 @@ pub fn load_compiler( ledger: &D::State, config: &Config, ) -> Result { + let tip_slot = ledger.cursor()?; let pparams = build_pparams::(genesis, ledger)?; let compiler = tx3_cardano::Compiler::new( pparams, tx3_cardano::Config { extra_fees: config.extra_fees, + tip_slot: tip_slot.as_ref().map(|p| p.slot()), }, ); From 7a0d43ba50826460915dc3523ad704c78b32a208 Mon Sep 17 00:00:00 2001 From: sofia-bobbiesi Date: Mon, 8 Sep 2025 15:16:57 -0300 Subject: [PATCH 2/5] fix(utxos): implement get_tip method to retrieve current slot from state cursor --- crates/trp/src/compiler.rs | 2 -- crates/trp/src/utxos.rs | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/trp/src/compiler.rs b/crates/trp/src/compiler.rs index 7eb85a834..aaed6fbf2 100644 --- a/crates/trp/src/compiler.rs +++ b/crates/trp/src/compiler.rs @@ -94,14 +94,12 @@ pub fn load_compiler( ledger: &D::State, config: &Config, ) -> Result { - let tip_slot = ledger.cursor()?; let pparams = build_pparams::(genesis, ledger)?; let compiler = tx3_cardano::Compiler::new( pparams, tx3_cardano::Config { extra_fees: config.extra_fees, - tip_slot: tip_slot.as_ref().map(|p| p.slot()), }, ); diff --git a/crates/trp/src/utxos.rs b/crates/trp/src/utxos.rs index 94697851d..b37bb56d9 100644 --- a/crates/trp/src/utxos.rs +++ b/crates/trp/src/utxos.rs @@ -75,4 +75,9 @@ impl UtxoStore for UtxoStoreAdapter { Ok(utxos) } + + async fn get_tip(&self) -> Result { + let cursor = self.state().cursor().map_err(Error::from)?; + Ok(cursor.unwrap().slot()) + } } From b3199dab5aadbee3aec8030e97bdebb6ec864ae1 Mon Sep 17 00:00:00 2001 From: sofia-bobbiesi Date: Tue, 9 Sep 2025 16:07:34 -0300 Subject: [PATCH 3/5] fix(compiler): add tip resolution in load_compiler and update error handling --- crates/trp/src/compiler.rs | 14 ++++++++++++-- crates/trp/src/error.rs | 5 +++++ crates/trp/src/methods.rs | 2 +- crates/trp/src/utxos.rs | 5 ----- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/crates/trp/src/compiler.rs b/crates/trp/src/compiler.rs index aaed6fbf2..7c6a98daa 100644 --- a/crates/trp/src/compiler.rs +++ b/crates/trp/src/compiler.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use pallas::ledger::validate::utils::{ConwayProtParams, MultiEraProtocolParameters}; use dolos_cardano::pparams; -use dolos_core::{Domain, Genesis, StateStore as _}; +use dolos_core::{ChainPoint, Domain, Genesis, StateStore as _}; use crate::{Config, Error}; @@ -88,7 +88,6 @@ fn build_pparams( Ok(out) } - pub fn load_compiler( genesis: &Genesis, ledger: &D::State, @@ -96,11 +95,22 @@ pub fn load_compiler( ) -> Result { let pparams = build_pparams::(genesis, ledger)?; + let cursor = ledger.cursor()?.ok_or(Error::TipNotResolved)?; + + let tip = match cursor { + ChainPoint::Specific(slot, hash) => tx3_cardano::ChainTip { + slot, + hash: hash.to_vec(), + }, + ChainPoint::Origin => return Err(Error::TipNotResolved), + }; + let compiler = tx3_cardano::Compiler::new( pparams, tx3_cardano::Config { extra_fees: config.extra_fees, }, + tip, ); Ok(compiler) diff --git a/crates/trp/src/error.rs b/crates/trp/src/error.rs index 2d26c3242..6e7b407ac 100644 --- a/crates/trp/src/error.rs +++ b/crates/trp/src/error.rs @@ -52,6 +52,9 @@ pub enum Error { #[error("tx script returned failure")] TxScriptFailure(Vec), + + #[error("failed to resolve tip slot/hash")] + TipNotResolved, } trait IntoErrorData { @@ -128,6 +131,7 @@ impl Error { pub const CODE_MISSING_TX_ARG: i32 = -32001; pub const CODE_INPUT_NOT_RESOLVED: i32 = -32002; pub const CODE_TX_SCRIPT_FAILURE: i32 = -32003; + pub const CODE_TIP_NOT_RESOLVED: i32 = -32004; pub fn code(&self) -> i32 { match self { @@ -149,6 +153,7 @@ impl Error { Error::MissingTxArg { .. } => Self::CODE_MISSING_TX_ARG, Error::InputNotResolved(_, _, _) => Self::CODE_INPUT_NOT_RESOLVED, Error::TxScriptFailure(_) => Self::CODE_TX_SCRIPT_FAILURE, + Error::TipNotResolved => Self::CODE_TIP_NOT_RESOLVED, } } diff --git a/crates/trp/src/methods.rs b/crates/trp/src/methods.rs index 23ed6f337..6f86b21ff 100644 --- a/crates/trp/src/methods.rs +++ b/crates/trp/src/methods.rs @@ -193,7 +193,7 @@ mod tests { const SUBJECT_PROTOCOL: &str = r#" party Sender; party Receiver; - + tx swap(quantity: Int) { input source { from: Sender, diff --git a/crates/trp/src/utxos.rs b/crates/trp/src/utxos.rs index b37bb56d9..94697851d 100644 --- a/crates/trp/src/utxos.rs +++ b/crates/trp/src/utxos.rs @@ -75,9 +75,4 @@ impl UtxoStore for UtxoStoreAdapter { Ok(utxos) } - - async fn get_tip(&self) -> Result { - let cursor = self.state().cursor().map_err(Error::from)?; - Ok(cursor.unwrap().slot()) - } } From 7432d366a894b26e8ec1da627ab2080fd9dbd855 Mon Sep 17 00:00:00 2001 From: sofia-bobbiesi Date: Thu, 11 Sep 2025 12:15:21 -0300 Subject: [PATCH 4/5] fix(compiler): change ChainTip to ChainPoint in load_compiler function --- crates/trp/src/compiler.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/trp/src/compiler.rs b/crates/trp/src/compiler.rs index 7c6a98daa..bd260e5b6 100644 --- a/crates/trp/src/compiler.rs +++ b/crates/trp/src/compiler.rs @@ -98,7 +98,7 @@ pub fn load_compiler( let cursor = ledger.cursor()?.ok_or(Error::TipNotResolved)?; let tip = match cursor { - ChainPoint::Specific(slot, hash) => tx3_cardano::ChainTip { + ChainPoint::Specific(slot, hash) => tx3_cardano::ChainPoint { slot, hash: hash.to_vec(), }, From 341450d4dccd20e4e0c3352a9d0b396d12a5f3fa Mon Sep 17 00:00:00 2001 From: sofia-bobbiesi Date: Mon, 15 Sep 2025 14:44:13 -0300 Subject: [PATCH 5/5] fix(compiler): include hash in ChainPoint creation --- crates/trp/src/compiler.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/trp/src/compiler.rs b/crates/trp/src/compiler.rs index 05f7c0a65..a108d04d3 100644 --- a/crates/trp/src/compiler.rs +++ b/crates/trp/src/compiler.rs @@ -57,10 +57,10 @@ pub fn load_compiler( let pparams = build_pparams::(domain)?; let cursor = domain.state().read_cursor()?.ok_or(Error::TipNotResolved)?; + let slot = cursor.slot(); + let hash = cursor.hash().map(|h| h.to_vec()).unwrap_or_default(); - let tip = tx3_cardano::ChainPoint { - slot: cursor.slot(), - }; + let tip = tx3_cardano::ChainPoint { slot, hash }; let compiler = tx3_cardano::Compiler::new( pparams,