From 789a1f49bf87296526e959454cae7563dff07933 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 16 Apr 2024 09:11:50 +0100 Subject: [PATCH 1/2] apply decay to BIC if it is positive --- pkg/requesthandler/accounts.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/requesthandler/accounts.go b/pkg/requesthandler/accounts.go index ceb698f02..b4437e088 100644 --- a/pkg/requesthandler/accounts.go +++ b/pkg/requesthandler/accounts.go @@ -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 acc.Credits.Value > 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 } From 042ea6b685c0e948f7fd661ab6887a630b854853 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 16 Apr 2024 09:21:07 +0100 Subject: [PATCH 2/2] muxxer suggestion --- pkg/requesthandler/accounts.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/requesthandler/accounts.go b/pkg/requesthandler/accounts.go index b4437e088..a8c56378c 100644 --- a/pkg/requesthandler/accounts.go +++ b/pkg/requesthandler/accounts.go @@ -37,7 +37,7 @@ func (r *RequestHandler) CongestionByAccountAddress(accountAddress *iotago.Accou blockIssuanceCredits := acc.Credits.Value // Apply decay to BIC if the value is positive - if acc.Credits.Value > 0 { + 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 { @@ -45,7 +45,7 @@ func (r *RequestHandler) CongestionByAccountAddress(accountAddress *iotago.Accou } blockIssuanceCredits = iotago.BlockIssuanceCredits(decayedBIC) } - + return &api.CongestionResponse{ Slot: commitment.Slot(), Ready: r.protocol.Engines.Main.Get().Scheduler.IsBlockIssuerReady(accountID, workScores...),