Skip to content

Commit

Permalink
fix: re-add rpc-indexes to support InputObject and ChangedObject
Browse files Browse the repository at this point in the history
…filters (partly revert #3142) (#5074) (#5088)

Co-authored-by: muXxer <[email protected]>
  • Loading branch information
lzpap and muXxer authored Jan 30, 2025
1 parent 6921f60 commit aed54b6
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/iota-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,12 @@ impl AuthorityState {
indexes
.index_tx(
cert.data().intent_message().value.sender(),
cert.data()
.intent_message()
.value
.input_objects()?
.iter()
.map(|o| o.object_id()),
effects
.all_changed_objects()
.into_iter()
Expand Down
73 changes: 73 additions & 0 deletions crates/iota-storage/src/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ pub struct IndexStoreTables {
#[default_options_override_fn = "transactions_to_addr_table_default_config"]
transactions_to_addr: DBMap<(IotaAddress, TxSequenceNumber), TransactionDigest>,

/// Index from object id to transactions that used that object id as input.
#[deprecated]
transactions_by_input_object_id: DBMap<(ObjectID, TxSequenceNumber), TransactionDigest>,

/// Index from object id to transactions that modified/created that object
/// id.
#[deprecated]
transactions_by_mutated_object_id: DBMap<(ObjectID, TxSequenceNumber), TransactionDigest>,

/// Index from package id, module and function identifier to transactions
/// that used that moce function call as input.
#[default_options_override_fn = "transactions_by_move_function_table_default_config"]
Expand Down Expand Up @@ -458,6 +467,7 @@ impl IndexStore {
pub async fn index_tx(
&self,
sender: IotaAddress,
active_inputs: impl Iterator<Item = ObjectID>,
mutated_objects: impl Iterator<Item = (ObjectRef, Owner)> + Clone,
move_functions: impl Iterator<Item = (ObjectID, Identifier, Identifier)> + Clone,
events: &TransactionEvents,
Expand All @@ -484,6 +494,21 @@ impl IndexStore {
std::iter::once(((sender, sequence), *digest)),
)?;

#[allow(deprecated)]
if !self.remove_deprecated_tables {
batch.insert_batch(
&self.tables.transactions_by_input_object_id,
active_inputs.map(|id| ((id, sequence), *digest)),
)?;

batch.insert_batch(
&self.tables.transactions_by_mutated_object_id,
mutated_objects
.clone()
.map(|(obj_ref, _)| ((obj_ref.0, sequence), *digest)),
)?;
}

batch.insert_batch(
&self.tables.transactions_by_move_function,
move_functions.map(|(obj_id, module, function)| {
Expand Down Expand Up @@ -657,6 +682,12 @@ impl IndexStore {
}) => Ok(self.get_transactions_by_move_function(
package, module, function, cursor, limit, reverse,
)?),
Some(TransactionFilter::InputObject(object_id)) => {
Ok(self.get_transactions_by_input_object(object_id, cursor, limit, reverse)?)
}
Some(TransactionFilter::ChangedObject(object_id)) => {
Ok(self.get_transactions_by_mutated_object(object_id, cursor, limit, reverse)?)
}
Some(TransactionFilter::FromAddress(address)) => {
Ok(self.get_transactions_from_addr(address, cursor, limit, reverse)?)
}
Expand Down Expand Up @@ -734,6 +765,46 @@ impl IndexStore {
})
}

pub fn get_transactions_by_input_object(
&self,
input_object: ObjectID,
cursor: Option<TxSequenceNumber>,
limit: Option<usize>,
reverse: bool,
) -> IotaResult<Vec<TransactionDigest>> {
if self.remove_deprecated_tables {
return Ok(vec![]);
}
#[allow(deprecated)]
Self::get_transactions_from_index(
&self.tables.transactions_by_input_object_id,
input_object,
cursor,
limit,
reverse,
)
}

pub fn get_transactions_by_mutated_object(
&self,
mutated_object: ObjectID,
cursor: Option<TxSequenceNumber>,
limit: Option<usize>,
reverse: bool,
) -> IotaResult<Vec<TransactionDigest>> {
if self.remove_deprecated_tables {
return Ok(vec![]);
}
#[allow(deprecated)]
Self::get_transactions_from_index(
&self.tables.transactions_by_mutated_object_id,
mutated_object,
cursor,
limit,
reverse,
)
}

pub fn get_transactions_from_addr(
&self,
addr: IotaAddress,
Expand Down Expand Up @@ -1573,6 +1644,7 @@ mod tests {
address,
vec![].into_iter(),
vec![].into_iter(),
vec![].into_iter(),
&TransactionEvents { data: vec![] },
object_index_changes,
&TransactionDigest::random(),
Expand Down Expand Up @@ -1616,6 +1688,7 @@ mod tests {
address,
vec![].into_iter(),
vec![].into_iter(),
vec![].into_iter(),
&TransactionEvents { data: vec![] },
object_index_changes,
&TransactionDigest::random(),
Expand Down
29 changes: 29 additions & 0 deletions crates/iota-tool/src/db_tool/index_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ pub fn search_index(
termination
)
}
"transactions_by_input_object_id" => {
get_db_entries!(
db_read_only_handle.transactions_by_input_object_id,
from_id_seq,
start,
termination
)
}
"transactions_by_mutated_object_id" => {
get_db_entries!(
db_read_only_handle.transactions_by_mutated_object_id,
from_id_seq,
start,
termination
)
}
"transactions_by_move_function" => {
get_db_entries!(
db_read_only_handle.transactions_by_move_function,
Expand Down Expand Up @@ -241,6 +257,19 @@ fn from_addr_seq(s: &str) -> Result<(IotaAddress, TxSequenceNumber), anyhow::Err
Ok((address, sequence_number))
}

fn from_id_seq(s: &str) -> Result<(ObjectID, TxSequenceNumber), anyhow::Error> {
// Remove whitespaces
let s = s.trim();
let tokens = s.split(',').collect::<Vec<&str>>();
if tokens.len() != 2 {
return Err(anyhow!("Invalid object id, sequence number pair"));
}
let oid = ObjectID::from_str(tokens[0].trim())?;
let sequence_number = TxSequenceNumber::from_str(tokens[1].trim())?;

Ok((oid, sequence_number))
}

fn from_id_module_function_txseq(
s: &str,
) -> Result<(ObjectID, String, String, TxSequenceNumber), anyhow::Error> {
Expand Down

0 comments on commit aed54b6

Please sign in to comment.