Skip to content

Commit ab7e0f4

Browse files
authored
Merge pull request #442 from namada-net/tiago/fix-this-shit
fix the fucking indexer
2 parents 6af4d19 + 9c8aec9 commit ab7e0f4

File tree

2 files changed

+81
-70
lines changed

2 files changed

+81
-70
lines changed

.github/workflows/queue_and_merge.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,18 @@ jobs:
8585
runs-on: ubuntu-latest
8686
name: Validate Swagger
8787

88+
services:
89+
swagger-editor:
90+
image: swaggerapi/swagger-editor
91+
ports:
92+
- 80:8080
93+
8894
steps:
8995
- uses: actions/checkout@v4
9096
- name: Validate OpenAPI definition
9197
uses: swaggerexpert/swagger-editor-validate@v1
9298
with:
99+
swagger-editor-url: http://localhost/
93100
definition-file: swagger.yml
94101

95102
format:

transactions/src/services/tx.rs

Lines changed: 74 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -65,56 +65,58 @@ pub fn get_ibc_packets(
6565
.end_events
6666
.iter()
6767
.filter_map(|event| {
68-
if let Some(attributes) = &event.attributes {
69-
match attributes {
70-
TxAttributesType::SendPacket(packet) => Some(IbcSequence {
71-
sequence_number: packet.sequence.clone(),
72-
source_port: packet.source_port.clone(),
73-
dest_port: packet.dest_port.clone(),
74-
source_channel: packet.source_channel.clone(),
75-
dest_channel: packet.dest_channel.clone(),
76-
timeout: packet.timeout_timestamp,
77-
tx_id: {
78-
if let Some(id) = event.inner_tx_hash.as_ref() {
79-
// the id was in the event. this should
80-
// be the case 99% of the times, unless
81-
// we're crawling through the history
82-
// of some older namada version, or
83-
// we encounter a pgf funding tx
84-
id.clone()
85-
} else if packet
86-
.as_fungible_token_packet()
87-
.is_some_and(|ics20_packet| {
88-
matches!(
89-
ics20_packet.sender.parse().ok(),
90-
Some(Address::Internal(_))
91-
)
92-
})
93-
{
94-
// this packet was sent by an internal address,
95-
// most likely the pgf (for pgf funding via
96-
// IBC). there is no inner tx id in this
97-
// case, let's add the hash of the packet
98-
// id, as a workaround.
99-
Id::Hash(
100-
Hash::sha256(packet.id())
101-
.to_string()
102-
.to_lowercase(),
103-
)
104-
} else {
105-
// this handles older namada versions
106-
legacy_extracted_id_tx_ids.next().expect(
107-
"Ibc sent packet should have a \
108-
corresponding tx",
109-
)
110-
}
68+
let attributes = event.attributes.as_ref()?;
69+
let TxAttributesType::SendPacket(packet) = attributes else {
70+
return None;
71+
};
72+
73+
Some(IbcSequence {
74+
sequence_number: packet.sequence.clone(),
75+
source_port: packet.source_port.clone(),
76+
dest_port: packet.dest_port.clone(),
77+
source_channel: packet.source_channel.clone(),
78+
dest_channel: packet.dest_channel.clone(),
79+
timeout: packet.timeout_timestamp,
80+
tx_id: {
81+
if let Some(id) = event.inner_tx_hash.as_ref() {
82+
// the id was in the event. this should
83+
// be the case 99% of the times, unless
84+
// we're crawling through the history
85+
// of some older namada version, or
86+
// we encounter a pgf funding tx
87+
txs.iter().find_map(|(wrapper_tx, inner_txs)| {
88+
inner_txs.iter().find(|inner_tx| {
89+
inner_tx.was_successful(wrapper_tx)
90+
&& &inner_tx.tx_id == id
91+
})?;
92+
Some(id.clone())
93+
})?
94+
} else if packet.as_fungible_token_packet().is_some_and(
95+
|ics20_packet| {
96+
matches!(
97+
ics20_packet.sender.parse().ok(),
98+
Some(Address::Internal(_))
99+
)
111100
},
112-
}),
113-
_ => None,
114-
}
115-
} else {
116-
None
117-
}
101+
) {
102+
// this packet was sent by an internal address,
103+
// most likely the pgf (for pgf funding via
104+
// IBC). there is no inner tx id in this
105+
// case, let's add the hash of the packet
106+
// id, as a workaround.
107+
Id::Hash(
108+
Hash::sha256(packet.id())
109+
.to_string()
110+
.to_lowercase(),
111+
)
112+
} else {
113+
// this handles older namada versions
114+
legacy_extracted_id_tx_ids.next().expect(
115+
"Ibc sent packet should have a corresponding tx",
116+
)
117+
}
118+
},
119+
})
118120
})
119121
.collect::<Vec<_>>()
120122
}
@@ -327,26 +329,6 @@ mod tests {
327329
tx_id,
328330
};
329331

330-
// get ibc seq just from the events + inner tx hash
331-
let block_result = mock_block_result(Some("deadbeef"), None);
332-
assert_eq!(
333-
get_ibc_packets(&block_result, &[]),
334-
vec![expected_seq(Id::Hash("deadbeef".to_string()))],
335-
);
336-
337-
// protocol transfer, there is no inner tx hash
338-
let block_result = mock_block_result(None, Some(PGF.to_string()));
339-
assert_eq!(
340-
get_ibc_packets(&block_result, &[]),
341-
vec![expected_seq(Id::Hash(
342-
Hash::sha256("transfer/channel-0/transfer/channel-0/1")
343-
.to_string()
344-
.to_lowercase()
345-
))],
346-
);
347-
348-
// no inner tx hash in the event, get it from the provided tx slice
349-
let block_result = mock_block_result(None, Some("a1aaaa".to_string()));
350332
let wrapper = WrapperTransaction {
351333
exit_code: TransactionExitStatus::Applied,
352334
tx_id: Id::Hash("eatshit".to_string()),
@@ -386,8 +368,30 @@ mod tests {
386368
)),
387369
..inner1.clone()
388370
};
371+
let txs = [(wrapper, vec![inner1, inner2])];
372+
373+
// get ibc seq just from the events + inner tx hash
374+
let block_result = mock_block_result(Some("deadbeef"), None);
375+
assert_eq!(
376+
get_ibc_packets(&block_result, &txs),
377+
vec![expected_seq(Id::Hash("deadbeef".to_string()))],
378+
);
379+
380+
// protocol transfer, there is no inner tx hash
381+
let block_result = mock_block_result(None, Some(PGF.to_string()));
382+
assert_eq!(
383+
get_ibc_packets(&block_result, &[]),
384+
vec![expected_seq(Id::Hash(
385+
Hash::sha256("transfer/channel-0/transfer/channel-0/1")
386+
.to_string()
387+
.to_lowercase()
388+
))],
389+
);
390+
391+
// no inner tx hash in the event, get it from the provided tx slice
392+
let block_result = mock_block_result(None, Some("a1aaaa".to_string()));
389393
assert_eq!(
390-
get_ibc_packets(&block_result, &[(wrapper, vec![inner1, inner2])]),
394+
get_ibc_packets(&block_result, &txs),
391395
vec![expected_seq(Id::Hash("deadbeef".to_string()))],
392396
);
393397
}

0 commit comments

Comments
 (0)