diff --git a/components/validator/issuer.go b/components/validator/issuer.go index a7d9955..6136d5c 100644 --- a/components/validator/issuer.go +++ b/components/validator/issuer.go @@ -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,20 @@ 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") + } + + 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")