Exemple #1
0
func (bucketNode *bucketNode) String() string {
	numChildren := 0
	for i := range bucketNode.childrenCryptoHash {
		if util.NotNil(bucketNode.childrenCryptoHash[i]) {
			numChildren++
		}
	}
	str := fmt.Sprintf("bucketKey={%s}\n NumChildren={%d}\n", bucketNode.bucketKey, numChildren)
	if numChildren == 0 {
		return str
	}

	str = str + "Childern crypto-hashes:\n"
	for i := range bucketNode.childrenCryptoHash {
		childCryptoHash := bucketNode.childrenCryptoHash[i]
		if util.NotNil(childCryptoHash) {
			str = str + fmt.Sprintf("childNumber={%d}, cryptoHash={%x}\n", i, childCryptoHash)
		}
	}
	return str
}
// Next - see interface 'statemgmt.StateSnapshotIterator' for details
func (snapshotItr *StateSnapshotIterator) Next() bool {
	var available bool
	for ; snapshotItr.dbItr.Valid(); snapshotItr.dbItr.Next() {

		// making a copy of key-value bytes because, underlying key bytes are reused by itr.
		// no need to free slices as iterator frees memory when closed.
		trieKeyBytes := statemgmt.Copy(snapshotItr.dbItr.Key().Data())
		trieNodeBytes := statemgmt.Copy(snapshotItr.dbItr.Value().Data())
		value := unmarshalTrieNodeValue(trieNodeBytes)
		if util.NotNil(value) {
			snapshotItr.currentKey = trieKeyEncoderImpl.decodeTrieKeyBytes(statemgmt.Copy(trieKeyBytes))
			snapshotItr.currentValue = value
			available = true
			snapshotItr.dbItr.Next()
			break
		}
	}
	return available
}
Exemple #3
0
func (bucketNode *bucketNode) computeCryptoHash() []byte {
	cryptoHashContent := []byte{}
	numChildren := 0
	for i, childCryptoHash := range bucketNode.childrenCryptoHash {
		if util.NotNil(childCryptoHash) {
			numChildren++
			logger.Debug("Appending crypto-hash for child bucket = [%s]", bucketNode.bucketKey.getChildKey(i))
			cryptoHashContent = append(cryptoHashContent, childCryptoHash...)
		}
	}
	if numChildren == 0 {
		logger.Debug("Returning <nil> crypto-hash of bucket = [%s] - because, it has not children", bucketNode.bucketKey)
		bucketNode.markedForDeletion = true
		return nil
	}
	if numChildren == 1 {
		logger.Debug("Propagating crypto-hash of single child node for bucket = [%s]", bucketNode.bucketKey)
		return cryptoHashContent
	}
	logger.Debug("Computing crypto-hash for bucket [%s] by merging [%d] children", bucketNode.bucketKey, numChildren)
	return openchainUtil.ComputeCryptoHash(cryptoHashContent)
}
Exemple #4
0
func (trieNode *trieNode) containsValue() bool {
	if trieNode.isRootNode() {
		return false
	}
	return ledgerUtil.NotNil(trieNode.value)
}