Skip to content

Commit

Permalink
Merge pull request #9 from iotaledger/feat/old-genesis-revive-chain
Browse files Browse the repository at this point in the history
Revive chain even if we cannot load the committee and we are ignoring being bootstrapped
  • Loading branch information
alexsporn authored Nov 16, 2023
2 parents a030d48 + e53e5b8 commit 886684f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion components/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
Name = "inx-validator"

// Version of the app.
Version = "1.0.0-alpha.4"
Version = "1.0.0-alpha.5"
)

func App() *app.App {
Expand Down
32 changes: 18 additions & 14 deletions components/validator/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func candidateAction(ctx context.Context) {
if err = issueCandidateBlock(ctx, now, currentAPI); err != nil {
Component.LogWarnf("error while trying to issue candidacy announcement: %s", err.Error())
}

}

func committeeMemberAction(ctx context.Context) {
Expand All @@ -75,33 +74,38 @@ func committeeMemberAction(ctx context.Context) {
currentSlot := currentAPI.TimeProvider().SlotFromTime(now)
currentEpoch := currentAPI.TimeProvider().EpochFromSlot(currentSlot)

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))
// 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))

return
}
return
}

if !isCommitteeMember {
Component.LogDebug("account %s is not a committee member in epoch %d", currentEpoch)
executor.ExecuteAt(CommitteeTask, func() { committeeMemberAction(ctx) }, currentAPI.TimeProvider().SlotStartTime(currentAPI.TimeProvider().EpochStart(currentEpoch+1)))
if !isCommitteeMember {
Component.LogDebug("account %s is not a committee member in epoch %d", currentEpoch)
executor.ExecuteAt(CommitteeTask, func() { committeeMemberAction(ctx) }, currentAPI.TimeProvider().SlotStartTime(currentAPI.TimeProvider().EpochStart(currentEpoch+1)))

return
return
}
}

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

// Validator block may ignore the bootstrap flag in order to bootstrap the network and begin acceptance.
if !ParamsValidator.IgnoreBootstrapped && !deps.NodeBridge.NodeStatus().GetIsBootstrapped() {
// 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.")

return
}

if err = issueValidatorBlock(ctx, now, currentAPI); err != nil {
// 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())
}
}
Expand Down

0 comments on commit 886684f

Please sign in to comment.