@@ -242,7 +242,7 @@ func (m *Manager) AggregationLoop(ctx context.Context, lazy bool) {
242242 }
243243 start := time .Now ()
244244 err := m .publishBlock (ctx )
245- if err != nil {
245+ if err != nil && ctx . Err () == nil {
246246 m .logger .Error ("error while publishing block" , "error" , err )
247247 }
248248 timer .Reset (m .getRemainingSleep (start ))
@@ -263,7 +263,7 @@ func (m *Manager) AggregationLoop(ctx context.Context, lazy bool) {
263263 case <- timer .C :
264264 // build a block with all the transactions received in the last 1 second
265265 err := m .publishBlock (ctx )
266- if err != nil {
266+ if err != nil && ctx . Err () == nil {
267267 m .logger .Error ("error while publishing block" , "error" , err )
268268 }
269269 // this can be used to notify multiple subscribers when a block has been built
@@ -397,12 +397,6 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error {
397397 return fmt .Errorf ("failed to save block responses: %w" , err )
398398 }
399399
400- // SaveValidators commits the DB tx
401- err = m .saveValidatorsToStore (bHeight )
402- if err != nil {
403- return err
404- }
405-
406400 m .store .SetHeight (bHeight )
407401
408402 if daHeight > newState .DAHeight {
@@ -564,19 +558,12 @@ func (m *Manager) getCommit(header types.Header) (*types.Commit, error) {
564558
565559// IsProposer returns whether or not the manager is a proposer
566560func (m * Manager ) IsProposer () (bool , error ) {
567- m .lastStateMtx .RLock ()
568- defer m .lastStateMtx .RUnlock ()
569- // if proposer is not set, assume self proposer
570- if m .lastState .Validators .Proposer == nil {
571- return true , nil
572- }
573-
574561 signerPubBytes , err := m .proposerKey .GetPublic ().Raw ()
575562 if err != nil {
576563 return false , err
577564 }
578565
579- return bytes .Equal (m .lastState .Validators . Proposer .PubKey .Bytes (), signerPubBytes ), nil
566+ return bytes .Equal (m .genesis .Validators [ 0 ] .PubKey .Bytes (), signerPubBytes ), nil
580567}
581568
582569func (m * Manager ) publishBlock (ctx context.Context ) error {
@@ -627,7 +614,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
627614 if err != nil {
628615 return nil
629616 }
630- block . SignedHeader . Header . NextAggregatorsHash = m . getNextAggregatorsHash ()
617+
631618 commit , err = m .getCommit (block .SignedHeader .Header )
632619 if err != nil {
633620 return err
@@ -636,8 +623,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
636623 // set the commit to current block's signed header
637624 block .SignedHeader .Commit = * commit
638625
639- block .SignedHeader .Validators = m .getLastStateValidators ()
640-
641626 // SaveBlock commits the DB tx
642627 err = m .store .SaveBlock (block , commit )
643628 if err != nil {
@@ -657,8 +642,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
657642 return err
658643 }
659644
660- block .SignedHeader .Header .NextAggregatorsHash = newState .NextValidators .Hash ()
661-
662645 commit , err = m .getCommit (block .SignedHeader .Header )
663646 if err != nil {
664647 return err
@@ -667,8 +650,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
667650 // set the commit to current block's signed header
668651 block .SignedHeader .Commit = * commit
669652
670- block .SignedHeader .Validators = m .getLastStateValidators ()
671-
672653 // Validate the created block before storing
673654 if err := m .executor .Validate (m .lastState , block ); err != nil {
674655 return fmt .Errorf ("failed to validate block: %w" , err )
@@ -702,12 +683,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
702683 return err
703684 }
704685
705- // SaveValidators commits the DB tx
706- err = m .saveValidatorsToStore (blockHeight )
707- if err != nil {
708- return err
709- }
710-
711686 newState .DAHeight = atomic .LoadUint64 (& m .daHeight )
712687 // After this call m.lastState is the NEW state returned from ApplyBlock
713688 // updateState also commits the DB tx
@@ -776,24 +751,6 @@ func (m *Manager) updateState(s types.State) error {
776751 return nil
777752}
778753
779- func (m * Manager ) saveValidatorsToStore (height uint64 ) error {
780- m .lastStateMtx .RLock ()
781- defer m .lastStateMtx .RUnlock ()
782- return m .store .SaveValidators (height , m .lastState .Validators )
783- }
784-
785- func (m * Manager ) getLastStateValidators () * cmtypes.ValidatorSet {
786- m .lastStateMtx .RLock ()
787- defer m .lastStateMtx .RUnlock ()
788- return m .lastState .Validators
789- }
790-
791- func (m * Manager ) getNextAggregatorsHash () types.Hash {
792- m .lastStateMtx .RLock ()
793- defer m .lastStateMtx .RUnlock ()
794- return m .lastState .NextValidators .Hash ()
795- }
796-
797754func (m * Manager ) getLastBlockTime () time.Time {
798755 m .lastStateMtx .RLock ()
799756 defer m .lastStateMtx .RUnlock ()
@@ -811,6 +768,7 @@ func (m *Manager) applyBlock(ctx context.Context, block *types.Block) (types.Sta
811768 defer m .lastStateMtx .RUnlock ()
812769 return m .executor .ApplyBlock (ctx , m .lastState , block )
813770}
771+
814772func updateState (s * types.State , res * abci.ResponseInitChain ) {
815773 // If the app did not return an app hash, we keep the one set from the genesis doc in
816774 // the state. We don't set appHash since we don't want the genesis doc app hash
@@ -843,13 +801,4 @@ func updateState(s *types.State, res *abci.ResponseInitChain) {
843801 // We update the last results hash with the empty hash, to conform with RFC-6962.
844802 s .LastResultsHash = merkle .HashFromByteSlices (nil )
845803
846- if len (res .Validators ) > 0 {
847- vals , err := cmtypes .PB2TM .ValidatorUpdates (res .Validators )
848- if err != nil {
849- // TODO(tzdybal): handle error properly
850- panic (err )
851- }
852- s .Validators = cmtypes .NewValidatorSet (vals )
853- s .NextValidators = cmtypes .NewValidatorSet (vals ).CopyIncrementProposerPriority (1 )
854- }
855804}
0 commit comments