Commit 4c49bccd authored by vipwzw's avatar vipwzw Committed by vipwzw

update chain33 06/06

parent 57150865
...@@ -191,12 +191,7 @@ func setTxDetailFromTxResult(TransactionDetail *types.TransactionDetail, txresul ...@@ -191,12 +191,7 @@ func setTxDetailFromTxResult(TransactionDetail *types.TransactionDetail, txresul
TransactionDetail.ActionName = txresult.GetTx().ActionName() TransactionDetail.ActionName = txresult.GetTx().ActionName()
//获取from地址 //获取from地址
addr := txresult.GetTx().From() TransactionDetail.Fromaddr = txresult.GetTx().From()
TransactionDetail.Fromaddr = addr
if TransactionDetail.GetTx().IsWithdraw() {
//swap from and to
TransactionDetail.Fromaddr, TransactionDetail.Tx.To = TransactionDetail.Tx.To, TransactionDetail.Fromaddr
}
} }
//ProcGetAddrOverview 获取addrOverview //ProcGetAddrOverview 获取addrOverview
......
...@@ -69,8 +69,6 @@ const ( ...@@ -69,8 +69,6 @@ const (
var TestNetSeeds = []string{ var TestNetSeeds = []string{
"114.55.101.159:13802", "114.55.101.159:13802",
"47.104.125.151:13802", "47.104.125.151:13802",
"47.104.125.97:13802",
"47.104.125.177:13802",
} }
// MainNetSeeds built-in list of seed // MainNetSeeds built-in list of seed
...@@ -78,13 +76,6 @@ var MainNetSeeds = []string{ ...@@ -78,13 +76,6 @@ var MainNetSeeds = []string{
"39.107.234.240:13802", "39.107.234.240:13802",
"39.105.88.66:13802", "39.105.88.66:13802",
"39.105.87.114:13802", "39.105.87.114:13802",
"39.105.85.247:13802",
"39.105.87.106:13802",
"39.105.76.78:13802",
"39.105.82.4:13802",
"39.105.43.225:13802",
"39.107.239.248:13802",
"39.105.83.33:13802",
"120.27.234.254:13802", "120.27.234.254:13802",
"116.62.169.41:13802", "116.62.169.41:13802",
"47.97.169.229:13802", "47.97.169.229:13802",
...@@ -125,4 +116,11 @@ var MainNetSeeds = []string{ ...@@ -125,4 +116,11 @@ var MainNetSeeds = []string{
"47.74.22.60:13802", "47.74.22.60:13802",
"47.74.22.86:13802", "47.74.22.86:13802",
"47.91.17.139:13802", "47.91.17.139:13802",
"49.4.51.190:13802",
"114.115.151.98:13802",
"114.116.6.132:13802",
"114.116.12.244:13802",
"114.116.114.77:13802",
"114.116.109.21:13802",
"114.116.50.182:13802",
} }
...@@ -361,18 +361,21 @@ func (m *Cli) GetHeaders(msg *queue.Message, taskindex int64) { ...@@ -361,18 +361,21 @@ func (m *Cli) GetHeaders(msg *queue.Message, taskindex int64) {
req := msg.GetData().(*pb.ReqBlocks) req := msg.GetData().(*pb.ReqBlocks)
pid := req.GetPid() pid := req.GetPid()
if len(pid) == 0 { if len(pid) == 0 {
log.Debug("GetHeaders:pid is nil")
msg.Reply(m.network.client.NewMessage("blockchain", pb.EventReply, pb.Reply{Msg: []byte("no pid")})) msg.Reply(m.network.client.NewMessage("blockchain", pb.EventReply, pb.Reply{Msg: []byte("no pid")}))
return return
} }
msg.Reply(m.network.client.NewMessage("blockchain", pb.EventReply, pb.Reply{IsOk: true, Msg: []byte("ok")})) msg.Reply(m.network.client.NewMessage("blockchain", pb.EventReply, pb.Reply{IsOk: true, Msg: []byte("ok")}))
peers, infos := m.network.node.GetActivePeers() peers, infos := m.network.node.GetActivePeers()
var pidIsActivePeer bool
for paddr, info := range infos { for paddr, info := range infos {
if info.GetName() == pid[0] { //匹配成功 if info.GetName() == pid[0] { //匹配成功
peer, ok := peers[paddr] peer, ok := peers[paddr]
if ok && peer != nil { if ok && peer != nil {
var err error var err error
pidIsActivePeer = true
headers, err := peer.mconn.gcli.GetHeaders(context.Background(), &pb.P2PGetHeaders{StartHeight: req.GetStart(), EndHeight: req.GetEnd(), headers, err := peer.mconn.gcli.GetHeaders(context.Background(), &pb.P2PGetHeaders{StartHeight: req.GetStart(), EndHeight: req.GetEnd(),
Version: m.network.node.nodeInfo.cfg.Version}, grpc.FailFast(true)) Version: m.network.node.nodeInfo.cfg.Version}, grpc.FailFast(true))
P2pComm.CollectPeerStat(err, peer) P2pComm.CollectPeerStat(err, peer)
...@@ -394,6 +397,10 @@ func (m *Cli) GetHeaders(msg *queue.Message, taskindex int64) { ...@@ -394,6 +397,10 @@ func (m *Cli) GetHeaders(msg *queue.Message, taskindex int64) {
} }
} }
} }
//当请求的pid不是ActivePeer时需要打印日志方便问题定位
if !pidIsActivePeer {
log.Debug("GetHeaders", "pid", pid[0], "ActivePeers", peers, "infos", infos)
}
} }
// GetBlocks get blocks information // GetBlocks get blocks information
...@@ -410,9 +417,9 @@ func (m *Cli) GetBlocks(msg *queue.Message, taskindex int64) { ...@@ -410,9 +417,9 @@ func (m *Cli) GetBlocks(msg *queue.Message, taskindex int64) {
} }
req := msg.GetData().(*pb.ReqBlocks) req := msg.GetData().(*pb.ReqBlocks)
log.Info("GetBlocks", "start", req.GetStart(), "end", req.GetEnd()) log.Debug("GetBlocks", "start", req.GetStart(), "end", req.GetEnd())
pids := req.GetPid() pids := req.GetPid()
log.Info("GetBlocks", "pids", pids) log.Debug("GetBlocks", "pids", pids)
var Inventorys = make([]*pb.Inventory, 0) var Inventorys = make([]*pb.Inventory, 0)
for i := req.GetStart(); i <= req.GetEnd(); i++ { for i := req.GetStart(); i <= req.GetEnd(); i++ {
var inv pb.Inventory var inv pb.Inventory
...@@ -426,7 +433,7 @@ func (m *Cli) GetBlocks(msg *queue.Message, taskindex int64) { ...@@ -426,7 +433,7 @@ func (m *Cli) GetBlocks(msg *queue.Message, taskindex int64) {
var downloadPeers []*Peer var downloadPeers []*Peer
peers, infos := m.network.node.GetActivePeers() peers, infos := m.network.node.GetActivePeers()
if len(pids) > 0 && pids[0] != "" { //指定Pid 下载数据 if len(pids) > 0 && pids[0] != "" { //指定Pid 下载数据
log.Info("fetch from peer in pids", "pids", pids) log.Debug("fetch from peer in pids", "pids", pids)
var pidmap = make(map[string]bool) var pidmap = make(map[string]bool)
for _, pid := range pids { for _, pid := range pids {
pidmap[pid] = true pidmap[pid] = true
...@@ -443,7 +450,7 @@ func (m *Cli) GetBlocks(msg *queue.Message, taskindex int64) { ...@@ -443,7 +450,7 @@ func (m *Cli) GetBlocks(msg *queue.Message, taskindex int64) {
} }
} else { } else {
log.Info("fetch from all peers in pids") log.Debug("fetch from all peers in pids")
for _, peer := range peers { for _, peer := range peers {
peerinfo, ok := infos[peer.Addr()] peerinfo, ok := infos[peer.Addr()]
if !ok { if !ok {
...@@ -458,7 +465,7 @@ func (m *Cli) GetBlocks(msg *queue.Message, taskindex int64) { ...@@ -458,7 +465,7 @@ func (m *Cli) GetBlocks(msg *queue.Message, taskindex int64) {
} }
if len(downloadPeers) == 0 { if len(downloadPeers) == 0 {
log.Error("GetBlocks", "downloadPeers", 0) log.Error("GetBlocks", "downloadPeers", 0, "peers", peers, "infos", infos)
msg.Reply(m.network.client.NewMessage("blockchain", pb.EventReply, pb.Reply{Msg: []byte("no downloadPeers")})) msg.Reply(m.network.client.NewMessage("blockchain", pb.EventReply, pb.Reply{Msg: []byte("no downloadPeers")}))
return return
} }
......
...@@ -296,6 +296,11 @@ func fmtTxDetail(tx *types.TransactionDetail, disableDetail bool) (*rpctypes.Tra ...@@ -296,6 +296,11 @@ func fmtTxDetail(tx *types.TransactionDetail, disableDetail bool) (*rpctypes.Tra
log.Info("GetTxByHashes", "Failed to DecodeTx due to", err) log.Info("GetTxByHashes", "Failed to DecodeTx due to", err)
return nil, err return nil, err
} }
// swap from with to
if tx.GetTx().IsWithdraw() {
tx.Fromaddr, tx.Tx.To = tx.Tx.To, tx.Fromaddr
tran.To = tx.Tx.GetRealToAddr()
}
return &rpctypes.TransactionDetail{ return &rpctypes.TransactionDetail{
Tx: tran, Tx: tran,
Height: tx.GetHeight(), Height: tx.GetHeight(),
......
...@@ -1405,3 +1405,21 @@ func TestChain33_ConvertExectoAddr(t *testing.T) { ...@@ -1405,3 +1405,21 @@ func TestChain33_ConvertExectoAddr(t *testing.T) {
err := client.ConvertExectoAddr(rpctypes.ExecNameParm{ExecName: "coins"}, &testResult) err := client.ConvertExectoAddr(rpctypes.ExecNameParm{ExecName: "coins"}, &testResult)
assert.NoError(t, err) assert.NoError(t, err)
} }
func Test_fmtTxDetail(t *testing.T) {
tx := &types.Transaction{Execer: []byte("coins")}
log := &types.ReceiptLog{Ty: 0, Log: []byte("test")}
receipt := &types.ReceiptData{Ty: 0, Logs: []*types.ReceiptLog{log}}
detail := &types.TransactionDetail{Tx: tx, Receipt: receipt}
var err error
//test withdraw swap from to
detail.Fromaddr = "from"
detail.Tx.Payload, err = common.FromHex("0x180322301080c2d72f2205636f696e732a22314761485970576d71414a7371527772706f4e6342385676674b7453776a63487174")
assert.NoError(t, err)
tx.To = "to"
tran, err := fmtTxDetail(detail, false)
assert.NoError(t, err)
assert.Equal(t, "to", tran.Fromaddr)
assert.Equal(t, "from", tx.To)
}
...@@ -70,6 +70,11 @@ func ConvertWalletTxDetailToJSON(in *types.WalletTxDetails, out *WalletTxDetails ...@@ -70,6 +70,11 @@ func ConvertWalletTxDetailToJSON(in *types.WalletTxDetails, out *WalletTxDetails
if err != nil { if err != nil {
continue continue
} }
if tx.Tx.IsWithdraw() {
//swap from and to
tx.Fromaddr, tx.Tx.To = tx.Tx.To, tx.Fromaddr
tran.To = tx.Tx.GetRealToAddr()
}
out.TxDetails = append(out.TxDetails, &WalletTxDetail{ out.TxDetails = append(out.TxDetails, &WalletTxDetail{
Tx: tran, Tx: tran,
Receipt: rd, Receipt: rd,
......
...@@ -76,6 +76,17 @@ func TestConvertWalletTxDetailToJSON(t *testing.T) { ...@@ -76,6 +76,17 @@ func TestConvertWalletTxDetailToJSON(t *testing.T) {
out := &WalletTxDetails{} out := &WalletTxDetails{}
err := ConvertWalletTxDetailToJSON(in, out) err := ConvertWalletTxDetailToJSON(in, out)
assert.NoError(t, err) assert.NoError(t, err)
//test withdraw swap from to
detail.Fromaddr = "from"
detail.Tx.Payload, err = common.FromHex("0x180322301080c2d72f2205636f696e732a22314761485970576d71414a7371527772706f4e6342385676674b7453776a63487174")
assert.NoError(t, err)
tx.To = "to"
out = &WalletTxDetails{}
err = ConvertWalletTxDetailToJSON(in, out)
assert.NoError(t, err)
assert.Equal(t, "to", out.TxDetails[0].FromAddr)
assert.Equal(t, "from", detail.Tx.To)
} }
func TestServer(t *testing.T) { func TestServer(t *testing.T) {
......
...@@ -285,7 +285,10 @@ func (mem *Mempool) RemoveTxsOfBlock(block *types.Block) bool { ...@@ -285,7 +285,10 @@ func (mem *Mempool) RemoveTxsOfBlock(block *types.Block) bool {
func (mem *Mempool) GetProperFeeRate() int64 { func (mem *Mempool) GetProperFeeRate() int64 {
baseFeeRate := mem.cache.GetProperFee() baseFeeRate := mem.cache.GetProperFee()
if mem.cfg.IsLevelFee { if mem.cfg.IsLevelFee {
return mem.getLevelFeeRate(baseFeeRate) levelFeeRate := mem.getLevelFeeRate(mem.cfg.MinTxFee)
if levelFeeRate > baseFeeRate {
return levelFeeRate
}
} }
return baseFeeRate return baseFeeRate
} }
...@@ -296,13 +299,12 @@ func (mem *Mempool) getLevelFeeRate(baseFeeRate int64) int64 { ...@@ -296,13 +299,12 @@ func (mem *Mempool) getLevelFeeRate(baseFeeRate int64) int64 {
sumByte := mem.cache.TotalByte() sumByte := mem.cache.TotalByte()
maxTxNumber := types.GetP(mem.Height()).MaxTxNumber maxTxNumber := types.GetP(mem.Height()).MaxTxNumber
switch { switch {
case (sumByte > int64(types.MaxBlockSize/100) && sumByte < int64(types.MaxBlockSize/20)) ||
(int64(mem.Size()) >= maxTxNumber/10 && int64(mem.Size()) < maxTxNumber/2):
feeRate = 10 * baseFeeRate
case sumByte >= int64(types.MaxBlockSize/20) || int64(mem.Size()) >= maxTxNumber/2: case sumByte >= int64(types.MaxBlockSize/20) || int64(mem.Size()) >= maxTxNumber/2:
feeRate = 100 * baseFeeRate feeRate = 100 * baseFeeRate
case sumByte >= int64(types.MaxBlockSize/100) || int64(mem.Size()) >= maxTxNumber/10:
feeRate = 10 * baseFeeRate
default: default:
return baseFeeRate feeRate = baseFeeRate
} }
if feeRate > 10000000 { if feeRate > 10000000 {
feeRate = 10000000 feeRate = 10000000
......
...@@ -124,7 +124,7 @@ func (mem *Mempool) checkTxs(msg *queue.Message) *queue.Message { ...@@ -124,7 +124,7 @@ func (mem *Mempool) checkTxs(msg *queue.Message) *queue.Message {
// checkLevelFee 检查阶梯手续费 // checkLevelFee 检查阶梯手续费
func (mem *Mempool) checkLevelFee(tx *types.TransactionCache) error { func (mem *Mempool) checkLevelFee(tx *types.TransactionCache) error {
//获取mempool里所有交易手续费总和 //获取mempool里所有交易手续费总和
feeRate := mem.GetProperFeeRate() feeRate := mem.getLevelFeeRate(mem.cfg.MinTxFee)
totalfee, err := tx.GetTotalFee(feeRate) totalfee, err := tx.GetTotalFee(feeRate)
if err != nil { if err != nil {
return err return err
......
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
"os" "os"
"os/user" "os/user"
"path/filepath" "path/filepath"
"testing"
"unicode" "unicode"
"strings" "strings"
...@@ -127,8 +126,14 @@ func CreateTxWithExecer(priv crypto.PrivKey, execer string) *types.Transaction { ...@@ -127,8 +126,14 @@ func CreateTxWithExecer(priv crypto.PrivKey, execer string) *types.Transaction {
return tx return tx
} }
//TestingT 测试类型
type TestingT interface {
Error(args ...interface{})
Log(args ...interface{})
}
// JSONPrint : print in json format // JSONPrint : print in json format
func JSONPrint(t *testing.T, input interface{}) { func JSONPrint(t TestingT, input interface{}) {
data, err := json.MarshalIndent(input, "", "\t") data, err := json.MarshalIndent(input, "", "\t")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
......
...@@ -227,12 +227,6 @@ func (store *Store) GetTxDetailByIter(TxList *types.ReqWalletTransactionList) (* ...@@ -227,12 +227,6 @@ func (store *Store) GetTxDetailByIter(TxList *types.ReqWalletTransactionList) (*
storelog.Error("GetTxDetailByIter", "proto.Unmarshal err:", err) storelog.Error("GetTxDetailByIter", "proto.Unmarshal err:", err)
return nil, types.ErrUnmarshal return nil, types.ErrUnmarshal
} }
if string(txdetail.Tx.GetExecer()) == "coins" && txdetail.Tx.ActionName() == "withdraw" {
//swap from and to
txdetail.Fromaddr, txdetail.Tx.To = txdetail.Tx.To, txdetail.Fromaddr
}
txhash := txdetail.GetTx().Hash()
txdetail.Txhash = txhash
txDetails.TxDetails[index] = &txdetail txDetails.TxDetails[index] = &txdetail
} }
return &txDetails, nil return &txDetails, nil
......
...@@ -1025,7 +1025,7 @@ func (wallet *Wallet) buildAndStoreWalletTxDetail(param *buildStoreWalletTxDetai ...@@ -1025,7 +1025,7 @@ func (wallet *Wallet) buildAndStoreWalletTxDetail(param *buildStoreWalletTxDetai
txdetail.Index = int64(param.index) txdetail.Index = int64(param.index)
txdetail.Receipt = param.block.Receipts[param.index] txdetail.Receipt = param.block.Receipts[param.index]
txdetail.Blocktime = param.block.Block.BlockTime txdetail.Blocktime = param.block.Block.BlockTime
txdetail.Txhash = param.tx.Hash()
txdetail.ActionName = txdetail.Tx.ActionName() txdetail.ActionName = txdetail.Tx.ActionName()
txdetail.Amount, Err = param.tx.Amount() txdetail.Amount, Err = param.tx.Amount()
if Err != nil { if Err != nil {
...@@ -1135,13 +1135,6 @@ func (wallet *Wallet) GetTxDetailByHashs(ReqHashes *types.ReqHashes) { ...@@ -1135,13 +1135,6 @@ func (wallet *Wallet) GetTxDetailByHashs(ReqHashes *types.ReqHashes) {
txdetail.Fromaddr = txdetal.GetFromaddr() txdetail.Fromaddr = txdetal.GetFromaddr()
txdetail.ActionName = txdetal.GetTx().ActionName() txdetail.ActionName = txdetal.GetTx().ActionName()
//由于Withdraw的交易在blockchain模块已经做了from和to地址的swap的操作。
//所以在此需要swap恢复回去。通过钱包的GetTxDetailByIter接口上送给前端时再做from和to地址的swap
//确保保存在数据库中是的最原始的数据,提供给上层显示时可以做swap方便客户理解
if txdetail.GetTx().IsWithdraw() {
txdetail.Fromaddr, txdetail.Tx.To = txdetail.Tx.To, txdetail.Fromaddr
}
txdetailbyte, err := proto.Marshal(&txdetail) txdetailbyte, err := proto.Marshal(&txdetail)
if err != nil { if err != nil {
walletlog.Error("GetTxDetailByHashs Marshal txdetail err", "Height", height, "index", txindex) walletlog.Error("GetTxDetailByHashs Marshal txdetail err", "Height", height, "index", txindex)
......
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