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
992151fa
Unverified
Commit
992151fa
authored
May 05, 2022
by
Péter Szilágyi
Committed by
GitHub
May 05, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #24817 from karalabe/fix-PC-regression
cmd, eth: fix required blocks regression
parents
0a9e384c
ecae8e4f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
58 deletions
+55
-58
main.go
cmd/geth/main.go
+1
-1
usage.go
cmd/geth/usage.go
+1
-1
flags.go
cmd/utils/flags.go
+14
-16
backend.go
eth/backend.go
+10
-10
config.go
eth/ethconfig/config.go
+2
-2
gen_config.go
eth/ethconfig/gen_config.go
+5
-5
handler.go
eth/handler.go
+22
-23
No files found.
cmd/geth/main.go
View file @
992151fa
...
...
@@ -105,7 +105,7 @@ var (
utils
.
UltraLightFractionFlag
,
utils
.
UltraLightOnlyAnnounceFlag
,
utils
.
LightNoSyncServeFlag
,
utils
.
Eth
Peer
RequiredBlocksFlag
,
utils
.
EthRequiredBlocksFlag
,
utils
.
LegacyWhitelistFlag
,
utils
.
BloomFilterSizeFlag
,
utils
.
CacheFlag
,
...
...
cmd/geth/usage.go
View file @
992151fa
...
...
@@ -46,7 +46,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils
.
EthStatsURLFlag
,
utils
.
IdentityFlag
,
utils
.
LightKDFFlag
,
utils
.
Eth
Peer
RequiredBlocksFlag
,
utils
.
EthRequiredBlocksFlag
,
},
utils
.
NetworkFlags
,
utils
.
DatabasePathFlags
),
},
{
...
...
cmd/utils/flags.go
View file @
992151fa
...
...
@@ -240,13 +240,13 @@ var (
Name
:
"lightkdf"
,
Usage
:
"Reduce key-derivation RAM & CPU usage at some expense of KDF strength"
,
}
Eth
Peer
RequiredBlocksFlag
=
cli
.
StringFlag
{
EthRequiredBlocksFlag
=
cli
.
StringFlag
{
Name
:
"eth.requiredblocks"
,
Usage
:
"Comma separated block number-to-hash mappings to require for peering (<number>=<hash>)"
,
}
LegacyWhitelistFlag
=
cli
.
StringFlag
{
Name
:
"whitelist"
,
Usage
:
"Comma separated block number-to-hash mappings to enforce (<number>=<hash>) (deprecated in favor of --
peer
.requiredblocks)"
,
Usage
:
"Comma separated block number-to-hash mappings to enforce (<number>=<hash>) (deprecated in favor of --
eth
.requiredblocks)"
,
}
BloomFilterSizeFlag
=
cli
.
Uint64Flag
{
Name
:
"bloomfilter.size"
,
...
...
@@ -1501,33 +1501,31 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
}
}
func
setPeerRequiredBlocks
(
ctx
*
cli
.
Context
,
cfg
*
ethconfig
.
Config
)
{
peerRequiredBlocks
:=
ctx
.
GlobalString
(
EthPeerRequiredBlocksFlag
.
Name
)
if
peerRequiredBlocks
==
""
{
func
setRequiredBlocks
(
ctx
*
cli
.
Context
,
cfg
*
ethconfig
.
Config
)
{
requiredBlocks
:=
ctx
.
GlobalString
(
EthRequiredBlocksFlag
.
Name
)
if
requiredBlocks
==
""
{
if
ctx
.
GlobalIsSet
(
LegacyWhitelistFlag
.
Name
)
{
log
.
Warn
(
"The flag --
rpc is deprecated and will be removed, please use --peer
.requiredblocks"
)
peerR
equiredBlocks
=
ctx
.
GlobalString
(
LegacyWhitelistFlag
.
Name
)
log
.
Warn
(
"The flag --
whitelist is deprecated and will be removed, please use --eth
.requiredblocks"
)
r
equiredBlocks
=
ctx
.
GlobalString
(
LegacyWhitelistFlag
.
Name
)
}
else
{
return
}
}
cfg
.
PeerRequiredBlocks
=
make
(
map
[
uint64
]
common
.
Hash
)
for
_
,
entry
:=
range
strings
.
Split
(
peerRequiredBlocks
,
","
)
{
cfg
.
RequiredBlocks
=
make
(
map
[
uint64
]
common
.
Hash
)
for
_
,
entry
:=
range
strings
.
Split
(
requiredBlocks
,
","
)
{
parts
:=
strings
.
Split
(
entry
,
"="
)
if
len
(
parts
)
!=
2
{
Fatalf
(
"Invalid
peer
required block entry: %s"
,
entry
)
Fatalf
(
"Invalid required block entry: %s"
,
entry
)
}
number
,
err
:=
strconv
.
ParseUint
(
parts
[
0
],
0
,
64
)
if
err
!=
nil
{
Fatalf
(
"Invalid
peer
required block number %s: %v"
,
parts
[
0
],
err
)
Fatalf
(
"Invalid required block number %s: %v"
,
parts
[
0
],
err
)
}
var
hash
common
.
Hash
if
err
=
hash
.
UnmarshalText
([]
byte
(
parts
[
1
]));
err
!=
nil
{
Fatalf
(
"Invalid
peer
required block hash %s: %v"
,
parts
[
1
],
err
)
Fatalf
(
"Invalid required block hash %s: %v"
,
parts
[
1
],
err
)
}
cfg
.
Peer
RequiredBlocks
[
number
]
=
hash
cfg
.
RequiredBlocks
[
number
]
=
hash
}
}
...
...
@@ -1594,7 +1592,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
setTxPool
(
ctx
,
&
cfg
.
TxPool
)
setEthash
(
ctx
,
cfg
)
setMiner
(
ctx
,
&
cfg
.
Miner
)
set
Peer
RequiredBlocks
(
ctx
,
cfg
)
setRequiredBlocks
(
ctx
,
cfg
)
setLes
(
ctx
,
cfg
)
// Cap the cache allowance and tune the garbage collector
...
...
eth/backend.go
View file @
992151fa
...
...
@@ -220,16 +220,16 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
checkpoint
=
params
.
TrustedCheckpoints
[
genesisHash
]
}
if
eth
.
handler
,
err
=
newHandler
(
&
handlerConfig
{
Database
:
chainDb
,
Chain
:
eth
.
blockchain
,
TxPool
:
eth
.
txPool
,
Merger
:
merger
,
Network
:
config
.
NetworkId
,
Sync
:
config
.
SyncMode
,
BloomCache
:
uint64
(
cacheLimit
),
EventMux
:
eth
.
eventMux
,
Checkpoint
:
checkpoint
,
PeerRequiredBlocks
:
config
.
Peer
RequiredBlocks
,
Database
:
chainDb
,
Chain
:
eth
.
blockchain
,
TxPool
:
eth
.
txPool
,
Merger
:
merger
,
Network
:
config
.
NetworkId
,
Sync
:
config
.
SyncMode
,
BloomCache
:
uint64
(
cacheLimit
),
EventMux
:
eth
.
eventMux
,
Checkpoint
:
checkpoint
,
RequiredBlocks
:
config
.
RequiredBlocks
,
});
err
!=
nil
{
return
nil
,
err
}
...
...
eth/ethconfig/config.go
View file @
992151fa
...
...
@@ -138,10 +138,10 @@ type Config struct {
TxLookupLimit
uint64
`toml:",omitempty"`
// The maximum number of blocks from head whose tx indices are reserved.
//
Peer
RequiredBlocks is a set of block number -> hash mappings which must be in the
// RequiredBlocks is a set of block number -> hash mappings which must be in the
// canonical chain of all remote peers. Setting the option makes geth verify the
// presence of these blocks for every new peer connection.
Peer
RequiredBlocks
map
[
uint64
]
common
.
Hash
`toml:"-"`
RequiredBlocks
map
[
uint64
]
common
.
Hash
`toml:"-"`
// Light client options
LightServ
int
`toml:",omitempty"`
// Maximum percentage of time allowed for serving LES requests
...
...
eth/ethconfig/gen_config.go
View file @
992151fa
...
...
@@ -26,7 +26,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
NoPruning
bool
NoPrefetch
bool
TxLookupLimit
uint64
`toml:",omitempty"`
PeerRequiredBlocks
map
[
uint64
]
common
.
Hash
`toml:"-"`
RequiredBlocks
map
[
uint64
]
common
.
Hash
`toml:"-"`
LightServ
int
`toml:",omitempty"`
LightIngress
int
`toml:",omitempty"`
LightEgress
int
`toml:",omitempty"`
...
...
@@ -71,7 +71,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc
.
NoPruning
=
c
.
NoPruning
enc
.
NoPrefetch
=
c
.
NoPrefetch
enc
.
TxLookupLimit
=
c
.
TxLookupLimit
enc
.
PeerRequiredBlocks
=
c
.
Peer
RequiredBlocks
enc
.
RequiredBlocks
=
c
.
RequiredBlocks
enc
.
LightServ
=
c
.
LightServ
enc
.
LightIngress
=
c
.
LightIngress
enc
.
LightEgress
=
c
.
LightEgress
...
...
@@ -120,7 +120,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
NoPruning
*
bool
NoPrefetch
*
bool
TxLookupLimit
*
uint64
`toml:",omitempty"`
PeerRequiredBlocks
map
[
uint64
]
common
.
Hash
`toml:"-"`
RequiredBlocks
map
[
uint64
]
common
.
Hash
`toml:"-"`
LightServ
*
int
`toml:",omitempty"`
LightIngress
*
int
`toml:",omitempty"`
LightEgress
*
int
`toml:",omitempty"`
...
...
@@ -184,8 +184,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if
dec
.
TxLookupLimit
!=
nil
{
c
.
TxLookupLimit
=
*
dec
.
TxLookupLimit
}
if
dec
.
Peer
RequiredBlocks
!=
nil
{
c
.
PeerRequiredBlocks
=
dec
.
Peer
RequiredBlocks
if
dec
.
RequiredBlocks
!=
nil
{
c
.
RequiredBlocks
=
dec
.
RequiredBlocks
}
if
dec
.
LightServ
!=
nil
{
c
.
LightServ
=
*
dec
.
LightServ
...
...
eth/handler.go
View file @
992151fa
...
...
@@ -77,17 +77,16 @@ type txPool interface {
// handlerConfig is the collection of initialization parameters to create a full
// node network handler.
type
handlerConfig
struct
{
Database
ethdb
.
Database
// Database for direct sync insertions
Chain
*
core
.
BlockChain
// Blockchain to serve data from
TxPool
txPool
// Transaction pool to propagate from
Merger
*
consensus
.
Merger
// The manager for eth1/2 transition
Network
uint64
// Network identifier to adfvertise
Sync
downloader
.
SyncMode
// Whether to snap or full sync
BloomCache
uint64
// Megabytes to alloc for snap sync bloom
EventMux
*
event
.
TypeMux
// Legacy event mux, deprecate for `feed`
Checkpoint
*
params
.
TrustedCheckpoint
// Hard coded checkpoint for sync challenges
PeerRequiredBlocks
map
[
uint64
]
common
.
Hash
// Hard coded map of required block hashes for sync challenges
Database
ethdb
.
Database
// Database for direct sync insertions
Chain
*
core
.
BlockChain
// Blockchain to serve data from
TxPool
txPool
// Transaction pool to propagate from
Merger
*
consensus
.
Merger
// The manager for eth1/2 transition
Network
uint64
// Network identifier to adfvertise
Sync
downloader
.
SyncMode
// Whether to snap or full sync
BloomCache
uint64
// Megabytes to alloc for snap sync bloom
EventMux
*
event
.
TypeMux
// Legacy event mux, deprecate for `feed`
Checkpoint
*
params
.
TrustedCheckpoint
// Hard coded checkpoint for sync challenges
RequiredBlocks
map
[
uint64
]
common
.
Hash
// Hard coded map of required block hashes for sync challenges
}
type
handler
struct
{
...
...
@@ -116,7 +115,7 @@ type handler struct {
txsSub
event
.
Subscription
minedBlockSub
*
event
.
TypeMuxSubscription
peerR
equiredBlocks
map
[
uint64
]
common
.
Hash
r
equiredBlocks
map
[
uint64
]
common
.
Hash
// channels for fetcher, syncer, txsyncLoop
quitSync
chan
struct
{}
...
...
@@ -133,16 +132,16 @@ func newHandler(config *handlerConfig) (*handler, error) {
config
.
EventMux
=
new
(
event
.
TypeMux
)
// Nicety initialization for tests
}
h
:=
&
handler
{
networkID
:
config
.
Network
,
forkFilter
:
forkid
.
NewFilter
(
config
.
Chain
),
eventMux
:
config
.
EventMux
,
database
:
config
.
Database
,
txpool
:
config
.
TxPool
,
chain
:
config
.
Chain
,
peers
:
newPeerSet
(),
merger
:
config
.
Merger
,
peerRequiredBlocks
:
config
.
Peer
RequiredBlocks
,
quitSync
:
make
(
chan
struct
{}),
networkID
:
config
.
Network
,
forkFilter
:
forkid
.
NewFilter
(
config
.
Chain
),
eventMux
:
config
.
EventMux
,
database
:
config
.
Database
,
txpool
:
config
.
TxPool
,
chain
:
config
.
Chain
,
peers
:
newPeerSet
(),
merger
:
config
.
Merger
,
requiredBlocks
:
config
.
RequiredBlocks
,
quitSync
:
make
(
chan
struct
{}),
}
if
config
.
Sync
==
downloader
.
FullSync
{
// The database seems empty as the current block is the genesis. Yet the snap
...
...
@@ -425,7 +424,7 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error {
}()
}
// If we have any explicit peer required block hashes, request them
for
number
:=
range
h
.
peerR
equiredBlocks
{
for
number
,
hash
:=
range
h
.
r
equiredBlocks
{
resCh
:=
make
(
chan
*
eth
.
Response
)
if
_
,
err
:=
peer
.
RequestHeadersByNumber
(
number
,
1
,
0
,
false
,
resCh
);
err
!=
nil
{
return
err
...
...
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