Skip to content

Commit 952bdeb

Browse files
committed
multi: enable struct alignment check, fix for often used
For structs we use often, such as the query options, we want to have proper alignment to save some memory space. Other structs that we only instantiate once or a few times we don't align in favor of better readability of the code.
1 parent 4ddceb5 commit 952bdeb

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

.golangci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ linters-settings:
99
gofmt:
1010
# simplify code: gofmt with `-s` option, true by default
1111
simplify: true
12+
maligned:
13+
suggest-new: true
1214

1315
linters:
1416
enable-all: true
@@ -20,9 +22,6 @@ linters:
2022
# even longer by marking them as 'nolint'.
2123
- lll
2224

23-
# We don't care (enough) about misaligned structs to lint that.
24-
- maligned
25-
2625
# We have long functions, especially in tests. Moving or renaming those would
2726
# trigger funlen problems that we may not want to solve at that time.
2827
- funlen

blockmanager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ type blockManagerCfg struct {
117117

118118
// blockManager provides a concurrency safe block manager for handling all
119119
// incoming blocks.
120-
type blockManager struct {
121-
started int32
122-
shutdown int32
120+
type blockManager struct { // nolint:maligned
121+
started int32 // To be used atomically.
122+
shutdown int32 // To be used atomically.
123123

124124
cfg *blockManagerCfg
125125

blockntfns/manager.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ var (
1919
// newSubscription is an internal message used within the SubscriptionManager to
2020
// denote a new client's intent to receive block notifications.
2121
type newSubscription struct {
22-
canceled sync.Once
22+
id uint64 // To be used atomically.
2323

24-
id uint64
24+
bestHeight uint32
25+
26+
canceled sync.Once
2527

2628
ntfnChan chan BlockNtfn
2729
ntfnQueue *queue.ConcurrentQueue
2830

29-
bestHeight uint32
30-
errChan chan error
31+
errChan chan error
3132

3233
quit chan struct{}
3334
wg sync.WaitGroup

neutrino.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ type peerSubscription struct {
559559
}
560560

561561
// ChainService is instantiated with functional options.
562-
type ChainService struct {
562+
type ChainService struct { // nolint:maligned
563563
// The following variables must only be used atomically.
564564
// Putting the uint64s first makes them 64-bit aligned for 32-bit systems.
565565
bytesReceived uint64 // Total bytes received from all peers since start.

query.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,37 @@ var (
5757
//
5858
// TODO: Make more query options that override global options.
5959
type queryOptions struct {
60+
// maxBatchSize is the maximum items that the query should return in the
61+
// case the optimisticBatch option is used. It saves bandwidth in the case
62+
// the caller has a limited amount of items to fetch but still wants to use
63+
// batching.
64+
maxBatchSize int64
65+
6066
// timeout lets the query know how long to wait for a peer to answer
6167
// the query before moving onto the next peer.
6268
timeout time.Duration
6369

64-
// numRetries tells the query how many times to retry asking each peer
65-
// the query.
66-
numRetries uint8
67-
6870
// peerConnectTimeout lets the query know how long to wait for the
6971
// underlying chain service to connect to a peer before giving up
7072
// on a query in case we don't have any peers.
7173
peerConnectTimeout time.Duration
7274

75+
// doneChan lets the query signal the caller when it's done, in case
76+
// it's run in a goroutine.
77+
doneChan chan<- struct{}
78+
7379
// encoding lets the query know which encoding to use when queueing
7480
// messages to a peer.
7581
encoding wire.MessageEncoding
7682

77-
// doneChan lets the query signal the caller when it's done, in case
78-
// it's run in a goroutine.
79-
doneChan chan<- struct{}
83+
// numRetries tells the query how many times to retry asking each peer
84+
// the query.
85+
numRetries uint8
8086

8187
// optimisticBatch indicates whether we expect more calls to follow,
8288
// and that we should attempt to batch more items with the query such
8389
// that they can be cached, avoiding the extra round trip.
8490
optimisticBatch optimisticBatchType
85-
86-
// maxBatchSize is the maximum items that the query should return in the
87-
// case the optimisticBatch option is used. It saves bandwidth in the case
88-
// the caller has a limited amount of items to fetch but still wants to use
89-
// batching.
90-
maxBatchSize int64
9191
}
9292

9393
// optimisticBatchType is a type indicating the kind of batching we want to

rescan.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,8 @@ txOutLoop:
12601260
// client with updateable filters. It's meant to be close to a drop-in
12611261
// replacement for the btcd rescan and notification functionality used in
12621262
// wallets. It only contains information about whether a goroutine is running.
1263-
type Rescan struct {
1264-
started uint32
1263+
type Rescan struct { // nolint:maligned
1264+
started uint32 // To be used atomically.
12651265

12661266
running chan struct{}
12671267
updateChan chan *updateOptions
@@ -1374,7 +1374,6 @@ func DisableDisconnectedNtfns(disabled bool) UpdateOption {
13741374

13751375
// Update sends an update to a long-running rescan/notification goroutine.
13761376
func (r *Rescan) Update(options ...UpdateOption) error {
1377-
13781377
ro := defaultRescanOptions()
13791378
for _, option := range r.options {
13801379
option(ro)

0 commit comments

Comments
 (0)