@@ -19,8 +19,8 @@ use miden_node_utils::limiter::{
1919} ;
2020use miden_protocol:: account:: AccountId ;
2121use miden_protocol:: block:: BlockNumber ;
22- use miden_protocol:: note:: { NoteId , Nullifier } ;
23- use miden_protocol:: transaction:: { OrderedTransactionHeaders , TransactionId } ;
22+ use miden_protocol:: note:: NoteHeader ;
23+ use miden_protocol:: transaction:: { InputNoteCommitment , OrderedTransactionHeaders , TransactionId } ;
2424use miden_protocol:: utils:: { Deserializable , Serializable } ;
2525
2626use super :: DatabaseError ;
@@ -38,33 +38,32 @@ pub struct TransactionRecordRaw {
3838 transaction_id : Vec < u8 > ,
3939 initial_state_commitment : Vec < u8 > ,
4040 final_state_commitment : Vec < u8 > ,
41- nullifiers : Vec < u8 > ,
41+ input_notes : Vec < u8 > ,
4242 output_notes : Vec < u8 > ,
4343 size_in_bytes : i64 ,
44+ fee : Vec < u8 > ,
4445}
4546
4647impl TryInto < crate :: db:: TransactionRecord > for TransactionRecordRaw {
4748 type Error = DatabaseError ;
4849 fn try_into ( self ) -> Result < crate :: db:: TransactionRecord , Self :: Error > {
4950 use miden_protocol:: Word ;
51+ use miden_protocol:: asset:: FungibleAsset ;
5052
51- let initial_state_commitment = self . initial_state_commitment ;
52- let final_state_commitment = self . final_state_commitment ;
53- let nullifiers_binary = self . nullifiers ;
54- let output_notes_binary = self . output_notes ;
55-
56- // Deserialize input notes as nullifiers and output notes as note IDs
57- let nullifiers: Vec < Nullifier > = Deserializable :: read_from_bytes ( & nullifiers_binary) ?;
58- let output_notes: Vec < NoteId > = Deserializable :: read_from_bytes ( & output_notes_binary) ?;
53+ let input_notes: Vec < InputNoteCommitment > =
54+ Deserializable :: read_from_bytes ( & self . input_notes ) ?;
55+ let output_notes: Vec < NoteHeader > = Deserializable :: read_from_bytes ( & self . output_notes ) ?;
56+ let fee = FungibleAsset :: read_from_bytes ( & self . fee ) ?;
5957
6058 Ok ( crate :: db:: TransactionRecord {
6159 account_id : AccountId :: read_from_bytes ( & self . account_id [ ..] ) ?,
6260 block_num : BlockNumber :: from_raw_sql ( self . block_num ) ?,
6361 transaction_id : TransactionId :: read_from_bytes ( & self . transaction_id [ ..] ) ?,
64- initial_state_commitment : Word :: read_from_bytes ( & initial_state_commitment) ?,
65- final_state_commitment : Word :: read_from_bytes ( & final_state_commitment) ?,
66- nullifiers ,
62+ initial_state_commitment : Word :: read_from_bytes ( & self . initial_state_commitment ) ?,
63+ final_state_commitment : Word :: read_from_bytes ( & self . final_state_commitment ) ?,
64+ input_notes ,
6765 output_notes,
66+ fee,
6867 } )
6968 }
7069}
@@ -108,9 +107,10 @@ pub struct TransactionSummaryRowInsert {
108107 block_num : i64 ,
109108 initial_state_commitment : Vec < u8 > ,
110109 final_state_commitment : Vec < u8 > ,
111- nullifiers : Vec < u8 > ,
110+ input_notes : Vec < u8 > ,
112111 output_notes : Vec < u8 > ,
113112 size_in_bytes : i64 ,
113+ fee : Vec < u8 > ,
114114}
115115
116116impl TransactionSummaryRowInsert {
@@ -124,50 +124,37 @@ impl TransactionSummaryRowInsert {
124124 ) -> Self {
125125 const HEADER_BASE_SIZE : usize = 4 + 32 + 16 + 64 ; // block_num + tx_id + account_id + commitments
126126
127- // Extract nullifiers from input notes and serialize them.
128- // We only store the nullifiers (not the full `InputNoteCommitment`) since
129- // that's all that's needed when reading back `TransactionRecords`.
130- let nullifiers: Vec < Nullifier > = transaction_header
131- . input_notes ( )
132- . iter ( )
133- . map ( miden_protocol:: transaction:: InputNoteCommitment :: nullifier)
134- . collect ( ) ;
135- let nullifiers_binary = nullifiers. to_bytes ( ) ;
127+ // Serialize input notes as full InputNoteCommitments (nullifier + optional NoteHeader).
128+ let input_notes: Vec < InputNoteCommitment > =
129+ transaction_header. input_notes ( ) . iter ( ) . cloned ( ) . collect ( ) ;
130+ let input_notes_binary = input_notes. to_bytes ( ) ;
136131
137- // Extract note IDs from output note headers and serialize them.
138- // We only store the `NoteId`s (not the full `NoteHeader` with metadata) since
139- // that's all that's needed when reading back `TransactionRecords`.
140- let output_note_ids: Vec < NoteId > = transaction_header
141- . output_notes ( )
142- . iter ( )
143- . map ( miden_protocol:: note:: NoteHeader :: id)
144- . collect ( ) ;
145- let output_notes_binary = output_note_ids. to_bytes ( ) ;
132+ // Serialize output notes as full NoteHeaders (NoteId + NoteMetadata).
133+ let output_notes: Vec < NoteHeader > = transaction_header. output_notes ( ) . to_vec ( ) ;
134+ let output_notes_binary = output_notes. to_bytes ( ) ;
146135
147136 // Manually calculate the estimated size of the transaction header to avoid
148137 // the cost of serialization. The size estimation includes:
149138 // - 4 bytes for block number
150139 // - 32 bytes for transaction ID
151140 // - 16 bytes for account ID
152141 // - 64 bytes for initial + final state commitments (32 bytes each)
153- // - 32 bytes per input note (nullifier size)
154- // - 500 bytes per output note (estimated size when converted to NoteSyncRecord)
155- //
156- // Note: 500 bytes per output note is an over-estimate but ensures we don't
157- // exceed memory limits when these transactions are later converted to proto records.
158- let nullifiers_size = ( transaction_header. input_notes ( ) . num_notes ( ) * 32 ) as usize ;
159- let output_notes_size = transaction_header. output_notes ( ) . len ( ) * 500 ;
160- let size_in_bytes = ( HEADER_BASE_SIZE + nullifiers_size + output_notes_size) as i64 ;
142+ // - ~64 bytes per input note (nullifier + optional NoteHeader)
143+ // - ~64 bytes per output note (NoteHeader = NoteId + NoteMetadata)
144+ let input_notes_size = ( transaction_header. input_notes ( ) . num_notes ( ) as usize ) * 64 ;
145+ let output_notes_size = transaction_header. output_notes ( ) . len ( ) * 64 ;
146+ let size_in_bytes = ( HEADER_BASE_SIZE + input_notes_size + output_notes_size) as i64 ;
161147
162148 Self {
163149 transaction_id : transaction_header. id ( ) . to_bytes ( ) ,
164150 account_id : transaction_header. account_id ( ) . to_bytes ( ) ,
165151 block_num : block_num. to_raw_sql ( ) ,
166152 initial_state_commitment : transaction_header. initial_state_commitment ( ) . to_bytes ( ) ,
167153 final_state_commitment : transaction_header. final_state_commitment ( ) . to_bytes ( ) ,
168- nullifiers : nullifiers_binary ,
154+ input_notes : input_notes_binary ,
169155 output_notes : output_notes_binary,
170156 size_in_bytes,
157+ fee : transaction_header. fee ( ) . to_bytes ( ) ,
171158 }
172159 }
173160}
0 commit comments