@@ -46,41 +46,55 @@ func (c *core) handleRequest(request *Request) error {
4646
4747 c .current .pendingRequest = request
4848 if c .state == StateAcceptRequest {
49- c .newRoundMutex .Lock ()
50- defer c .newRoundMutex .Unlock ()
51-
52- if c .newRoundTimer != nil {
53- c .newRoundTimer .Stop ()
54- c .newRoundTimer = nil
55- }
56-
57- delay := time .Duration (0 )
58-
59- block , ok := request .Proposal .(* types.Block )
60-
61- if ok && len (block .Transactions ()) == 0 { // if empty block
62- config := c .config .GetConfig (c .current .Sequence ())
63-
64- if config .EmptyBlockPeriod > config .BlockPeriod {
65- log .Info ("EmptyBlockPeriod detected adding delay to request" , "EmptyBlockPeriod" , config .EmptyBlockPeriod , "BlockTime" , block .Time ())
66- // Because the seal has an additional delay on the block period you need to subtract it from the delay
67- delay = time .Duration (config .EmptyBlockPeriod - config .BlockPeriod ) * time .Second
68- header := block .Header ()
69- // Because the block period has already been added to the time we subtract it here
70- header .Time = header .Time + config .EmptyBlockPeriod - config .BlockPeriod
71- request .Proposal = block .WithSeal (header )
72- }
73- }
74-
75- c .newRoundTimer = time .AfterFunc (delay , func () {
76- c .newRoundTimer = nil
77-
49+ config := c .config .GetConfig (c .current .Sequence ())
50+ if config .EmptyBlockPeriod == 0 { // emptyBlockPeriod is not set
7851 // Start ROUND-CHANGE timer
7952 c .newRoundChangeTimer ()
8053
8154 // Send PRE-PREPARE message to other validators
8255 c .sendPreprepareMsg (request )
83- })
56+ } else { // emptyBlockPeriod is set
57+ c .newRoundMutex .Lock ()
58+ defer c .newRoundMutex .Unlock ()
59+
60+ if c .newRoundTimer != nil {
61+ c .newRoundTimer .Stop ()
62+ c .newRoundTimer = nil
63+ }
64+
65+ delay := time .Duration (0 )
66+
67+ block , ok := request .Proposal .(* types.Block )
68+ if ok && len (block .Transactions ()) == 0 { // if empty block
69+ config := c .config .GetConfig (c .current .Sequence ())
70+
71+ if config .EmptyBlockPeriod > config .BlockPeriod {
72+ log .Info ("EmptyBlockPeriod detected adding delay to request" , "EmptyBlockPeriod" , config .EmptyBlockPeriod , "BlockTime" , block .Time ())
73+ // Because the seal has an additional delay on the block period you need to subtract it from the delay
74+ delay = time .Duration (config .EmptyBlockPeriod - config .BlockPeriod ) * time .Second
75+ header := block .Header ()
76+ // Because the block period has already been added to the time we subtract it here
77+ header .Time = header .Time + config .EmptyBlockPeriod - config .BlockPeriod
78+ request .Proposal = block .WithSeal (header )
79+ }
80+ }
81+ if delay > 0 {
82+ c .newRoundTimer = time .AfterFunc (delay , func () {
83+ c .newRoundTimer = nil
84+ // Start ROUND-CHANGE timer
85+ c .newRoundChangeTimer ()
86+
87+ // Send PRE-PREPARE message to other validators
88+ c .sendPreprepareMsg (request )
89+ })
90+ } else {
91+ // Start ROUND-CHANGE timer
92+ c .newRoundChangeTimer ()
93+
94+ // Send PRE-PREPARE message to other validators
95+ c .sendPreprepareMsg (request )
96+ }
97+ }
8498 }
8599
86100 return nil
0 commit comments