Commit fdd6f88c authored by yukang's avatar yukang

Merge branch 'master' into para_rpc_test

parents f114b71d 25b3c68b
...@@ -205,7 +205,7 @@ func (client *client) InitBlock() { ...@@ -205,7 +205,7 @@ func (client *client) InitBlock() {
newblock.BlockTime = genesisBlockTime newblock.BlockTime = genesisBlockTime
newblock.ParentHash = zeroHash[:] newblock.ParentHash = zeroHash[:]
newblock.MainHash = mainHash newblock.MainHash = mainHash
newblock.MainHeight = startHeight newblock.MainHeight = startHeight - 1
tx := client.CreateGenesisTx() tx := client.CreateGenesisTx()
newblock.Txs = tx newblock.Txs = tx
newblock.TxHash = merkle.CalcMerkleRoot(newblock.Txs) newblock.TxHash = merkle.CalcMerkleRoot(newblock.Txs)
......
...@@ -98,6 +98,7 @@ writeBlockSeconds=2 ...@@ -98,6 +98,7 @@ writeBlockSeconds=2
#主链每隔几个没有相关交易的区块,平行链上打包空区块 #主链每隔几个没有相关交易的区块,平行链上打包空区块
emptyBlockInterval=4 emptyBlockInterval=4
MainBlockHashForkHeight=1 MainBlockHashForkHeight=1
MainForkParacrossCommitTx=5
MainParaSelfConsensusForkHeight=300 MainParaSelfConsensusForkHeight=300
SearchHashMatchedBlockDepth=100 SearchHashMatchedBlockDepth=100
#验证账户,验证节点需要配置自己的账户,并且钱包导入对应种子,非验证节点留空 #验证账户,验证节点需要配置自己的账户,并且钱包导入对应种子,非验证节点留空
......
Title="user.p.guodun." Title="user.p.para."
# TestNet=true TestNet=false
CoinSymbol="paracoin" CoinSymbol="para"
EnableParaFork=true
[log] [log]
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit # 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
...@@ -37,7 +38,9 @@ singleMode=true ...@@ -37,7 +38,9 @@ singleMode=true
batchsync=false batchsync=false
isRecordBlockSequence=false isRecordBlockSequence=false
isParaChain = true isParaChain = true
enableTxQuickIndex=false enableTxQuickIndex=true
# 升级storedb是否重新执行localdb,bityuan主链升级不需要开启,平行链升级需要开启
enableReExecLocal=true
[p2p] [p2p]
seeds=[] seeds=[]
...@@ -92,6 +95,7 @@ targetTimePerBlock = 16 ...@@ -92,6 +95,7 @@ targetTimePerBlock = 16
[consensus.sub.para] [consensus.sub.para]
#主链节点的grpc服务器ip,当前可以支持多ip负载均衡,如“101.37.227.226:8802,39.97.20.242:8802,47.107.15.126:8802,jiedian2.bityuan.com,cloud.bityuan.com” #主链节点的grpc服务器ip,当前可以支持多ip负载均衡,如“101.37.227.226:8802,39.97.20.242:8802,47.107.15.126:8802,jiedian2.bityuan.com,cloud.bityuan.com”
#ParaRemoteGrpcClient="101.37.227.226:8802,39.97.20.242:8802,47.107.15.126:8802,jiedian2.bityuan.com,cloud.bityuan.com"
ParaRemoteGrpcClient="localhost:8802" ParaRemoteGrpcClient="localhost:8802"
#主链指定高度的区块开始同步 #主链指定高度的区块开始同步
startHeight=345850 startHeight=345850
...@@ -107,20 +111,34 @@ waitBlocks4CommitMsg=2 ...@@ -107,20 +111,34 @@ waitBlocks4CommitMsg=2
searchHashMatchedBlockDepth=10000 searchHashMatchedBlockDepth=10000
#创世地址额度 #创世地址额度
genesisAmount=100000000 genesisAmount=100000000
#主链支持平行链共识tx分叉高度,需要和主链保持严格一致 #主链支持平行链共识tx分叉高度,需要和主链保持严格一致,不可修改,2270000是bityuan主链对应高度, ycc或其他按实际修改
MainForkParacrossCommitTx=-1 MainForkParacrossCommitTx=2270000
#平行链自共识开启对应的主链高度,需要大于等于MainForkParacrossCommitTx #平行链自共识开启对应的主链高度,需要大于等于MainForkParacrossCommitTx=2270000, -1 不开启
MainParaSelfConsensusForkHeight=-1 MainParaSelfConsensusForkHeight=-1
[store] [store]
name="mavl" name="kvmvccmavl"
driver="leveldb" driver="leveldb"
storedbVersion="2.0.0"
dbPath="paradatadir/mavltree" dbPath="paradatadir/mavltree"
dbCache=128 dbCache=128
[store.sub.mavl]
enableMavlPrefix=false
enableMVCC=false
enableMavlPrune=false
pruneHeight=10000
enableMemTree=true
enableMemVal=true
[store.sub.kvmvccmavl]
enableMVCCIter=true
enableMavlPrefix=false enableMavlPrefix=false
enableMVCC=false enableMVCC=false
enableMavlPrune=false enableMavlPrune=false
pruneHeight=10000 pruneHeight=10000
enableMemTree=true
enableMemVal=true
[wallet] [wallet]
minFee=100000 minFee=100000
...@@ -134,31 +152,135 @@ minerdisable=true ...@@ -134,31 +152,135 @@ minerdisable=true
isFree=true isFree=true
minExecFee=100000 minExecFee=100000
enableStat=false enableStat=false
enableMVCC=false
[exec.sub.relay] [exec.sub.relay]
genesis="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" genesis="1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP"
[exec.sub.manage] [exec.sub.manage]
superManager=[ superManager=["1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP"]
"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S",
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv",
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
]
[exec.sub.token] [exec.sub.token]
saveTokenTxList=true saveTokenTxList=true
tokenApprs = [ tokenApprs=[]
"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S",
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK",
"1LY8GFia5EiyoTodMLfkB5PHNNpXRqxhyB",
"1GCzJDS6HbgTQ2emade7mEJGGWFfA15pS9",
"1JYB8sxi4He5pZWHCd3Zi2nypQ4JMB6AxN",
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv",
]
[exec.sub.paracross] [exec.sub.paracross]
#平行链自共识停止n个空块的对应主链高度后,超级账户可以直接参与投票 #平行链自共识停止n个空块的对应主链高度后,超级账户可以直接参与投票,这个高度只在主链有效
paraConsensusStopBlocks=100 paraConsensusStopBlocks=30000
#系统中所有的fork,默认用chain33的测试网络的
#但是我们可以替换
[fork.system]
ForkChainParamV1= 0
ForkCheckTxDup=0
ForkBlockHash= 1
ForkMinerTime= 0
ForkTransferExec=0
ForkExecKey=0
ForkTxGroup=0
ForkResetTx0=0
ForkWithdraw=0
ForkExecRollback=0
ForkCheckBlockTime=0
ForkTxHeight=0
ForkTxGroupPara=0
ForkChainParamV2=0
ForkMultiSignAddress=0
ForkStateDBSet=0
ForkLocalDBAccess=0
ForkBlockCheck=0
ForkBase58AddressCheck=0
#平行链上使能平行链执行器如user.p.x.coins执行器的注册,缺省为0,对已有的平行链需要设置一个fork高度
ForkEnableParaRegExec=0
[fork.sub.coins]
Enable=0
[fork.sub.ticket]
Enable=0
ForkTicketId =0
ForkTicketVrf =0
[fork.sub.retrieve]
Enable=0
ForkRetrive=0
[fork.sub.hashlock]
Enable=0
[fork.sub.manage]
Enable=0
ForkManageExec=0
[fork.sub.token]
Enable=0
ForkTokenBlackList= 0
ForkBadTokenSymbol= 0
ForkTokenPrice=0
ForkTokenSymbolWithNumber=0
ForkTokenCheck= 0
[fork.sub.trade]
Enable=0
ForkTradeBuyLimit= 0
ForkTradeAsset= 0
ForkTradeID = 0
[fork.sub.paracross]
Enable=0
ForkParacrossWithdrawFromParachain=0
ForkParacrossCommitTx=0
[fork.sub.evm]
Enable=0
ForkEVMState=0
ForkEVMABI=0
ForkEVMFrozen=0
ForkEVMKVHash=0
[fork.sub.blackwhite]
Enable=0
ForkBlackWhiteV2=0
[fork.sub.cert]
Enable=0
[fork.sub.guess]
Enable=0
[fork.sub.lottery]
Enable=0
[fork.sub.oracle]
Enable=0
[fork.sub.relay]
Enable=0
[fork.sub.norm]
Enable=0
[fork.sub.pokerbull]
Enable=0
[fork.sub.privacy]
Enable=0
[fork.sub.game]
Enable=0
[fork.sub.multisig]
Enable=0
[fork.sub.unfreeze]
Enable=0
ForkTerminatePart=0
ForkUnfreezeIDX= 0
#对已有的平行链如果不是从0开始同步数据,需要设置这个kvmvccmavl的对应平行链高度的fork,如果从0开始同步,statehash会跟以前mavl的不同
[fork.sub.store-kvmvccmavl]
ForkKvmvccmavl=0
[pprof] [pprof]
listenAddr = "localhost:6061" listenAddr = "localhost:6061"
\ No newline at end of file
...@@ -46,6 +46,20 @@ function para_set_toml() { ...@@ -46,6 +46,20 @@ function para_set_toml() {
sed -i $xsedfix 's/^grpcBindAddr=.*/grpcBindAddr="0.0.0.0:8902"/g' "${1}" sed -i $xsedfix 's/^grpcBindAddr=.*/grpcBindAddr="0.0.0.0:8902"/g' "${1}"
sed -i $xsedfix 's/^whitelist=.*/whitelist=["localhost","127.0.0.1","0.0.0.0"]/g' "${1}" sed -i $xsedfix 's/^whitelist=.*/whitelist=["localhost","127.0.0.1","0.0.0.0"]/g' "${1}"
sed -i $xsedfix 's/^ParaRemoteGrpcClient=.*/ParaRemoteGrpcClient="nginx:8803"/g' "${1}" sed -i $xsedfix 's/^ParaRemoteGrpcClient=.*/ParaRemoteGrpcClient="nginx:8803"/g' "${1}"
sed -i $xsedfix 's/^genesis="1JmFaA6unrCFYEWP.*/genesis="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"/g' "${1}"
# shellcheck disable=SC1004
sed -i $xsedfix 's/^superManager=.*/superManager=["1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S",\
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv",\
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"]/g' "${1}"
# shellcheck disable=SC1004
sed -i $xsedfix 's/^tokenApprs=.*/tokenApprs=[ "1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S",\
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK",\
"1LY8GFia5EiyoTodMLfkB5PHNNpXRqxhyB",\
"1GCzJDS6HbgTQ2emade7mEJGGWFfA15pS9",\
"1JYB8sxi4He5pZWHCd3Zi2nypQ4JMB6AxN",\
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv",]/g' "${1}"
} }
function para_set_wallet() { function para_set_wallet() {
...@@ -312,7 +326,7 @@ function para_cross_transfer_withdraw() { ...@@ -312,7 +326,7 @@ function para_cross_transfer_withdraw() {
echo "${hash}" echo "${hash}"
sleep 15 sleep 15
${CLI} send para asset_withdraw --title user.p.para. -a 0.7 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01 hash2=$(${CLI} send para asset_withdraw --title user.p.para. -a 0.7 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01)
local times=200 local times=200
while true; do while true; do
...@@ -323,6 +337,9 @@ function para_cross_transfer_withdraw() { ...@@ -323,6 +337,9 @@ function para_cross_transfer_withdraw() {
times=$((times - 1)) times=$((times - 1))
if [ $times -le 0 ]; then if [ $times -le 0 ]; then
echo "para_cross_transfer_withdraw failed" echo "para_cross_transfer_withdraw failed"
${CLI} tx query -s "$hash2"
${PARA_CLI} tx query -s "$hash2"
${PARA_CLI} asset balance -a 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -e user.p.para.paracross --asset_exec paracross --asset_symbol coins.para
exit 1 exit 1
fi fi
else else
......
...@@ -224,15 +224,19 @@ func hasCommited(addrs []string, addr string) (bool, int) { ...@@ -224,15 +224,19 @@ func hasCommited(addrs []string, addr string) (bool, int) {
return false, 0 return false, 0
} }
func getDappForkHeight(fork string) int64 { func getDappForkHeight(forkKey string) int64 {
var forkHeight int64 var forkHeight int64
if types.IsPara() { if types.IsPara() {
forkHeight = types.Conf("config.consensus.sub.para").GInt("MainForkParacrossCommitTx") key := forkKey
if forkKey == pt.ForkCommitTx {
key = "MainForkParacrossCommitTx"
}
forkHeight = types.Conf("config.consensus.sub.para").GInt(key)
if forkHeight <= 0 { if forkHeight <= 0 {
forkHeight = types.MaxHeight forkHeight = types.MaxHeight
} }
} else { } else {
forkHeight = types.GetDappFork(pt.ParaX, fork) forkHeight = types.GetDappFork(pt.ParaX, forkKey)
} }
return forkHeight return forkHeight
} }
...@@ -437,7 +441,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error ...@@ -437,7 +441,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
} }
haveCrossTxs := len(commit.Status.CrossTxHashs) > 0 haveCrossTxs := len(commit.Status.CrossTxHashs) > 0
if commit.Status.Height > 0 && types.IsDappFork(commit.Status.MainBlockHeight, pt.ParaX, pt.ForkCommitTx) && commit.Status.CrossTxHashs[0] == nil { if commit.Status.Height > 0 && types.IsDappFork(commit.Status.MainBlockHeight, pt.ParaX, pt.ForkCommitTx) && len(commit.Status.CrossTxHashs[0]) == 0 {
haveCrossTxs = false haveCrossTxs = false
} }
......
...@@ -46,7 +46,7 @@ func checkReceiptExecOk(receipt *types.ReceiptData) bool { ...@@ -46,7 +46,7 @@ func checkReceiptExecOk(receipt *types.ReceiptData) bool {
// 1, 主链+平行链 user.p.xx.paracross 交易组 混合跨链资产转移 paracross主链执行成功 // 1, 主链+平行链 user.p.xx.paracross 交易组 混合跨链资产转移 paracross主链执行成功
// 2, 平行链 user.p.xx.paracross + user.p.xx.other 混合平行链组合 paracross主链执行成功 // 2, 平行链 user.p.xx.paracross + user.p.xx.other 混合平行链组合 paracross主链执行成功
// 3, 平行链 user.p.xx.other 交易组 混合平行链组合 other主链pack // 3, 平行链 user.p.xx.other 交易组 混合平行链组合 other主链pack
func filterParaTxGroup(title string, tx *types.Transaction, main *types.BlockDetail, index int) ([]*types.Transaction, int) { func filterParaTxGroup(title string, tx *types.Transaction, main *types.BlockDetail, index int, forkHeight int64) ([]*types.Transaction, int) {
var headIdx int var headIdx int
for i := index; i >= 0; i-- { for i := index; i >= 0; i-- {
...@@ -58,6 +58,12 @@ func filterParaTxGroup(title string, tx *types.Transaction, main *types.BlockDet ...@@ -58,6 +58,12 @@ func filterParaTxGroup(title string, tx *types.Transaction, main *types.BlockDet
endIdx := headIdx + int(tx.GroupCount) endIdx := headIdx + int(tx.GroupCount)
for i := headIdx; i < endIdx; i++ { for i := headIdx; i < endIdx; i++ {
if types.IsPara() && main.Block.Height < forkHeight {
if types.IsSpecificParaExecName(title, string(main.Block.Txs[i].Execer)) {
continue
}
}
if !checkReceiptExecOk(main.Receipts[i]) { if !checkReceiptExecOk(main.Receipts[i]) {
return nil, endIdx return nil, endIdx
} }
...@@ -69,17 +75,18 @@ func filterParaTxGroup(title string, tx *types.Transaction, main *types.BlockDet ...@@ -69,17 +75,18 @@ func filterParaTxGroup(title string, tx *types.Transaction, main *types.BlockDet
//FilterTxsForPara include some main tx in tx group before ForkParacrossCommitTx //FilterTxsForPara include some main tx in tx group before ForkParacrossCommitTx
func FilterTxsForPara(title string, main *types.BlockDetail) []*types.Transaction { func FilterTxsForPara(title string, main *types.BlockDetail) []*types.Transaction {
var txs []*types.Transaction var txs []*types.Transaction
forkHeight := getDappForkHeight(pt.ForkCommitTx)
for i := 0; i < len(main.Block.Txs); i++ { for i := 0; i < len(main.Block.Txs); i++ {
tx := main.Block.Txs[i] tx := main.Block.Txs[i]
if types.IsSpecificParaExecName(title, string(tx.Execer)) { if types.IsSpecificParaExecName(title, string(tx.Execer)) {
if tx.GroupCount >= 2 { if tx.GroupCount >= 2 {
mainTxs, endIdx := filterParaTxGroup(title, tx, main, i) mainTxs, endIdx := filterParaTxGroup(title, tx, main, i, forkHeight)
txs = append(txs, mainTxs...) txs = append(txs, mainTxs...)
i = endIdx - 1 i = endIdx - 1
continue continue
} }
//单独的paracross跨链合约 如果主链执行失败也要排除 //单独的paracross tx 如果主链执行失败也要排除, 6.2fork原因 没有排除 非user.p.xx.paracross的平行链交易
if bytes.HasSuffix(tx.Execer, []byte(pt.ParaX)) && !checkReceiptExecOk(main.Receipts[i]) { if main.Block.Height >= forkHeight && bytes.HasSuffix(tx.Execer, []byte(pt.ParaX)) && !checkReceiptExecOk(main.Receipts[i]) {
continue continue
} }
......
...@@ -16,7 +16,6 @@ import ( ...@@ -16,7 +16,6 @@ import (
) )
var klog = log.New("module", "kvmvccdb") var klog = log.New("module", "kvmvccdb")
var maxRollbackNum = 200
// SetLogLevel set log level // SetLogLevel set log level
func SetLogLevel(level string) { func SetLogLevel(level string) {
...@@ -257,7 +256,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error) ...@@ -257,7 +256,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
} else if maxVersion == height-1 { } else if maxVersion == height-1 {
return nil, nil return nil, nil
} else { } else {
count := 1
for i := maxVersion; i >= height; i-- { for i := maxVersion; i >= height; i-- {
hash, err := mvccs.mvcc.GetVersionHash(i) hash, err := mvccs.mvcc.GetVersionHash(i)
if err != nil { if err != nil {
...@@ -272,11 +270,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error) ...@@ -272,11 +270,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
kvset = append(kvset, kvlist...) kvset = append(kvset, kvlist...)
klog.Debug("store kvmvcc checkVersion DelMVCC4Height", "height", i, "maxVersion", maxVersion) klog.Debug("store kvmvcc checkVersion DelMVCC4Height", "height", i, "maxVersion", maxVersion)
//为避免高度差过大时出现异常,做一个保护,一次最多回滚200个区块
count++
if count >= maxRollbackNum {
break
}
} }
} }
......
...@@ -255,7 +255,7 @@ func TestKvmvccdbRollbackBatch(t *testing.T) { ...@@ -255,7 +255,7 @@ func TestKvmvccdbRollbackBatch(t *testing.T) {
maxVersion, err = store.mvcc.GetMaxVersion() maxVersion, err = store.mvcc.GetMaxVersion()
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
assert.Equal(t, int64(3), maxVersion) assert.Equal(t, int64(1), maxVersion)
get2 := &types.StoreGet{StateHash: hash, Keys: keys} get2 := &types.StoreGet{StateHash: hash, Keys: keys}
values2 := store.Get(get2) values2 := store.Get(get2)
......
...@@ -363,7 +363,7 @@ func TestKvmvccdbRollbackBatch(t *testing.T) { ...@@ -363,7 +363,7 @@ func TestKvmvccdbRollbackBatch(t *testing.T) {
maxVersion, err = store.mvcc.GetMaxVersion() maxVersion, err = store.mvcc.GetMaxVersion()
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
assert.Equal(t, int64(3), maxVersion) assert.Equal(t, int64(1), maxVersion)
get2 := &types.StoreGet{StateHash: hash, Keys: keys} get2 := &types.StoreGet{StateHash: hash, Keys: keys}
values2 := store.Get(get2) values2 := store.Get(get2)
......
...@@ -10,6 +10,8 @@ import ( ...@@ -10,6 +10,8 @@ import (
"strconv" "strconv"
"sync/atomic" "sync/atomic"
"time"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
dbm "github.com/33cn/chain33/common/db" dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/queue" "github.com/33cn/chain33/queue"
...@@ -26,7 +28,6 @@ const ( ...@@ -26,7 +28,6 @@ const (
) )
var ( var (
maxRollbackNum = 200
// 是否开启裁剪 // 是否开启裁剪
enablePrune bool enablePrune bool
// 每个10000裁剪一次 // 每个10000裁剪一次
...@@ -294,7 +295,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error) ...@@ -294,7 +295,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
} else if maxVersion == height-1 { } else if maxVersion == height-1 {
return nil, nil return nil, nil
} else { } else {
count := 1
for i := maxVersion; i >= height; i-- { for i := maxVersion; i >= height; i-- {
hash, err := mvccs.mvcc.GetVersionHash(i) hash, err := mvccs.mvcc.GetVersionHash(i)
if err != nil { if err != nil {
...@@ -309,11 +309,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error) ...@@ -309,11 +309,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
kvset = append(kvset, kvlist...) kvset = append(kvset, kvlist...)
kmlog.Debug("store kvmvcc checkVersion DelMVCC4Height", "height", i, "maxVersion", maxVersion) kmlog.Debug("store kvmvcc checkVersion DelMVCC4Height", "height", i, "maxVersion", maxVersion)
//为避免高度差过大时出现异常,做一个保护,一次最多回滚200个区块
count++
if count >= maxRollbackNum {
break
}
} }
} }
...@@ -345,7 +340,10 @@ func pruning(db dbm.DB, height int64) { ...@@ -345,7 +340,10 @@ func pruning(db dbm.DB, height int64) {
func pruningMVCC(db dbm.DB, height int64) { func pruningMVCC(db dbm.DB, height int64) {
setPruning(pruningStateStart) setPruning(pruningStateStart)
defer setPruning(pruningStateEnd) defer setPruning(pruningStateEnd)
start := time.Now()
pruningFirst(db, height) pruningFirst(db, height)
end := time.Now()
kmlog.Debug("pruningMVCC", "height", height, "cost", end.Sub(start))
} }
func pruningFirst(db dbm.DB, curHeight int64) { func pruningFirst(db dbm.DB, curHeight int64) {
......
...@@ -1242,7 +1242,6 @@ func (bs *BlockStore) SetStoreUpgradeMeta(meta *types.UpgradeMeta) error { ...@@ -1242,7 +1242,6 @@ func (bs *BlockStore) SetStoreUpgradeMeta(meta *types.UpgradeMeta) error {
const ( const (
seqStatusOk = iota seqStatusOk = iota
seqStatusNeedCreate seqStatusNeedCreate
seqStatusNeedDelete
) )
//CheckSequenceStatus 配置的合法性检测 //CheckSequenceStatus 配置的合法性检测
...@@ -1267,25 +1266,12 @@ func (bs *BlockStore) CheckSequenceStatus(recordSequence bool) int { ...@@ -1267,25 +1266,12 @@ func (bs *BlockStore) CheckSequenceStatus(recordSequence bool) int {
storeLog.Error("CheckSequenceStatus", "lastHeight", lastHeight, "lastSequence", lastSequence) storeLog.Error("CheckSequenceStatus", "lastHeight", lastHeight, "lastSequence", lastSequence)
return seqStatusNeedCreate return seqStatusNeedCreate
} }
//通过lastSequence获取对应的blockhash != lastHeader.hash 报错
if lastSequence != -1 {
blockSequence, err := bs.GetBlockSequence(lastSequence)
if err != nil {
storeLog.Error("CheckSequenceStatus", "lastSequence", lastSequence, "GetBlockSequence err", err)
panic(err)
}
lastHeader := bs.LastHeader()
if !bytes.Equal(lastHeader.Hash, blockSequence.Hash) {
storeLog.Error("CheckSequenceStatus:", "lastHeight", lastHeight, "lastSequence", lastSequence, "lastHeader.Hash", common.ToHex(lastHeader.Hash), "blockSequence.Hash", common.ToHex(blockSequence.Hash))
return seqStatusNeedCreate
}
}
return seqStatusOk return seqStatusOk
} }
//去使能isRecordBlockSequence时的检测 //去使能isRecordBlockSequence时的检测
if lastSequence != -1 { if lastSequence != -1 {
storeLog.Error("CheckSequenceStatus", "lastSequence", lastSequence) storeLog.Error("CheckSequenceStatus", "lastSequence", lastSequence)
return seqStatusNeedDelete panic("can not disable isRecordBlockSequence")
} }
return seqStatusOk return seqStatusOk
} }
...@@ -1348,51 +1334,3 @@ func (bs *BlockStore) CreateSequences(batchSize int64) { ...@@ -1348,51 +1334,3 @@ func (bs *BlockStore) CreateSequences(batchSize int64) {
} }
storeLog.Info("CreateSequences done") storeLog.Info("CreateSequences done")
} }
//DeleteSequences 删除本地数据库里的sequence记录
func (bs *BlockStore) DeleteSequences(batchSize int64) {
lastSeq, err := bs.LoadBlockLastSequence()
if err != nil {
if err != types.ErrHeightNotExist {
storeLog.Error("DeleteSequences LoadBlockLastSequence", "error", err)
panic("DeleteSequences LoadBlockLastSequence" + err.Error())
}
}
storeLog.Info("DeleteSequences LoadBlockLastSequence", "start", lastSeq)
newBatch := bs.NewBatch(true)
for i := lastSeq; i >= 0; i-- {
seq := i
header, err := bs.GetBlockHeaderByHeight(i)
if err != nil {
storeLog.Error("DeleteSequences GetBlockHeaderByHeight", "height", i, "error", err)
panic("DeleteSequences GetBlockHeaderByHeight" + err.Error())
}
// seq->hash
newBatch.Delete(calcSequenceToHashKey(seq, bs.isParaChain))
// hash -> seq
newBatch.Delete(calcHashToSequenceKey(header.Hash, bs.isParaChain))
if lastSeq-i == batchSize {
storeLog.Info("DeleteSequences ", "height", i)
newBatch.Set(calcLastSeqKey(bs.isParaChain), types.Encode(&types.Int64{Data: i - 1}))
err = newBatch.Write()
if err != nil {
storeLog.Error("DeleteSequences newBatch.Write", "error", err)
panic("DeleteSequences newBatch.Write" + err.Error())
}
lastSeq = i - 1
newBatch.Reset()
}
}
// last seq
newBatch.Delete(calcLastSeqKey(bs.isParaChain))
err = newBatch.Write()
if err != nil {
storeLog.Error("DeleteSequences newBatch.Write", "error", err)
panic("DeleteSequences newBatch.Write" + err.Error())
}
storeLog.Info("DeleteSequences done")
}
...@@ -176,10 +176,4 @@ func TestSeqCreateAndDelete(t *testing.T) { ...@@ -176,10 +176,4 @@ func TestSeqCreateAndDelete(t *testing.T) {
seq, err = blockStore.GetSequenceByHash([]byte("0")) seq, err = blockStore.GetSequenceByHash([]byte("0"))
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, int64(0), seq) assert.Equal(t, int64(0), seq)
blockStore.saveSequence = false
blockStore.DeleteSequences(10)
seq, err = blockStore.LoadBlockLastSequence()
assert.NotNil(t, err)
assert.Equal(t, int64(-1), seq)
} }
...@@ -248,8 +248,6 @@ func (chain *BlockChain) InitBlockChain() { ...@@ -248,8 +248,6 @@ func (chain *BlockChain) InitBlockChain() {
seqStatus := chain.blockStore.CheckSequenceStatus(chain.isRecordBlockSequence) seqStatus := chain.blockStore.CheckSequenceStatus(chain.isRecordBlockSequence)
if seqStatus == seqStatusNeedCreate { if seqStatus == seqStatusNeedCreate {
chain.blockStore.CreateSequences(100000) chain.blockStore.CreateSequences(100000)
} else if seqStatus == seqStatusNeedDelete {
chain.blockStore.DeleteSequences(100000)
} }
//先缓存最新的128个block信息到cache中 //先缓存最新的128个block信息到cache中
......
...@@ -312,7 +312,7 @@ func addSignRawTxFlags(cmd *cobra.Command) { ...@@ -312,7 +312,7 @@ func addSignRawTxFlags(cmd *cobra.Command) {
cmd.Flags().StringP("key", "k", "", "private key (optional)") cmd.Flags().StringP("key", "k", "", "private key (optional)")
cmd.Flags().StringP("addr", "a", "", "account address (optional)") cmd.Flags().StringP("addr", "a", "", "account address (optional)")
cmd.Flags().StringP("expire", "e", "120s", "transaction expire time") cmd.Flags().StringP("expire", "e", "120s", "transaction expire time")
cmd.Flags().Float64P("fee", "f", 0, "transaction fee (optional)") cmd.Flags().Float64P("fee", "f", 0, "transaction fee (optional), auto set proper fee if not set or zero fee")
cmd.Flags().StringP("to", "t", "", "new to addr (optional)") cmd.Flags().StringP("to", "t", "", "new to addr (optional)")
// A duration string is a possibly signed sequence of // A duration string is a possibly signed sequence of
......
...@@ -117,7 +117,11 @@ func (wallet *Wallet) sendTransaction(payload types.Message, execer []byte, priv ...@@ -117,7 +117,11 @@ func (wallet *Wallet) sendTransaction(payload types.Message, execer []byte, priv
if err != nil { if err != nil {
return nil, err return nil, err
} }
tx.Fee = proper.ProperFee fee, err := tx.GetRealFee(proper.ProperFee)
if err != nil {
return nil, err
}
tx.Fee = fee
tx.SetExpire(time.Second * 120) tx.SetExpire(time.Second * 120)
tx.Sign(int32(SignType), priv) tx.Sign(int32(SignType), priv)
reply, err := wallet.sendTx(tx) reply, err := wallet.sendTx(tx)
...@@ -231,7 +235,11 @@ func (wallet *Wallet) createSendToAddress(addrto string, amount int64, note stri ...@@ -231,7 +235,11 @@ func (wallet *Wallet) createSendToAddress(addrto string, amount int64, note stri
if err != nil { if err != nil {
return nil, err return nil, err
} }
tx.Fee = proper.ProperFee fee, err := tx.GetRealFee(proper.ProperFee)
if err != nil {
return nil, err
}
tx.Fee = fee
if tx.To == "" { if tx.To == "" {
tx.To = addrto tx.To = addrto
} }
......
...@@ -86,6 +86,17 @@ func (wallet *Wallet) ProcSignRawTx(unsigned *types.ReqSignRawTx) (string, error ...@@ -86,6 +86,17 @@ func (wallet *Wallet) ProcSignRawTx(unsigned *types.ReqSignRawTx) (string, error
} }
if unsigned.Fee != 0 { if unsigned.Fee != 0 {
tx.Fee = unsigned.Fee tx.Fee = unsigned.Fee
} else {
//get proper fee if not set
proper, err := wallet.api.GetProperFee(nil)
if err != nil {
return "", err
}
fee, err := tx.GetRealFee(proper.ProperFee)
if err != nil {
return "", err
}
tx.Fee = fee
} }
expire, err := types.ParseExpire(unsigned.GetExpire()) expire, err := types.ParseExpire(unsigned.GetExpire())
......
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