From 2ac36cb36ba090c7ba0c1482fe250e82c843329f Mon Sep 17 00:00:00 2001 From: Chengcheng Zhang <943420582@qq.com> Date: Wed, 23 Sep 2020 10:03:27 +0800 Subject: [PATCH] add net info (#548) * update * update * update * update * update * update --- toolbar/federation/service/node.go | 7 +++++++ toolbar/federation/synchron/sidechain_keeper.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) 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 } -- 2.11.0