aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2019-05-17 07:13:50 +0800
committerGitHub <noreply@github.com>2019-05-17 07:13:50 +0800
commit2f855bfa2893ad0e0fbb0072d317340385091868 (patch)
tree16e0efe677f6b984c8eb7ee7d39f036951e1a9c8
parent8cce620311cdd17f388e8d258a02eb8ccb35adb5 (diff)
parentf35975ea21d4018ea5dccfdce3c420de5b5f5140 (diff)
downloadgo-tangerine-2f855bfa2893ad0e0fbb0072d317340385091868.tar
go-tangerine-2f855bfa2893ad0e0fbb0072d317340385091868.tar.gz
go-tangerine-2f855bfa2893ad0e0fbb0072d317340385091868.tar.bz2
go-tangerine-2f855bfa2893ad0e0fbb0072d317340385091868.tar.lz
go-tangerine-2f855bfa2893ad0e0fbb0072d317340385091868.tar.xz
go-tangerine-2f855bfa2893ad0e0fbb0072d317340385091868.tar.zst
go-tangerine-2f855bfa2893ad0e0fbb0072d317340385091868.zip
Merge pull request #19591 from karalabe/64bit-align
core/rawdb, eth/downloader: align 64bit atomic fields
-rw-r--r--core/rawdb/freezer.go6
-rw-r--r--core/rawdb/freezer_table.go6
-rw-r--r--eth/downloader/downloader.go10
3 files changed, 17 insertions, 5 deletions
diff --git a/core/rawdb/freezer.go b/core/rawdb/freezer.go
index 67ed87d66..33da53787 100644
--- a/core/rawdb/freezer.go
+++ b/core/rawdb/freezer.go
@@ -66,8 +66,12 @@ const (
// reserving it for go-ethereum. This would also reduce the memory requirements
// of Geth, and thus also GC overhead.
type freezer struct {
+ // WARNING: The `frozen` field is accessed atomically. On 32 bit platforms, only
+ // 64-bit aligned fields can be atomic. The struct is guaranteed to be so aligned,
+ // so take advantage of that (https://golang.org/pkg/sync/atomic/#pkg-note-BUG).
+ frozen uint64 // Number of blocks already frozen
+
tables map[string]*freezerTable // Data tables for storing everything
- frozen uint64 // Number of blocks already frozen
instanceLock fileutil.Releaser // File-system lock to prevent double opens
}
diff --git a/core/rawdb/freezer_table.go b/core/rawdb/freezer_table.go
index 673a181e4..d1ece414b 100644
--- a/core/rawdb/freezer_table.go
+++ b/core/rawdb/freezer_table.go
@@ -73,6 +73,11 @@ func (i *indexEntry) marshallBinary() []byte {
// It consists of a data file (snappy encoded arbitrary data blobs) and an indexEntry
// file (uncompressed 64 bit indices into the data file).
type freezerTable struct {
+ // WARNING: The `items` field is accessed atomically. On 32 bit platforms, only
+ // 64-bit aligned fields can be atomic. The struct is guaranteed to be so aligned,
+ // so take advantage of that (https://golang.org/pkg/sync/atomic/#pkg-note-BUG).
+ items uint64 // Number of items stored in the table (including items removed from tail)
+
noCompression bool // if true, disables snappy compression. Note: does not work retroactively
maxFileSize uint32 // Max file size for data-files
name string
@@ -86,7 +91,6 @@ type freezerTable struct {
// In the case that old items are deleted (from the tail), we use itemOffset
// to count how many historic items have gone missing.
- items uint64 // Number of items stored in the table (including items removed from tail)
itemOffset uint32 // Offset (number of discarded items)
headBytes uint32 // Number of bytes written to the head file
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 495fa0e74..321c4473b 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -98,6 +98,13 @@ var (
)
type Downloader struct {
+ // WARNING: The `rttEstimate` and `rttConfidence` fields are accessed atomically.
+ // On 32 bit platforms, only 64-bit aligned fields can be atomic. The struct is
+ // guaranteed to be so aligned, so take advantage of that. For more information,
+ // see https://golang.org/pkg/sync/atomic/#pkg-note-BUG.
+ rttEstimate uint64 // Round trip time to target for download requests
+ rttConfidence uint64 // Confidence in the estimated RTT (unit: millionths to allow atomic ops)
+
mode SyncMode // Synchronisation mode defining the strategy used (per sync cycle)
mux *event.TypeMux // Event multiplexer to announce sync operation events
@@ -109,9 +116,6 @@ type Downloader struct {
stateDB ethdb.Database // Database to state sync into (and deduplicate via)
stateBloom *trie.SyncBloom // Bloom filter for fast trie node existence checks
- rttEstimate uint64 // Round trip time to target for download requests
- rttConfidence uint64 // Confidence in the estimated RTT (unit: millionths to allow atomic ops)
-
// Statistics
syncStatsChainOrigin uint64 // Origin block number where syncing started at
syncStatsChainHeight uint64 // Highest block number known when syncing started