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

Revert "ledger: increase locks granularity in lookupWithoutRewards" #5620

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 2 additions & 12 deletions ledger/acctupdates.go
Original file line number Diff line number Diff line change
Expand Up @@ -1327,29 +1327,23 @@ func (au *accountUpdates) lookupWithoutRewards(rnd basics.Round, addr basics.Add
return
}

deltas := au.deltas[:offset]
rewardsVersion = au.versions[offset]
rewardsLevel = au.roundTotals[offset].RewardsLevel

// check if we've had this address modified in the past rounds. ( i.e. if it's in the deltas )
macct, indeltas := au.accounts[addr]
if synchronized {
au.accountsMu.RUnlock()
needUnlock = false
}

if indeltas {
// Check if this is the most recent round, in which case, we can
// use a cache of the most recent account state.
if offset == uint64(currentDeltaLen) {
if offset == uint64(len(au.deltas)) {
return macct.data, rnd, rewardsVersion, rewardsLevel, nil
}
// the account appears in the deltas, but we don't know if it appears in the
// delta range of [0..offset-1], so we'll need to check. Walk deltas
// backwards to ensure that later updates take priority if present.
for offset > 0 {
offset--
d, ok := deltas[offset].Accts.GetData(addr)
d, ok := au.deltas[offset].Accts.GetData(addr)
if ok {
// the returned validThrough here is not optimal, but it still correct. We could get a more accurate value by scanning
// the deltas forward, but this would be time consuming loop, which might not pay off.
Expand All @@ -1364,10 +1358,6 @@ func (au *accountUpdates) lookupWithoutRewards(rnd basics.Round, addr basics.Add
rnd = currentDbRound + basics.Round(currentDeltaLen)
}

if synchronized {
au.accountsMu.RLock()
needUnlock = true
}
// check the baseAccounts -
if macct, has := au.baseAccounts.read(addr); has {
// we don't technically need this, since it's already in the baseAccounts, however, writing this over
Expand Down