github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/orderer/sbft/simplebft/commit.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package simplebft
    18  
    19  import "reflect"
    20  
    21  func (s *SBFT) maybeSendCommit() {
    22  	if s.cur.prepared || len(s.cur.prep) < s.commonCaseQuorum()-1 {
    23  		return
    24  	}
    25  	s.sendCommit()
    26  	s.processBacklog()
    27  }
    28  
    29  func (s *SBFT) sendCommit() {
    30  	s.cur.prepared = true
    31  	c := s.cur.subject
    32  	s.sys.Persist(s.chainId, prepared, &c)
    33  	s.broadcast(&Msg{&Msg_Commit{&c}})
    34  }
    35  
    36  func (s *SBFT) handleCommit(c *Subject, src uint64) {
    37  	if c.Seq.Seq < s.cur.subject.Seq.Seq {
    38  		// old message
    39  		return
    40  	}
    41  
    42  	if !reflect.DeepEqual(c, &s.cur.subject) {
    43  		log.Warningf("replica %d: commit does not match expected subject %v %x, got %v %x",
    44  			s.id, s.cur.subject.Seq, s.cur.subject.Digest, c.Seq, c.Digest)
    45  		return
    46  	}
    47  	if _, ok := s.cur.commit[src]; ok {
    48  		log.Infof("replica %d: duplicate commit for %v from %d", s.id, *c.Seq, src)
    49  		return
    50  	}
    51  	s.cur.commit[src] = c
    52  	s.cancelViewChangeTimer()
    53  
    54  	//maybe mark as comitted
    55  	if s.cur.committed || len(s.cur.commit) < s.commonCaseQuorum() {
    56  		return
    57  	}
    58  	s.cur.committed = true
    59  	log.Noticef("replica %d: executing %v %x", s.id, s.cur.subject.Seq, s.cur.subject.Digest)
    60  
    61  	s.sys.Persist(s.chainId, committed, &s.cur.subject)
    62  
    63  	s.sendCheckpoint()
    64  	s.processBacklog()
    65  }