Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supprot disable empty block for tdpos and single consensus #458

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading