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
5db8f447
Commit
5db8f447
authored
9 years ago
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
eth: fix #1319, put an upper limit on the known txns and blocks
parent
6fc85f1e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
eth/peer.go
+19
-0
19 additions, 0 deletions
eth/peer.go
with
19 additions
and
0 deletions
eth/peer.go
+
19
−
0
View file @
5db8f447
...
...
@@ -20,6 +20,11 @@ var (
errNotRegistered
=
errors
.
New
(
"peer is not registered"
)
)
const
(
maxKnownTxs
=
32768
// Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownBlocks
=
1024
// Maximum block hashes to keep in the known list (prevent DOS)
)
type
statusMsgData
struct
{
ProtocolVersion
uint32
NetworkId
uint32
...
...
@@ -101,12 +106,26 @@ func (p *peer) SetTd(td *big.Int) {
// MarkBlock marks a block as known for the peer, ensuring that the block will
// never be propagated to this particular peer.
func
(
p
*
peer
)
MarkBlock
(
hash
common
.
Hash
)
{
// If we reached the memory allowance, drop a previously known block hash
if
p
.
knownBlocks
.
Size
()
>=
maxKnownBlocks
{
p
.
knownBlocks
.
Each
(
func
(
item
interface
{})
bool
{
p
.
knownBlocks
.
Remove
(
item
)
return
p
.
knownBlocks
.
Size
()
>=
maxKnownBlocks
})
}
p
.
knownBlocks
.
Add
(
hash
)
}
// MarkTransaction marks a transaction as known for the peer, ensuring that it
// will never be propagated to this particular peer.
func
(
p
*
peer
)
MarkTransaction
(
hash
common
.
Hash
)
{
// If we reached the memory allowance, drop a previously known transaction hash
if
p
.
knownTxs
.
Size
()
>=
maxKnownTxs
{
p
.
knownTxs
.
Each
(
func
(
item
interface
{})
bool
{
p
.
knownTxs
.
Remove
(
item
)
return
p
.
knownTxs
.
Size
()
>=
maxKnownTxs
})
}
p
.
knownTxs
.
Add
(
hash
)
}
...
...
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