Skip to content

Commit

Permalink
Merge pull request #34 from iotaledger/feat/check-bic
Browse files Browse the repository at this point in the history
Check BIC before sending a candidacy announcement to avoid blocking the accounts
  • Loading branch information
alexsporn authored Apr 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents faf7e9b + 8def559 commit de8aeed
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion components/validator/issuer.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,10 @@ import (
"github.com/iotaledger/iota.go/v4/builder"
)

var ErrBlockTooRecent = ierrors.New("block is too recent compared to latest commitment")
var (
ErrBlockTooRecent = ierrors.New("block is too recent compared to latest commitment")
ErrNotEnoughBlockIssuanceCredits = ierrors.New("not enough block issuance credits")
)

type TaskType uint8

@@ -154,6 +157,21 @@ func issueCandidateBlock(ctx context.Context, blockIssuingTime time.Time, curren
return ierrors.Wrap(err, "error creating block")
}

nodeClient, err := deps.NodeBridge.INXNodeClient()
if err != nil {
return ierrors.Wrap(err, "error getting node client")
}

congestionResp, err := nodeClient.Congestion(ctx, validatorAccount.ID().ToAddress().(*iotago.AccountAddress), 0, addressableCommitment.MustID())
if err != nil {
return ierrors.Wrap(err, "error getting congestion")
}

//nolint:forcetypeassert // we know that the body is a BasicBlockBody
if congestionResp.BlockIssuanceCredits < 0 || iotago.Mana(congestionResp.BlockIssuanceCredits) < candidacyBlock.Body.(*iotago.BasicBlockBody).MaxBurnedMana {
return ierrors.WithMessagef(ErrNotEnoughBlockIssuanceCredits, "account BIC %d is not enough to send candidacy announcement with MaxBurnedMana %d", congestionResp.BlockIssuanceCredits, candidacyBlock.Body.(*iotago.BasicBlockBody).MaxBurnedMana)
}

blockID, err := submitBlock(ctx, candidacyBlock)
if err != nil {
return ierrors.Wrap(err, "error issuing candidacy announcement block")

0 comments on commit de8aeed

Please sign in to comment.