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
87e510d9
Unverified
Commit
87e510d9
authored
Jun 19, 2023
by
Dan Laine
Committed by
GitHub
Jun 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
internal/ethapi, les: use slices package for sorting (#27492)
Co-authored-by:
Felix Lange
<
fjl@twurst.com
>
parent
a8482127
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
56 deletions
+22
-56
api_test.go
internal/ethapi/api_test.go
+3
-10
servingqueue.go
les/servingqueue.go
+11
-25
limiter.go
les/utils/limiter.go
+8
-21
No files found.
internal/ethapi/api_test.go
View file @
87e510d9
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
package
ethapi
package
ethapi
import
(
import
(
"bytes"
"context"
"context"
"crypto/ecdsa"
"crypto/ecdsa"
"encoding/json"
"encoding/json"
...
@@ -25,7 +24,6 @@ import (
...
@@ -25,7 +24,6 @@ import (
"hash"
"hash"
"math/big"
"math/big"
"reflect"
"reflect"
"sort"
"testing"
"testing"
"time"
"time"
...
@@ -48,6 +46,7 @@ import (
...
@@ -48,6 +46,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/rpc"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/sha3"
"golang.org/x/crypto/sha3"
"golang.org/x/exp/slices"
)
)
func
TestTransaction_RoundTripRpcJSON
(
t
*
testing
.
T
)
{
func
TestTransaction_RoundTripRpcJSON
(
t
*
testing
.
T
)
{
...
@@ -649,19 +648,13 @@ type Account struct {
...
@@ -649,19 +648,13 @@ type Account struct {
addr
common
.
Address
addr
common
.
Address
}
}
type
Accounts
[]
Account
func
newAccounts
(
n
int
)
(
accounts
[]
Account
)
{
func
(
a
Accounts
)
Len
()
int
{
return
len
(
a
)
}
func
(
a
Accounts
)
Swap
(
i
,
j
int
)
{
a
[
i
],
a
[
j
]
=
a
[
j
],
a
[
i
]
}
func
(
a
Accounts
)
Less
(
i
,
j
int
)
bool
{
return
bytes
.
Compare
(
a
[
i
]
.
addr
.
Bytes
(),
a
[
j
]
.
addr
.
Bytes
())
<
0
}
func
newAccounts
(
n
int
)
(
accounts
Accounts
)
{
for
i
:=
0
;
i
<
n
;
i
++
{
for
i
:=
0
;
i
<
n
;
i
++
{
key
,
_
:=
crypto
.
GenerateKey
()
key
,
_
:=
crypto
.
GenerateKey
()
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
accounts
=
append
(
accounts
,
Account
{
key
:
key
,
addr
:
addr
})
accounts
=
append
(
accounts
,
Account
{
key
:
key
,
addr
:
addr
})
}
}
s
ort
.
Sort
(
accounts
)
s
lices
.
SortFunc
(
accounts
,
func
(
a
,
b
Account
)
bool
{
return
a
.
addr
.
Less
(
b
.
addr
)
}
)
return
accounts
return
accounts
}
}
...
...
les/servingqueue.go
View file @
87e510d9
...
@@ -17,12 +17,12 @@
...
@@ -17,12 +17,12 @@
package
les
package
les
import
(
import
(
"sort"
"sync"
"sync"
"sync/atomic"
"sync/atomic"
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/common/prque"
"github.com/ethereum/go-ethereum/common/prque"
"golang.org/x/exp/slices"
)
)
// servingQueue allows running tasks in a limited number of threads and puts the
// servingQueue allows running tasks in a limited number of threads and puts the
...
@@ -180,35 +180,19 @@ func (sq *servingQueue) threadController() {
...
@@ -180,35 +180,19 @@ func (sq *servingQueue) threadController() {
}
}
}
}
type
(
// peerTasks lists the tasks received from a given peer when selecting peers to freeze
// peerTasks lists the tasks received from a given peer when selecting peers to freeze
type
peerTasks
struct
{
peerTasks
struct
{
peer
*
clientPeer
peer
*
clientPeer
list
[]
*
servingTask
list
[]
*
servingTask
sumTime
uint64
sumTime
uint64
priority
float64
priority
float64
}
// peerList is a sortable list of peerTasks
peerList
[]
*
peerTasks
)
func
(
l
peerList
)
Len
()
int
{
return
len
(
l
)
}
func
(
l
peerList
)
Less
(
i
,
j
int
)
bool
{
return
l
[
i
]
.
priority
<
l
[
j
]
.
priority
}
func
(
l
peerList
)
Swap
(
i
,
j
int
)
{
l
[
i
],
l
[
j
]
=
l
[
j
],
l
[
i
]
}
}
// freezePeers selects the peers with the worst priority queued tasks and freezes
// freezePeers selects the peers with the worst priority queued tasks and freezes
// them until burstTime goes under burstDropLimit or all peers are frozen
// them until burstTime goes under burstDropLimit or all peers are frozen
func
(
sq
*
servingQueue
)
freezePeers
()
{
func
(
sq
*
servingQueue
)
freezePeers
()
{
peerMap
:=
make
(
map
[
*
clientPeer
]
*
peerTasks
)
peerMap
:=
make
(
map
[
*
clientPeer
]
*
peerTasks
)
var
peerList
peerList
var
peerList
[]
*
peerTasks
if
sq
.
best
!=
nil
{
if
sq
.
best
!=
nil
{
sq
.
queue
.
Push
(
sq
.
best
,
sq
.
best
.
priority
)
sq
.
queue
.
Push
(
sq
.
best
,
sq
.
best
.
priority
)
}
}
...
@@ -231,7 +215,9 @@ func (sq *servingQueue) freezePeers() {
...
@@ -231,7 +215,9 @@ func (sq *servingQueue) freezePeers() {
tasks
.
list
=
append
(
tasks
.
list
,
task
)
tasks
.
list
=
append
(
tasks
.
list
,
task
)
tasks
.
sumTime
+=
task
.
expTime
tasks
.
sumTime
+=
task
.
expTime
}
}
sort
.
Sort
(
peerList
)
slices
.
SortFunc
(
peerList
,
func
(
a
,
b
*
peerTasks
)
bool
{
return
a
.
priority
<
b
.
priority
})
drop
:=
true
drop
:=
true
for
_
,
tasks
:=
range
peerList
{
for
_
,
tasks
:=
range
peerList
{
if
drop
{
if
drop
{
...
...
les/utils/limiter.go
View file @
87e510d9
...
@@ -17,10 +17,10 @@
...
@@ -17,10 +17,10 @@
package
utils
package
utils
import
(
import
(
"sort"
"sync"
"sync"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enode"
"golang.org/x/exp/slices"
)
)
const
maxSelectionWeight
=
1000000000
// maximum selection weight of each individual node/address group
const
maxSelectionWeight
=
1000000000
// maximum selection weight of each individual node/address group
...
@@ -340,24 +340,9 @@ func (l *Limiter) Stop() {
...
@@ -340,24 +340,9 @@ func (l *Limiter) Stop() {
l
.
cond
.
Signal
()
l
.
cond
.
Signal
()
}
}
type
(
type
dropListItem
struct
{
dropList
[]
dropListItem
dropListItem
struct
{
nq
*
nodeQueue
nq
*
nodeQueue
priority
float64
priority
float64
}
)
func
(
l
dropList
)
Len
()
int
{
return
len
(
l
)
}
func
(
l
dropList
)
Less
(
i
,
j
int
)
bool
{
return
l
[
i
]
.
priority
<
l
[
j
]
.
priority
}
func
(
l
dropList
)
Swap
(
i
,
j
int
)
{
l
[
i
],
l
[
j
]
=
l
[
j
],
l
[
i
]
}
}
// dropRequests selects the nodes with the highest queued request cost to selection
// dropRequests selects the nodes with the highest queued request cost to selection
...
@@ -366,7 +351,7 @@ func (l dropList) Swap(i, j int) {
...
@@ -366,7 +351,7 @@ func (l dropList) Swap(i, j int) {
func
(
l
*
Limiter
)
dropRequests
()
{
func
(
l
*
Limiter
)
dropRequests
()
{
var
(
var
(
sumValue
float64
sumValue
float64
list
dropList
list
[]
dropListItem
)
)
for
_
,
nq
:=
range
l
.
nodes
{
for
_
,
nq
:=
range
l
.
nodes
{
sumValue
+=
nq
.
value
sumValue
+=
nq
.
value
...
@@ -384,7 +369,9 @@ func (l *Limiter) dropRequests() {
...
@@ -384,7 +369,9 @@ func (l *Limiter) dropRequests() {
priority
:
w
/
float64
(
nq
.
sumCost
),
priority
:
w
/
float64
(
nq
.
sumCost
),
})
})
}
}
sort
.
Sort
(
list
)
slices
.
SortFunc
(
list
,
func
(
a
,
b
dropListItem
)
bool
{
return
a
.
priority
<
b
.
priority
})
for
_
,
item
:=
range
list
{
for
_
,
item
:=
range
list
{
for
_
,
request
:=
range
item
.
nq
.
queue
{
for
_
,
request
:=
range
item
.
nq
.
queue
{
close
(
request
.
process
)
close
(
request
.
process
)
...
...
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