Skip to content

Commit

Permalink
Merge pull request #912 from iotaledger/feat/decay-BIC-api
Browse files Browse the repository at this point in the history
Decay BIC in API request handler
  • Loading branch information
muXxer authored Apr 16, 2024
2 parents 2c5aeb3 + 042ea6b commit 04445a0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/requesthandler/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,22 @@ func (r *RequestHandler) CongestionByAccountAddress(accountAddress *iotago.Accou
return nil, ierrors.WithMessagef(echo.ErrNotFound, "account %s not found", accountID.ToHex())
}

blockIssuanceCredits := acc.Credits.Value
// Apply decay to BIC if the value is positive
if blockIssuanceCredits > 0 {
manaDecayProvider := r.APIProvider().APIForSlot(commitment.Slot()).ManaDecayProvider()
decayedBIC, err := manaDecayProvider.DecayManaBySlots(iotago.Mana(acc.Credits.Value), acc.Credits.UpdateSlot, commitment.Slot())
if err != nil {
return nil, ierrors.WithMessagef(echo.ErrInternalServerError, "failed to decay BIC for account %s: %w", accountID.ToHex(), err)
}
blockIssuanceCredits = iotago.BlockIssuanceCredits(decayedBIC)
}

return &api.CongestionResponse{
Slot: commitment.Slot(),
Ready: r.protocol.Engines.Main.Get().Scheduler.IsBlockIssuerReady(accountID, workScores...),
ReferenceManaCost: commitment.ReferenceManaCost(),
BlockIssuanceCredits: acc.Credits.Value,
BlockIssuanceCredits: blockIssuanceCredits,
}, nil
}

Expand Down

0 comments on commit 04445a0

Please sign in to comment.