Skip to content

Commit

Permalink
fix(bens): fix skipping check of existing domains (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenzing authored Aug 1, 2024
1 parent dd3157b commit 459ddf5
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 40 deletions.
4 changes: 2 additions & 2 deletions blockscout-ens/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blockscout-ens/bens-logic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
tokio = { version = "1.23", features = [ "rt-multi-thread", "macros" ] }
alloy-ccip-read = "0.1.1"
alloy-ccip-read = "0.1.2"
anyhow = "1"
hex = "0.4"
chrono = "0.4"
Expand Down
3 changes: 2 additions & 1 deletion blockscout-ens/bens-logic/src/subgraph/domain_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use std::str::FromStr;

#[tracing::instrument(
level = "info",
skip(domain),
skip_all,
fields(
domain_name = domain.name,
native_token_contract = ?name.deployed_protocol.protocol.info.native_token_contract,
),
err,
)]
Expand Down
2 changes: 2 additions & 0 deletions blockscout-ens/bens-logic/src/subgraph/ens/ccip_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct DomainInfoFromCcipRead {
pub addr: Address,
pub resolver_address: Address,
pub stored_offchain: bool,
pub resolved_with_wildcard: bool,
}

#[instrument(
Expand All @@ -42,6 +43,7 @@ pub async fn call_to_resolver(
resolver_address,
name: name.inner.name.clone(),
stored_offchain: result.ccip_read_used,
resolved_with_wildcard: result.wildcard_used,
})
}

Expand Down
37 changes: 10 additions & 27 deletions blockscout-ens/bens-logic/src/subgraph/ens/wildcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::str::FromStr;
convert = r#"{
from_user.inner.id.to_string()
}"#,
time = 3600, // 60 * 60 seconds = 1 hour
time = 14400, // 4 * 60 * 60 seconds = 4 hours
size = 500,
sync_writes = true,
with_cached_flag = true,
Expand Down Expand Up @@ -56,38 +56,21 @@ async fn try_wildcard_resolution(
let Some((resolver_address, maybe_existing_domain)) = any_resolver(db, from_user).await? else {
return Ok(None);
};

let maybe_found_domain = maybe_existing_domain.and_then(|domain| {
if domain.id == from_user.inner.id {
Some(domain)
} else {
None
}
});

if let Some(domain) = &maybe_found_domain {
if !domain.resolved_with_wildcard {
// we found domain that resolved by graph node already, skip it
return Ok(None);
} else {
// domain is resolved with wildcard, so we need to recheck it
tracing::info!(
domain_id = domain.id,
domain_name = domain.name,
"found domain with wildcard-resolution, rechecking it"
)
}
};

let result = ccip_read::call_to_resolver(from_user, resolver_address)
.await
.context("resolve using ccip call")?;

if !result.addr.is_zero() {
let maybe_domain_to_update = maybe_existing_domain.and_then(|domain| {
if domain.id == from_user.inner.id {
Some(domain)
} else {
None
}
});
Ok(Some(creation_domain_from_rpc_resolution(
from_user,
result,
maybe_found_domain,
maybe_domain_to_update,
)))
} else {
Ok(None)
Expand Down Expand Up @@ -179,7 +162,7 @@ fn creation_domain_from_rpc_resolution(
resolver: Some(resolver.to_string()),
is_migrated: true,
stored_offchain: ccip_read_info.stored_offchain,
resolved_with_wildcard: true,
resolved_with_wildcard: ccip_read_info.resolved_with_wildcard,
created_at: now.timestamp().into(),
owner: Address::ZERO.to_string(),
wrapped_owner: None,
Expand Down
8 changes: 1 addition & 7 deletions blockscout-ens/bens-logic/src/subgraph/patcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ impl SubgraphPatcher {
) -> Result<(), anyhow::Error> {
let protocol = from_user.deployed_protocol.protocol;
let level = from_user.inner.level();
let range = if from_user.tld_is_native() {
// sub.domain.eth
3..=MAX_LEVEL
} else {
// any_domains.xyz
2..=MAX_LEVEL
};
let range = 2..=MAX_LEVEL;
let level_is_fine = range.contains(&level);
if protocol.info.try_offchain_resolve && level_is_fine {
offchain_resolve(db, from_user).await?
Expand Down
8 changes: 6 additions & 2 deletions blockscout-ens/bens-logic/src/subgraph/sql/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ async fn update_domain(
r#"
UPDATE {schema}.domain
SET
resolved_address = $1
WHERE vid = $2
resolved_address = $1,
stored_offchain = $2,
resolved_with_wildcard = $3
WHERE vid = $4
"#
))
.bind(&domain.resolved_address)
.bind(domain.stored_offchain)
.bind(domain.resolved_with_wildcard)
.bind(vid)
.execute(pool)
.await?;
Expand Down
1 change: 1 addition & 0 deletions blockscout-ens/bens-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub async fn run(settings: Settings) -> Result<(), anyhow::Error> {
.context("database connect")?,
);
if settings.database.run_migrations {
tracing::info!("running migrations");
bens_logic::migrations::run(&pool).await?;
}
let networks = settings
Expand Down

0 comments on commit 459ddf5

Please sign in to comment.