-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculated blockNumber in a separate go-routine for logging (#1025)
* Cached block number in logger * Revert "Cached block number in logger" This reverts commit 760e3ad. * Added block/block.go for calculating latestBlock in a seperate goroutine * Fetched block number from block package * log corrections
- Loading branch information
Showing
5 changed files
with
47 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package block | ||
|
||
import ( | ||
"context" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/sirupsen/logrus" | ||
"razor/core" | ||
"time" | ||
) | ||
|
||
var latestBlock *types.Header | ||
|
||
func GetLatestBlock() *types.Header { | ||
return latestBlock | ||
} | ||
|
||
func SetLatestBlock(block *types.Header) { | ||
latestBlock = block | ||
} | ||
|
||
func CalculateLatestBlock(client *ethclient.Client) { | ||
for { | ||
if client != nil { | ||
latestHeader, err := client.HeaderByNumber(context.Background(), nil) | ||
if err != nil { | ||
logrus.Error("CalculateBlockNumber: Error in fetching block: ", err) | ||
continue | ||
} | ||
SetLatestBlock(latestHeader) | ||
} | ||
time.Sleep(time.Second * time.Duration(core.BlockNumberInterval)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters