@@ -241,7 +241,7 @@ func (m *Manager) AggregationLoop(ctx context.Context, lazy bool) {
241241 }
242242 start := time .Now ()
243243 err := m .publishBlock (ctx )
244- if err != nil {
244+ if err != nil && ctx . Err () == nil {
245245 m .logger .Error ("error while publishing block" , "error" , err )
246246 }
247247 timer .Reset (m .getRemainingSleep (start ))
@@ -262,7 +262,7 @@ func (m *Manager) AggregationLoop(ctx context.Context, lazy bool) {
262262 case <- timer .C :
263263 // build a block with all the transactions received in the last 1 second
264264 err := m .publishBlock (ctx )
265- if err != nil {
265+ if err != nil && ctx . Err () == nil {
266266 m .logger .Error ("error while publishing block" , "error" , err )
267267 }
268268 // this can be used to notify multiple subscribers when a block has been built
@@ -396,12 +396,6 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error {
396396 return fmt .Errorf ("failed to save block responses: %w" , err )
397397 }
398398
399- // SaveValidators commits the DB tx
400- err = m .saveValidatorsToStore (bHeight )
401- if err != nil {
402- return err
403- }
404-
405399 m .store .SetHeight (bHeight )
406400
407401 if daHeight > newState .DAHeight {
@@ -563,19 +557,12 @@ func (m *Manager) getCommit(header types.Header) (*types.Commit, error) {
563557
564558// IsProposer returns whether or not the manager is a proposer
565559func (m * Manager ) IsProposer () (bool , error ) {
566- m .lastStateMtx .RLock ()
567- defer m .lastStateMtx .RUnlock ()
568- // if proposer is not set, assume self proposer
569- if m .lastState .Validators .Proposer == nil {
570- return true , nil
571- }
572-
573560 signerPubBytes , err := m .proposerKey .GetPublic ().Raw ()
574561 if err != nil {
575562 return false , err
576563 }
577564
578- return bytes .Equal (m .lastState .Validators . Proposer .PubKey .Bytes (), signerPubBytes ), nil
565+ return bytes .Equal (m .genesis .Validators [ 0 ] .PubKey .Bytes (), signerPubBytes ), nil
579566}
580567
581568func (m * Manager ) publishBlock (ctx context.Context ) error {
@@ -629,7 +616,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
629616 if err != nil {
630617 return nil
631618 }
632- block . SignedHeader . Header . NextAggregatorsHash = m . getNextAggregatorsHash ()
619+
633620 commit , err = m .getCommit (block .SignedHeader .Header )
634621 if err != nil {
635622 return err
@@ -638,8 +625,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
638625 // set the commit to current block's signed header
639626 block .SignedHeader .Commit = * commit
640627
641- block .SignedHeader .Validators = m .getLastStateValidators ()
642-
643628 // SaveBlock commits the DB tx
644629 err = m .store .SaveBlock (block , commit )
645630 if err != nil {
@@ -659,8 +644,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
659644 return err
660645 }
661646
662- block .SignedHeader .Header .NextAggregatorsHash = newState .NextValidators .Hash ()
663-
664647 commit , err = m .getCommit (block .SignedHeader .Header )
665648 if err != nil {
666649 return err
@@ -669,8 +652,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
669652 // set the commit to current block's signed header
670653 block .SignedHeader .Commit = * commit
671654
672- block .SignedHeader .Validators = m .getLastStateValidators ()
673-
674655 // Validate the created block before storing
675656 if err := m .executor .Validate (m .lastState , block ); err != nil {
676657 return fmt .Errorf ("failed to validate block: %w" , err )
@@ -704,12 +685,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
704685 return err
705686 }
706687
707- // SaveValidators commits the DB tx
708- err = m .saveValidatorsToStore (blockHeight )
709- if err != nil {
710- return err
711- }
712-
713688 newState .DAHeight = atomic .LoadUint64 (& m .daHeight )
714689 // After this call m.lastState is the NEW state returned from ApplyBlock
715690 // updateState also commits the DB tx
@@ -778,24 +753,6 @@ func (m *Manager) updateState(s types.State) error {
778753 return nil
779754}
780755
781- func (m * Manager ) saveValidatorsToStore (height uint64 ) error {
782- m .lastStateMtx .RLock ()
783- defer m .lastStateMtx .RUnlock ()
784- return m .store .SaveValidators (height , m .lastState .Validators )
785- }
786-
787- func (m * Manager ) getLastStateValidators () * cmtypes.ValidatorSet {
788- m .lastStateMtx .RLock ()
789- defer m .lastStateMtx .RUnlock ()
790- return m .lastState .Validators
791- }
792-
793- func (m * Manager ) getNextAggregatorsHash () types.Hash {
794- m .lastStateMtx .RLock ()
795- defer m .lastStateMtx .RUnlock ()
796- return m .lastState .NextValidators .Hash ()
797- }
798-
799756func (m * Manager ) getLastBlockTime () time.Time {
800757 m .lastStateMtx .RLock ()
801758 defer m .lastStateMtx .RUnlock ()
@@ -813,6 +770,7 @@ func (m *Manager) applyBlock(ctx context.Context, block *types.Block) (types.Sta
813770 defer m .lastStateMtx .RUnlock ()
814771 return m .executor .ApplyBlock (ctx , m .lastState , block )
815772}
773+
816774func updateState (s * types.State , res * abci.ResponseInitChain ) {
817775 // If the app did not return an app hash, we keep the one set from the genesis doc in
818776 // the state. We don't set appHash since we don't want the genesis doc app hash
@@ -845,13 +803,4 @@ func updateState(s *types.State, res *abci.ResponseInitChain) {
845803 // We update the last results hash with the empty hash, to conform with RFC-6962.
846804 s .LastResultsHash = merkle .HashFromByteSlices (nil )
847805
848- if len (res .Validators ) > 0 {
849- vals , err := cmtypes .PB2TM .ValidatorUpdates (res .Validators )
850- if err != nil {
851- // TODO(tzdybal): handle error properly
852- panic (err )
853- }
854- s .Validators = cmtypes .NewValidatorSet (vals )
855- s .NextValidators = cmtypes .NewValidatorSet (vals ).CopyIncrementProposerPriority (1 )
856- }
857806}
0 commit comments