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
60ec41ce
Unverified
Commit
60ec41ce
authored
Aug 23, 2023
by
Marius van der Wijden
Committed by
GitHub
Aug 23, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
miner: refactor getSealingBlock method (#27993)
parent
feb8f416
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
14 deletions
+42
-14
payload_building.go
miner/payload_building.go
+22
-2
worker.go
miner/worker.go
+2
-10
worker_test.go
miner/worker_test.go
+18
-2
No files found.
miner/payload_building.go
View file @
60ec41ce
...
...
@@ -175,10 +175,20 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
// Build the initial version with no transaction included. It should be fast
// enough to run. The empty payload can at least make sure there is something
// to deliver for not missing slot.
empty
:=
w
.
getSealingBlock
(
args
.
Parent
,
args
.
Timestamp
,
args
.
FeeRecipient
,
args
.
Random
,
args
.
Withdrawals
,
true
)
emptyParams
:=
&
generateParams
{
timestamp
:
args
.
Timestamp
,
forceTime
:
true
,
parentHash
:
args
.
Parent
,
coinbase
:
args
.
FeeRecipient
,
random
:
args
.
Random
,
withdrawals
:
args
.
Withdrawals
,
noTxs
:
true
,
}
empty
:=
w
.
getSealingBlock
(
emptyParams
)
if
empty
.
err
!=
nil
{
return
nil
,
empty
.
err
}
// Construct a payload object for return.
payload
:=
newPayload
(
empty
.
block
,
args
.
Id
())
...
...
@@ -195,11 +205,21 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
// by the timestamp parameter.
endTimer
:=
time
.
NewTimer
(
time
.
Second
*
12
)
fullParams
:=
&
generateParams
{
timestamp
:
args
.
Timestamp
,
forceTime
:
true
,
parentHash
:
args
.
Parent
,
coinbase
:
args
.
FeeRecipient
,
random
:
args
.
Random
,
withdrawals
:
args
.
Withdrawals
,
noTxs
:
false
,
}
for
{
select
{
case
<-
timer
.
C
:
start
:=
time
.
Now
()
r
:=
w
.
getSealingBlock
(
args
.
Parent
,
args
.
Timestamp
,
args
.
FeeRecipient
,
args
.
Random
,
args
.
Withdrawals
,
false
)
r
:=
w
.
getSealingBlock
(
fullParams
)
if
r
.
err
==
nil
{
payload
.
update
(
r
,
time
.
Since
(
start
))
}
...
...
miner/worker.go
View file @
60ec41ce
...
...
@@ -1106,17 +1106,9 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti
// getSealingBlock generates the sealing block based on the given parameters.
// The generation result will be passed back via the given channel no matter
// the generation itself succeeds or not.
func
(
w
*
worker
)
getSealingBlock
(
par
ent
common
.
Hash
,
timestamp
uint64
,
coinbase
common
.
Address
,
random
common
.
Hash
,
withdrawals
types
.
Withdrawals
,
noTxs
bool
)
*
newPayloadResult
{
func
(
w
*
worker
)
getSealingBlock
(
par
ams
*
generateParams
)
*
newPayloadResult
{
req
:=
&
getWorkReq
{
params
:
&
generateParams
{
timestamp
:
timestamp
,
forceTime
:
true
,
parentHash
:
parent
,
coinbase
:
coinbase
,
random
:
random
,
withdrawals
:
withdrawals
,
noTxs
:
noTxs
,
},
params
:
params
,
result
:
make
(
chan
*
newPayloadResult
,
1
),
}
select
{
...
...
miner/worker_test.go
View file @
60ec41ce
...
...
@@ -452,7 +452,15 @@ func testGetSealingWork(t *testing.T, chainConfig *params.ChainConfig, engine co
// This API should work even when the automatic sealing is not enabled
for
_
,
c
:=
range
cases
{
r
:=
w
.
getSealingBlock
(
c
.
parent
,
timestamp
,
c
.
coinbase
,
c
.
random
,
nil
,
false
)
r
:=
w
.
getSealingBlock
(
&
generateParams
{
parentHash
:
c
.
parent
,
timestamp
:
timestamp
,
coinbase
:
c
.
coinbase
,
random
:
c
.
random
,
withdrawals
:
nil
,
noTxs
:
false
,
forceTime
:
true
,
})
if
c
.
expectErr
{
if
r
.
err
==
nil
{
t
.
Error
(
"Expect error but get nil"
)
...
...
@@ -468,7 +476,15 @@ func testGetSealingWork(t *testing.T, chainConfig *params.ChainConfig, engine co
// This API should work even when the automatic sealing is enabled
w
.
start
()
for
_
,
c
:=
range
cases
{
r
:=
w
.
getSealingBlock
(
c
.
parent
,
timestamp
,
c
.
coinbase
,
c
.
random
,
nil
,
false
)
r
:=
w
.
getSealingBlock
(
&
generateParams
{
parentHash
:
c
.
parent
,
timestamp
:
timestamp
,
coinbase
:
c
.
coinbase
,
random
:
c
.
random
,
withdrawals
:
nil
,
noTxs
:
false
,
forceTime
:
true
,
})
if
c
.
expectErr
{
if
r
.
err
==
nil
{
t
.
Error
(
"Expect error but get nil"
)
...
...
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