Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

put synchronous back when block has to be propose immediately #1615

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 44 additions & 30 deletions consensus/istanbul/qbft/core/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,55 @@ func (c *core) handleRequest(request *Request) error {

c.current.pendingRequest = request
if c.state == StateAcceptRequest {
c.newRoundMutex.Lock()
defer c.newRoundMutex.Unlock()

if c.newRoundTimer != nil {
c.newRoundTimer.Stop()
c.newRoundTimer = nil
}

delay := time.Duration(0)

block, ok := request.Proposal.(*types.Block)

if ok && len(block.Transactions()) == 0 { // if empty block
config := c.config.GetConfig(c.current.Sequence())

if config.EmptyBlockPeriod > config.BlockPeriod {
log.Info("EmptyBlockPeriod detected adding delay to request", "EmptyBlockPeriod", config.EmptyBlockPeriod, "BlockTime", block.Time())
// Because the seal has an additional delay on the block period you need to subtract it from the delay
delay = time.Duration(config.EmptyBlockPeriod-config.BlockPeriod) * time.Second
header := block.Header()
// Because the block period has already been added to the time we subtract it here
header.Time = header.Time + config.EmptyBlockPeriod - config.BlockPeriod
request.Proposal = block.WithSeal(header)
}
}

c.newRoundTimer = time.AfterFunc(delay, func() {
c.newRoundTimer = nil

config := c.config.GetConfig(c.current.Sequence())
if config.EmptyBlockPeriod == 0 { // emptyBlockPeriod is not set
// Start ROUND-CHANGE timer
c.newRoundChangeTimer()

// Send PRE-PREPARE message to other validators
c.sendPreprepareMsg(request)
})
} else { // emptyBlockPeriod is set
c.newRoundMutex.Lock()
defer c.newRoundMutex.Unlock()

if c.newRoundTimer != nil {
c.newRoundTimer.Stop()
c.newRoundTimer = nil
}

delay := time.Duration(0)

block, ok := request.Proposal.(*types.Block)
if ok && len(block.Transactions()) == 0 { // if empty block
config := c.config.GetConfig(c.current.Sequence())

if config.EmptyBlockPeriod > config.BlockPeriod {
log.Info("EmptyBlockPeriod detected adding delay to request", "EmptyBlockPeriod", config.EmptyBlockPeriod, "BlockTime", block.Time())
// Because the seal has an additional delay on the block period you need to subtract it from the delay
delay = time.Duration(config.EmptyBlockPeriod-config.BlockPeriod) * time.Second
header := block.Header()
// Because the block period has already been added to the time we subtract it here
header.Time = header.Time + config.EmptyBlockPeriod - config.BlockPeriod
request.Proposal = block.WithSeal(header)
}
}
if delay > 0 {
c.newRoundTimer = time.AfterFunc(delay, func() {
c.newRoundTimer = nil
// Start ROUND-CHANGE timer
c.newRoundChangeTimer()

// Send PRE-PREPARE message to other validators
c.sendPreprepareMsg(request)
})
} else {
// Start ROUND-CHANGE timer
c.newRoundChangeTimer()

// Send PRE-PREPARE message to other validators
c.sendPreprepareMsg(request)
}
}
}

return nil
Expand Down