mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-15 08:23:46 +00:00
Remove once.do
This commit is contained in:
parent
54bbdff1e4
commit
50c0b662cf
1 changed files with 9 additions and 8 deletions
|
|
@ -35,7 +35,6 @@ import (
|
||||||
var (
|
var (
|
||||||
// MaxCheckpointLength is the maximum number of blocks that can be requested for constructing a checkpoint root hash
|
// MaxCheckpointLength is the maximum number of blocks that can be requested for constructing a checkpoint root hash
|
||||||
MaxCheckpointLength = uint64(math.Pow(2, 15))
|
MaxCheckpointLength = uint64(math.Pow(2, 15))
|
||||||
once sync.Once
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// API is a user facing RPC API to allow controlling the signer and voting
|
// API is a user facing RPC API to allow controlling the signer and voting
|
||||||
|
|
@ -124,13 +123,7 @@ func (api *API) GetCurrentValidators() ([]*Validator, error) {
|
||||||
|
|
||||||
// GetRootHash returns the merkle root of the start to end block headers
|
// GetRootHash returns the merkle root of the start to end block headers
|
||||||
func (api *API) GetRootHash(start int64, end int64) ([]byte, error) {
|
func (api *API) GetRootHash(start int64, end int64) ([]byte, error) {
|
||||||
var err error
|
if err := api.initializeRootHashCache(); err != nil {
|
||||||
once.Do(func() {
|
|
||||||
if api.rootHashCache == nil {
|
|
||||||
api.rootHashCache, err = lru.NewARC(10)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
key := getRootHashKey(start, end)
|
key := getRootHashKey(start, end)
|
||||||
|
|
@ -184,6 +177,14 @@ func (api *API) GetRootHash(start int64, end int64) ([]byte, error) {
|
||||||
return root, nil
|
return root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) initializeRootHashCache() error {
|
||||||
|
var err error
|
||||||
|
if api.rootHashCache == nil {
|
||||||
|
api.rootHashCache, err = lru.NewARC(10)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func getRootHashKey(start int64, end int64) string {
|
func getRootHashKey(start int64, end int64) string {
|
||||||
return strconv.FormatInt(start, 10) + "-" + strconv.FormatInt(end, 10)
|
return strconv.FormatInt(start, 10) + "-" + strconv.FormatInt(end, 10)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue