Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(NOBIDS) ens: handle old invalid entries #2921

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions db/ens.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/gobitfly/eth2-beaconchain-explorer/metrics"
"github.com/gobitfly/eth2-beaconchain-explorer/types"
"github.com/gobitfly/eth2-beaconchain-explorer/utils"
"github.com/sirupsen/logrus"

gcp_bigtable "cloud.google.com/go/bigtable"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -419,37 +420,38 @@ func validateEnsAddress(client *ethclient.Client, address common.Address, alread
alreadyChecked.address[address] = true
alreadyChecked.mux.Unlock()

currentName, err := GetEnsNameForAddress(address)
names := []string{}
err := ReaderDb.Select(&names, `SELECT ens_name FROM ens WHERE address = $1 AND is_primary_name AND valid_to >= now()`, address.Bytes())
if err != nil && err != sql.ErrNoRows {
return err
}

if err != nil && currentName != "" {
err = validateEnsName(client, currentName, alreadyChecked)
for _, name := range names {
if name != "" {
err = validateEnsName(client, name, alreadyChecked)
if err != nil {
return err
}
}
reverseName, err := go_ens.ReverseResolve(client, address)
if err != nil {
return err
if err.Error() == "not a resolver" ||
err.Error() == "no resolution" ||
err.Error() == "execution reverted" ||
strings.HasPrefix(err.Error(), "name is not valid") {
logger.Warnf("reverse resolving address [%v] resulted in a skippable error [%s], skipping it", address, err.Error())
} else {
return fmt.Errorf("error could not reverse resolve address [%v]: %w", address, err)
}
}
}

reverseName, err := go_ens.ReverseResolve(client, address)
if err != nil {
if err.Error() == "not a resolver" ||
err.Error() == "no resolution" ||
err.Error() == "execution reverted" ||
strings.HasPrefix(err.Error(), "name is not valid") {
logger.Warnf("reverse resolving address [%v] resulted in a skippable error [%s], skipping it", address, err.Error())
} else {
return fmt.Errorf("error could not reverse resolve address [%v]: %w", address, err)
if reverseName != name {
err = validateEnsName(client, reverseName, alreadyChecked)
if err != nil {
return err
}
}
}

if reverseName == currentName {
return nil
}
err = validateEnsName(client, reverseName, alreadyChecked)
if err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -563,7 +565,12 @@ func validateEnsName(client *ethclient.Client, name string, alreadyChecked *EnsC
return fmt.Errorf("error writing ens data for name [%v]: %w", name, err)
}

logger.Infof("Name [%v] resolved -> %x, expires: %v, is primary: %v", name, addr, expires, isPrimary)
logrus.WithFields(logrus.Fields{
"name": name,
"address": addr,
"expires": expires,
"reverseName": reverseName,
}).Infof("validated ens name")
return nil
}

Expand Down
Loading