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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
b40c796f
Commit
b40c796f
authored
9 years ago
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
eth/downloader: preallocate the block cache
parent
1d7bf3d3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
eth/downloader/downloader.go
+4
-4
4 additions, 4 deletions
eth/downloader/downloader.go
eth/downloader/downloader_test.go
+1
-1
1 addition, 1 deletion
eth/downloader/downloader_test.go
eth/downloader/queue.go
+9
-16
9 additions, 16 deletions
eth/downloader/queue.go
with
14 additions
and
21 deletions
eth/downloader/downloader.go
+
4
−
4
View file @
b40c796f
...
...
@@ -341,12 +341,12 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
active
.
getHashes
(
head
)
continue
}
// We're done,
allocat
e the download cache and proceed pulling the blocks
// We're done,
prepar
e the download cache and proceed pulling the blocks
offset
:=
0
if
block
:=
d
.
getBlock
(
head
);
block
!=
nil
{
offset
=
int
(
block
.
NumberU64
()
+
1
)
}
d
.
queue
.
Alloc
(
offset
)
d
.
queue
.
Prepare
(
offset
)
finished
=
true
case
blockPack
:=
<-
d
.
blockCh
:
...
...
@@ -504,7 +504,7 @@ out:
}
// Get a possible chunk. If nil is returned no chunk
// could be returned due to no hashes available.
request
:=
d
.
queue
.
Reserve
(
peer
)
request
:=
d
.
queue
.
Reserve
(
peer
,
peer
.
Capacity
()
)
if
request
==
nil
{
continue
}
...
...
@@ -551,7 +551,7 @@ func (d *Downloader) banBlocks(peerId string, head common.Hash) error {
if
peer
==
nil
{
return
nil
}
request
:=
d
.
queue
.
Reserve
(
peer
)
request
:=
d
.
queue
.
Reserve
(
peer
,
MaxBlockFetch
)
if
request
==
nil
{
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
eth/downloader/downloader_test.go
+
1
−
1
View file @
b40c796f
...
...
@@ -186,7 +186,7 @@ func TestSynchronisation(t *testing.T) {
if
err
:=
tester
.
sync
(
"peer"
,
hashes
[
0
]);
err
!=
nil
{
t
.
Fatalf
(
"failed to synchronise blocks: %v"
,
err
)
}
if
queued
:=
len
(
tester
.
downloader
.
queue
.
block
Cache
);
queued
!=
targetBlocks
{
if
queued
:=
len
(
tester
.
downloader
.
queue
.
block
Pool
);
queued
!=
targetBlocks
{
t
.
Fatalf
(
"synchronised block mismatch: have %v, want %v"
,
queued
,
targetBlocks
)
}
}
...
...
This diff is collapsed.
Click to expand it.
eth/downloader/queue.go
+
9
−
16
View file @
b40c796f
...
...
@@ -50,10 +50,11 @@ type queue struct {
// newQueue creates a new download queue for scheduling block retrieval.
func
newQueue
()
*
queue
{
return
&
queue
{
hashPool
:
make
(
map
[
common
.
Hash
]
int
),
hashQueue
:
prque
.
New
(),
pendPool
:
make
(
map
[
string
]
*
fetchRequest
),
blockPool
:
make
(
map
[
common
.
Hash
]
int
),
hashPool
:
make
(
map
[
common
.
Hash
]
int
),
hashQueue
:
prque
.
New
(),
pendPool
:
make
(
map
[
string
]
*
fetchRequest
),
blockPool
:
make
(
map
[
common
.
Hash
]
int
),
blockCache
:
make
([]
*
Block
,
blockCacheLimit
),
}
}
...
...
@@ -70,7 +71,7 @@ func (q *queue) Reset() {
q
.
blockPool
=
make
(
map
[
common
.
Hash
]
int
)
q
.
blockOffset
=
0
q
.
blockCache
=
nil
q
.
blockCache
=
make
([]
*
Block
,
blockCacheLimit
)
}
// Size retrieves the number of hashes in the queue, returning separately for
...
...
@@ -208,7 +209,7 @@ func (q *queue) TakeBlocks() []*Block {
// Reserve reserves a set of hashes for the given peer, skipping any previously
// failed download.
func
(
q
*
queue
)
Reserve
(
p
*
peer
)
*
fetchRequest
{
func
(
q
*
queue
)
Reserve
(
p
*
peer
,
count
int
)
*
fetchRequest
{
q
.
lock
.
Lock
()
defer
q
.
lock
.
Unlock
()
...
...
@@ -345,20 +346,12 @@ func (q *queue) Deliver(id string, blocks []*types.Block) (err error) {
return
nil
}
// Alloc ensures that the block cache is the correct size, given a starting
// offset, and a memory cap.
func
(
q
*
queue
)
Alloc
(
offset
int
)
{
// Prepare configures the block cache offset to allow accepting inbound blocks.
func
(
q
*
queue
)
Prepare
(
offset
int
)
{
q
.
lock
.
Lock
()
defer
q
.
lock
.
Unlock
()
if
q
.
blockOffset
<
offset
{
q
.
blockOffset
=
offset
}
size
:=
len
(
q
.
hashPool
)
if
size
>
blockCacheLimit
{
size
=
blockCacheLimit
}
if
len
(
q
.
blockCache
)
<
size
{
q
.
blockCache
=
append
(
q
.
blockCache
,
make
([]
*
Block
,
size
-
len
(
q
.
blockCache
))
...
)
}
}
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