From: Chengcheng Zhang <943420582@qq.com> Date: Wed, 23 Sep 2020 02:03:27 +0000 (+0800) Subject: add net info (#548) X-Git-Tag: v4.8.11~2 X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=2ac36cb36ba090c7ba0c1482fe250e82c843329f;hp=b3c1fe7a33650df6e14ae64bca2a3e8d46664aaa add net info (#548) * update * update * update * update * update * update --- diff --git a/toolbar/federation/service/node.go b/toolbar/federation/service/node.go index 5ca0042e..48aac545 100644 --- a/toolbar/federation/service/node.go +++ b/toolbar/federation/service/node.go @@ -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"` diff --git a/toolbar/federation/synchron/sidechain_keeper.go b/toolbar/federation/synchron/sidechain_keeper.go index 0e513146..8d00c781 100644 --- a/toolbar/federation/synchron/sidechain_keeper.go +++ b/toolbar/federation/synchron/sidechain_keeper.go @@ -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 }