Skip to content

Commit 361a435

Browse files
fix(indexer): fix event detection with different packages (#1036)
* fix(indexer): fix and future proof event detection with different packages * clippy * clippy * address review comments * cleanup * typos: allow packageid * log checkpoint for events only once * add check that event package ids aren't empty, cleanup * Update .typos.toml * Update indexer/src/config.rs --------- Co-authored-by: Thibault Martinez <thibault@iota.org>
1 parent 50588ff commit 361a435

File tree

10 files changed

+214
-36
lines changed

10 files changed

+214
-36
lines changed

.typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extend-ignore-identifiers-re = [
99
"^[a-zA-Z0-9_]{47}$",
1010
"^[a-zA-Z0-9_]{49}$",
1111
"^[a-zA-Z0-9_]{56,}$",
12+
"^packageid$",
1213
]
1314

1415
[files]

indexer/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ Run the following commands also from the root directory.
1212
### Set the environment variables
1313

1414
```bash
15-
cd scripts && pnpm ts-node utils/envs.ts localnet > ../indexer/docker/.env && cd ..
15+
# localnet
16+
cd scripts && pnpm run envsForIndexer localnet ../indexer/docker/.env && cd ..
17+
# testnet
18+
cd scripts && pnpm run envsForIndexer testnet ../indexer/docker/.env && cd ..
1619
```
1720

1821
### Build the indexer image

indexer/docker/docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
services:
22
iota-names-indexer:
33
container_name: iota-names-indexer
4-
depends_on:
5-
prometheus:
6-
condition: service_started
74
build:
85
context: ..
96
dockerfile: docker/Dockerfile
@@ -40,6 +37,7 @@ services:
4037
- IOTA_NAMES_SUBNAMES_PACKAGE_ADDRESS=${IOTA_NAMES_SUBNAMES_PACKAGE_ADDRESS}
4138
- IOTA_NAMES_TEMP_SUBNAME_PROXY_PACKAGE_ADDRESS=${IOTA_NAMES_TEMP_SUBNAME_PROXY_PACKAGE_ADDRESS}
4239
- IOTA_NAMES_AUCTION_HOUSE_OBJECT_ID=${IOTA_NAMES_AUCTION_HOUSE_OBJECT_ID}
40+
- EVENT_PACKAGE_IDS=${EVENT_PACKAGE_IDS}
4341
extra_hosts:
4442
- "host.docker.internal:host-gateway"
4543
command:

indexer/docker/update_progress.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# This script updates the progress_store file for the iota-names-indexer.
4+
# It can be used for testing by skipping syncing large parts of the history
5+
# and testing only from specific checkpoints, allowing faster test runs.
6+
7+
# Testnet checkpoints for reference:
8+
# Name bought with package id v2 161879819 https://explorer.iota.org/txblock/HkK2osCd8Wj8jh7dsTBB1xTVZmHJbFm7Y27XTuGncws8?network=testnet
9+
# ./indexer/docker/update_progress.sh 161879819
10+
11+
if [ $# -ne 1 ]; then
12+
echo "Usage: $0 <new_progress_value>"
13+
exit 1
14+
fi
15+
16+
NEW_VALUE=$1
17+
18+
cd "$(dirname "$0")"
19+
20+
echo "Stopping the iota-names-indexer container..."
21+
docker-compose down
22+
23+
echo "Updating progress_store to $NEW_VALUE..."
24+
sudo rm -f /tmp/progress_store
25+
sudo sh -c "echo '{\"iota_names_reader\": $NEW_VALUE}' > /tmp/progress_store"
26+
27+
echo "Copying updated file to volume..."
28+
sudo cp /tmp/progress_store /var/lib/docker/volumes/docker_indexer_progress/_data/progress_store
29+
30+
echo "Restarting the container..."
31+
32+
docker-compose up
33+

indexer/src/config.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::str::FromStr;
4+
use std::{collections::HashSet, str::FromStr};
55

66
use iota_names::config::IotaNamesConfig;
77
use iota_protocol_config::Chain;
@@ -21,6 +21,9 @@ pub struct IotaNamesExtendedConfig {
2121
pub subname_proxy_package_address: IotaAddress,
2222
/// ID of the `AuctionHouse` object.
2323
pub auction_house_id: ObjectID,
24+
/// List of package addresses for events. Not strictly defined to support
25+
/// new versions.
26+
pub event_package_ids: HashSet<IotaAddress>,
2427
pub iota_names_config: IotaNamesConfig,
2528
}
2629

@@ -38,6 +41,7 @@ impl IotaNamesExtendedConfig {
3841
subnames_package_address: IotaAddress,
3942
subname_proxy_package_address: IotaAddress,
4043
auction_house_id: ObjectID,
44+
event_package_ids: HashSet<IotaAddress>,
4145
iota_names_config: IotaNamesConfig,
4246
) -> Self {
4347
Self {
@@ -46,19 +50,25 @@ impl IotaNamesExtendedConfig {
4650
subnames_package_address,
4751
subname_proxy_package_address,
4852
auction_house_id,
53+
event_package_ids,
4954
iota_names_config,
5055
}
5156
}
5257

5358
pub fn from_env() -> anyhow::Result<Self> {
5459
let iota_names_config = IotaNamesConfig::from_env()?;
5560

61+
let event_package_ids: HashSet<IotaAddress> = serde_json::from_str(
62+
&std::env::var("EVENT_PACKAGE_IDS").unwrap_or_else(|_| "[]".to_string()),
63+
)?;
64+
5665
Ok(Self::new(
5766
std::env::var("IOTA_NAMES_AUCTION_PACKAGE_ADDRESS")?.parse()?,
5867
std::env::var("IOTA_NAMES_COUPONS_PACKAGE_ADDRESS")?.parse()?,
5968
std::env::var("IOTA_NAMES_SUBNAMES_PACKAGE_ADDRESS")?.parse()?,
6069
std::env::var("IOTA_NAMES_TEMP_SUBNAME_PROXY_PACKAGE_ADDRESS")?.parse()?,
6170
std::env::var("IOTA_NAMES_AUCTION_HOUSE_OBJECT_ID")?.parse()?,
71+
event_package_ids,
6272
iota_names_config,
6373
))
6474
}
@@ -94,13 +104,24 @@ impl IotaNamesExtendedConfig {
94104
IotaAddress::from_str(TEMP_SUBNAME_PROXY_PACKAGE_ADDRESS).unwrap();
95105
let auction_house_id = ObjectID::from_str(AUCTION_HOUSE_ID).unwrap();
96106

107+
let iota_names_config = IotaNamesConfig::testnet();
108+
let event_package_ids = HashSet::from([
109+
auction_package_address,
110+
coupons_package_address,
111+
subnames_package_address,
112+
subname_proxy_package_address,
113+
iota_names_config.package_address,
114+
iota_names_config.payments_package_address,
115+
]);
116+
97117
Self::new(
98118
auction_package_address,
99119
coupons_package_address,
100120
subnames_package_address,
101121
subname_proxy_package_address,
102122
auction_house_id,
103-
IotaNamesConfig::testnet(),
123+
event_package_ids,
124+
iota_names_config,
104125
)
105126
}
106127

@@ -124,25 +145,31 @@ impl IotaNamesExtendedConfig {
124145
IotaAddress::from_str(TEMP_SUBNAME_PROXY_PACKAGE_ADDRESS).unwrap();
125146
let auction_house_id = ObjectID::from_str(AUCTION_HOUSE_ID).unwrap();
126147

148+
let iota_names_config = IotaNamesConfig::devnet();
149+
let event_package_ids = HashSet::from([
150+
auction_package_address,
151+
coupons_package_address,
152+
subnames_package_address,
153+
subname_proxy_package_address,
154+
iota_names_config.package_address,
155+
iota_names_config.payments_package_address,
156+
]);
157+
127158
Self::new(
128159
auction_package_address,
129160
coupons_package_address,
130161
subnames_package_address,
131162
subname_proxy_package_address,
132163
auction_house_id,
133-
IotaNamesConfig::devnet(),
164+
event_package_ids,
165+
iota_names_config,
134166
)
135167
}
136168

137169
/// Checks whether the given package address is an IOTA-Names one.
138170
pub fn is_iota_names_package(&self, package_address: impl Into<IotaAddress>) -> bool {
139171
let package_address = package_address.into();
140172

141-
package_address == self.auction_package_address
142-
|| package_address == self.coupons_package_address
143-
|| package_address == self.iota_names_config.package_address
144-
|| package_address == self.iota_names_config.payments_package_address
145-
|| package_address == self.subnames_package_address
146-
|| package_address == self.subname_proxy_package_address
173+
self.event_package_ids.contains(&package_address)
147174
}
148175
}

indexer/src/events.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
77

88
use crate::config::IotaNamesExtendedConfig;
99

10+
#[derive(Debug)]
1011
pub(crate) enum IotaNamesEvent {
1112
// `auctions`
1213
AuctionStarted(AuctionStartedEvent),
@@ -36,7 +37,7 @@ impl IotaNamesEvent {
3637
event: &Event,
3738
config: &IotaNamesExtendedConfig,
3839
) -> anyhow::Result<Option<Self>> {
39-
if !config.is_iota_names_package(event.package_id) {
40+
if !config.is_iota_names_package(event.type_.address) {
4041
return Ok(None);
4142
}
4243

@@ -77,7 +78,7 @@ impl IotaNamesEvent {
7778

7879
// `auctions`
7980

80-
#[derive(Serialize, Deserialize)]
81+
#[derive(Debug, Serialize, Deserialize)]
8182
pub(crate) struct AuctionStartedEvent {
8283
pub name: Name,
8384
pub start_timestamp_ms: u64,
@@ -86,20 +87,20 @@ pub(crate) struct AuctionStartedEvent {
8687
pub bidder: IotaAddress,
8788
}
8889

89-
#[derive(Serialize, Deserialize)]
90+
#[derive(Debug, Serialize, Deserialize)]
9091
pub(crate) struct AuctionBidEvent {
9192
pub name: Name,
9293
pub bid: u64,
9394
pub bidder: IotaAddress,
9495
}
9596

96-
#[derive(Serialize, Deserialize)]
97+
#[derive(Debug, Serialize, Deserialize)]
9798
pub(crate) struct AuctionExtendedEvent {
9899
pub name: Name,
99100
pub end_timestamp_ms: u64,
100101
}
101102

102-
#[derive(Serialize, Deserialize)]
103+
#[derive(Debug, Serialize, Deserialize)]
103104
pub(crate) struct AuctionFinalizedEvent {
104105
pub name: Name,
105106
pub start_timestamp_ms: u64,
@@ -110,63 +111,63 @@ pub(crate) struct AuctionFinalizedEvent {
110111

111112
// `coupons`
112113

113-
#[derive(Serialize, Deserialize)]
114+
#[derive(Debug, Serialize, Deserialize)]
114115
#[repr(u8)]
115116
pub enum CouponKind {
116117
Percentage = 0,
117118
Fixed = 1,
118119
}
119120

120-
#[derive(Serialize, Deserialize)]
121+
#[derive(Debug, Serialize, Deserialize)]
121122
pub struct CouponAppliedEvent {
122123
pub kind: CouponKind,
123124
pub discount: u64,
124125
}
125126

126127
// `iota-names`
127128

128-
#[derive(Serialize, Deserialize)]
129+
#[derive(Debug, Serialize, Deserialize)]
129130
pub(crate) struct NameRecordAddedEvent {
130131
pub name: Name,
131132
pub name_record: NameRecord,
132133
}
133134

134-
#[derive(Serialize, Deserialize)]
135+
#[derive(Debug, Serialize, Deserialize)]
135136
pub(crate) struct NameRecordRemovedEvent {
136137
pub name: Name,
137138
}
138139

139-
#[derive(Serialize, Deserialize)]
140+
#[derive(Debug, Serialize, Deserialize)]
140141
pub(crate) struct TargetAddressSetEvent {
141142
pub name: Name,
142143
pub target_address: Option<IotaAddress>,
143144
}
144145

145-
#[derive(Serialize, Deserialize)]
146+
#[derive(Debug, Serialize, Deserialize)]
146147
pub(crate) struct ReverseLookupSetEvent {
147148
pub default_address: IotaAddress,
148149
pub default_name: Name,
149150
}
150151

151-
#[derive(Serialize, Deserialize)]
152+
#[derive(Debug, Serialize, Deserialize)]
152153
pub(crate) struct ReverseLookupUnsetEvent {
153154
pub default_address: IotaAddress,
154155
pub default_name: Name,
155156
}
156157

157-
#[derive(Serialize, Deserialize)]
158+
#[derive(Debug, Serialize, Deserialize)]
158159
pub(crate) struct UserDataSetEvent {
159160
pub key: String,
160161
pub value: String,
161162
pub new: bool,
162163
}
163164

164-
#[derive(Serialize, Deserialize)]
165+
#[derive(Debug, Serialize, Deserialize)]
165166
pub(crate) struct UserDataUnsetEvent {
166167
pub key: String,
167168
}
168169

169-
#[derive(Serialize, Deserialize)]
170+
#[derive(Debug, Serialize, Deserialize)]
170171
pub(crate) struct TransactionEvent {
171172
pub app: String,
172173
pub name: Name,
@@ -181,26 +182,26 @@ pub(crate) struct TransactionEvent {
181182

182183
// `subnames`
183184

184-
#[derive(Serialize, Deserialize)]
185+
#[derive(Debug, Serialize, Deserialize)]
185186
pub struct NodeSubnameCreatedEvent {
186187
pub name: Name,
187188
pub expiration_timestamp_ms: u64,
188189
pub allow_creation: bool,
189190
pub allow_time_extension: bool,
190191
}
191192

192-
#[derive(Serialize, Deserialize)]
193+
#[derive(Debug, Serialize, Deserialize)]
193194
pub struct NodeSubnameBurnedEvent {
194195
pub name: Name,
195196
}
196197

197-
#[derive(Serialize, Deserialize)]
198+
#[derive(Debug, Serialize, Deserialize)]
198199
pub struct LeafSubnameCreatedEvent {
199200
pub name: Name,
200201
pub target: IotaAddress,
201202
}
202203

203-
#[derive(Serialize, Deserialize)]
204+
#[derive(Debug, Serialize, Deserialize)]
204205
pub struct LeafSubnameRemovedEvent {
205206
pub name: Name,
206207
}

indexer/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ impl Command {
143143
IotaNamesExtendedConfig::from_chain(&chain)
144144
}
145145
};
146+
if iota_names_config.event_package_ids.is_empty() {
147+
panic!("No EVENT_PACKAGE_IDS provided in the environment variables");
148+
}
146149
info!("Starting with IOTA-Names config: {iota_names_config:#?}");
147150
tasks.spawn(async move {
148151
let worker = IotaNamesWorker::new(

0 commit comments

Comments
 (0)