Add a workaround for waiting till node is synced with network (#565)
This commit is contained in:
parent
755a646bd4
commit
889eeca31d
|
@ -181,7 +181,7 @@ func (s *RPCTestSuite) TestCallContextResult() {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
var balance hexutil.Big
|
var balance hexutil.Big
|
||||||
err := client.CallContext(ctx, &balance, "eth_getBalance", "0xbF164ca341326a03b547c05B343b2E21eFAe24b9", "latest")
|
err := client.CallContext(ctx, &balance, "eth_getBalance", TestConfig.Account1.Address, "latest")
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
s.True(balance.ToInt().Cmp(big.NewInt(0)) > 0, "balance should be higher than 0")
|
s.True(balance.ToInt().Cmp(big.NewInt(0)) > 0, "balance should be higher than 0")
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,9 @@ type NodeManager interface {
|
||||||
// AddPeer adds URL of static peer
|
// AddPeer adds URL of static peer
|
||||||
AddPeer(url string) error
|
AddPeer(url string) error
|
||||||
|
|
||||||
|
// PeerCount returns number of connected peers
|
||||||
|
PeerCount() int
|
||||||
|
|
||||||
// LightEthereumService exposes reference to LES service running on top of the node
|
// LightEthereumService exposes reference to LES service running on top of the node
|
||||||
LightEthereumService() (*les.LightEthereum, error)
|
LightEthereumService() (*les.LightEthereum, error)
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,18 @@ func (mr *MockNodeManagerMockRecorder) AddPeer(url interface{}) *gomock.Call {
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddPeer", reflect.TypeOf((*MockNodeManager)(nil).AddPeer), url)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddPeer", reflect.TypeOf((*MockNodeManager)(nil).AddPeer), url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PeerCount mocks base method
|
||||||
|
func (m *MockNodeManager) PeerCount() int {
|
||||||
|
ret := m.ctrl.Call(m, "PeerCount")
|
||||||
|
ret0, _ := ret[0].(int)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// PeerCount indicates an expected call of PeerCount
|
||||||
|
func (mr *MockNodeManagerMockRecorder) PeerCount() *gomock.Call {
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerCount", reflect.TypeOf((*MockNodeManager)(nil).PeerCount))
|
||||||
|
}
|
||||||
|
|
||||||
// LightEthereumService mocks base method
|
// LightEthereumService mocks base method
|
||||||
func (m *MockNodeManager) LightEthereumService() (*les.LightEthereum, error) {
|
func (m *MockNodeManager) LightEthereumService() (*les.LightEthereum, error) {
|
||||||
ret := m.ctrl.Call(m, "LightEthereumService")
|
ret := m.ctrl.Call(m, "LightEthereumService")
|
||||||
|
|
|
@ -295,6 +295,13 @@ func (m *NodeManager) addPeer(url string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *NodeManager) PeerCount() int {
|
||||||
|
if m.node == nil || m.node.Server() == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return m.node.Server().PeerCount()
|
||||||
|
}
|
||||||
|
|
||||||
// ResetChainData remove chain data from data directory.
|
// ResetChainData remove chain data from data directory.
|
||||||
// Node is stopped, and new node is started, with clean data directory.
|
// Node is stopped, and new node is started, with clean data directory.
|
||||||
func (m *NodeManager) ResetChainData() (<-chan struct{}, error) {
|
func (m *NodeManager) ResetChainData() (<-chan struct{}, error) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/status-im/status-go/geth/common"
|
"github.com/status-im/status-go/geth/common"
|
||||||
|
"github.com/status-im/status-go/geth/log"
|
||||||
"github.com/status-im/status-go/geth/params"
|
"github.com/status-im/status-go/geth/params"
|
||||||
|
|
||||||
_ "github.com/stretchr/testify/suite" // required to register testify flags
|
_ "github.com/stretchr/testify/suite" // required to register testify flags
|
||||||
|
@ -113,22 +114,32 @@ func EnsureNodeSync(nodeManager common.NodeManager) {
|
||||||
defer timeout.Stop()
|
defer timeout.Stop()
|
||||||
ticker := time.NewTicker(1 * time.Second)
|
ticker := time.NewTicker(1 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timeout.C:
|
case <-timeout.C:
|
||||||
panic("timeout during node synchronization")
|
panic("timeout during node synchronization")
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
downloader := les.Downloader()
|
downloader := les.Downloader()
|
||||||
|
if downloader == nil {
|
||||||
if downloader != nil {
|
continue
|
||||||
isSyncing := downloader.Synchronising()
|
|
||||||
progress := downloader.Progress()
|
|
||||||
|
|
||||||
if !isSyncing && progress.HighestBlock > 0 && progress.CurrentBlock >= progress.HighestBlock {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if nodeManager.PeerCount() == 0 {
|
||||||
|
log.Debug("No establishished connections with a peers, continue waiting for a sync")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if downloader.Synchronising() {
|
||||||
|
log.Debug("synchronization is in progress")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
progress := downloader.Progress()
|
||||||
|
if progress.CurrentBlock >= progress.HighestBlock {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Debug(
|
||||||
|
fmt.Sprintf("synchronization is not finished yet: current block %d < highest block %d",
|
||||||
|
progress.CurrentBlock, progress.HighestBlock),
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue