Skip to content

Commit

Permalink
Merge pull request #17 from iotaledger/use-validation-blocks-per-slot
Browse files Browse the repository at this point in the history
Use `ValidationBlocksPerSlot` protocol parameter
  • Loading branch information
muXxer authored Nov 29, 2023
2 parents 4689670 + c831bb9 commit c4c25d7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
22 changes: 13 additions & 9 deletions components/validator/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ func committeeMemberAction(ctx context.Context) {
currentAPI := deps.NodeBridge.APIProvider().APIForTime(now)
currentSlot := currentAPI.TimeProvider().SlotFromTime(now)
currentEpoch := currentAPI.TimeProvider().EpochFromSlot(currentSlot)
slotDurationMillis := int64(currentAPI.ProtocolParameters().SlotDurationInSeconds()) * 1000
// Calculate the broadcast interval in milliseconds.
broadcastIntervalMillis := slotDurationMillis / int64(currentAPI.ProtocolParameters().ValidationBlocksPerSlot())
committeeBroadcastInterval := time.Duration(broadcastIntervalMillis * int64(time.Millisecond))

// If we are bootstrapped let's check if we are part of the committee.
if deps.NodeBridge.NodeStatus().GetIsBootstrapped() {
isCommitteeMember, err := deps.NodeBridge.ReadIsCommitteeMember(ctx, validatorAccount.ID(), currentSlot)
if err != nil {
Component.LogWarnf("error while checking if account %s is a committee member in slot %d: %s", validatorAccount.ID(), currentSlot, err.Error())
executor.ExecuteAt(CommitteeTask, func() { committeeMemberAction(ctx) }, now.Add(ParamsValidator.CommitteeBroadcastInterval))
executor.ExecuteAt(CommitteeTask, func() { committeeMemberAction(ctx) }, now.Add(committeeBroadcastInterval))

return
}
Expand All @@ -92,21 +96,21 @@ func committeeMemberAction(ctx context.Context) {
}
}

// Schedule next committeeMemberAction regardless of whether the node is bootstrapped or validator block is issued
// Schedule next committeeMemberAction regardless of whether the node is bootstrapped or validation block is issued
// as it must be issued as part of validator's responsibility.
executor.ExecuteAt(CommitteeTask, func() { committeeMemberAction(ctx) }, now.Add(ParamsValidator.CommitteeBroadcastInterval))
executor.ExecuteAt(CommitteeTask, func() { committeeMemberAction(ctx) }, now.Add(committeeBroadcastInterval))

// If we are not bootstrapped and we are _not_ ignoring such condition, we return.
if !deps.NodeBridge.NodeStatus().GetIsBootstrapped() && !ParamsValidator.IgnoreBootstrapped {
Component.LogDebug("not issuing validator block because node is not bootstrapped yet.")
Component.LogDebug("not issuing validation block because node is not bootstrapped yet.")

return
}

// If we are either bootstrapped (and we are part of the committee) or we are ignoring being bootstrapped we issue
// a validation block, reviving the chain if necessary.
if err := issueValidatorBlock(ctx, now, currentAPI); err != nil {
Component.LogWarnf("error while trying to issue validator block: %s", err.Error())
if err := issueValidationBlock(ctx, now, currentAPI, committeeBroadcastInterval); err != nil {
Component.LogWarnf("error while trying to issue validation block: %s", err.Error())
}
}

Expand Down Expand Up @@ -148,7 +152,7 @@ func issueCandidateBlock(ctx context.Context, blockIssuingTime time.Time, curren
return nil
}

func issueValidatorBlock(ctx context.Context, blockIssuingTime time.Time, currentAPI iotago.API) error {
func issueValidationBlock(ctx context.Context, blockIssuingTime time.Time, currentAPI iotago.API, committeeBroadcastInterval time.Duration) error {
protocolParametersHash, err := currentAPI.ProtocolParameters().Hash()
if err != nil {
return ierrors.Wrapf(err, "failed to get protocol parameters hash")
Expand Down Expand Up @@ -196,10 +200,10 @@ func issueValidatorBlock(ctx context.Context, blockIssuingTime time.Time, curren

blockID, err := deps.NodeBridge.SubmitBlock(ctx, validationBlock)
if err != nil {
return ierrors.Wrapf(err, "error issuing validator block")
return ierrors.Wrapf(err, "error issuing validation block")
}

Component.LogDebugf("issued validator block: %s - commitment %s %d - latest finalized slot %d", blockID, validationBlock.Header.SlotCommitmentID, validationBlock.Header.SlotCommitmentID.Slot(), validationBlock.Header.LatestFinalizedSlot)
Component.LogDebugf("issued validation block: %s - commitment %s %d - latest finalized slot %d - broadcast interval %v", blockID, validationBlock.Header.SlotCommitmentID, validationBlock.Header.SlotCommitmentID.Slot(), validationBlock.Header.LatestFinalizedSlot, committeeBroadcastInterval.Truncate(time.Millisecond))

return nil
}
Expand Down
2 changes: 0 additions & 2 deletions components/validator/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (

// ParametersValidator contains the definition of the configuration parameters used by the Validator component.
type ParametersValidator struct {
// CommitteeBroadcastInterval the interval at which the node will broadcast its committee validator block.
CommitteeBroadcastInterval time.Duration `default:"500ms" usage:"the interval at which committee validator block will be broadcast"`
// CandidacyRetryInterval the interval at which broadcast of candidacy announcement block will be retried
CandidacyRetryInterval time.Duration `default:"10s" usage:"the interval at which broadcast of candidacy announcement block will be retried"`
// IssueCandidacyPayload sets whether the node should issue a candidacy payload.
Expand Down
1 change: 0 additions & 1 deletion config_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"targetNetworkName": ""
},
"validator": {
"committeeBroadcastInterval": "500ms",
"candidacyRetryInterval": "10s",
"issueCandidacyPayload": true,
"ignoreBootstrapped": false,
Expand Down
14 changes: 6 additions & 8 deletions configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,18 @@ Example:

## <a id="validator"></a> 4. Validator

| Name | Description | Type | Default value |
| -------------------------- | ------------------------------------------------------------------------------------------------------------ | ------- | ------------- |
| committeeBroadcastInterval | The interval at which committee validator block will be broadcast | string | "500ms" |
| candidacyRetryInterval | The interval at which broadcast of candidacy announcement block will be retried | string | "10s" |
| issueCandidacyPayload | Whether the node should issue a candidacy payload | boolean | true |
| ignoreBootstrapped | Whether the Validator component should start issuing validator blocks before the main engine is bootstrapped | boolean | false |
| accountAddress | The account address of the validator account that will issue the blocks | string | "" |
| Name | Description | Type | Default value |
| ---------------------- | ------------------------------------------------------------------------------------------------------------ | ------- | ------------- |
| candidacyRetryInterval | The interval at which broadcast of candidacy announcement block will be retried | string | "10s" |
| issueCandidacyPayload | Whether the node should issue a candidacy payload | boolean | true |
| ignoreBootstrapped | Whether the Validator component should start issuing validator blocks before the main engine is bootstrapped | boolean | false |
| accountAddress | The account address of the validator account that will issue the blocks | string | "" |

Example:

```json
{
"validator": {
"committeeBroadcastInterval": "500ms",
"candidacyRetryInterval": "10s",
"issueCandidacyPayload": true,
"ignoreBootstrapped": false,
Expand Down

0 comments on commit c4c25d7

Please sign in to comment.