Skip to content

Commit

Permalink
Revert "ledger: increase locks granularity in lookupWithoutRewards (#…
Browse files Browse the repository at this point in the history
…5527)"

This reverts commit 12e537c.
  • Loading branch information
algorandskiy authored Jul 29, 2023
1 parent fd15f4e commit 272fc41
Showing 1 changed file with 2 additions and 12 deletions.
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

0 comments on commit 272fc41

Please sign in to comment.