Skip to content

Commit

Permalink
Reintroduce artificial delay on block generator
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Jul 28, 2022
1 parent 398f63f commit 62f406a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions harness/engine/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func Profile1(index int, node *DuskNode, consensusKeysPath string) {
// viper.Set("mempool.preallocTxs", "100")
viper.Set("mempool.poolType", "diskpool")
viper.Set("mempool.diskpoolDir", node.Dir+"/mempool.db")
viper.Set("mempool.extractionDelaySecs", "3")

viper.Set("mempool.maxInvItems", "10000")
viper.Set("mempool.propagateTimeout", "100ms")
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ type mempoolConfiguration struct {

// Enables mempool updates at startup
Updates updates

ExtractionDelaySecs uint32
}

type updates struct {
Expand Down
16 changes: 10 additions & 6 deletions pkg/core/consensus/blockgenerator/candidate/blockgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,14 @@ func (bg *generator) execute(ctx context.Context, txs []transactions.ContractCal
}

// fetchOrTimeout will keep trying to FetchMempoolTxs() until either
// we get some txs or or the timeout expires.
func (bg *generator) FetchOrTimeout(keys [][]byte) ([]transactions.ContractCall, error) {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
// we get some txs or the timeout expires.
func (bg *generator) fetchOrTimeout(keys [][]byte) ([]transactions.ContractCall, error) {
delay := config.Get().Mempool.ExtractionDelaySecs
if delay == 0 {
return bg.FetchMempoolTxs(keys)
}

ctx, cancel := context.WithTimeout(context.Background(), time.Duration(delay)*time.Second)
defer cancel()

tick := time.NewTicker(500 * time.Millisecond)
Expand All @@ -139,8 +144,7 @@ func (bg *generator) FetchOrTimeout(keys [][]byte) ([]transactions.ContractCall,
for {
select {
case <-ctx.Done():
txs, err := bg.FetchMempoolTxs(keys)
return txs, err
return bg.FetchMempoolTxs(keys)
case <-tick.C:
txs, err := bg.FetchMempoolTxs(keys)
if err != nil {
Expand All @@ -157,7 +161,7 @@ func (bg *generator) FetchOrTimeout(keys [][]byte) ([]transactions.ContractCall,
// GenerateBlock generates a candidate block, by constructing the header and filling it
// with transactions from the mempool.
func (bg *generator) GenerateBlock(round uint64, seed, prevBlockHash []byte, prevBlockTimestamp int64, keys [][]byte) (*block.Block, error) {
txs, err := bg.FetchMempoolTxs(keys)
txs, err := bg.fetchOrTimeout(keys)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 62f406a

Please sign in to comment.