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

add config to para self consensus fork

parent 28f8d396
...@@ -47,11 +47,11 @@ var ( ...@@ -47,11 +47,11 @@ var (
emptyBlockInterval int64 = 4 //write empty block every interval blocks in mainchain emptyBlockInterval int64 = 4 //write empty block every interval blocks in mainchain
zeroHash [32]byte zeroHash [32]byte
//current miner tx take any privatekey for unify all nodes sign purpose, and para chain is free //current miner tx take any privatekey for unify all nodes sign purpose, and para chain is free
minerPrivateKey = "6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b" minerPrivateKey = "6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
searchHashMatchDepth int32 = 100 searchHashMatchDepth int32 = 100
mainBlockHashForkHeight int64 = types.MaxHeight //calc block hash fork height in main chain mainBlockHashForkHeight int64 = 209186 //calc block hash fork height in main chain
mainParaCommitTxForkHeight int64 = types.MaxHeight //support paracross commit tx fork height in main chain mainParaSelfConsensusForkHeight int64 = types.MaxHeight //support paracross commit tx fork height in main chain
curMainChainHeight int64 curMainChainHeight int64 //当前实时的主链高度
) )
func init() { func init() {
...@@ -72,14 +72,16 @@ type client struct { ...@@ -72,14 +72,16 @@ type client struct {
} }
type subConfig struct { type subConfig struct {
WriteBlockSeconds int64 `json:"writeBlockSeconds,omitempty"` WriteBlockSeconds int64 `json:"writeBlockSeconds,omitempty"`
ParaRemoteGrpcClient string `json:"paraRemoteGrpcClient,omitempty"` ParaRemoteGrpcClient string `json:"paraRemoteGrpcClient,omitempty"`
StartHeight int64 `json:"startHeight,omitempty"` StartHeight int64 `json:"startHeight,omitempty"`
EmptyBlockInterval int64 `json:"emptyBlockInterval,omitempty"` EmptyBlockInterval int64 `json:"emptyBlockInterval,omitempty"`
AuthAccount string `json:"authAccount,omitempty"` AuthAccount string `json:"authAccount,omitempty"`
WaitBlocks4CommitMsg int32 `json:"waitBlocks4CommitMsg,omitempty"` WaitBlocks4CommitMsg int32 `json:"waitBlocks4CommitMsg,omitempty"`
SearchHashMatchedBlockDepth int32 `json:"searchHashMatchedBlockDepth,omitempty"` SearchHashMatchedBlockDepth int32 `json:"searchHashMatchedBlockDepth,omitempty"`
GenesisAmount int64 `json:"genesisAmount,omitempty"` GenesisAmount int64 `json:"genesisAmount,omitempty"`
MainBlockHashForkHeight int64 `json:"mainBlockHashForkHeight,omitempty"`
MainParaSelfConsensusForkHeight int64 `json:"mainParaSelfConsensusForkHeight,omitempty"`
} }
// New function to init paracross env // New function to init paracross env
...@@ -107,6 +109,13 @@ func New(cfg *types.Consensus, sub []byte) queue.Module { ...@@ -107,6 +109,13 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
if subcfg.SearchHashMatchedBlockDepth > 0 { if subcfg.SearchHashMatchedBlockDepth > 0 {
searchHashMatchDepth = subcfg.SearchHashMatchedBlockDepth searchHashMatchDepth = subcfg.SearchHashMatchedBlockDepth
} }
if subcfg.MainBlockHashForkHeight > 0 {
mainBlockHashForkHeight = subcfg.MainBlockHashForkHeight
}
if subcfg.MainParaSelfConsensusForkHeight > 0 {
mainParaSelfConsensusForkHeight = subcfg.MainParaSelfConsensusForkHeight
}
pk, err := hex.DecodeString(minerPrivateKey) pk, err := hex.DecodeString(minerPrivateKey)
if err != nil { if err != nil {
...@@ -198,15 +207,6 @@ func (client *client) InitBlock() { ...@@ -198,15 +207,6 @@ func (client *client) InitBlock() {
} else { } else {
client.SetCurrentBlock(block) 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) ...@@ -350,7 +350,7 @@ func checkTxInMainBlock(targetTx *types.Transaction, detail *types.BlockDetail)
} }
func isMainCommitHeightForked() bool { func isMainCommitHeightForked() bool {
return curMainChainHeight > mainParaCommitTxForkHeight+100 return curMainChainHeight > mainParaSelfConsensusForkHeight+100
} }
//当前未考虑获取key非常多失败的场景, 如果获取height非常多,block模块会比较大,但是使用完了就释放了 //当前未考虑获取key非常多失败的场景, 如果获取height非常多,block模块会比较大,但是使用完了就释放了
......
...@@ -32,6 +32,8 @@ function para_set_toml() { ...@@ -32,6 +32,8 @@ function para_set_toml() {
sed -i $xsedfix 's/^# TestNet=.*/TestNet=true/g' "${1}" sed -i $xsedfix 's/^# TestNet=.*/TestNet=true/g' "${1}"
sed -i $xsedfix 's/^startHeight=.*/startHeight=0/g' "${1}" sed -i $xsedfix 's/^startHeight=.*/startHeight=0/g' "${1}"
sed -i $xsedfix 's/^emptyBlockInterval=.*/emptyBlockInterval=4/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 # rpc
sed -i $xsedfix 's/^jrpcBindAddr=.*/jrpcBindAddr="0.0.0.0:8901"/g' "${1}" 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 { ...@@ -318,10 +318,14 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
if err != nil { if err != nil {
return err return err
} }
if payload.Ty == pt.ParacrossActionAssetTransfer || payload.Ty == pt.ParacrossActionAssetWithdraw || if payload.Ty == pt.ParacrossActionAssetTransfer || payload.Ty == pt.ParacrossActionAssetWithdraw {
payload.Ty == pt.ParacrossActionCommit {
return nil return nil
} }
if c.GetHeight() > types.GetDappFork(pt.ParaX, pt.ForkCommitTx) {
if payload.Ty == pt.ParacrossActionCommit {
return nil
}
}
} }
return types.ErrNotAllow 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