Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
29f12020
Commit
29f12020
authored
10 years ago
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added block cache delete method
parent
0d1a9ce6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
block_cache.go
core/block_cache.go
+17
-0
block_cache_test.go
core/block_cache_test.go
+12
-0
No files found.
core/block_cache.go
View file @
29f12020
...
...
@@ -56,6 +56,23 @@ func (bc *BlockCache) Push(block *types.Block) {
bc
.
hashes
[
len
(
bc
.
hashes
)
-
1
]
=
hash
}
func
(
bc
*
BlockCache
)
Delete
(
hash
common
.
Hash
)
{
bc
.
mu
.
Lock
()
defer
bc
.
mu
.
Unlock
()
if
_
,
ok
:=
bc
.
blocks
[
hash
];
ok
{
delete
(
bc
.
blocks
,
hash
)
for
i
,
h
:=
range
bc
.
hashes
{
if
hash
==
h
{
bc
.
hashes
=
bc
.
hashes
[
:
i
+
copy
(
bc
.
hashes
[
i
:
],
bc
.
hashes
[
i
+
1
:
])]
// or ? => bc.hashes = append(bc.hashes[:i], bc.hashes[i+1]...)
break
}
}
}
}
func
(
bc
*
BlockCache
)
Get
(
hash
common
.
Hash
)
*
types
.
Block
{
bc
.
mu
.
RLock
()
defer
bc
.
mu
.
RUnlock
()
...
...
This diff is collapsed.
Click to expand it.
core/block_cache_test.go
View file @
29f12020
...
...
@@ -46,3 +46,15 @@ func TestInclusion(t *testing.T) {
}
}
}
func
TestDeletion
(
t
*
testing
.
T
)
{
chain
:=
newChain
(
3
)
cache
:=
NewBlockCache
(
3
)
insertChainCache
(
cache
,
chain
)
cache
.
Delete
(
chain
[
1
]
.
Hash
())
if
cache
.
Has
(
chain
[
1
]
.
Hash
())
{
t
.
Errorf
(
"expected %x not to be included"
)
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment