feat(batch_proposer): add batchTxNumThreshold (#178)

This commit is contained in:
HAOYUatHZ
2022-12-26 10:17:16 +08:00
committed by GitHub
parent 22f6781c26
commit 8ad8a1b6f0
6 changed files with 15 additions and 8 deletions

View File

@@ -50,6 +50,7 @@
"batch_proposer_config": {
"proof_generation_freq": 1,
"batch_gas_threshold": 3000000,
"batch_tx_num_threshold": 135,
"batch_time_sec": 300,
"batch_blocks_limit": 100,
"skipped_opcodes": [

View File

@@ -24,6 +24,8 @@ type L2Config struct {
type BatchProposerConfig struct {
// Proof generation frequency, generating proof every k blocks
ProofGenerationFreq uint64 `json:"proof_generation_freq"`
// Txnum threshold in a batch
BatchTxNumThreshold uint64 `json:"batch_tx_num_threshold"`
// Gas threshold in a batch
BatchGasThreshold uint64 `json:"batch_gas_threshold"`
// Time waited to generate a batch even if gas_threshold not met

View File

@@ -18,9 +18,10 @@ type batchProposer struct {
orm database.OrmFactory
batchTimeSec uint64
batchGasThreshold uint64
batchBlocksLimit uint64
batchTimeSec uint64
batchGasThreshold uint64
batchTxNumThreshold uint64
batchBlocksLimit uint64
proofGenerationFreq uint64
skippedOpcodes map[string]struct{}
@@ -32,6 +33,7 @@ func newBatchProposer(cfg *config.BatchProposerConfig, orm database.OrmFactory)
orm: orm,
batchTimeSec: cfg.BatchTimeSec,
batchGasThreshold: cfg.BatchGasThreshold,
batchTxNumThreshold: cfg.BatchTxNumThreshold,
batchBlocksLimit: cfg.BatchBlocksLimit,
proofGenerationFreq: cfg.ProofGenerationFreq,
skippedOpcodes: cfg.SkippedOpcodes,
@@ -59,16 +61,17 @@ func (w *batchProposer) tryProposeBatch() error {
}
var (
length = len(blocks)
gasUsed uint64
length = len(blocks)
gasUsed, txNum uint64
)
// add blocks into batch until reach batchGasThreshold
for i, block := range blocks {
if gasUsed+block.GasUsed > w.batchGasThreshold {
if (gasUsed+block.GasUsed > w.batchGasThreshold) || (txNum+block.TxNum > w.batchTxNumThreshold) {
blocks = blocks[:i]
break
}
gasUsed += block.GasUsed
txNum += block.TxNum
}
// if too few gas gathered, but we don't want to halt, we then check the first block in the batch:

View File

@@ -46,6 +46,7 @@ func testBatchProposer(t *testing.T) {
proposer := newBatchProposer(&config.BatchProposerConfig{
ProofGenerationFreq: 1,
BatchGasThreshold: 3000000,
BatchTxNumThreshold: 135,
BatchTimeSec: 1,
BatchBlocksLimit: 100,
}, db)

View File

@@ -157,7 +157,7 @@ func (w *WatcherClient) tryFetchRunningMissingBlocks(ctx context.Context, backTr
if err2 != nil {
return fmt.Errorf("failed to GetBlockResultByHash: %v. number: %v", err2, number)
}
log.Info("retrieved block trace", "height", trace.Header.Number, "hash", trace.Header.Hash)
log.Info("retrieved block trace", "height", trace.Header.Number, "hash", trace.Header.Hash().String())
traces = append(traces, trace)

View File

@@ -5,7 +5,7 @@ import (
"runtime/debug"
)
var tag = "prealpha-v8.3"
var tag = "prealpha-v8.4"
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {