diff --git a/harness/engine/profiles.go b/harness/engine/profiles.go index fb5ee99c8..7aad87a09 100644 --- a/harness/engine/profiles.go +++ b/harness/engine/profiles.go @@ -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") diff --git a/pkg/config/groups.go b/pkg/config/groups.go index f2b8813a9..1af48d137 100644 --- a/pkg/config/groups.go +++ b/pkg/config/groups.go @@ -137,6 +137,8 @@ type mempoolConfiguration struct { // Enables mempool updates at startup Updates updates + + ExtractionDelaySecs uint32 } type updates struct { diff --git a/pkg/core/consensus/blockgenerator/candidate/blockgenerator.go b/pkg/core/consensus/blockgenerator/candidate/blockgenerator.go index 24b160272..629be1b99 100644 --- a/pkg/core/consensus/blockgenerator/candidate/blockgenerator.go +++ b/pkg/core/consensus/blockgenerator/candidate/blockgenerator.go @@ -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) @@ -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 { @@ -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 }