Skip to content

Commit

Permalink
[FAB-3712] Optimize struct memory alignment
Browse files Browse the repository at this point in the history
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 <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed May 9, 2017
1 parent 0fe5cb2 commit a5d4c04
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions core/chaincode/chaincode_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,8 @@ type ChaincodeSupport struct {
runningChaincodes *runningChaincodes
peerAddress string
ccStartupTimeout time.Duration
userRunsCC bool
peerNetworkID string
peerID string
peerTLS bool
peerTLSCertFile string
peerTLSKeyFile string
peerTLSSvrHostOrd string
Expand All @@ -229,6 +227,8 @@ type ChaincodeSupport struct {
shimLogLevel string
logFormat string
executetimeout time.Duration
userRunsCC bool
peerTLS bool
}

// DuplicateChaincodeHandlerError returned if attempt to register same chaincodeID while a stream already exists.
Expand Down
8 changes: 4 additions & 4 deletions core/comm/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ import (
//A SecureServerConfig structure is used to configure security (e.g. TLS) for a
//GRPCServer instance
type SecureServerConfig struct {
//Whether or not to use TLS for communication
UseTLS bool
//PEM-encoded X509 public key to be used by the server for TLS communication
ServerCertificate []byte
//PEM-encoded private key to be used by the server for TLS communication
ServerKey []byte
//Set of PEM-encoded X509 certificate authorities to optionally send
//as part of the server handshake
ServerRootCAs [][]byte
//Whether or not TLS client must present certificates for authentication
RequireClientCert bool
//Set of PEM-encoded X509 certificate authorities to use when verifying
//client certificates
ClientRootCAs [][]byte
//Whether or not to use TLS for communication
UseTLS bool
//Whether or not TLS client must present certificates for authentication
RequireClientCert bool
}

//GRPCServer defines an interface representing a GRPC-based server
Expand Down
13 changes: 8 additions & 5 deletions core/ledger/kvledger/txmgmt/rwsetutil/query_results_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ var (
// The `Done` function does the final processing and returns the final output
type RangeQueryResultsHelper struct {
pendingResults []*kvrwset.KVRead
hashingEnabled bool
maxDegree uint32
mt *merkleTree
maxDegree uint32
hashingEnabled bool
}

// NewRangeQueryResultsHelper constructs a RangeQueryResultsHelper
func NewRangeQueryResultsHelper(enableHashing bool, maxDegree uint32) (*RangeQueryResultsHelper, error) {
helper := &RangeQueryResultsHelper{nil, enableHashing, maxDegree, nil}
helper := &RangeQueryResultsHelper{pendingResults: nil,
hashingEnabled: enableHashing,
maxDegree: maxDegree,
mt: nil}
if enableHashing {
var err error
if helper.mt, err = newMerkleTree(maxDegree); err != nil {
Expand Down Expand Up @@ -147,16 +150,16 @@ func serializeKVReads(kvReads []*kvrwset.KVRead) ([]byte, error) {
//////////// Merkle tree building code ///////

type merkleTree struct {
maxDegree uint32
tree map[MerkleTreeLevel][]Hash
maxLevel MerkleTreeLevel
maxDegree uint32
}

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

// update takes a hash that forms the next leaf level (level-1) node in the merkle tree.
Expand Down
8 changes: 4 additions & 4 deletions core/scc/sysccapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ var sysccLogger = flogging.MustGetLogger("sccapi")
// when the fabric comes up. SystemChaincodes are installed by adding an
// entry in importsysccs.go
type SystemChaincode struct {
// Enabled a convenient switch to enable/disable system chaincode without
// having to remove entry from importsysccs.go
Enabled bool

//Unique name of the system chaincode
Name string

Expand All @@ -65,6 +61,10 @@ type SystemChaincode struct {
// by way of a chaincode-to-chaincode
// invocation
InvokableCC2CC bool

// Enabled a convenient switch to enable/disable system chaincode without
// having to remove entry from importsysccs.go
Enabled bool
}

// RegisterSysCC registers the given system chaincode with the peer
Expand Down
6 changes: 3 additions & 3 deletions gossip/comm/comm_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func NewCommInstance(s *grpc.Server, cert *tls.Certificate, idStore identity.Map
}

type commImpl struct {
skipHandshake bool
selfCertHash []byte
peerIdentity api.PeerIdentityType
idMapper identity.Mapper
Expand All @@ -154,16 +153,17 @@ type commImpl struct {
secureDialOpts func() []grpc.DialOption
connStore *connectionStore
PKIID []byte
port int
deadEndpoints chan common.PKIidType
msgPublisher *ChannelDeMultiplexer
lock *sync.RWMutex
lsnr net.Listener
gSrv *grpc.Server
exitChan chan struct{}
stopping int32
stopWG sync.WaitGroup
subscriptions []chan proto.ReceivedMessage
port int
stopping int32
skipHandshake bool
}

func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidType) (*connection, error) {
Expand Down
21 changes: 9 additions & 12 deletions gossip/gossip/msgstore/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,18 @@ type MessageStore interface {
}

type messageStoreImpl struct {
pol common.MessageReplacingPolicy
lock sync.RWMutex
messages []*msg
invTrigger invalidationTrigger

expirable bool
msgTTL time.Duration
expiredCount int

pol common.MessageReplacingPolicy
lock sync.RWMutex
messages []*msg
invTrigger invalidationTrigger
msgTTL time.Duration
expiredCount int
externalLock func()
externalUnlock func()
expireMsgCallback func(msg interface{})

doneCh chan struct{}
stopOnce sync.Once
doneCh chan struct{}
stopOnce sync.Once
expirable bool
}

type msg struct {
Expand Down
4 changes: 2 additions & 2 deletions gossip/gossip/pull/pullstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ type MembershipService interface {
type Config struct {
ID string
PullInterval time.Duration // Duration between pull invocations
PeerCountToSelect int // Number of peers to initiate pull with
Tag proto.GossipMessage_Tag
Channel common.ChainID
PeerCountToSelect int // Number of peers to initiate pull with
Tag proto.GossipMessage_Tag
MsgType proto.PullMsgType
}

Expand Down
4 changes: 2 additions & 2 deletions gossip/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ type GossipStateProviderImpl struct {

stateRequestCh chan proto.ReceivedMessage

stateTransferActive int32

stopCh chan struct{}

done sync.WaitGroup

once sync.Once

stateTransferActive int32
}

var logger *logging.Logger // package-level logger
Expand Down

0 comments on commit a5d4c04

Please sign in to comment.