Commit e9bd0511 authored by mdj33's avatar mdj33 Committed by vipwzw

multi-version

parent 36fdfd31
......@@ -101,8 +101,7 @@ ParaRemoteGrpcClient="localhost:8802"
startHeight=345850
#打包时间间隔,单位秒
writeBlockSeconds=2
#主链每隔几个没有相关交易的区块,平行链上打包空区块
emptyBlockInterval=50
#验证账户,验证节点需要配置自己的账户,并且钱包导入对应种子,非验证节点留空
authAccount=""
#云端主链节点切换后,平行链适配新主链节点block,回溯查找和自己记录的相同blockhash的深度
......@@ -117,6 +116,12 @@ MainParaSelfConsensusForkHeight=-1
MainLoopCheckCommitTxDoneForkHeight=-1
#主链过滤平行链tx
FetchFilterParaTxsEnable=-1
#主链每隔几个没有相关平行链交易的区块,平行链上打包空区块,缺省从平行链blockHeight=0开始,依次增长,空块间隔不能为0
[[consensus.sub.para.emptyBlockInterval]]
blockHeight=0
intervel=50
[store]
name="kvmvccmavl"
......
......@@ -36,7 +36,7 @@ const (
minerPrivateKey = "6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
defaultGenesisAmount int64 = 1e8
poolMainBlockSec int64 = 5
defaultEmptyBlockInterval int64 = 4 //write empty block every interval blocks in mainchain
defaultEmptyBlockInterval int64 = 50 //write empty block every interval blocks in mainchain
defaultSearchMatchedBlockDepth int32 = 10000
defaultMainBlockHashForkHeight int64 = 209186 //calc block hash fork height in main chain
mainParaSelfConsensusForkHeight int64 = types.MaxHeight //para chain self consensus height switch, must >= ForkParacrossCommitTx of main
......@@ -69,28 +69,33 @@ type client struct {
quitCreate chan struct{}
}
type emptyBlockInterval struct {
BlockHeight int64 `json:"blockHeight,omitempty"`
Interval int64 `json:"interval,omitempty"`
}
type subConfig struct {
WriteBlockSeconds int64 `json:"writeBlockSeconds,omitempty"`
ParaRemoteGrpcClient string `json:"paraRemoteGrpcClient,omitempty"`
StartHeight int64 `json:"startHeight,omitempty"`
EmptyBlockInterval int64 `json:"emptyBlockInterval,omitempty"`
AuthAccount string `json:"authAccount,omitempty"`
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"`
MainForkParacrossCommitTx int64 `json:"mainForkParacrossCommitTx,omitempty"`
WaitConsensStopTimes uint32 `json:"waitConsensStopTimes,omitempty"`
MaxCacheCount int64 `json:"maxCacheCount,omitempty"`
MaxSyncErrCount int32 `json:"maxSyncErrCount,omitempty"`
FetchFilterParaTxsEnable uint32 `json:"fetchFilterParaTxsEnable,omitempty"`
BatchFetchBlockCount int64 `json:"batchFetchBlockCount,omitempty"`
ParaConsensStartHeight int64 `json:"paraConsensStartHeight,omitempty"`
MultiDownloadOpen int32 `json:"multiDownloadOpen,omitempty"`
MultiDownInvNumPerJob int64 `json:"multiDownInvNumPerJob,omitempty"`
MultiDownJobBuffNum uint32 `json:"multiDownJobBuffNum,omitempty"`
MultiDownServerRspTime uint32 `json:"multiDownServerRspTime,omitempty"`
WriteBlockSeconds int64 `json:"writeBlockSeconds,omitempty"`
ParaRemoteGrpcClient string `json:"paraRemoteGrpcClient,omitempty"`
StartHeight int64 `json:"startHeight,omitempty"`
EmptyBlockInterval []*emptyBlockInterval `json:"emptyBlockInterval,omitempty"`
AuthAccount string `json:"authAccount,omitempty"`
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"`
MainForkParacrossCommitTx int64 `json:"mainForkParacrossCommitTx,omitempty"`
WaitConsensStopTimes uint32 `json:"waitConsensStopTimes,omitempty"`
MaxCacheCount int64 `json:"maxCacheCount,omitempty"`
MaxSyncErrCount int32 `json:"maxSyncErrCount,omitempty"`
FetchFilterParaTxsEnable bool `json:"fetchFilterParaTxsEnable,omitempty"`
BatchFetchBlockCount int64 `json:"batchFetchBlockCount,omitempty"`
ParaConsensStartHeight int64 `json:"paraConsensStartHeight,omitempty"`
MultiDownloadOpen bool `json:"multiDownloadOpen,omitempty"`
MultiDownInvNumPerJob int64 `json:"multiDownInvNumPerJob,omitempty"`
MultiDownJobBuffNum uint32 `json:"multiDownJobBuffNum,omitempty"`
MultiDownServerRspTime uint32 `json:"multiDownServerRspTime,omitempty"`
}
// New function to init paracross env
......@@ -107,9 +112,15 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
if subcfg.WriteBlockSeconds <= 0 {
subcfg.WriteBlockSeconds = poolMainBlockSec
}
if subcfg.EmptyBlockInterval <= 0 {
subcfg.EmptyBlockInterval = defaultEmptyBlockInterval
if len(subcfg.EmptyBlockInterval) == 0 {
interval := &emptyBlockInterval{Interval: defaultEmptyBlockInterval}
subcfg.EmptyBlockInterval = append(subcfg.EmptyBlockInterval, interval)
}
err := checkEmptyBlockInterval(subcfg.EmptyBlockInterval)
if err != nil {
panic("para EmptyBlockInterval config not correct")
}
if subcfg.SearchHashMatchedBlockDepth <= 0 {
subcfg.SearchHashMatchedBlockDepth = defaultSearchMatchedBlockDepth
}
......@@ -125,10 +136,6 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
subcfg.MainForkParacrossCommitTx = mainForkParacrossCommitTx
}
if subcfg.FetchFilterParaTxsEnable > 0 {
fetchFilterParaTxsEnable = true
}
if subcfg.BatchFetchBlockCount <= 0 {
subcfg.BatchFetchBlockCount = types.MaxBlockCountPerTime
}
......@@ -213,9 +220,6 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
if subcfg.MultiDownJobBuffNum > 0 {
para.multiDldCli.jobBufferNum = subcfg.MultiDownJobBuffNum
}
if subcfg.MultiDownloadOpen > 0 {
para.multiDldCli.multiDldOpen = true
}
if subcfg.MultiDownServerRspTime > 0 {
para.multiDldCli.serverTimeout = subcfg.MultiDownServerRspTime
......@@ -225,6 +229,24 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
return para
}
func checkEmptyBlockInterval(in []*emptyBlockInterval) error {
for i := 0; i < len(in); i++ {
if i == 0 && in[i].BlockHeight != 0 {
plog.Error("EmptyBlockInterval,first blockHeight should be 0", "height", in[i].BlockHeight)
return types.ErrInvalidParam
}
if i > 0 && in[i].BlockHeight <= in[i-1].BlockHeight {
plog.Error("EmptyBlockInterval,blockHeight should be sequence", "preHeight", in[i-1].BlockHeight, "laterHeight", in[i].BlockHeight)
return types.ErrInvalidParam
}
if in[i].Interval <= 0 {
plog.Error("EmptyBlockInterval,interval should big than 0", "height", in[i].BlockHeight)
return types.ErrInvalidParam
}
}
return nil
}
//para 不检查任何的交易
func (client *client) CheckBlock(parent *types.Block, current *types.BlockDetail) error {
err := checkMinerTx(current)
......
......@@ -219,3 +219,64 @@ func TestGetLastBlockInfo(t *testing.T) {
assert.Equal(t, int64(10), mainSeq)
assert.Equal(t, lastBlock.Height, block.Height)
}
func TestGetEmptyInterval(t *testing.T) {
int1 := &emptyBlockInterval{BlockHeight: 0, Interval: 1}
int2 := &emptyBlockInterval{BlockHeight: 10, Interval: 10}
int3 := &emptyBlockInterval{BlockHeight: 15, Interval: 15}
ints := []*emptyBlockInterval{int1, int2, int3}
para := new(client)
para.subCfg = &subConfig{EmptyBlockInterval: ints}
lastBlock := &pt.ParaLocalDbBlock{Height: 1}
ret := para.getEmptyInterval(lastBlock)
assert.Equal(t, int1.Interval, ret)
lastBlock = &pt.ParaLocalDbBlock{Height: 10}
ret = para.getEmptyInterval(lastBlock)
assert.Equal(t, int2.Interval, ret)
lastBlock = &pt.ParaLocalDbBlock{Height: 11}
ret = para.getEmptyInterval(lastBlock)
assert.Equal(t, int2.Interval, ret)
lastBlock = &pt.ParaLocalDbBlock{Height: 16}
ret = para.getEmptyInterval(lastBlock)
assert.Equal(t, int3.Interval, ret)
}
func TestCheckEmptyInterval(t *testing.T) {
int1 := &emptyBlockInterval{BlockHeight: 0, Interval: 1}
int2 := &emptyBlockInterval{BlockHeight: 10, Interval: 10}
int3 := &emptyBlockInterval{BlockHeight: 15, Interval: 15}
int1.BlockHeight = 5
ints := []*emptyBlockInterval{int1, int2, int3}
err := checkEmptyBlockInterval(ints)
assert.Equal(t, types.ErrInvalidParam, err)
int1.BlockHeight = 0
int3.BlockHeight = 5
ints = []*emptyBlockInterval{int1, int2, int3}
err = checkEmptyBlockInterval(ints)
assert.Equal(t, types.ErrInvalidParam, err)
int3.BlockHeight = 10
ints = []*emptyBlockInterval{int1, int2, int3}
err = checkEmptyBlockInterval(ints)
assert.Equal(t, types.ErrInvalidParam, err)
int3.BlockHeight = 15
int2.Interval = 0
ints = []*emptyBlockInterval{int1, int2, int3}
err = checkEmptyBlockInterval(ints)
assert.Equal(t, types.ErrInvalidParam, err)
int2.Interval = 2
ints = []*emptyBlockInterval{int1, int2, int3}
err = checkEmptyBlockInterval(ints)
assert.Equal(t, nil, err)
}
......@@ -13,16 +13,14 @@ import (
"sync/atomic"
"fmt"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/types"
paraexec "github.com/33cn/plugin/plugin/dapp/paracross/executor"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
)
var (
fetchFilterParaTxsEnable bool
)
func (client *client) addLocalBlock(height int64, block *pt.ParaLocalDbBlock) error {
set := &types.LocalDBSet{}
......@@ -316,12 +314,12 @@ func (client *client) getBatchSeqCount(currSeq int64) (int64, error) {
}
if lastSeq > currSeq {
if lastSeq-currSeq > client.subCfg.EmptyBlockInterval {
if lastSeq-currSeq > client.subCfg.EmptyBlockInterval[0].Interval {
atomic.StoreInt32(&client.caughtUp, 0)
} else {
atomic.StoreInt32(&client.caughtUp, 1)
}
if fetchFilterParaTxsEnable && lastSeq-currSeq > client.subCfg.BatchFetchBlockCount {
if client.subCfg.FetchFilterParaTxsEnable && lastSeq-currSeq > client.subCfg.BatchFetchBlockCount {
return client.subCfg.BatchFetchBlockCount - 1, nil
}
return 0, nil
......@@ -435,7 +433,7 @@ func (client *client) requestFilterParaTxs(currSeq int64, count int64, preMainBl
}
func (client *client) RequestTx(currSeq int64, count int64, preMainBlockHash []byte) (*types.ParaTxDetails, error) {
if fetchFilterParaTxsEnable {
if client.subCfg.FetchFilterParaTxsEnable {
return client.requestFilterParaTxs(currSeq, count, preMainBlockHash)
}
......@@ -452,6 +450,15 @@ func (client *client) processHashNotMatchError(currSeq int64, lastSeqMainHash []
return currSeq, lastSeqMainHash, err
}
func (client *client) getEmptyInterval(lastBlock *pt.ParaLocalDbBlock) int64 {
for i := len(client.subCfg.EmptyBlockInterval) - 1; i >= 0; i-- {
if lastBlock.Height >= client.subCfg.EmptyBlockInterval[i].BlockHeight {
return client.subCfg.EmptyBlockInterval[i].Interval
}
}
panic(fmt.Sprintf("emptyBlockInterval not set for height=%d", lastBlock.Height))
}
func (client *client) procLocalBlock(mainBlock *types.ParaTxDetail) (bool, error) {
lastSeqMainHeight := mainBlock.Header.Height
......@@ -460,12 +467,13 @@ func (client *client) procLocalBlock(mainBlock *types.ParaTxDetail) (bool, error
plog.Error("Parachain getLastLocalBlock", "err", err)
return false, err
}
emptyInterval := client.getEmptyInterval(lastBlock)
txs := paraexec.FilterTxsForPara(mainBlock)
plog.Info("Parachain process block", "lastBlockHeight", lastBlock.Height, "lastBlockMainHeight", lastBlock.MainHeight,
"lastBlockMainHash", common.ToHex(lastBlock.MainHash), "currMainHeight", lastSeqMainHeight,
"curMainHash", common.ToHex(mainBlock.Header.Hash), "seqTy", mainBlock.Type)
"curMainHash", common.ToHex(mainBlock.Header.Hash), "emptyIntval", emptyInterval, "seqTy", mainBlock.Type)
if mainBlock.Type == types.DelBlock {
if len(txs) == 0 {
......@@ -479,7 +487,7 @@ func (client *client) procLocalBlock(mainBlock *types.ParaTxDetail) (bool, error
}
//AddAct
if len(txs) == 0 {
if lastSeqMainHeight-lastBlock.MainHeight < client.subCfg.EmptyBlockInterval {
if lastSeqMainHeight-lastBlock.MainHeight < emptyInterval {
return false, nil
}
plog.Info("Create empty block", "newHeight", lastBlock.Height+1)
......
......@@ -64,7 +64,6 @@ type multiDldClient struct {
serverTimeout uint32
conns []*connectCli
connsCheckDone bool
multiDldOpen bool
wg sync.WaitGroup
mtx sync.Mutex
}
......@@ -157,7 +156,7 @@ func (m *multiDldClient) getConns(inv *inventory) error {
}
func (m *multiDldClient) tryMultiServerDownload() {
if !m.multiDldOpen {
if !m.paraClient.subCfg.MultiDownloadOpen {
return
}
......
......@@ -35,7 +35,7 @@ func init() {
types.RegisterDappFork(ParaX, "Enable", 0)
types.RegisterDappFork(ParaX, "ForkParacrossWithdrawFromParachain", 1298600)
types.RegisterDappFork(ParaX, ForkCommitTx, 1850000)
types.RegisterDappFork(ParaX, ForkLoopCheckCommitTxDone, types.MaxHeight)
types.RegisterDappFork(ParaX, ForkLoopCheckCommitTxDone, 3230000)
}
// GetExecName get para exec name
......
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