OSDN Git Service

add net info (#548)
authorChengcheng Zhang <943420582@qq.com>
Wed, 23 Sep 2020 02:03:27 +0000 (10:03 +0800)
committerGitHub <noreply@github.com>
Wed, 23 Sep 2020 02:03:27 +0000 (10:03 +0800)
* update

* update

* update

* update

* update

* update

toolbar/federation/service/node.go
toolbar/federation/synchron/sidechain_keeper.go

index 5ca0042..48aac54 100644 (file)
@@ -3,6 +3,7 @@ package service
 import (
        "encoding/json"
 
+       "github.com/bytom/vapor/api"
        "github.com/bytom/vapor/errors"
        "github.com/bytom/vapor/protocol/bc"
        "github.com/bytom/vapor/toolbar/common"
@@ -36,6 +37,12 @@ func (n *Node) GetBlockCount() (uint64, error) {
        return res.BlockCount, n.request(url, nil, res)
 }
 
+func (n *Node) GetNetInfo() (*api.NetInfo, error) {
+       url := "/net-info"
+       res := &api.NetInfo{}
+       return res, n.request(url, nil, res)
+}
+
 type getRawBlockReq struct {
        BlockHeight uint64 `json:"block_height"`
        BlockHash   string `json:"block_hash"`
index 0e51314..8d00c78 100644 (file)
@@ -270,12 +270,12 @@ func (s *sidechainKeeper) syncBlock() (bool, error) {
                return false, errors.Wrap(err, "query chain")
        }
 
-       height, err := s.node.GetBlockCount()
+       netInfo, err := s.node.GetNetInfo()
        if err != nil {
                return false, err
        }
 
-       if height <= chain.BlockHeight+s.cfg.Confirmations {
+       if netInfo.IrreversibleBlock <= chain.BlockHeight {
                return false, nil
        }