Commit 8f8ae28f authored by caopingcp's avatar caopingcp

tendermint wait block

parent 95a394d8
...@@ -567,17 +567,20 @@ func (client *Client) CommitBlock(block *types.Block) error { ...@@ -567,17 +567,20 @@ func (client *Client) CommitBlock(block *types.Block) error {
// WaitBlock by height // WaitBlock by height
func (client *Client) WaitBlock(height int64) bool { func (client *Client) WaitBlock(height int64) bool {
retry := 0 ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
beg := time.Now()
for { for {
newHeight, err := client.getLastHeight() select {
if err == nil && newHeight >= height { case <-ticker.C:
return true tendermintlog.Info("Still waiting block......", "height", height, "cost", time.Since(beg))
} default:
retry++ newHeight, err := client.getLastHeight()
time.Sleep(100 * time.Millisecond) if err == nil && newHeight >= height {
if retry >= 100 { return true
tendermintlog.Error("Wait block fail", "height", height, "CurrentHeight", newHeight) }
return false time.Sleep(100 * time.Millisecond)
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment