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

Commit 04445a0

Browse files
authored
Merge pull request #912 from iotaledger/feat/decay-BIC-api
Decay BIC in API request handler
2 parents 2c5aeb3 + 042ea6b commit 04445a0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Diff for: pkg/requesthandler/accounts.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,22 @@ func (r *RequestHandler) CongestionByAccountAddress(accountAddress *iotago.Accou
3535
return nil, ierrors.WithMessagef(echo.ErrNotFound, "account %s not found", accountID.ToHex())
3636
}
3737

38+
blockIssuanceCredits := acc.Credits.Value
39+
// Apply decay to BIC if the value is positive
40+
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())
43+
if err != nil {
44+
return nil, ierrors.WithMessagef(echo.ErrInternalServerError, "failed to decay BIC for account %s: %w", accountID.ToHex(), err)
45+
}
46+
blockIssuanceCredits = iotago.BlockIssuanceCredits(decayedBIC)
47+
}
48+
3849
return &api.CongestionResponse{
3950
Slot: commitment.Slot(),
4051
Ready: r.protocol.Engines.Main.Get().Scheduler.IsBlockIssuerReady(accountID, workScores...),
4152
ReferenceManaCost: commitment.ReferenceManaCost(),
42-
BlockIssuanceCredits: acc.Credits.Value,
53+
BlockIssuanceCredits: blockIssuanceCredits,
4354
}, nil
4455
}
4556

0 commit comments

Comments
 (0)