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
8c63d0d2
Commit
8c63d0d2
authored
Oct 04, 2018
by
Anton Evangelatov
Committed by
Péter Szilágyi
Oct 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swarm/storage: extract isValid. correctly remove invalid chunks from store on migration (#17835)
parent
18950591
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
21 deletions
+21
-21
localstore.go
swarm/storage/localstore.go
+21
-21
No files found.
swarm/storage/localstore.go
View file @
8c63d0d2
...
@@ -83,6 +83,22 @@ func NewTestLocalStoreForAddr(params *LocalStoreParams) (*LocalStore, error) {
...
@@ -83,6 +83,22 @@ func NewTestLocalStoreForAddr(params *LocalStoreParams) (*LocalStore, error) {
return
localStore
,
nil
return
localStore
,
nil
}
}
// isValid returns true if chunk passes any of the LocalStore Validators.
// isValid also returns true if LocalStore has no Validators.
func
(
ls
*
LocalStore
)
isValid
(
chunk
Chunk
)
bool
{
// by default chunks are valid. if we have 0 validators, then all chunks are valid.
valid
:=
true
// ls.Validators contains a list of one validator per chunk type.
// if one validator succeeds, then the chunk is valid
for
_
,
v
:=
range
ls
.
Validators
{
if
valid
=
v
.
Validate
(
chunk
.
Address
(),
chunk
.
Data
());
valid
{
break
}
}
return
valid
}
// Put is responsible for doing validation and storage of the chunk
// Put is responsible for doing validation and storage of the chunk
// by using configured ChunkValidators, MemStore and LDBStore.
// by using configured ChunkValidators, MemStore and LDBStore.
// If the chunk is not valid, its GetErrored function will
// If the chunk is not valid, its GetErrored function will
...
@@ -96,15 +112,7 @@ func NewTestLocalStoreForAddr(params *LocalStoreParams) (*LocalStore, error) {
...
@@ -96,15 +112,7 @@ func NewTestLocalStoreForAddr(params *LocalStoreParams) (*LocalStore, error) {
// After the LDBStore.Put, it is ensured that the MemStore
// After the LDBStore.Put, it is ensured that the MemStore
// contains the chunk with the same data, but nil ReqC channel.
// contains the chunk with the same data, but nil ReqC channel.
func
(
ls
*
LocalStore
)
Put
(
ctx
context
.
Context
,
chunk
Chunk
)
error
{
func
(
ls
*
LocalStore
)
Put
(
ctx
context
.
Context
,
chunk
Chunk
)
error
{
valid
:=
true
if
!
ls
.
isValid
(
chunk
)
{
// ls.Validators contains a list of one validator per chunk type.
// if one validator succeeds, then the chunk is valid
for
_
,
v
:=
range
ls
.
Validators
{
if
valid
=
v
.
Validate
(
chunk
.
Address
(),
chunk
.
Data
());
valid
{
break
}
}
if
!
valid
{
return
ErrChunkInvalid
return
ErrChunkInvalid
}
}
...
@@ -200,18 +208,10 @@ func (ls *LocalStore) Migrate() error {
...
@@ -200,18 +208,10 @@ func (ls *LocalStore) Migrate() error {
if
schema
==
""
{
if
schema
==
""
{
log
.
Debug
(
"running migrations for"
,
"schema"
,
schema
,
"runtime-schema"
,
CurrentDbSchema
)
log
.
Debug
(
"running migrations for"
,
"schema"
,
schema
,
"runtime-schema"
,
CurrentDbSchema
)
cleanupFunc
:=
func
(
c
*
chunk
)
bool
{
// delete chunks that are not valid, i.e. chunks that do not pass any of the ls.Validators
// if one of the ls.Validators passes, it means a chunk is of particular type and it is valid
ls
.
DbStore
.
Cleanup
(
func
(
c
*
chunk
)
bool
{
valid
:=
false
return
!
ls
.
isValid
(
c
)
for
_
,
v
:=
range
ls
.
Validators
{
})
if
valid
=
v
.
Validate
(
c
.
Address
(),
c
.
Data
());
valid
{
break
}
}
return
valid
}
ls
.
DbStore
.
Cleanup
(
cleanupFunc
)
err
:=
ls
.
DbStore
.
PutSchema
(
DbSchemaPurity
)
err
:=
ls
.
DbStore
.
PutSchema
(
DbSchemaPurity
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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