aboutsummaryrefslogblamecommitdiff
path: root/src/consensus.cpp
blob: d19d790aa19261c4c8a7b66b108312aa7ae1931a (plain) (tree)
1
2
3
4
5
6
7
8
9








                                    
                                    


                    
                                                      

                                        
                                                   





                                      
                        
               









                                                               
                                                                    













                                                        
                                                        















                                                                         
                                                       





                                                      
                                                                 

                                
                            









                                                             


                                                        



                                                                          
                                                          



                                                                   
     
              


                                                      
                                               


                                                   
     
                   

                        


                
                                                                 
                                                                
                                                  



                                                  

                                
                                            





                                                       
                              
                                    

                                            
                          
                   






                                                      
                                                        
                   

                                                                            
                           


                                                           
                      





                                                              
                                                   









                                     




                                               
     


                                                           
                               



                             
                                     

                                                               
                   



                                                      

                                                           
                                                   
                                     
                                        

                       
                                                     



                                              
                                                       




                                     






                                                              




























                                                                          


























                                                                       


                                                          
       

 
                                                       


                                                                   

 






                                                      

                                        
                    

 





                                                               





                                           



                                                    

                                                                     

                                                         
                        


 
#include <cassert>
#include <stack>

#include "hotstuff/util.h"
#include "hotstuff/consensus.h"

#define LOG_INFO HOTSTUFF_LOG_INFO
#define LOG_DEBUG HOTSTUFF_LOG_DEBUG
#define LOG_WARN HOTSTUFF_LOG_WARN
#define LOG_PROTO HOTSTUFF_LOG_PROTO

namespace hotstuff {

/* The core logic of HotStuff, is fairly simple :). */
/*** begin HotStuff protocol logic ***/
HotStuffCore::HotStuffCore(ReplicaID id,
                            privkey_bt &&priv_key):
        b0(new Block(true, 1)),
        bqc(b0),
        bexec(b0),
        vheight(0),
        priv_key(std::move(priv_key)),
        tails{bqc},
        neg_vote(false),
        id(id),
        storage(new EntityStorage()) {
    storage->add_blk(b0);
    b0->qc_ref = b0;
}

void HotStuffCore::sanity_check_delivered(const block_t &blk) {
    if (!blk->delivered)
        throw std::runtime_error("block not delivered");
}

block_t HotStuffCore::get_delivered_blk(const uint256_t &blk_hash) {
    block_t blk = storage->find_blk(blk_hash);
    if (blk == nullptr || !blk->delivered)
        throw std::runtime_error("block not delivered");
    return std::move(blk);
}

bool HotStuffCore::on_deliver_blk(const block_t &blk) {