func (i *Noops) notifyBlockAdded(block *pb.Block, delta *statemgmt.StateDelta) error { //make Payload nil to reduce block size.. //anything else to remove .. do we need StateDelta ? for _, tx := range block.Transactions { tx.Payload = nil } data, err := proto.Marshal(&pb.BlockState{Block: block, StateDelta: delta.Marshal()}) if err != nil { return fmt.Errorf("Fail to marshall BlockState structure: %v", err) } if logger.IsEnabledFor(logging.DEBUG) { logger.Debug("Broadcasting OpenchainMessage_SYNC_BLOCK_ADDED to non-validators") } // Broadcast SYNC_BLOCK_ADDED to connected NVPs // VPs already know about this newly added block since they participate // in the execution. That is, they can compare their current block with // the network block msg := &pb.OpenchainMessage{Type: pb.OpenchainMessage_SYNC_BLOCK_ADDED, Payload: data, Timestamp: util.CreateUtcTimestamp()} if errs := i.stack.Broadcast(msg, pb.PeerEndpoint_NON_VALIDATOR); nil != errs { return fmt.Errorf("Failed to broadcast with errors: %v", errs) } return nil }
// PrepareWorkingSet - method implementation for interface 'statemgmt.HashableState' func (stateImpl *StateImpl) PrepareWorkingSet(stateDelta *statemgmt.StateDelta) error { logger.Debug("Enter - PrepareWorkingSet()") if stateDelta.IsEmpty() { logger.Debug("Ignoring working-set as it is empty") return nil } stateImpl.dataNodesDelta = newDataNodesDelta(stateDelta) stateImpl.bucketTreeDelta = newBucketTreeDelta() stateImpl.recomputeCryptoHash = true return nil }
func newDataNodesDelta(stateDelta *statemgmt.StateDelta) *dataNodesDelta { dataNodesDelta := &dataNodesDelta{make(map[bucketKey]dataNodes)} chaincodeIDs := stateDelta.GetUpdatedChaincodeIds(false) for _, chaincodeID := range chaincodeIDs { updates := stateDelta.GetUpdates(chaincodeID) for key, updatedValue := range updates { if stateDelta.RollBackwards { dataNodesDelta.add(chaincodeID, key, updatedValue.GetPreviousValue()) } else { dataNodesDelta.add(chaincodeID, key, updatedValue.GetValue()) } } } for _, dataNodes := range dataNodesDelta.byBucket { sort.Sort(dataNodes) } return dataNodesDelta }
func newTrieDelta(stateDelta *statemgmt.StateDelta) *trieDelta { trieDelta := &trieDelta{0, make(map[int]levelDeltaMap)} chaincodes := stateDelta.GetUpdatedChaincodeIds(false) for _, chaincodeID := range chaincodes { updates := stateDelta.GetUpdates(chaincodeID) for key, updatedvalue := range updates { if updatedvalue.IsDelete() { trieDelta.delete(chaincodeID, key) } else { if stateDelta.RollBackwards { trieDelta.set(chaincodeID, key, updatedvalue.GetPreviousValue()) } else { trieDelta.set(chaincodeID, key, updatedvalue.GetValue()) } } } } return trieDelta }