Commit bb3a9784 authored by mdj33's avatar mdj33 Committed by 33cn

add config to para self consensus fork

parent 28f8d396
......@@ -49,9 +49,9 @@ var (
//current miner tx take any privatekey for unify all nodes sign purpose, and para chain is free
minerPrivateKey = "6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
searchHashMatchDepth int32 = 100
mainBlockHashForkHeight int64 = types.MaxHeight //calc block hash fork height in main chain
mainParaCommitTxForkHeight int64 = types.MaxHeight //support paracross commit tx fork height in main chain
curMainChainHeight int64
mainBlockHashForkHeight int64 = 209186 //calc block hash fork height in main chain
mainParaSelfConsensusForkHeight int64 = types.MaxHeight //support paracross commit tx fork height in main chain
curMainChainHeight int64 //当前实时的主链高度
)
func init() {
......@@ -80,6 +80,8 @@ type subConfig struct {
WaitBlocks4CommitMsg int32 `json:"waitBlocks4CommitMsg,omitempty"`
SearchHashMatchedBlockDepth int32 `json:"searchHashMatchedBlockDepth,omitempty"`
GenesisAmount int64 `json:"genesisAmount,omitempty"`
MainBlockHashForkHeight int64 `json:"mainBlockHashForkHeight,omitempty"`
MainParaSelfConsensusForkHeight int64 `json:"mainParaSelfConsensusForkHeight,omitempty"`
}
// New function to init paracross env
......@@ -107,6 +109,13 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
if subcfg.SearchHashMatchedBlockDepth > 0 {
searchHashMatchDepth = subcfg.SearchHashMatchedBlockDepth
}
if subcfg.MainBlockHashForkHeight > 0 {
mainBlockHashForkHeight = subcfg.MainBlockHashForkHeight
}
if subcfg.MainParaSelfConsensusForkHeight > 0 {
mainParaSelfConsensusForkHeight = subcfg.MainParaSelfConsensusForkHeight
}
pk, err := hex.DecodeString(minerPrivateKey)
if err != nil {
......@@ -198,15 +207,6 @@ func (client *client) InitBlock() {
} else {
client.SetCurrentBlock(block)
}
// get main chain calc block hash fork height
mainBlockHashForkHeight, err = client.GetForkHeightOnMainChain("ForkBlockHash")
if err != nil {
panic(err)
}
mainParaCommitTxForkHeight, err = client.GetForkHeightOnMainChain(pt.ParaX + "-" + pt.ForkCommitTx)
if err != nil {
panic(err)
}
}
......
......@@ -350,7 +350,7 @@ func checkTxInMainBlock(targetTx *types.Transaction, detail *types.BlockDetail)
}
func isMainCommitHeightForked() bool {
return curMainChainHeight > mainParaCommitTxForkHeight+100
return curMainChainHeight > mainParaSelfConsensusForkHeight+100
}
//当前未考虑获取key非常多失败的场景, 如果获取height非常多,block模块会比较大,但是使用完了就释放了
......
......@@ -32,6 +32,8 @@ function para_set_toml() {
sed -i $xsedfix 's/^# TestNet=.*/TestNet=true/g' "${1}"
sed -i $xsedfix 's/^startHeight=.*/startHeight=0/g' "${1}"
sed -i $xsedfix 's/^emptyBlockInterval=.*/emptyBlockInterval=4/g' "${1}"
sed -i $xsedfix '/^emptyBlockInterval=.*/a MainBlockHashForkHeight=1' "${1}"
sed -i $xsedfix '/^emptyBlockInterval=.*/a MainParaSelfConsensusForkHeight=300' "${1}"
# rpc
sed -i $xsedfix 's/^jrpcBindAddr=.*/jrpcBindAddr="0.0.0.0:8901"/g' "${1}"
......
......@@ -318,10 +318,14 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
if err != nil {
return err
}
if payload.Ty == pt.ParacrossActionAssetTransfer || payload.Ty == pt.ParacrossActionAssetWithdraw ||
payload.Ty == pt.ParacrossActionCommit {
if payload.Ty == pt.ParacrossActionAssetTransfer || payload.Ty == pt.ParacrossActionAssetWithdraw {
return nil
}
if c.GetHeight() > types.GetDappFork(pt.ParaX, pt.ForkCommitTx) {
if payload.Ty == pt.ParacrossActionCommit {
return nil
}
}
}
return types.ErrNotAllow
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment