aboutsummaryrefslogblamecommitdiff
path: root/include/hotstuff/consensus.h
blob: e0f2ecc343c71a466102a7e0434cbc424e6b7acb (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
















                                                                           


                             
                  











                               
                





                                                                                        


                                                                          







                                                                         
                                       
                                 

                                                             
                       
 
                                                         
                                                    


                                                                   
                                          
                                           
                                                    


                                                                         



                                  
                                                      


                             





                                                                               
                                   
 

                                                                             














                                                                               


                                                                            
                                                          
                                                        
                                                         








                                                                               
                                               
                                                      




















                                                                                                  
                                                     












                                                                              
                                    

                                                                  

                                                      

                                
                                               
                                                  
                                                        
                                           
                                                                               
                                  
                                                         




                                         

                               



                                                                            
                                             
                                
                               

                               



                                                  




                                              
                      

                                 
                                                                        





                                                      
                                                         
                            





                                     

                            
                                         




                                                          
                                          
                         



                                  




                                          
                                 
                                                         




                                                  
                                        



                                              

                                       




                                                                   
                                                 

     


                                                                                                  
                                                              


           



                                                   
                                                  
                            


     













































                                                               


      
/**
 * Copyright 2018 VMware
 * Copyright 2018 Ted Yin
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _HOTSTUFF_CONSENSUS_H
#define _HOTSTUFF_CONSENSUS_H

#include <cassert>
#include <set>
#include <unordered_map>

#include "hotstuff/promise.hpp"
#include "hotstuff/type.h"
#include "hotstuff/entity.h"
#include "hotstuff/crypto.h"

namespace hotstuff {

struct Proposal;
struct Vote;
struct Finality;

/** Abstraction for HotStuff protocol state machine (without network implementation). */
class HotStuffCore {
    block_t b0;                                  /** the genesis block */
    /* === state variables === */
    /** block containing the QC for the highest block having one */
    std::pair<block_t, quorum_cert_bt> hqc;   /**< highest QC */
    block_t b_lock;                            /**< locked block */
    block_t b_exec;                            /**< last executed block */
    uint32_t vheight;          /**< height of the block last voted for */
    /* === auxilliary variables === */
    privkey_bt priv_key;            /**< private key for signing votes */
    std::set<block_t, BlockHeightCmp> tails;   /**< set of tail blocks */
    ReplicaConfig config;                   /**< replica configuration */
    /* === async event queues === */
    std::unordered_map<block_t, promise_t> qc_waiting;
    promise_t propose_waiting;
    promise_t receive_proposal_waiting;
    promise_t hqc_update_waiting;
    /* == feature switches == */
    /** always vote negatively, useful for some PaceMakers */
    bool vote_disabled;

    block_t get_delivered_blk(const