• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: 提交

Golang implemented sidechain for Bytom


Commit MetaInfo

修订版5e927937d2e52829db9f8e3be959b42be1af3994 (tree)
时间2020-02-19 18:37:43
作者ipqhjjybj <250657661@qq.c...>
Commiteripqhjjybj

Log Message

change rollback func return info

更改概述

差异

--- a/cmd/vapord/commands/rollback_node.go
+++ b/cmd/vapord/commands/rollback_node.go
@@ -25,9 +25,12 @@ var rollbackCmd = &cobra.Command{
2525 log.WithFields(log.Fields{"module": logModule}).Fatal("height should >= 0")
2626 }
2727
28- if err = node.Rollback(config, uint64(height)); err != nil {
28+ var finalHeight uint64
29+ if finalHeight, err = node.Rollback(config, uint64(height)); err != nil {
2930 log.WithFields(log.Fields{"module": logModule, "err": err}).Fatal("failed to rollback")
3031 }
32+
33+ log.WithFields(log.Fields{"module": logModule}).Infof("success to rollback height of %d", finalHeight)
3134 },
3235 }
3336
--- a/node/node.go
+++ b/node/node.go
@@ -163,14 +163,14 @@ func NewNode(config *cfg.Config) *Node {
163163 }
164164
165165 // Rollback rollback chain from one height to targetHeight
166-func Rollback(config *cfg.Config, targetHeight uint64) error {
166+func Rollback(config *cfg.Config, targetHeight uint64) (uint64, error) {
167167 if err := initNodeConfig(config); err != nil {
168- return err
168+ return 0, err
169169 }
170170
171171 // Get store
172172 if config.DBBackend != "leveldb" {
173- return errors.New("Param db_backend is invalid, use leveldb")
173+ return 0, errors.New("Param db_backend is invalid, use leveldb")
174174 }
175175
176176 coreDB := dbm.NewDB("core", config.DBBackend, config.DBDir())
@@ -181,12 +181,12 @@ func Rollback(config *cfg.Config, targetHeight uint64) error {
181181 txPool := protocol.NewTxPool(store, []protocol.DustFilterer{movCore}, dispatcher)
182182 chain, err := protocol.NewChain(store, txPool, []protocol.Protocoler{movCore}, dispatcher)
183183 if err != nil {
184- return err
184+ return 0, err
185185 }
186186
187187 hsm, err := pseudohsm.New(config.KeysDir())
188188 if err != nil {
189- cmn.Exit(cmn.Fmt("initialize HSM failed: %v", err))
189+ return 0, err
190190 }
191191
192192 walletDB := dbm.NewDB("wallet", config.DBBackend, config.DBDir())
@@ -196,15 +196,14 @@ func Rollback(config *cfg.Config, targetHeight uint64) error {
196196 assets := asset.NewRegistry(walletDB, chain)
197197 wallet, err := w.NewWallet(walletStore, accounts, assets, hsm, chain, dispatcher, config.Wallet.TxIndex)
198198 if err != nil {
199- return err
199+ return 0, err
200200 }
201201
202202 if err := wallet.Rollback(targetHeight); err != nil {
203- return err
203+ return 0, err
204204 }
205205
206- log.WithFields(log.Fields{"module": logModule}).Infof("success to rollback height of %d", chain.BestBlockHeight())
207- return nil
206+ return chain.BestBlockHeight(), nil
208207 }
209208
210209 func initNodeConfig(config *cfg.Config) error {
--- a/wallet/wallet.go
+++ b/wallet/wallet.go
@@ -320,7 +320,7 @@ func (w *Wallet) Rollback(targetHeight uint64) error {
320320 return err
321321 }
322322
323- for detachBlockHeader.Height > targetHeight {
323+ for w.Status.WorkHeight > targetHeight {
324324 blockHash := detachBlockHeader.Hash()
325325 block, err := w.Chain.GetBlockByHash(&blockHash)
326326 if err != nil {
Show on old repository browser