From 9bac2dd5e374c9d779ee7be669d04caa45a41c95 Mon Sep 17 00:00:00 2001 From: Nguyen Ba Tam Date: Mon, 27 Aug 2018 14:45:26 +0700 Subject: [PATCH] update return error when update M1 --- cmd/tomo/main.go | 5 ++++- core/blockchain.go | 19 ++++++++----------- eth/downloader/downloader.go | 7 +++++-- eth/downloader/downloader_test.go | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/cmd/tomo/main.go b/cmd/tomo/main.go index 8b4bcb8f0d..0cae7de10e 100644 --- a/cmd/tomo/main.go +++ b/cmd/tomo/main.go @@ -349,7 +349,10 @@ func startNode(ctx *cli.Context, stack *node.Node) { log.Info("Enabled staking node!!!") } case <-core.M1Ch: - ethereum.BlockChain().UpdateM1() + err := ethereum.BlockChain().UpdateM1() + if(err !=nil){ + log.Error("Error when update M1",err) + } } } }() diff --git a/core/blockchain.go b/core/blockchain.go index ad312ed3d7..1c8884d6af 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -698,7 +698,7 @@ func (bc *BlockChain) procFutureBlocks() { type WriteStatus byte const ( - NonStatTy WriteStatus = iota + NonStatTy WriteStatus = iota CanonStatTy SideStatTy ) @@ -1594,9 +1594,9 @@ func (bc *BlockChain) GetClient() (*ethclient.Client, error) { return bc.Client, nil } -func (bc *BlockChain) UpdateM1() { +func (bc *BlockChain) UpdateM1() error { if bc.Config().Posv == nil { - return + return errors.New("Posv not found in config") } engine := bc.Engine().(*posv.Posv) log.Info("It's time to update new set of masternodes for the next epoch...") @@ -1608,29 +1608,25 @@ func (bc *BlockChain) UpdateM1() { addr := common.HexToAddress(common.MasternodeVotingSMC) validator, err := contractValidator.NewTomoValidator(addr, client) if err != nil { - log.Crit("Fail to get validator smc: %v", err) + return err } opts := new(bind.CallOpts) candidates, err := validator.GetCandidates(opts) if err != nil { - log.Crit("Can't get list of masternode candidates: %v", err) + return err } var ms []posv.Masternode for _, candidate := range candidates { v, err := validator.GetCandidateCap(opts, candidate) if err != nil { - log.Warn("Can't get cap of a masternode candidate. Will ignore him", "address", candidate, "error", err) + return err } //TODO: smart contract shouldn't return "0x0000000000000000000000000000000000000000" if candidate.String() != "0x0000000000000000000000000000000000000000" { ms = append(ms, posv.Masternode{Address: candidate, Stake: v.String()}) } } - //// order by cap - //sort.Slice(ms, func(i, j int) bool { - // return ms[i].Stake > ms[j].Stake - //}) log.Info("Ordered list of masternode candidates") for _, m := range ms { fmt.Printf("address: %s, stake: %s\n", m.Address.String(), m.Stake) @@ -1642,8 +1638,9 @@ func (bc *BlockChain) UpdateM1() { log.Info("Updating new set of masternodes") err = engine.UpdateMasternodes(bc, bc.CurrentHeader(), ms) if err != nil { - log.Crit("Can't update masternodes: %v", err) + return err } log.Info("Masternodes are ready for the next epoch") } + return nil } diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index d4ab38a740..4180ae2eaa 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -173,7 +173,7 @@ type LightChain interface { // BlockChain encapsulates functions required to sync a (full or fast) blockchain. type BlockChain interface { Config() *params.ChainConfig - UpdateM1() + UpdateM1() error LightChain // HasBlock verifies a block's presence in the local chain. @@ -1349,7 +1349,10 @@ func (d *Downloader) processFullSyncContent() error { } // prepare set of masternodes for the next epoch if (inserts[len(inserts)-1].Header.Number.Uint64() % epoch) == (epoch - gap) { - d.blockchain.UpdateM1() + err := d.blockchain.UpdateM1() + if (err != nil) { + log.Error("Error when update M1", err) + } } } start = end + 1 diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index 1e1e64afdc..d3f422de64 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -458,7 +458,7 @@ func (dl *downloadTester) dropPeer(id string) { // Config retrieves the blockchain's chain configuration. func (dl *downloadTester) Config() *params.ChainConfig { return params.TestChainConfig } -func (dl *downloadTester) UpdateM1() {} +func (dl *downloadTester) UpdateM1() error { return nil } type downloadTesterPeer struct { dl *downloadTester