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:
Andrea Maria Piana 2020-04-09 14:48:55 +02:00
parent 2948544b7a
commit 79be6eaf3a
4 changed files with 11 additions and 9 deletions

View File

@ -1 +1 @@
0.51.0
0.51.1

View File

@ -8,13 +8,13 @@ import (
// maxRetries is the maximum number of attempts we do before giving up
const maxRetries uint64 = 11
// ENSBackoffTimeMs is the step of the exponential backoff
// we retry roughly for 17 hours after receiving the message 2^11 * 30000
const ENSBackoffTimeMs uint64 = 30000
// ENSBackoffTimeSec is the step of the exponential backoff
// we retry roughly for 17 hours after receiving the message 2^11 * 30
const ENSBackoffTimeSec uint64 = 30
// We calculate if it's too early to retry, by exponentially backing off
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 {

View File

@ -34,7 +34,7 @@ func (s *ENSSuite) TestShouldBeVerified() {
ENSVerificationRetries: 4,
},
Expected: true,
TimeNow: 10 + ENSBackoffTimeMs*4*16 + 1,
TimeNow: 10 + ENSBackoffTimeSec*4*16 + 1,
},
{
Name: "Empty name",
@ -63,7 +63,7 @@ func (s *ENSSuite) TestShouldBeVerified() {
ENSVerificationRetries: 4,
},
Expected: false,
TimeNow: 10 + ENSBackoffTimeMs*4*16 - 1,
TimeNow: 10 + ENSBackoffTimeSec*4*16 - 1,
},
{
Name: "max retries reached",
@ -73,7 +73,7 @@ func (s *ENSSuite) TestShouldBeVerified() {
ENSVerificationRetries: 11,
},
Expected: false,
TimeNow: 10 + ENSBackoffTimeMs*5*2048 + 1,
TimeNow: 10 + ENSBackoffTimeSec*5*2048 + 1,
},
}
for _, tc := range testCases {

View File

@ -2057,7 +2057,8 @@ func (m *Messenger) VerifyENSNames(ctx context.Context, rpcEndpoint, contractAdd
var ensDetails []enstypes.ENSDetails
now := m.getTimesource().GetCurrentTime()
// Now in seconds
now := m.getTimesource().GetCurrentTime() / 1000
for _, contact := range m.allContacts {
if shouldENSBeVerified(contact, now) {
ensDetails = append(ensDetails, enstypes.ENSDetails{
@ -2091,6 +2092,7 @@ func (m *Messenger) VerifyENSNames(ctx context.Context, rpcEndpoint, contractAdd
zap.String("publicKey", details.PublicKeyString),
zap.Error(details.Error),
)
contact.ENSVerificationRetries++
}
response.Contacts = append(response.Contacts, contact)
}