Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check BIC before sending a candidacy announcement to avoid blocking the accounts #34

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@
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
Loading