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
28b39267
Commit
28b39267
authored
Apr 30, 2015
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
core, eth: verify td of received blocks
parent
9b6e8f61
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/chain_manager.go
+4
-2
4 additions, 2 deletions
core/chain_manager.go
eth/handler.go
+21
-1
21 additions, 1 deletion
eth/handler.go
with
25 additions
and
3 deletions
core/chain_manager.go
+
4
−
2
View file @
28b39267
...
...
@@ -511,6 +511,10 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
if
block
==
nil
{
continue
}
// Setting block.Td regardless of error (known for example) prevents errors down the line
// in the protocol handler
block
.
Td
=
new
(
big
.
Int
)
.
Set
(
CalculateTD
(
block
,
self
.
GetBlock
(
block
.
ParentHash
())))
// Call in to the block processor and check for errors. It's likely that if one block fails
// all others will fail too (unless a known block is returned).
logs
,
err
:=
self
.
processor
.
Process
(
block
)
...
...
@@ -545,8 +549,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
return
i
,
err
}
block
.
Td
=
new
(
big
.
Int
)
.
Set
(
CalculateTD
(
block
,
self
.
GetBlock
(
block
.
ParentHash
())))
self
.
mu
.
Lock
()
{
cblock
:=
self
.
currentBlock
...
...
This diff is collapsed.
Click to expand it.
eth/handler.go
+
21
−
1
View file @
28b39267
...
...
@@ -125,6 +125,7 @@ func NewProtocolManager(protocolVersion, networkId int, mux *event.TypeMux, txpo
func
(
pm
*
ProtocolManager
)
removePeer
(
peer
*
peer
)
{
pm
.
pmu
.
Lock
()
defer
pm
.
pmu
.
Unlock
()
pm
.
downloader
.
UnregisterPeer
(
peer
.
id
)
delete
(
pm
.
peers
,
peer
.
id
)
}
...
...
@@ -223,7 +224,6 @@ func (pm *ProtocolManager) handle(p *peer) error {
pm
.
downloader
.
RegisterPeer
(
p
.
id
,
p
.
recentHash
,
p
.
requestHashes
,
p
.
requestBlocks
)
defer
func
()
{
pm
.
downloader
.
UnregisterPeer
(
p
.
id
)
pm
.
removePeer
(
p
)
}()
...
...
@@ -392,6 +392,12 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
return
nil
}
if
err
:=
self
.
verifyTd
(
p
,
request
);
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infoln
(
err
)
// XXX for now return nil so it won't disconnect (we should in the future)
return
nil
}
self
.
BroadcastBlock
(
hash
,
request
.
Block
)
}
else
{
// adding blocks is synchronous
...
...
@@ -406,6 +412,10 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
glog
.
V
(
logger
.
Detail
)
.
Infoln
(
"downloader err:"
,
err
)
return
}
if
err
:=
self
.
verifyTd
(
p
,
request
);
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infoln
(
err
)
return
}
self
.
BroadcastBlock
(
hash
,
request
.
Block
)
}()
}
...
...
@@ -415,6 +425,16 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
return
nil
}
func
(
pm
*
ProtocolManager
)
verifyTd
(
peer
*
peer
,
request
newBlockMsgData
)
error
{
if
request
.
Block
.
Td
.
Cmp
(
request
.
TD
)
!=
0
{
glog
.
V
(
logger
.
Detail
)
.
Infoln
(
peer
)
return
fmt
.
Errorf
(
"invalid TD on block(%v) from peer(%s): block.td=%v, request.td=%v"
,
request
.
Block
.
Number
(),
peer
.
id
,
request
.
Block
.
Td
,
request
.
TD
)
}
return
nil
}
// BroadcastBlock will propagate the block to its connected peers. It will sort
// out which peers do not contain the block in their block set and will do a
// sqrt(peers) to determine the amount of peers we broadcast to.
...
...
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