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

multi-version

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