Increment retry count when ENS verification fails
We did not increment the counter when verification failed, which meant that we would not backoff and retry more often that we should have.
This commit is contained in:
parent
2948544b7a
commit
79be6eaf3a
|
@ -8,13 +8,13 @@ import (
|
||||||
// maxRetries is the maximum number of attempts we do before giving up
|
// maxRetries is the maximum number of attempts we do before giving up
|
||||||
const maxRetries uint64 = 11
|
const maxRetries uint64 = 11
|
||||||
|
|
||||||
// ENSBackoffTimeMs is the step of the exponential backoff
|
// ENSBackoffTimeSec is the step of the exponential backoff
|
||||||
// we retry roughly for 17 hours after receiving the message 2^11 * 30000
|
// we retry roughly for 17 hours after receiving the message 2^11 * 30
|
||||||
const ENSBackoffTimeMs uint64 = 30000
|
const ENSBackoffTimeSec uint64 = 30
|
||||||
|
|
||||||
// We calculate if it's too early to retry, by exponentially backing off
|
// We calculate if it's too early to retry, by exponentially backing off
|
||||||
func verifiedENSRecentlyEnough(now, verifiedAt, retries uint64) bool {
|
func verifiedENSRecentlyEnough(now, verifiedAt, retries uint64) bool {
|
||||||
return now < verifiedAt+ENSBackoffTimeMs*retries*uint64(math.Exp2(float64(retries)))
|
return now < verifiedAt+ENSBackoffTimeSec*retries*uint64(math.Exp2(float64(retries)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldENSBeVerified(c *Contact, now uint64) bool {
|
func shouldENSBeVerified(c *Contact, now uint64) bool {
|
||||||
|
|
|
@ -34,7 +34,7 @@ func (s *ENSSuite) TestShouldBeVerified() {
|
||||||
ENSVerificationRetries: 4,
|
ENSVerificationRetries: 4,
|
||||||
},
|
},
|
||||||
Expected: true,
|
Expected: true,
|
||||||
TimeNow: 10 + ENSBackoffTimeMs*4*16 + 1,
|
TimeNow: 10 + ENSBackoffTimeSec*4*16 + 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Empty name",
|
Name: "Empty name",
|
||||||
|
@ -63,7 +63,7 @@ func (s *ENSSuite) TestShouldBeVerified() {
|
||||||
ENSVerificationRetries: 4,
|
ENSVerificationRetries: 4,
|
||||||
},
|
},
|
||||||
Expected: false,
|
Expected: false,
|
||||||
TimeNow: 10 + ENSBackoffTimeMs*4*16 - 1,
|
TimeNow: 10 + ENSBackoffTimeSec*4*16 - 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "max retries reached",
|
Name: "max retries reached",
|
||||||
|
@ -73,7 +73,7 @@ func (s *ENSSuite) TestShouldBeVerified() {
|
||||||
ENSVerificationRetries: 11,
|
ENSVerificationRetries: 11,
|
||||||
},
|
},
|
||||||
Expected: false,
|
Expected: false,
|
||||||
TimeNow: 10 + ENSBackoffTimeMs*5*2048 + 1,
|
TimeNow: 10 + ENSBackoffTimeSec*5*2048 + 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
|
@ -2057,7 +2057,8 @@ func (m *Messenger) VerifyENSNames(ctx context.Context, rpcEndpoint, contractAdd
|
||||||
|
|
||||||
var ensDetails []enstypes.ENSDetails
|
var ensDetails []enstypes.ENSDetails
|
||||||
|
|
||||||
now := m.getTimesource().GetCurrentTime()
|
// Now in seconds
|
||||||
|
now := m.getTimesource().GetCurrentTime() / 1000
|
||||||
for _, contact := range m.allContacts {
|
for _, contact := range m.allContacts {
|
||||||
if shouldENSBeVerified(contact, now) {
|
if shouldENSBeVerified(contact, now) {
|
||||||
ensDetails = append(ensDetails, enstypes.ENSDetails{
|
ensDetails = append(ensDetails, enstypes.ENSDetails{
|
||||||
|
@ -2091,6 +2092,7 @@ func (m *Messenger) VerifyENSNames(ctx context.Context, rpcEndpoint, contractAdd
|
||||||
zap.String("publicKey", details.PublicKeyString),
|
zap.String("publicKey", details.PublicKeyString),
|
||||||
zap.Error(details.Error),
|
zap.Error(details.Error),
|
||||||
)
|
)
|
||||||
|
contact.ENSVerificationRetries++
|
||||||
}
|
}
|
||||||
response.Contacts = append(response.Contacts, contact)
|
response.Contacts = append(response.Contacts, contact)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue