Skip to content

Commit 874504f

Browse files
muXxerlzpap
authored andcommitted
fix: re-add rpc-indexes to support InputObject and ChangedObject filters (partly revert #3142) (#5074)
1 parent 6921f60 commit 874504f

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

crates/iota-core/src/authority.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,12 @@ impl AuthorityState {
20972097
indexes
20982098
.index_tx(
20992099
cert.data().intent_message().value.sender(),
2100+
cert.data()
2101+
.intent_message()
2102+
.value
2103+
.input_objects()?
2104+
.iter()
2105+
.map(|o| o.object_id()),
21002106
effects
21012107
.all_changed_objects()
21022108
.into_iter()

crates/iota-storage/src/indexes.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ pub struct IndexStoreTables {
160160
#[default_options_override_fn = "transactions_to_addr_table_default_config"]
161161
transactions_to_addr: DBMap<(IotaAddress, TxSequenceNumber), TransactionDigest>,
162162

163+
/// Index from object id to transactions that used that object id as input.
164+
#[deprecated]
165+
transactions_by_input_object_id: DBMap<(ObjectID, TxSequenceNumber), TransactionDigest>,
166+
167+
/// Index from object id to transactions that modified/created that object
168+
/// id.
169+
#[deprecated]
170+
transactions_by_mutated_object_id: DBMap<(ObjectID, TxSequenceNumber), TransactionDigest>,
171+
163172
/// Index from package id, module and function identifier to transactions
164173
/// that used that moce function call as input.
165174
#[default_options_override_fn = "transactions_by_move_function_table_default_config"]
@@ -458,6 +467,7 @@ impl IndexStore {
458467
pub async fn index_tx(
459468
&self,
460469
sender: IotaAddress,
470+
active_inputs: impl Iterator<Item = ObjectID>,
461471
mutated_objects: impl Iterator<Item = (ObjectRef, Owner)> + Clone,
462472
move_functions: impl Iterator<Item = (ObjectID, Identifier, Identifier)> + Clone,
463473
events: &TransactionEvents,
@@ -484,6 +494,21 @@ impl IndexStore {
484494
std::iter::once(((sender, sequence), *digest)),
485495
)?;
486496

497+
#[allow(deprecated)]
498+
if !self.remove_deprecated_tables {
499+
batch.insert_batch(
500+
&self.tables.transactions_by_input_object_id,
501+
active_inputs.map(|id| ((id, sequence), *digest)),
502+
)?;
503+
504+
batch.insert_batch(
505+
&self.tables.transactions_by_mutated_object_id,
506+
mutated_objects
507+
.clone()
508+
.map(|(obj_ref, _)| ((obj_ref.0, sequence), *digest)),
509+
)?;
510+
}
511+
487512
batch.insert_batch(
488513
&self.tables.transactions_by_move_function,
489514
move_functions.map(|(obj_id, module, function)| {
@@ -657,6 +682,12 @@ impl IndexStore {
657682
}) => Ok(self.get_transactions_by_move_function(
658683
package, module, function, cursor, limit, reverse,
659684
)?),
685+
Some(TransactionFilter::InputObject(object_id)) => {
686+
Ok(self.get_transactions_by_input_object(object_id, cursor, limit, reverse)?)
687+
}
688+
Some(TransactionFilter::ChangedObject(object_id)) => {
689+
Ok(self.get_transactions_by_mutated_object(object_id, cursor, limit, reverse)?)
690+
}
660691
Some(TransactionFilter::FromAddress(address)) => {
661692
Ok(self.get_transactions_from_addr(address, cursor, limit, reverse)?)
662693
}
@@ -734,6 +765,46 @@ impl IndexStore {
734765
})
735766
}
736767

768+
pub fn get_transactions_by_input_object(
769+
&self,
770+
input_object: ObjectID,
771+
cursor: Option<TxSequenceNumber>,
772+
limit: Option<usize>,
773+
reverse: bool,
774+
) -> IotaResult<Vec<TransactionDigest>> {
775+
if self.remove_deprecated_tables {
776+
return Ok(vec![]);
777+
}
778+
#[allow(deprecated)]
779+
Self::get_transactions_from_index(
780+
&self.tables.transactions_by_input_object_id,
781+
input_object,
782+
cursor,
783+
limit,
784+
reverse,
785+
)
786+
}
787+
788+
pub fn get_transactions_by_mutated_object(
789+
&self,
790+
mutated_object: ObjectID,
791+
cursor: Option<TxSequenceNumber>,
792+
limit: Option<usize>,
793+
reverse: bool,
794+
) -> IotaResult<Vec<TransactionDigest>> {
795+
if self.remove_deprecated_tables {
796+
return Ok(vec![]);
797+
}
798+
#[allow(deprecated)]
799+
Self::get_transactions_from_index(
800+
&self.tables.transactions_by_mutated_object_id,
801+
mutated_object,
802+
cursor,
803+
limit,
804+
reverse,
805+
)
806+
}
807+
737808
pub fn get_transactions_from_addr(
738809
&self,
739810
addr: IotaAddress,
@@ -1573,6 +1644,7 @@ mod tests {
15731644
address,
15741645
vec![].into_iter(),
15751646
vec![].into_iter(),
1647+
vec![].into_iter(),
15761648
&TransactionEvents { data: vec![] },
15771649
object_index_changes,
15781650
&TransactionDigest::random(),
@@ -1616,6 +1688,7 @@ mod tests {
16161688
address,
16171689
vec![].into_iter(),
16181690
vec![].into_iter(),
1691+
vec![].into_iter(),
16191692
&TransactionEvents { data: vec![] },
16201693
object_index_changes,
16211694
&TransactionDigest::random(),

crates/iota-tool/src/db_tool/index_search.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ pub fn search_index(
6767
termination
6868
)
6969
}
70+
"transactions_by_input_object_id" => {
71+
get_db_entries!(
72+
db_read_only_handle.transactions_by_input_object_id,
73+
from_id_seq,
74+
start,
75+
termination
76+
)
77+
}
78+
"transactions_by_mutated_object_id" => {
79+
get_db_entries!(
80+
db_read_only_handle.transactions_by_mutated_object_id,
81+
from_id_seq,
82+
start,
83+
termination
84+
)
85+
}
7086
"transactions_by_move_function" => {
7187
get_db_entries!(
7288
db_read_only_handle.transactions_by_move_function,
@@ -241,6 +257,19 @@ fn from_addr_seq(s: &str) -> Result<(IotaAddress, TxSequenceNumber), anyhow::Err
241257
Ok((address, sequence_number))
242258
}
243259

260+
fn from_id_seq(s: &str) -> Result<(ObjectID, TxSequenceNumber), anyhow::Error> {
261+
// Remove whitespaces
262+
let s = s.trim();
263+
let tokens = s.split(',').collect::<Vec<&str>>();
264+
if tokens.len() != 2 {
265+
return Err(anyhow!("Invalid object id, sequence number pair"));
266+
}
267+
let oid = ObjectID::from_str(tokens[0].trim())?;
268+
let sequence_number = TxSequenceNumber::from_str(tokens[1].trim())?;
269+
270+
Ok((oid, sequence_number))
271+
}
272+
244273
fn from_id_module_function_txseq(
245274
s: &str,
246275
) -> Result<(ObjectID, String, String, TxSequenceNumber), anyhow::Error> {

0 commit comments

Comments
 (0)