Skip to content

Commit

Permalink
Check BIC before sending a candidacy announcement to avoid blocking t…
Browse files Browse the repository at this point in the history
…he accounts
  • Loading branch information
alexsporn committed Apr 19, 2024
1 parent faf7e9b commit dc9e578
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion components/validator/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {

Check failure on line 170 in components/validator/issuer.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] components/validator/issuer.go#L170

type assertion must be checked (forcetypeassert)
Raw output
components/validator/issuer.go:170:99: type assertion must be checked (forcetypeassert)
	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)

Check failure on line 171 in components/validator/issuer.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] components/validator/issuer.go#L171

type assertion must be checked (forcetypeassert)
Raw output
components/validator/issuer.go:171:187: type assertion must be checked (forcetypeassert)
		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")
Expand Down

0 comments on commit dc9e578

Please sign in to comment.