github.com/koko1123/flow-go-1@v0.29.6/consensus/recovery/follower.go (about)

     1  package recovery
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/rs/zerolog"
     7  
     8  	"github.com/koko1123/flow-go-1/consensus/hotstuff"
     9  	"github.com/koko1123/flow-go-1/consensus/hotstuff/forks"
    10  	"github.com/koko1123/flow-go-1/consensus/hotstuff/model"
    11  	"github.com/koko1123/flow-go-1/model/flow"
    12  )
    13  
    14  // Follower recovers the HotStuff state for a follower instance.
    15  // It reads the pending blocks from storage and pass them to the input Finalizer
    16  // instance to recover its state from before the restart.
    17  func Follower(
    18  	log zerolog.Logger,
    19  	finalizer forks.Finalizer,
    20  	validator hotstuff.Validator,
    21  	finalized *flow.Header,
    22  	pending []*flow.Header,
    23  ) error {
    24  	return Recover(log, finalized, pending, validator, func(proposal *model.Proposal) error {
    25  		// add it to finalizer
    26  		err := finalizer.AddBlock(proposal.Block)
    27  		if err != nil {
    28  			return fmt.Errorf("could not add block to finalizer: %w", err)
    29  		}
    30  		log.Debug().
    31  			Uint64("block_view", proposal.Block.View).
    32  			Hex("block_id", proposal.Block.BlockID[:]).
    33  			Msg("block recovered")
    34  		return nil
    35  	})
    36  }