Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 5690ffe

Browse files
authored
Merge pull request #954 from iotaledger/fix/accounts-early-return
Fix: Too greedy cut-off condition in accounts getter
2 parents 06d43dc + 29b51ab commit 5690ffe

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

pkg/protocol/engine/accounts/accountsledger/manager.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,6 @@ func (m *Manager) Account(accountID iotago.AccountID, targetSlot iotago.SlotInde
200200
}
201201

202202
func (m *Manager) account(accountID iotago.AccountID, targetSlot iotago.SlotIndex) (accountData *accounts.AccountData, exists bool, err error) {
203-
// if m.latestCommittedSlot < maxCommittableAge we should have all history
204-
maxCommittableAge := m.apiProvider.APIForSlot(targetSlot).ProtocolParameters().MaxCommittableAge()
205-
if m.latestCommittedSlot >= maxCommittableAge && targetSlot+maxCommittableAge < m.latestCommittedSlot {
206-
return nil, false, ierrors.Errorf("can't calculate account, target slot index older than allowed (%d<%d)", targetSlot, m.latestCommittedSlot-maxCommittableAge)
207-
}
208-
209203
if targetSlot > m.latestCommittedSlot {
210204
return nil, false, ierrors.Errorf("can't retrieve account, slot %d is not committed yet, latest committed slot: %d", targetSlot, m.latestCommittedSlot)
211205
}

pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func (o *SybilProtection) slotFinalized(slot iotago.SlotIndex) {
298298
// Otherwise, skip committee selection because it's too late and the committee has been reused.
299299
epochEndSlot := timeProvider.EpochEnd(epoch)
300300
if slot+apiForSlot.ProtocolParameters().EpochNearingThreshold() == epochEndSlot &&
301-
epochEndSlot > o.lastCommittedSlot+apiForSlot.ProtocolParameters().MaxCommittableAge() {
301+
o.lastCommittedSlot < epochEndSlot-apiForSlot.ProtocolParameters().MaxCommittableAge() {
302302
newCommittee, err := o.selectNewCommittee(slot)
303303
if err != nil {
304304
panic(ierrors.Wrap(err, "error while selecting new committee"))

pkg/requesthandler/accounts.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,34 @@ func (r *RequestHandler) CongestionByAccountAddress(accountAddress *iotago.Accou
2727
}
2828

2929
accountID := accountAddress.AccountID()
30-
acc, exists, err := r.protocol.Engines.Main.Get().Ledger.Account(accountID, commitment.Slot())
30+
targetSlot := commitment.Slot()
31+
maxCommittableAge := r.protocol.APIForSlot(targetSlot).ProtocolParameters().MaxCommittableAge()
32+
latestCommittedSlot := r.protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot()
33+
34+
if latestCommittedSlot >= maxCommittableAge && targetSlot+maxCommittableAge < latestCommittedSlot {
35+
return nil, ierrors.Errorf("can't calculate account, target slot index older than allowed (%d<%d)", targetSlot, latestCommittedSlot-maxCommittableAge)
36+
}
37+
38+
acc, exists, err := r.protocol.Engines.Main.Get().Ledger.Account(accountID, targetSlot)
3139
if err != nil {
3240
return nil, ierrors.WithMessagef(echo.ErrInternalServerError, "failed to get account %s from the Ledger: %w", accountID.ToHex(), err)
33-
}
34-
if !exists {
41+
} else if !exists {
3542
return nil, ierrors.WithMessagef(echo.ErrNotFound, "account %s not found", accountID.ToHex())
3643
}
3744

3845
blockIssuanceCredits := acc.Credits.Value
3946
// Apply decay to BIC if the value is positive
4047
if blockIssuanceCredits > 0 {
41-
manaDecayProvider := r.APIProvider().APIForSlot(commitment.Slot()).ManaDecayProvider()
42-
decayedBIC, err := manaDecayProvider.DecayManaBySlots(iotago.Mana(acc.Credits.Value), acc.Credits.UpdateSlot, commitment.Slot())
48+
manaDecayProvider := r.APIProvider().APIForSlot(targetSlot).ManaDecayProvider()
49+
decayedBIC, err := manaDecayProvider.DecayManaBySlots(iotago.Mana(acc.Credits.Value), acc.Credits.UpdateSlot, targetSlot)
4350
if err != nil {
4451
return nil, ierrors.WithMessagef(echo.ErrInternalServerError, "failed to decay BIC for account %s: %w", accountID.ToHex(), err)
4552
}
4653
blockIssuanceCredits = iotago.BlockIssuanceCredits(decayedBIC)
4754
}
4855

4956
return &api.CongestionResponse{
50-
Slot: commitment.Slot(),
57+
Slot: targetSlot,
5158
Ready: r.protocol.Engines.Main.Get().Scheduler.IsBlockIssuerReady(accountID, workScores...),
5259
ReferenceManaCost: commitment.ReferenceManaCost(),
5360
BlockIssuanceCredits: blockIssuanceCredits,

0 commit comments

Comments
 (0)