Skip to content

Commit a5d4c04

Browse files
committed
[FAB-3712] Optimize struct memory alignment
https://github.com/opennota/check can be used for checking struct alignment. Our code has some places in which we could use to have better struct alignment. This attends to all reported problems in gossip, and some in core. Change-Id: I7145e8b08a910c5cf20f1ae1b1e4366392e66031 Signed-off-by: Yacov Manevich <[email protected]>
1 parent 0fe5cb2 commit a5d4c04

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
lines changed

core/chaincode/chaincode_support.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,8 @@ type ChaincodeSupport struct {
217217
runningChaincodes *runningChaincodes
218218
peerAddress string
219219
ccStartupTimeout time.Duration
220-
userRunsCC bool
221220
peerNetworkID string
222221
peerID string
223-
peerTLS bool
224222
peerTLSCertFile string
225223
peerTLSKeyFile string
226224
peerTLSSvrHostOrd string
@@ -229,6 +227,8 @@ type ChaincodeSupport struct {
229227
shimLogLevel string
230228
logFormat string
231229
executetimeout time.Duration
230+
userRunsCC bool
231+
peerTLS bool
232232
}
233233

234234
// DuplicateChaincodeHandlerError returned if attempt to register same chaincodeID while a stream already exists.

core/comm/server.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ import (
3232
//A SecureServerConfig structure is used to configure security (e.g. TLS) for a
3333
//GRPCServer instance
3434
type SecureServerConfig struct {
35-
//Whether or not to use TLS for communication
36-
UseTLS bool
3735
//PEM-encoded X509 public key to be used by the server for TLS communication
3836
ServerCertificate []byte
3937
//PEM-encoded private key to be used by the server for TLS communication
4038
ServerKey []byte
4139
//Set of PEM-encoded X509 certificate authorities to optionally send
4240
//as part of the server handshake
4341
ServerRootCAs [][]byte
44-
//Whether or not TLS client must present certificates for authentication
45-
RequireClientCert bool
4642
//Set of PEM-encoded X509 certificate authorities to use when verifying
4743
//client certificates
4844
ClientRootCAs [][]byte
45+
//Whether or not to use TLS for communication
46+
UseTLS bool
47+
//Whether or not TLS client must present certificates for authentication
48+
RequireClientCert bool
4949
}
5050

5151
//GRPCServer defines an interface representing a GRPC-based server

core/ledger/kvledger/txmgmt/rwsetutil/query_results_helper.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ var (
6161
// The `Done` function does the final processing and returns the final output
6262
type RangeQueryResultsHelper struct {
6363
pendingResults []*kvrwset.KVRead
64-
hashingEnabled bool
65-
maxDegree uint32
6664
mt *merkleTree
65+
maxDegree uint32
66+
hashingEnabled bool
6767
}
6868

6969
// NewRangeQueryResultsHelper constructs a RangeQueryResultsHelper
7070
func NewRangeQueryResultsHelper(enableHashing bool, maxDegree uint32) (*RangeQueryResultsHelper, error) {
71-
helper := &RangeQueryResultsHelper{nil, enableHashing, maxDegree, nil}
71+
helper := &RangeQueryResultsHelper{pendingResults: nil,
72+
hashingEnabled: enableHashing,
73+
maxDegree: maxDegree,
74+
mt: nil}
7275
if enableHashing {
7376
var err error
7477
if helper.mt, err = newMerkleTree(maxDegree); err != nil {
@@ -147,16 +150,16 @@ func serializeKVReads(kvReads []*kvrwset.KVRead) ([]byte, error) {
147150
//////////// Merkle tree building code ///////
148151

149152
type merkleTree struct {
150-
maxDegree uint32
151153
tree map[MerkleTreeLevel][]Hash
152154
maxLevel MerkleTreeLevel
155+
maxDegree uint32
153156
}
154157

155158
func newMerkleTree(maxDegree uint32) (*merkleTree, error) {
156159
if maxDegree < 2 {
157160
return nil, fmt.Errorf("maxDegree [is %d] should not be less than 2 in the merkle tree", maxDegree)
158161
}
159-
return &merkleTree{maxDegree, make(map[MerkleTreeLevel][]Hash), 1}, nil
162+
return &merkleTree{make(map[MerkleTreeLevel][]Hash), 1, maxDegree}, nil
160163
}
161164

162165
// update takes a hash that forms the next leaf level (level-1) node in the merkle tree.

core/scc/sysccapi.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ var sysccLogger = flogging.MustGetLogger("sccapi")
3939
// when the fabric comes up. SystemChaincodes are installed by adding an
4040
// entry in importsysccs.go
4141
type SystemChaincode struct {
42-
// Enabled a convenient switch to enable/disable system chaincode without
43-
// having to remove entry from importsysccs.go
44-
Enabled bool
45-
4642
//Unique name of the system chaincode
4743
Name string
4844

@@ -65,6 +61,10 @@ type SystemChaincode struct {
6561
// by way of a chaincode-to-chaincode
6662
// invocation
6763
InvokableCC2CC bool
64+
65+
// Enabled a convenient switch to enable/disable system chaincode without
66+
// having to remove entry from importsysccs.go
67+
Enabled bool
6868
}
6969

7070
// RegisterSysCC registers the given system chaincode with the peer

gossip/comm/comm_impl.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ func NewCommInstance(s *grpc.Server, cert *tls.Certificate, idStore identity.Map
145145
}
146146

147147
type commImpl struct {
148-
skipHandshake bool
149148
selfCertHash []byte
150149
peerIdentity api.PeerIdentityType
151150
idMapper identity.Mapper
@@ -154,16 +153,17 @@ type commImpl struct {
154153
secureDialOpts func() []grpc.DialOption
155154
connStore *connectionStore
156155
PKIID []byte
157-
port int
158156
deadEndpoints chan common.PKIidType
159157
msgPublisher *ChannelDeMultiplexer
160158
lock *sync.RWMutex
161159
lsnr net.Listener
162160
gSrv *grpc.Server
163161
exitChan chan struct{}
164-
stopping int32
165162
stopWG sync.WaitGroup
166163
subscriptions []chan proto.ReceivedMessage
164+
port int
165+
stopping int32
166+
skipHandshake bool
167167
}
168168

169169
func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidType) (*connection, error) {

gossip/gossip/msgstore/msgs.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,18 @@ type MessageStore interface {
105105
}
106106

107107
type messageStoreImpl struct {
108-
pol common.MessageReplacingPolicy
109-
lock sync.RWMutex
110-
messages []*msg
111-
invTrigger invalidationTrigger
112-
113-
expirable bool
114-
msgTTL time.Duration
115-
expiredCount int
116-
108+
pol common.MessageReplacingPolicy
109+
lock sync.RWMutex
110+
messages []*msg
111+
invTrigger invalidationTrigger
112+
msgTTL time.Duration
113+
expiredCount int
117114
externalLock func()
118115
externalUnlock func()
119116
expireMsgCallback func(msg interface{})
120-
121-
doneCh chan struct{}
122-
stopOnce sync.Once
117+
doneCh chan struct{}
118+
stopOnce sync.Once
119+
expirable bool
123120
}
124121

125122
type msg struct {

gossip/gossip/pull/pullstore.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ type MembershipService interface {
5959
type Config struct {
6060
ID string
6161
PullInterval time.Duration // Duration between pull invocations
62-
PeerCountToSelect int // Number of peers to initiate pull with
63-
Tag proto.GossipMessage_Tag
6462
Channel common.ChainID
63+
PeerCountToSelect int // Number of peers to initiate pull with
64+
Tag proto.GossipMessage_Tag
6565
MsgType proto.PullMsgType
6666
}
6767

gossip/state/state.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ type GossipStateProviderImpl struct {
106106

107107
stateRequestCh chan proto.ReceivedMessage
108108

109-
stateTransferActive int32
110-
111109
stopCh chan struct{}
112110

113111
done sync.WaitGroup
114112

115113
once sync.Once
114+
115+
stateTransferActive int32
116116
}
117117

118118
var logger *logging.Logger // package-level logger

0 commit comments

Comments
 (0)