good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
54bbdff1
Commit
54bbdff1
authored
May 6, 2020
by
atvanguard
Browse files
Options
Downloads
Patches
Plain Diff
Initialize apiCache in once.do
parent
bbe6522f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
consensus/bor/api.go
+13
-18
13 additions, 18 deletions
consensus/bor/api.go
with
13 additions
and
18 deletions
consensus/bor/api.go
+
13
−
18
View file @
54bbdff1
...
...
@@ -35,6 +35,7 @@ import (
var
(
// MaxCheckpointLength is the maximum number of blocks that can be requested for constructing a checkpoint root hash
MaxCheckpointLength
=
uint64
(
math
.
Pow
(
2
,
15
))
once
sync
.
Once
)
// API is a user facing RPC API to allow controlling the signer and voting
...
...
@@ -123,11 +124,18 @@ func (api *API) GetCurrentValidators() ([]*Validator, error) {
// GetRootHash returns the merkle root of the start to end block headers
func
(
api
*
API
)
GetRootHash
(
start
int64
,
end
int64
)
([]
byte
,
error
)
{
key
:=
getKey
(
start
,
end
)
if
root
,
err
:=
api
.
lookupCache
(
key
);
err
!=
nil
{
var
err
error
once
.
Do
(
func
()
{
if
api
.
rootHashCache
==
nil
{
api
.
rootHashCache
,
err
=
lru
.
NewARC
(
10
)
}
})
if
err
!=
nil
{
return
nil
,
err
}
else
if
root
!=
nil
{
return
root
,
nil
}
key
:=
getRootHashKey
(
start
,
end
)
if
root
,
known
:=
api
.
rootHashCache
.
Get
(
key
);
known
{
return
root
.
([]
byte
),
nil
}
length
:=
uint64
(
end
-
start
+
1
)
if
length
>
MaxCheckpointLength
{
...
...
@@ -176,19 +184,6 @@ func (api *API) GetRootHash(start int64, end int64) ([]byte, error) {
return
root
,
nil
}
func
(
api
*
API
)
lookupCache
(
key
string
)
([]
byte
,
error
)
{
var
err
error
if
api
.
rootHashCache
==
nil
{
if
api
.
rootHashCache
,
err
=
lru
.
NewARC
(
10
);
err
!=
nil
{
return
nil
,
err
}
}
if
root
,
known
:=
api
.
rootHashCache
.
Get
(
key
);
known
{
return
root
.
([]
byte
),
nil
}
return
nil
,
nil
}
func
getKey
(
start
int64
,
end
int64
)
string
{
func
getRootHashKey
(
start
int64
,
end
int64
)
string
{
return
strconv
.
FormatInt
(
start
,
10
)
+
"-"
+
strconv
.
FormatInt
(
end
,
10
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment