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
3768b007
Unverified
Commit
3768b007
authored
Apr 18, 2023
by
s7v7nislands
Committed by
GitHub
Apr 18, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
consensus/ethash: use atomic type (#27068)
parent
b1972627
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
14 deletions
+14
-14
algorithm.go
consensus/ethash/algorithm.go
+6
-6
ethash.go
consensus/ethash/ethash.go
+8
-8
No files found.
consensus/ethash/algorithm.go
View file @
3768b007
...
...
@@ -163,7 +163,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
rows
:=
int
(
size
)
/
hashBytes
// Start a monitoring goroutine to report progress on low end devices
var
progress
u
int32
var
progress
atomic
.
U
int32
done
:=
make
(
chan
struct
{})
defer
close
(
done
)
...
...
@@ -174,7 +174,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
case
<-
done
:
return
case
<-
time
.
After
(
3
*
time
.
Second
)
:
logger
.
Info
(
"Generating ethash verification cache"
,
"percentage"
,
atomic
.
LoadUint32
(
&
progress
)
*
100
/
uint32
(
rows
)
/
(
cacheRounds
+
1
),
"elapsed"
,
common
.
PrettyDuration
(
time
.
Since
(
start
)))
logger
.
Info
(
"Generating ethash verification cache"
,
"percentage"
,
progress
.
Load
(
)
*
100
/
uint32
(
rows
)
/
(
cacheRounds
+
1
),
"elapsed"
,
common
.
PrettyDuration
(
time
.
Since
(
start
)))
}
}
}()
...
...
@@ -185,7 +185,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
keccak512
(
cache
,
seed
)
for
offset
:=
uint64
(
hashBytes
);
offset
<
size
;
offset
+=
hashBytes
{
keccak512
(
cache
[
offset
:
],
cache
[
offset
-
hashBytes
:
offset
])
atomic
.
AddUint32
(
&
progress
,
1
)
progress
.
Add
(
1
)
}
// Use a low-round version of randmemohash
temp
:=
make
([]
byte
,
hashBytes
)
...
...
@@ -200,7 +200,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
bitutil
.
XORBytes
(
temp
,
cache
[
srcOff
:
srcOff
+
hashBytes
],
cache
[
xorOff
:
xorOff
+
hashBytes
])
keccak512
(
cache
[
dstOff
:
],
temp
)
atomic
.
AddUint32
(
&
progress
,
1
)
progress
.
Add
(
1
)
}
}
// Swap the byte order on big endian systems and return
...
...
@@ -299,7 +299,7 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) {
var
pend
sync
.
WaitGroup
pend
.
Add
(
threads
)
var
progress
u
int64
var
progress
atomic
.
U
int64
for
i
:=
0
;
i
<
threads
;
i
++
{
go
func
(
id
int
)
{
defer
pend
.
Done
()
...
...
@@ -323,7 +323,7 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) {
}
copy
(
dataset
[
index
*
hashBytes
:
],
item
)
if
status
:=
atomic
.
AddUint64
(
&
progress
,
1
);
status
%
percent
==
0
{
if
status
:=
progress
.
Add
(
1
);
status
%
percent
==
0
{
logger
.
Info
(
"Generating DAG in progress"
,
"percentage"
,
(
status
*
100
)
/
(
size
/
hashBytes
),
"elapsed"
,
common
.
PrettyDuration
(
time
.
Since
(
start
)))
}
}
...
...
consensus/ethash/ethash.go
View file @
3768b007
...
...
@@ -308,12 +308,12 @@ func (c *cache) finalizer() {
// dataset wraps an ethash dataset with some metadata to allow easier concurrent use.
type
dataset
struct
{
epoch
uint64
// Epoch for which this cache is relevant
dump
*
os
.
File
// File descriptor of the memory mapped cache
mmap
mmap
.
MMap
// Memory map itself to unmap before releasing
dataset
[]
uint32
// The actual cache data content
once
sync
.
Once
// Ensures the cache is generated only once
done
uint32
// Atomic flag to determine generation status
epoch
uint64
// Epoch for which this cache is relevant
dump
*
os
.
File
// File descriptor of the memory mapped cache
mmap
mmap
.
MMap
// Memory map itself to unmap before releasing
dataset
[]
uint32
// The actual cache data content
once
sync
.
Once
// Ensures the cache is generated only once
done
atomic
.
Bool
// Atomic flag to determine generation status
}
// newDataset creates a new ethash mining dataset and returns it as a plain Go
...
...
@@ -326,7 +326,7 @@ func newDataset(epoch uint64) *dataset {
func
(
d
*
dataset
)
generate
(
dir
string
,
limit
int
,
lock
bool
,
test
bool
)
{
d
.
once
.
Do
(
func
()
{
// Mark the dataset generated after we're done. This is needed for remote
defer
atomic
.
StoreUint32
(
&
d
.
done
,
1
)
defer
d
.
done
.
Store
(
true
)
csize
:=
cacheSize
(
d
.
epoch
*
epochLength
+
1
)
dsize
:=
datasetSize
(
d
.
epoch
*
epochLength
+
1
)
...
...
@@ -390,7 +390,7 @@ func (d *dataset) generate(dir string, limit int, lock bool, test bool) {
// or not (it may not have been started at all). This is useful for remote miners
// to default to verification caches instead of blocking on DAG generations.
func
(
d
*
dataset
)
generated
()
bool
{
return
atomic
.
LoadUint32
(
&
d
.
done
)
==
1
return
d
.
done
.
Load
()
}
// finalizer closes any file handlers and memory maps open.
...
...
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