Skip to content

Commit

Permalink
increase chain speed (#21)
Browse files Browse the repository at this point in the history
increase chain speed to 0.2s
  • Loading branch information
R-Santev authored Aug 22, 2024
1 parent a4577a8 commit c08ed35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions consensus/polybft/block_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type BlockBuilder struct {
func (b *BlockBuilder) Reset() error {
// set the timestamp
parentTime := time.Unix(int64(b.params.Parent.Timestamp), 0)
headerTime := parentTime.Add(b.params.BlockTime)
headerTime := parentTime.Add(time.Millisecond * 200)

if headerTime.Before(time.Now().UTC()) {
headerTime = time.Now().UTC()
Expand Down Expand Up @@ -157,13 +157,14 @@ func (b *BlockBuilder) WriteTx(tx *types.Transaction) error {

// Fill fills the block with transactions from the txpool
func (b *BlockBuilder) Fill() {
blockTimer := time.NewTimer(b.params.BlockTime)
minBlockTimer := time.NewTimer(time.Millisecond * 200)
maxBlockTimer := time.NewTimer(b.params.BlockTime)

b.params.TxPool.Prepare()
write:
for {
select {
case <-blockTimer.C:
case <-maxBlockTimer.C:
return
default:
tx := b.params.TxPool.Peek()
Expand All @@ -181,7 +182,7 @@ write:
}

// wait for the timer to expire
<-blockTimer.C
<-minBlockTimer.C
}

// Receipts returns the collection of transaction receipts for given block
Expand Down
2 changes: 1 addition & 1 deletion consensus/polybft/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ func validateHeaderFields(parent *types.Header, header *types.Header, blockTimeD
return fmt.Errorf("invalid gas limit: have %v, max %v", header.GasUsed, header.GasLimit)
}
// verify time has passed
if header.Timestamp <= parent.Timestamp {
if header.Timestamp < parent.Timestamp {
return fmt.Errorf("timestamp older than parent")
}
// verify mix digest
Expand Down

0 comments on commit c08ed35

Please sign in to comment.