-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
amit-momin
commented
Nov 15, 2023
- 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.
I see that you haven't updated any CHANGELOG files. Would it make sense to do so? |
1d1b496
to
649ef08
Compare
common/txmgr/broadcaster.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
8f1eb8c
to
8fa1c7f
Compare
common/txmgr/broadcaster.go
Outdated
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
a628bc8
to
5bf5aae
Compare
5bf5aae
to
103d05d
Compare
SonarQube Quality Gate |
* Updated loading next sequence map to avoid startup failure * Moved logic to populate next sequence map during runtime * Added changelog * Addressed feedback * Addressed feedback
* Updated loading next sequence map to avoid startup failure * Moved logic to populate next sequence map during runtime * Added changelog * Addressed feedback * Addressed feedback