@@ -27,27 +27,34 @@ func (r *RequestHandler) CongestionByAccountAddress(accountAddress *iotago.Accou
27
27
}
28
28
29
29
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 )
31
39
if err != nil {
32
40
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 {
35
42
return nil , ierrors .WithMessagef (echo .ErrNotFound , "account %s not found" , accountID .ToHex ())
36
43
}
37
44
38
45
blockIssuanceCredits := acc .Credits .Value
39
46
// Apply decay to BIC if the value is positive
40
47
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 )
43
50
if err != nil {
44
51
return nil , ierrors .WithMessagef (echo .ErrInternalServerError , "failed to decay BIC for account %s: %w" , accountID .ToHex (), err )
45
52
}
46
53
blockIssuanceCredits = iotago .BlockIssuanceCredits (decayedBIC )
47
54
}
48
55
49
56
return & api.CongestionResponse {
50
- Slot : commitment . Slot () ,
57
+ Slot : targetSlot ,
51
58
Ready : r .protocol .Engines .Main .Get ().Scheduler .IsBlockIssuerReady (accountID , workScores ... ),
52
59
ReferenceManaCost : commitment .ReferenceManaCost (),
53
60
BlockIssuanceCredits : blockIssuanceCredits ,
0 commit comments