Commit dec3c7f9 authored by liuyuhang's avatar liuyuhang

Merge branch 'mod_kvmvcc_rollback' of https://github.com/lyh169/plugin into mod_kvmvcc_rollback

parents 464470ba 5c060cf7
......@@ -205,7 +205,7 @@ func (client *client) InitBlock() {
newblock.BlockTime = genesisBlockTime
newblock.ParentHash = zeroHash[:]
newblock.MainHash = mainHash
newblock.MainHeight = startHeight
newblock.MainHeight = startHeight - 1
tx := client.CreateGenesisTx()
newblock.Txs = tx
newblock.TxHash = merkle.CalcMerkleRoot(newblock.Txs)
......
......@@ -98,6 +98,7 @@ writeBlockSeconds=2
#主链每隔几个没有相关交易的区块,平行链上打包空区块
emptyBlockInterval=4
MainBlockHashForkHeight=1
MainForkParacrossCommitTx=5
MainParaSelfConsensusForkHeight=300
SearchHashMatchedBlockDepth=100
#验证账户,验证节点需要配置自己的账户,并且钱包导入对应种子,非验证节点留空
......
Title="user.p.guodun."
# TestNet=true
CoinSymbol="paracoin"
Title="user.p.para."
TestNet=false
CoinSymbol="para"
EnableParaFork=true
[log]
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
......@@ -37,7 +38,9 @@ singleMode=true
batchsync=false
isRecordBlockSequence=false
isParaChain = true
enableTxQuickIndex=false
enableTxQuickIndex=true
# 升级storedb是否重新执行localdb,bityuan主链升级不需要开启,平行链升级需要开启
enableReExecLocal=true
[p2p]
seeds=[]
......@@ -92,6 +95,7 @@ targetTimePerBlock = 16
[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”
#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"
#主链指定高度的区块开始同步
startHeight=345850
......@@ -107,20 +111,34 @@ waitBlocks4CommitMsg=2
searchHashMatchedBlockDepth=10000
#创世地址额度
genesisAmount=100000000
#主链支持平行链共识tx分叉高度,需要和主链保持严格一致
MainForkParacrossCommitTx=-1
#平行链自共识开启对应的主链高度,需要大于等于MainForkParacrossCommitTx
#主链支持平行链共识tx分叉高度,需要和主链保持严格一致,不可修改,2270000是bityuan主链对应高度, ycc或其他按实际修改
MainForkParacrossCommitTx=2270000
#平行链自共识开启对应的主链高度,需要大于等于MainForkParacrossCommitTx=2270000, -1 不开启
MainParaSelfConsensusForkHeight=-1
[store]
name="mavl"
name="kvmvccmavl"
driver="leveldb"
storedbVersion="2.0.0"
dbPath="paradatadir/mavltree"
dbCache=128
[store.sub.mavl]
enableMavlPrefix=false
enableMVCC=false
enableMavlPrune=false
pruneHeight=10000
enableMemTree=true
enableMemVal=true
[store.sub.kvmvccmavl]
enableMVCCIter=true
enableMavlPrefix=false
enableMVCC=false
enableMavlPrune=false
pruneHeight=10000
enableMemTree=true
enableMemVal=true
[wallet]
minFee=100000
......@@ -134,31 +152,135 @@ minerdisable=true
isFree=true
minExecFee=100000
enableStat=false
enableMVCC=false
[exec.sub.relay]
genesis="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
genesis="1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP"
[exec.sub.manage]
superManager=[
"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S",
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv",
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
]
superManager=["1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP"]
[exec.sub.token]
saveTokenTxList=true
tokenApprs = [
"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S",
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK",
"1LY8GFia5EiyoTodMLfkB5PHNNpXRqxhyB",
"1GCzJDS6HbgTQ2emade7mEJGGWFfA15pS9",
"1JYB8sxi4He5pZWHCd3Zi2nypQ4JMB6AxN",
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv",
]
tokenApprs=[]
[exec.sub.paracross]
#平行链自共识停止n个空块的对应主链高度后,超级账户可以直接参与投票
paraConsensusStopBlocks=100
#平行链自共识停止n个空块的对应主链高度后,超级账户可以直接参与投票,这个高度只在主链有效
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]
listenAddr = "localhost:6061"
listenAddr = "localhost:6061"
\ No newline at end of file
......@@ -18,31 +18,224 @@ echo_rst() {
}
paracross_GetBlock2MainInfo() {
local height
height=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"paracross.GetBlock2MainInfo","params":[{"start":1,"end":3}]}' -H 'content-type:text/plain;' ${UNIT_HTTP} | jq -r ".result.items[1].height")
[ "$height" -eq 2 ]
rst=$?
local rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_lock() {
local ok
ok=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Lock","params":[]}' -H 'content-type:text/plain;' ${UNIT_HTTP} | jq -r ".result.isOK")
[ "$ok" == true ]
rst=$?
local rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_unlock() {
local ok
ok=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.UnLock","params":[{"passwd":"1314fuzamei","timeout":0}]}' -H 'content-type:text/plain;' ${UNIT_HTTP} | jq -r ".result.isOK")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function paracross_SignAndSend() {
local signedTx
local sendedTx
signedTx=$(curl -ksd '{"method":"Chain33.SignRawTx","params":[{"expire":"120s","fee":'"$1"',"privkey":"'"$2"'","txHex":"'"$3"'"}]}' ${UNIT_HTTP} | jq -r ".result")
#echo "signedTx:$signedTx"
sendedTx=$(curl -ksd '{"method":"Chain33.SendTransaction","params":[{"data":"'"$signedTx"'"}]}' ${UNIT_HTTP} | jq -r ".result")
echo "sendedTx:$sendedTx"
}
function paracross_QueryBalance() {
local req
local resp
local balance
req='{"method":"Chain33.GetBalance", "params":[{"addresses" : ["'"$1"'"], "execer" : "paracross","asset_exec":"paracross","asset_symbol":"coins.bty"}]}'
resp=$(curl -ksd "$req" "${UNIT_HTTP}")
balance=$(jq -r '.result[0].balance' <<<"$resp")
echo "$balance"
return $?
}
function paracross_Transfer_Withdraw() {
echo "=========== ## para cross transfer/withdraw (main to para) test start"
#fromAddr 跨链资产转移地址
local fromAddr="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
#privkey 地址签名
local privkey="0x4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01"
#paracrossAddr 合约地址
local paracrossAddr="1HPkPopVe3ERfvaAgedDtJQ792taZFEHCe"
#amount_save 存钱到合约地址
local amount_save=100000000
#amount_should 应转移金额
local amount_should=27000000
#withdraw_should 应取款金额
local withdraw_should=13000000
#fee 交易费
local fee=1000000
#转移前余额
local para_balance_before
#转移后余额
local para_balance_after
#取钱后余额
local para_balance_withdraw_after
#构造交易哈希
local tx_hash
#实际转移金额
local amount_real
#实际取钱金额
local withdraw_real
#1. 查询资产转移前余额状态
para_balance_before=$(paracross_QueryBalance "$fromAddr")
echo "before transferring:$para_balance_before"
#2 存钱到合约地址
tx_hash=$(curl -ksd '{"method":"Chain33.CreateRawTransaction","params":[{"to":"'"$paracrossAddr"'","amount":'$amount_save'}]}' ${UNIT_HTTP} | jq -r ".result")
##echo "tx:$tx"
paracross_SignAndSend $fee "$privkey" "$tx_hash"
#3 资产从主链转移到平行链
tx_hash=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"paracross","actionName":"ParacrossAssetTransfer","payload":{"execer":"user.p.para.paracross","execName":"user.p.para.paracross","to":"'"$fromAddr"'","amount":'$amount_should'}}]}' ${UNIT_HTTP} | jq -r ".result")
#echo "rawTx:$rawTx"
paracross_SignAndSend $fee "$privkey" "$tx_hash"
sleep 30
#4 查询转移后余额状态
para_balance_after=$(paracross_QueryBalance "$fromAddr")
echo "after transferring:$para_balance_after"
#real_amount 实际转移金额
amount_real=$((para_balance_after - para_balance_before))
#5 取钱
tx_hash=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"paracross","actionName":"ParacrossAssetWithdraw","payload":{"IsWithdraw":true,"execer":"user.p.para.paracross","execName":"user.p.para.paracross","to":"'"$fromAddr"'","amount":'$withdraw_should'}}]}' ${UNIT_HTTP} | jq -r ".result")
#echo "rawTx:$rawTx"
paracross_SignAndSend $fee "$privkey" "$tx_hash"
sleep 15
#6 查询取钱后余额状态
para_balance_withdraw_after=$(paracross_QueryBalance "$fromAddr")
echo "after withdrawing :$para_balance_withdraw_after"
#实际取钱金额
withdraw_real=$((para_balance_after - para_balance_withdraw_after))
#echo $withdraw_real
#7 验证转移是否正确
[ "$amount_real" == "$amount_should" ] && [ "$withdraw_should" == "$withdraw_real" ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
echo "=========== ## para cross transfer/withdraw (main to para) test start end"
}
function paracross_IsSync() {
local ok
ok=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"paracross.IsSync","params":[]}' -H 'content-type:text/plain;' ${UNIT_HTTP} | jq -r ".result")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function paracross_ListTitles() {
local resp
local ok
resp=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"paracross.ListTitles","params":[]}' -H 'content-type:text/plain;' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("titles"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function paracross_GetHeight() {
local resp
local ok
resp=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"paracross.GetHeight","params":[]}' -H 'content-type:text/plain;' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("consensHeight"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function paracross_GetNodeGroupAddrs() {
local resp
local ok
resp=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"paracross.GetNodeGroupAddrs","params":[{"title":"user.p.para."}]}' -H 'content-type:text/plain;' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("key","value"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function paracross_GetNodeGroupStatus() {
local resp
local ok
resp=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"paracross.GetNodeGroupStatus","params":[{"title":"user.p.para."}]}' -H 'content-type:text/plain;' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function paracross_ListNodeGroupStatus() {
local resp
local ok
resp=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"paracross.ListNodeGroupStatus","params":[{"title":"user.p.para.","status":2}]}' -H 'content-type:text/plain;' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function paracross_ListNodeStatus() {
local resp
local ok
resp=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"paracross.ListNodeStatus","params":[{"title":"user.p.para.","status":4}]}' -H 'content-type:text/plain;' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function run_main_testcases() {
chain33_lock
chain33_unlock
paracross_GetBlock2MainInfo
#paracross_IsSync
paracross_ListTitles
#paracross_GetHeight
paracross_GetNodeGroupAddrs
paracross_GetNodeGroupStatus
paracross_ListNodeGroupStatus
paracross_ListNodeStatus
#paracross_Transfer_Withdraw
}
......@@ -50,6 +243,14 @@ function run_para_testcases() {
chain33_lock
chain33_unlock
paracross_GetBlock2MainInfo
paracross_IsSync
paracross_ListTitles
paracross_GetHeight
paracross_GetNodeGroupAddrs
paracross_GetNodeGroupStatus
paracross_ListNodeGroupStatus
paracross_ListNodeStatus
paracross_Transfer_Withdraw
}
......
......@@ -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/^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/^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() {
......@@ -312,7 +326,7 @@ function para_cross_transfer_withdraw() {
echo "${hash}"
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
while true; do
......@@ -323,6 +337,9 @@ function para_cross_transfer_withdraw() {
times=$((times - 1))
if [ $times -le 0 ]; then
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
fi
else
......@@ -897,6 +914,7 @@ function paracross() {
elif [ "${2}" == "test" ]; then
para_test "${1}"
dapp_rpc_test "${3}"
fi
if [ "${2}" == "forkInit" ]; then
......
......@@ -224,15 +224,19 @@ func hasCommited(addrs []string, addr string) (bool, int) {
return false, 0
}
func getDappForkHeight(fork string) int64 {
func getDappForkHeight(forkKey string) int64 {
var forkHeight int64
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 {
forkHeight = types.MaxHeight
}
} else {
forkHeight = types.GetDappFork(pt.ParaX, fork)
forkHeight = types.GetDappFork(pt.ParaX, forkKey)
}
return forkHeight
}
......@@ -437,7 +441,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
}
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
}
......
......@@ -46,7 +46,7 @@ func checkReceiptExecOk(receipt *types.ReceiptData) bool {
// 1, 主链+平行链 user.p.xx.paracross 交易组 混合跨链资产转移 paracross主链执行成功
// 2, 平行链 user.p.xx.paracross + user.p.xx.other 混合平行链组合 paracross主链执行成功
// 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
for i := index; i >= 0; i-- {
......@@ -58,6 +58,12 @@ func filterParaTxGroup(title string, tx *types.Transaction, main *types.BlockDet
endIdx := headIdx + int(tx.GroupCount)
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]) {
return nil, endIdx
}
......@@ -69,17 +75,18 @@ func filterParaTxGroup(title string, tx *types.Transaction, main *types.BlockDet
//FilterTxsForPara include some main tx in tx group before ForkParacrossCommitTx
func FilterTxsForPara(title string, main *types.BlockDetail) []*types.Transaction {
var txs []*types.Transaction
forkHeight := getDappForkHeight(pt.ForkCommitTx)
for i := 0; i < len(main.Block.Txs); i++ {
tx := main.Block.Txs[i]
if types.IsSpecificParaExecName(title, string(tx.Execer)) {
if tx.GroupCount >= 2 {
mainTxs, endIdx := filterParaTxGroup(title, tx, main, i)
mainTxs, endIdx := filterParaTxGroup(title, tx, main, i, forkHeight)
txs = append(txs, mainTxs...)
i = endIdx - 1
continue
}
//单独的paracross跨链合约 如果主链执行失败也要排除
if bytes.HasSuffix(tx.Execer, []byte(pt.ParaX)) && !checkReceiptExecOk(main.Receipts[i]) {
//单独的paracross tx 如果主链执行失败也要排除, 6.2fork原因 没有排除 非user.p.xx.paracross的平行链交易
if main.Block.Height >= forkHeight && bytes.HasSuffix(tx.Execer, []byte(pt.ParaX)) && !checkReceiptExecOk(main.Receipts[i]) {
continue
}
......
......@@ -1242,7 +1242,6 @@ func (bs *BlockStore) SetStoreUpgradeMeta(meta *types.UpgradeMeta) error {
const (
seqStatusOk = iota
seqStatusNeedCreate
seqStatusNeedDelete
)
//CheckSequenceStatus 配置的合法性检测
......@@ -1267,25 +1266,12 @@ func (bs *BlockStore) CheckSequenceStatus(recordSequence bool) int {
storeLog.Error("CheckSequenceStatus", "lastHeight", lastHeight, "lastSequence", lastSequence)
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
}
//去使能isRecordBlockSequence时的检测
if lastSequence != -1 {
storeLog.Error("CheckSequenceStatus", "lastSequence", lastSequence)
return seqStatusNeedDelete
panic("can not disable isRecordBlockSequence")
}
return seqStatusOk
}
......@@ -1348,51 +1334,3 @@ func (bs *BlockStore) CreateSequences(batchSize int64) {
}
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) {
seq, err = blockStore.GetSequenceByHash([]byte("0"))
assert.Nil(t, err)
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() {
seqStatus := chain.blockStore.CheckSequenceStatus(chain.isRecordBlockSequence)
if seqStatus == seqStatusNeedCreate {
chain.blockStore.CreateSequences(100000)
} else if seqStatus == seqStatusNeedDelete {
chain.blockStore.DeleteSequences(100000)
}
//先缓存最新的128个block信息到cache中
......
......@@ -312,7 +312,7 @@ func addSignRawTxFlags(cmd *cobra.Command) {
cmd.Flags().StringP("key", "k", "", "private key (optional)")
cmd.Flags().StringP("addr", "a", "", "account address (optional)")
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)")
// A duration string is a possibly signed sequence of
......
......@@ -86,6 +86,13 @@ func (wallet *Wallet) ProcSignRawTx(unsigned *types.ReqSignRawTx) (string, error
}
if unsigned.Fee != 0 {
tx.Fee = unsigned.Fee
} else {
//get proper fee if not set
proper, err := wallet.api.GetProperFee(nil)
if err != nil {
return "", err
}
tx.Fee = proper.ProperFee
}
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