Skip to content

Commit

Permalink
supprot disable empty block for tdpos and single consensus
Browse files Browse the repository at this point in the history
  • Loading branch information
godeamon committed Dec 19, 2023
1 parent d295a7a commit 66ffb74
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bcs/ledger/xledger/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,3 +1504,7 @@ func (t *State) GetContractDesc(contractName string) (*protos.WasmCodeDesc, erro
}
return valDesc, err
}

func (t *State) HasUnconfirmTx() bool {
return t.tx.Mempool.GetTxCounnt() != 0
}
2 changes: 2 additions & 0 deletions example/xchain/conf/engine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ blockBroadcastMode: 0
txidCacheExpiredTime: 3m
# txIdCacheGCInterval set clean up interval for tx cache
txIdCacheGCInterval: 10m
# disableEmptyBlocks is the flag for disable empty block, supprot consensus: tdpos/single, not support chainedBFT
disableEmptyBlocks: false
1 change: 1 addition & 0 deletions kernel/engines/xuperos/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type EngineConf struct {
SyncBlockFilterMode int `yaml:"syncBlockFilterMode,omitempty"`
// SyncFactorForFactorBucketMode only use for SyncWithFactorBucket mode of SyncBlockFilterMode configuration item
SyncFactorForFactorBucketMode float64 `yaml:"SyncFactorForFactorBucketMode,omitempty"`
DisableEmptyBlocks bool `yaml:"disableEmptyBlocks,omitempty"`
}

func LoadEngineConf(cfgFile string) (*EngineConf, error) {
Expand Down
12 changes: 12 additions & 0 deletions kernel/engines/xuperos/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ func (m *Miner) step() error {
}
m.status = statusMining

if m.ctx.EngCtx.EngCfg.DisableEmptyBlocks && !m.ctx.State.HasUnconfirmTx() {
consensusStatus, err := m.ctx.Consensus.GetConsensusStatus()
if err != nil {
return err
}

if consensusStatus.GetConsensusName() == "single" ||
consensusStatus.GetConsensusName() == "tdpos" {
return nil
}
}

// 开始挖矿
err = m.mining(ctx)
if err != nil {
Expand Down

0 comments on commit 66ffb74

Please sign in to comment.