Unverified Commit ab6c58e7 authored by lyh169's avatar lyh169 Committed by GitHub

Merge branch 'master' into mod_global_config

parents 0c014439 2366eb92
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/33cn/chain33 v0.0.0-20191017025459-6d5c61c7d134 h1:uglc+qoZXRLxsLn9TdwLV5YDzjnRbLV0QjaxqvVFh4M=
github.com/33cn/chain33 v0.0.0-20191017025459-6d5c61c7d134/go.mod h1:4I8n+Zyf3t0UKM5jjpqJY627Tub62oXkLsdzIv4r6rQ=
github.com/33cn/chain33 v0.0.0-20191017084333-edce70d31ccc h1:ZE5zFLMdGTiHF7fZcVk+uOT16Q5gwmT4p01MSz/9ZBQ=
github.com/33cn/chain33 v0.0.0-20191028082607-ea7ecac59540 h1:4m9EV1D3KdhY84QJhhhWCVgGsVa/Hb91sjWQdpg5ItE=
github.com/33cn/chain33 v0.0.0-20191028082607-ea7ecac59540/go.mod h1:4I8n+Zyf3t0UKM5jjpqJY627Tub62oXkLsdzIv4r6rQ=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7 h1:PqzgE6kAMi81xWQA2QIVxjWkFHptGgC547vchpUbtFo=
......
......@@ -324,12 +324,26 @@ function paracross_testTxGroup() {
#curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"user.p.para.paracross","actionName":"ParacrossAssetTransfer","payload":{"execName":"user.p.para.paracross","to":"1MAuE8QSbbech3bVKK2JPJJxYxNtT95oSU","amount":100000000}}]}' http://172.20.0.5:8901
# 资产从平行链转移到平行链合约
tx_hash_transferExec=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${paracross_execer_name}"'","actionName":"TransferToExec","payload":{"execName":"'"${paracross_execer_name}"'","to":"'"${trade_exec_addr}"'","amount":'${amount_trade}', "cointoken":"coins.bty"}}]}' "${para_ip}" | jq -r ".result")
#curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"user.p.para.paracross","actionName":"TransferToExec","payload":{"execName":"user.p.para.paracross","to":"12bihjzbaYWjcpDiiy9SuAWeqNksQdiN13","amount":10000000, "cointoken":"coins.bty"}}]}' http://172.20.0.5:8901
req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${paracross_execer_name}"'","actionName":"TransferToExec","payload":{"execName":"'"${paracross_execer_name}"'","to":"'"${trade_exec_addr}"'","amount":'${amount_trade}', "cointoken":"coins.bty"}}]'
echo "$req"
resp=$(curl -ksd "{$req}" "${para_ip}")
echo "$resp"
err=$(jq '(.error)' <<<"$resp")
if [ "$err" != null ]; then
echo "$resp"
exit 1
fi
tx_hash_transferExec=$(jq -r ".result" <<<"$resp")
#create tx group with none
tx_hash_group=$(curl -ksd '{"method":"Chain33.CreateNoBlanaceTxs","params":[{"txHexs":["'"${tx_hash_asset}"'","'"${tx_hash_transferExec}"'"],"privkey":"'"${test_prikey}"'","expire":"120"}]}' "${para_ip}" | jq -r ".result")
#curl -ksd '{"method":"Chain33.CreateNoBlanaceTxs","params":[{"txHexs":["0a15757365722e702e706172612e7061726163726f7373122e10904e22291080c2d72f2222314d41754538515362626563683362564b4b324a504a4a7859784e745439356f535520a08d0630d195faf7d3a1ec9a4c3a223139574a4a7639366e4b4155347348465771476d7371666a786433376a617a716969","0a15757365722e702e706172612e7061726163726f7373124f1004424b0a09636f696e732e6274791080ade2042215757365722e702e706172612e7061726163726f73732a2231326269686a7a626159576a637044696979395375415765714e6b735164694e313320a08d0630a8c984ebb2bb90a5613a223139574a4a7639366e4b4155347348465771476d7371666a786433376a617a716969"],"privkey":"4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01","expire":"120"}]}' http://172.20.0.5:8901
req='"method":"Chain33.CreateNoBlanaceTxs","params":[{"txHexs":["'"${tx_hash_asset}"'","'"${tx_hash_transferExec}"'"],"privkey":"'"${test_prikey}"'","expire":"120s"}]'
resp=$(curl -ksd "{$req}" "${para_ip}")
err=$(jq '(.error)' <<<"$resp")
if [ "$err" != null ]; then
echo "$resp"
exit 1
fi
tx_hash_group=$(jq -r ".result" <<<"$resp")
#sign 1
tx_sign=$(curl -ksd '{"method":"Chain33.SignRawTx","params":[{"privkey":"'"$test_prikey"'","txHex":"'"$tx_hash_group"'","index":2,"expire":"120s"}]}' "${para_ip}" | jq -r ".result")
......
......@@ -70,15 +70,25 @@ func (cache *Queue) Walk(count int, cb func(tx *mempool.Item) bool) {
func (cache *Queue) GetProperFee() int64 {
var sumFeeRate int64
var properFeeRate int64
if cache.Size() == 0 {
if cache.Size() < 100 {
return cache.subConfig.ProperFee
}
i := 0
var txSize int
var feeRate int64
cache.Walk(100, func(item *mempool.Item) bool {
txSize = proto.Size(item.Value)
feeRate = item.Value.Fee / int64(txSize/1000+1)
//总单元费率的个数, 单个交易根据txsize/1000 + 1计算
unitFeeNum := proto.Size(item.Value)/1000 + 1
//交易组计算
if count := item.Value.GetGroupCount(); count > 0 {
unitFeeNum = int(count)
txs, err := item.Value.GetTxGroup()
if err != nil {
for _, tx := range txs.GetTxs() {
unitFeeNum += proto.Size(tx) / 1000
}
}
}
feeRate = item.Value.Fee / int64(unitFeeNum)
sumFeeRate += feeRate
i++
return true
......
......@@ -41,7 +41,7 @@ var (
func initEnv(size int64) *Queue {
if size == 0 {
size = 100
size = 1000
}
_, sub := types.InitCfg("chain33.test.toml")
var subcfg subConfig
......@@ -158,13 +158,26 @@ func TestQueueDirection(t *testing.T) {
func TestGetProperFee(t *testing.T) {
cache := initEnv(0)
assert.Equal(t, cache.subConfig.ProperFee, cache.GetProperFee())
txs, err := types.CreateTxGroup([]*types.Transaction{tx2, tx3, tx5}, 1200000)
assert.NoError(t, err)
tx := txs.Tx()
groupItem := &drivers.Item{Value: tx, Priority: tx.Fee, EnterTime: item1.EnterTime - 1}
assert.Equal(t, cache.subConfig.ProperFee, cache.GetProperFee())
cache.Push(item1)
cache.Push(item4)
cache.GetProperFee()
txSize1 := proto.Size(item1.Value)
txSize2 := proto.Size(item4.Value)
assert.Equal(t, (item1.Value.Fee/int64(txSize1/1000+1)+item4.Value.Fee/int64(txSize2/1000+1))/2, cache.GetProperFee())
assert.NoError(t, cache.Push(groupItem))
for i := 0; i < 97; i++ {
item := *item1
tempTx := *item1.Value
item.Value = &tempTx
item.Value.Nonce = int64(i + 1)
assert.NoError(t, cache.Push(&item))
}
properFee := cache.GetProperFee()
feeRate1 := item1.Value.Fee / int64(proto.Size(item1.Value)/1000+1)
feeRate2 := item4.Value.Fee / int64(proto.Size(item4.Value)/1000+1)
t.Log(feeRate1, feeRate2)
assert.Equal(t, (feeRate1*98+feeRate2+1200000)/100, properFee)
}
func TestRealNodeMempool(t *testing.T) {
......
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