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

add create empty blocks config for single consensus #432

Closed
Closed
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
}
3 changes: 3 additions & 0 deletions example/xchain/conf/engine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ blockBroadcastMode: 0
txidCacheExpiredTime: 3m
# txIdCacheGCInterval set clean up interval for tx cache
txIdCacheGCInterval: 10m

# 只有在 single 共识下生效,true:不创建空区块
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
13 changes: 12 additions & 1 deletion kernel/engines/xuperos/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (

statusFollowing = 0
statusMining = 1
ConsensusSingle = "single"
ConsensusTDPoS = "tdpos"
)

const (
Expand Down Expand Up @@ -206,7 +208,16 @@ func (m *Miner) step() error {
trace("syncUpValidators")
}
m.status = statusMining

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对于挖矿条件的判断,实现在m.mining(ctx)中可读性会不会更好一些?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m.mining(ctx) 已经开始挖矿了,所以我放到外面了。

Copy link
Collaborator

@zhugelianglongming zhugelianglongming Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主要是有个疑问:

  • mining() 实现的第一部分为"共识挖矿前处理"的定义是什么?
  • 打包区块前的判断逻辑,根据什么判断要放在mining()的函数头部 还是 函数调用前?

Copy link
Collaborator

@zhugelianglongming zhugelianglongming Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

空块判断不太算 ProcessBeforeMiner 的内容

节点若为矿工,首先通过Consensus模块ProcessBeforeMiner接口更新自己共识内存状态,准备开始生产区块。
5. 共识算法 — XuperChain 官方文档 文档

Copy link
Collaborator

@zhugelianglongming zhugelianglongming Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我有一点建议是:

  • 上层调用的时候,在确认是挖矿状态后,就只负责调用挖矿函数。
  • 至于挖矿的前置处理、特殊判断(比如空块判断)等,可以在挖矿过程中,分阶段处理。

更具体的,在这个 case,我可能会建议实现在m.packBlock
相当于打包过程中,对区块大小的上限和下限分别进行判断处理。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

共识这些接口开源文档里都有

}
// 目前不出空块配置只在 single 共识下生效
if consensusStatus.GetConsensusName() == ConsensusTDPoS {
return nil
}
}
// 开始挖矿
err = m.mining(ctx)
if err != nil {
Expand Down
Loading