From cd59b922ed2e5b241a1a9d968412180bd4330f85 Mon Sep 17 00:00:00 2001 From: parmarrushabh Date: Thu, 4 Oct 2018 12:31:18 +0530 Subject: [PATCH] skip changes if no candidates found --- cmd/XDC/main.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cmd/XDC/main.go b/cmd/XDC/main.go index 69a1cd5377..fc07f31813 100644 --- a/cmd/XDC/main.go +++ b/cmd/XDC/main.go @@ -368,14 +368,14 @@ func startNode(ctx *cli.Context, stack *node.Node) { opts := new(bind.CallOpts) candidates, err := validator.GetCandidates(opts) if err != nil { - utils.Fatalf("Can't get list of candidates: %v", err) + utils.Fatalf("Can't get list of masternode candidates: %v", err) } var ms []clique.Masternode for _, candidate := range candidates { v, err := validator.GetCandidateCap(opts, candidate) if err != nil { - log.Warn("Can't get cap of a candidate. Will ignore him", "address", candidate, "error", err) + log.Warn("Can't get cap of a masternode candidate. Will ignore him", "address", candidate, "error", err) } ms = append(ms, clique.Masternode{Address: candidate, Stake: v.Int64()}) } @@ -383,14 +383,20 @@ func startNode(ctx *cli.Context, stack *node.Node) { sort.Slice(ms, func(i, j int) bool { return ms[i].Stake > ms[j].Stake }) - // update masternodes - err = ethereum.UpdateMasternodes(ms) - if err != nil { - utils.Fatalf("Can't update masternodes: %v", err) + log.Info("Ordered list of masternode candidates", "candidates", ms) + if len(ms) == 0 { + log.Info("No masternode candidates found. Keep the current masternodes set for the next epoch") + } else { + // update masternodes + log.Info("Updating new set of masternodes") + err = ethereum.UpdateMasternodes(ms) + if err != nil { + utils.Fatalf("Can't update masternodes: %v", err) + } + log.Info("Masternodes are ready for the next epoch") } - log.Info("Masternodes are ready for the next epoch") } } }() } -} \ No newline at end of file +}