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
31b33349
Unverified
Commit
31b33349
authored
Dec 10, 2018
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/utils, eth: minor polishes on whitelist code
parent
48b70ecf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
41 deletions
+29
-41
flags.go
cmd/utils/flags.go
+18
-23
handler.go
eth/handler.go
+11
-18
No files found.
cmd/utils/flags.go
View file @
31b33349
...
@@ -1077,30 +1077,25 @@ func setEthash(ctx *cli.Context, cfg *eth.Config) {
...
@@ -1077,30 +1077,25 @@ func setEthash(ctx *cli.Context, cfg *eth.Config) {
}
}
func
setWhitelist
(
ctx
*
cli
.
Context
,
cfg
*
eth
.
Config
)
{
func
setWhitelist
(
ctx
*
cli
.
Context
,
cfg
*
eth
.
Config
)
{
if
ctx
.
GlobalIsSet
(
WhitelistFlag
.
Name
)
{
whitelist
:=
ctx
.
GlobalString
(
WhitelistFlag
.
Name
)
entries
:=
strings
.
Split
(
ctx
.
String
(
WhitelistFlag
.
Name
),
","
)
if
whitelist
==
""
{
whitelist
:=
make
(
map
[
uint64
]
common
.
Hash
)
return
for
_
,
entry
:=
range
entries
{
}
split
:=
strings
.
SplitN
(
entry
,
"="
,
2
)
cfg
.
Whitelist
=
make
(
map
[
uint64
]
common
.
Hash
)
if
len
(
split
)
!=
2
{
for
_
,
entry
:=
range
strings
.
Split
(
whitelist
,
","
)
{
Fatalf
(
"invalid whitelist entry: %s"
,
entry
)
parts
:=
strings
.
Split
(
entry
,
"="
)
}
if
len
(
parts
)
!=
2
{
Fatalf
(
"Invalid whitelist entry: %s"
,
entry
)
bn
,
err
:=
strconv
.
ParseUint
(
split
[
0
],
0
,
64
)
if
err
!=
nil
{
Fatalf
(
"Invalid whitelist block number %s: %v"
,
split
[
0
],
err
)
}
hash
:=
common
.
Hash
{}
err
=
hash
.
UnmarshalText
([]
byte
(
split
[
1
]))
if
err
!=
nil
{
Fatalf
(
"Invalid whitelist hash %s: %v"
,
split
[
1
],
err
)
}
whitelist
[
bn
]
=
hash
}
}
number
,
err
:=
strconv
.
ParseUint
(
parts
[
0
],
0
,
64
)
cfg
.
Whitelist
=
whitelist
if
err
!=
nil
{
Fatalf
(
"Invalid whitelist block number %s: %v"
,
parts
[
0
],
err
)
}
var
hash
common
.
Hash
if
err
=
hash
.
UnmarshalText
([]
byte
(
parts
[
1
]));
err
!=
nil
{
Fatalf
(
"Invalid whitelist hash %s: %v"
,
parts
[
1
],
err
)
}
cfg
.
Whitelist
[
number
]
=
hash
}
}
}
}
...
...
eth/handler.go
View file @
31b33349
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
package
eth
package
eth
import
(
import
(
"bytes"
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
...
@@ -311,17 +310,13 @@ func (pm *ProtocolManager) handle(p *peer) error {
...
@@ -311,17 +310,13 @@ func (pm *ProtocolManager) handle(p *peer) error {
}
}
}()
}()
}
}
// If we have any explicit whitelist block hashes, request them
// If we have any explicit whitelist block hashes, request them
for
bn
:=
range
pm
.
whitelist
{
for
number
:=
range
pm
.
whitelist
{
p
.
Log
()
.
Debug
(
"Requesting whitelist block"
,
"number"
,
bn
)
if
err
:=
p
.
RequestHeadersByNumber
(
number
,
1
,
0
,
false
);
err
!=
nil
{
if
err
:=
p
.
RequestHeadersByNumber
(
bn
,
1
,
0
,
false
);
err
!=
nil
{
p
.
Log
()
.
Error
(
"whitelist request failed"
,
"err"
,
err
,
"number"
,
bn
,
"peer"
,
p
.
id
)
return
err
return
err
}
}
}
}
// Handle incoming messages until the connection is torn down
// main loop. handle incoming messages.
for
{
for
{
if
err
:=
pm
.
handleMsg
(
p
);
err
!=
nil
{
if
err
:=
pm
.
handleMsg
(
p
);
err
!=
nil
{
p
.
Log
()
.
Debug
(
"Ethereum message handling failed"
,
"err"
,
err
)
p
.
Log
()
.
Debug
(
"Ethereum message handling failed"
,
"err"
,
err
)
...
@@ -466,16 +461,6 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
...
@@ -466,16 +461,6 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
// Filter out any explicitly requested headers, deliver the rest to the downloader
// Filter out any explicitly requested headers, deliver the rest to the downloader
filter
:=
len
(
headers
)
==
1
filter
:=
len
(
headers
)
==
1
if
filter
{
if
filter
{
// Check for any responses not matching our whitelist
if
expected
,
ok
:=
pm
.
whitelist
[
headers
[
0
]
.
Number
.
Uint64
()];
ok
{
actual
:=
headers
[
0
]
.
Hash
()
if
!
bytes
.
Equal
(
expected
.
Bytes
(),
actual
.
Bytes
())
{
p
.
Log
()
.
Info
(
"Dropping peer with non-matching whitelist block"
,
"number"
,
headers
[
0
]
.
Number
.
Uint64
(),
"hash"
,
actual
,
"expected"
,
expected
)
return
errors
.
New
(
"whitelist block mismatch"
)
}
p
.
Log
()
.
Debug
(
"Whitelist block verified"
,
"number"
,
headers
[
0
]
.
Number
.
Uint64
(),
"hash"
,
expected
)
}
// If it's a potential DAO fork check, validate against the rules
// If it's a potential DAO fork check, validate against the rules
if
p
.
forkDrop
!=
nil
&&
pm
.
chainconfig
.
DAOForkBlock
.
Cmp
(
headers
[
0
]
.
Number
)
==
0
{
if
p
.
forkDrop
!=
nil
&&
pm
.
chainconfig
.
DAOForkBlock
.
Cmp
(
headers
[
0
]
.
Number
)
==
0
{
// Disable the fork drop timer
// Disable the fork drop timer
...
@@ -490,6 +475,14 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
...
@@ -490,6 +475,14 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
p
.
Log
()
.
Debug
(
"Verified to be on the same side of the DAO fork"
)
p
.
Log
()
.
Debug
(
"Verified to be on the same side of the DAO fork"
)
return
nil
return
nil
}
}
// Otherwise if it's a whitelisted block, validate against the set
if
want
,
ok
:=
pm
.
whitelist
[
headers
[
0
]
.
Number
.
Uint64
()];
ok
{
if
hash
:=
headers
[
0
]
.
Hash
();
want
!=
hash
{
p
.
Log
()
.
Info
(
"Whitelist mismatch, dropping peer"
,
"number"
,
headers
[
0
]
.
Number
.
Uint64
(),
"hash"
,
hash
,
"want"
,
want
)
return
errors
.
New
(
"whitelist block mismatch"
)
}
p
.
Log
()
.
Debug
(
"Whitelist block verified"
,
"number"
,
headers
[
0
]
.
Number
.
Uint64
(),
"hash"
,
want
)
}
// Irrelevant of the fork checks, send the header to the fetcher just in case
// Irrelevant of the fork checks, send the header to the fetcher just in case
headers
=
pm
.
fetcher
.
FilterHeaders
(
p
.
id
,
headers
,
time
.
Now
())
headers
=
pm
.
fetcher
.
FilterHeaders
(
p
.
id
,
headers
,
time
.
Now
())
}
}
...
...
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