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

Update loading next sequence map to avoid startup failure #11307

Merged
merged 5 commits into from
Nov 16, 2023

Conversation

amit-momin
Copy link
Contributor

  • Updated loading next sequence map logic during Broadcaster startup to not return an error. This allows the Broadcaster to not fail startup due to something like an RPC call failure.
  • Updated the sequence syncer to load a sequence from the tx table or on-chain if it is not found in the map. This allows the Broadcaster to populate the next sequence map for relevant addresses if it was not during startup.

Copy link
Contributor

I see that you haven't updated any CHANGELOG files. Would it make sense to do so?

@amit-momin amit-momin force-pushed the bugfix/load-next-seq-map-failure branch 2 times, most recently from 1d1b496 to 649ef08 Compare November 15, 2023 20:07
@amit-momin amit-momin changed the title [WIP] Updated loading next sequence map to avoid startup failure [WIP] Update loading next sequence map to avoid startup failure Nov 15, 2023
@@ -397,6 +401,14 @@ func (eb *Broadcaster[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) Sync
// Address not found in map so skip sync
if err != nil {
eb.logger.Criticalw("Failed to retrieve local next sequence for address", "address", addr.String(), "err", err)
// Try to retrieve next sequence from on-chain to load the map
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that SyncSequence is only called if that option was set to true for broadcaster.
So if a particular fromAddress couldn't sync a sequence at initialization time, then it will never get a sequence.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest that use the method GetNextSequence(address ADDR)
Inside there, if you don't find the seq from the map, then directly call getSequenceForAddr(), and also set it in the map.
That will ensure all addresses can sync and get seq if they missed doing it at init time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic has been moved to GetNextSequence in the latest commit.

@amit-momin amit-momin changed the title [WIP] Update loading next sequence map to avoid startup failure Update loading next sequence map to avoid startup failure Nov 15, 2023
@amit-momin amit-momin marked this pull request as ready for review November 15, 2023 22:44
@amit-momin amit-momin requested review from samsondav and a team as code owners November 15, 2023 22:44
@amit-momin amit-momin force-pushed the bugfix/load-next-seq-map-failure branch from 8f1eb8c to 8fa1c7f Compare November 15, 2023 22:49
eb.sequenceLock.Lock()
defer eb.sequenceLock.Unlock()
// Get next sequence from map
seq, exists := eb.nextSequenceMap[address]
if !exists {
return seq, errors.New(fmt.Sprint("address not found in next sequence map: ", address))
eb.logger.Criticalw("address not found in local next sequence map. Attempting to search and populate sequence.", "address", address.String())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be a critical error. It just means that we couldn't fetch sequence from onchain due to an unavailable RPC.
Maybe just an info log.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do! It does also mean that we can't broadcast any transaction for that address since we don't have a nonce for it

Copy link
Contributor

@prashantkumar1982 prashantkumar1982 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@amit-momin amit-momin force-pushed the bugfix/load-next-seq-map-failure branch 2 times, most recently from a628bc8 to 5bf5aae Compare November 16, 2023 02:41
@amit-momin amit-momin force-pushed the bugfix/load-next-seq-map-failure branch from 5bf5aae to 103d05d Compare November 16, 2023 02:45
@cl-sonarqube-production
Copy link

@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue Nov 16, 2023
Merged via the queue into develop with commit 01fbf8e Nov 16, 2023
87 checks passed
@prashantkumar1982 prashantkumar1982 deleted the bugfix/load-next-seq-map-failure branch November 16, 2023 16:52
amit-momin added a commit that referenced this pull request Nov 16, 2023
* Updated loading next sequence map to avoid startup failure

* Moved logic to populate next sequence map during runtime

* Added changelog

* Addressed feedback

* Addressed feedback
amit-momin added a commit that referenced this pull request Nov 16, 2023
* Updated loading next sequence map to avoid startup failure

* Moved logic to populate next sequence map during runtime

* Added changelog

* Addressed feedback

* Addressed feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants