From d2cca0e2625e1aa1d4af3ee8e496dbfe3fd99eb2 Mon Sep 17 00:00:00 2001 From: yangchuang <1715222986@qq.com> Date: Wed, 9 Oct 2019 10:02:36 +0800 Subject: [PATCH] fix test bug --- common/util/debug.go | 2 - .../cs_protocol_manager.go | 1 - core/chain-config/config.go | 2 +- core/chain-config/config_test.go | 2 +- core/dipperin/miner_builder.go | 2 +- core/dipperin/node.go | 15 ++++---- core/dipperin/node_builder.go | 2 +- core/dipperin/node_test.go | 4 +- core/model/transactionsign.go | 2 +- third-party/log/dp_logger.go | 30 +++++++-------- third-party/log/log15_test.go | 14 +++---- third-party/p2p/dial.go | 2 +- third-party/p2p/discover/table.go | 38 +++++++++---------- third-party/p2p/discover/udp.go | 10 ++--- 14 files changed, 61 insertions(+), 65 deletions(-) diff --git a/common/util/debug.go b/common/util/debug.go index 2a5306fc..4ea2c445 100644 --- a/common/util/debug.go +++ b/common/util/debug.go @@ -37,5 +37,3 @@ func WriteDebugStack(toFile string) error { buf = buf[:runtime.Stack(buf, true)] return ioutil.WriteFile(toFile, buf, 0755) } - - diff --git a/core/chain-communication/cs_protocol_manager.go b/core/chain-communication/cs_protocol_manager.go index 98581477..97f90cad 100644 --- a/core/chain-communication/cs_protocol_manager.go +++ b/core/chain-communication/cs_protocol_manager.go @@ -825,7 +825,6 @@ func (pm *CsProtocolManager) HandShake(p PmAbstractPeer) error { //NodeType: } log.Debug("before sign hand shake msg", "data hash", sData.DataHash().Hex()) - log.Debug("the node type is:", "type", nodeConf.GetNodeType()) if nodeConf.GetNodeType() != chain_config.NodeTypeOfNormal { // sign if signB, err := pbftSigner.SignHash(sData.DataHash().Bytes()); err != nil { diff --git a/core/chain-config/config.go b/core/chain-config/config.go index f2a86317..3d455e34 100644 --- a/core/chain-config/config.go +++ b/core/chain-config/config.go @@ -100,7 +100,7 @@ func defaultChainConfig() *ChainConfig { VerifierBootNodeNumber: 4, BlockTimeRestriction: 15 * time.Second, } - log.Info("the verifierNumber is:","number",c.VerifierNumber) + log.Info("the verifierNumber is:", "number", c.VerifierNumber) switch os.Getenv(BootEnvTagName) { case "mercury": c.NetworkID = 99 diff --git a/core/chain-config/config_test.go b/core/chain-config/config_test.go index 679e36d3..826032ca 100644 --- a/core/chain-config/config_test.go +++ b/core/chain-config/config_test.go @@ -34,7 +34,7 @@ import ( func TestLoadDefaultBootID(t *testing.T) { if GetChainConfig().VerifierNumber != 22 { - log.Info("the verifier number is","number",GetChainConfig().VerifierNumber) + log.Info("the verifier number is", "number", GetChainConfig().VerifierNumber) panic("verifier num is not 22") } diff --git a/core/dipperin/miner_builder.go b/core/dipperin/miner_builder.go index f39dbfbc..50b5a918 100644 --- a/core/dipperin/miner_builder.go +++ b/core/dipperin/miner_builder.go @@ -52,6 +52,6 @@ func NewMinerNode(master string, coinbase string, minerCount int, p2pListenAddr p2pServer.Protocols = append(p2pServer.Protocols, minePm.GetProtocol()) // init miner - n = NewCsNode([]NodeService{p2pServer},NodeConfig{}) + n = NewCsNode([]NodeService{p2pServer}, NodeConfig{}) return } diff --git a/core/dipperin/node.go b/core/dipperin/node.go index 263e59ad..f54dc997 100644 --- a/core/dipperin/node.go +++ b/core/dipperin/node.go @@ -34,10 +34,10 @@ type NodeService interface { Stop() } -func NewCsNode(services []NodeService,conf NodeConfig) *CsNode { +func NewCsNode(services []NodeService, conf NodeConfig) *CsNode { return &CsNode{ services: services, - nodeName:conf.Name, + nodeName: conf.Name, } } @@ -46,13 +46,13 @@ type CsNode struct { wg sync.WaitGroup chokePoint uint32 - nodeName string + nodeName string } func (n *CsNode) AddService(service NodeService) { n.services = append(n.services, service) } -func logDebugStack(){ +func logDebugStack() { buf := make([]byte, 5*1024*1024) log.Stack.Info("the runtime stack is:~~~~~~~~~~~~~~~~~~~~") buf = buf[:runtime.Stack(buf, true)] @@ -61,9 +61,9 @@ func logDebugStack(){ } -func printStackInfo(nodeName string){ - tick := time.NewTicker(2*time.Minute) - for{ +func printStackInfo(nodeName string) { + tick := time.NewTicker(2 * time.Minute) + for { select { case <-tick.C: logDebugStack() @@ -71,7 +71,6 @@ func printStackInfo(nodeName string){ } } - func (n *CsNode) Start() (err error) { startSuccess := true // If the startup is completed in 20 seconds, there is a service blocked (the virtual machine is too bad, it cannot be started in a few seconds) diff --git a/core/dipperin/node_builder.go b/core/dipperin/node_builder.go index 2511ea7c..605f438e 100644 --- a/core/dipperin/node_builder.go +++ b/core/dipperin/node_builder.go @@ -138,7 +138,7 @@ func NewBftNode(nodeConfig NodeConfig) (n Node) { baseComponent.rpcService.AddApis(eApis) } - n = NewCsNode(nodeServices,NodeConfig{}) + n = NewCsNode(nodeServices, NodeConfig{}) baseComponent.DipperinConfig.Node = n return diff --git a/core/dipperin/node_test.go b/core/dipperin/node_test.go index 190e9271..93b52bf0 100644 --- a/core/dipperin/node_test.go +++ b/core/dipperin/node_test.go @@ -37,7 +37,7 @@ func (s fakeNodeService) Stop() { } func TestNewCsNode(t *testing.T) { - csNode := NewCsNode([]NodeService{fakeNodeService{}},NodeConfig{}) + csNode := NewCsNode([]NodeService{fakeNodeService{}}, NodeConfig{}) err := csNode.Start() assert.NoError(t, err) @@ -51,7 +51,7 @@ func TestNewCsNode(t *testing.T) { func TestCsNode_Start(t *testing.T) { chokeTimeout = time.Millisecond * 50 - csNode := NewCsNode([]NodeService{},NodeConfig{}) + csNode := NewCsNode([]NodeService{}, NodeConfig{}) err := csNode.Start() assert.NoError(t, err) } diff --git a/core/model/transactionsign.go b/core/model/transactionsign.go index d32eb368..f0b648bb 100644 --- a/core/model/transactionsign.go +++ b/core/model/transactionsign.go @@ -157,7 +157,7 @@ func (ds DipperinSigner) GetSenderPublicKey(tx *Transaction) (*ecdsa.PublicKey, S := tx.wit.S if V.BitLen() > 8 { - log.Health.Info("GetSenderPublicKey the error V is:","V",V) + log.Health.Info("GetSenderPublicKey the error V is:", "V", V) return &emptyPk, ErrInvalidSig } if !cs_crypto.ValidSigValue(R, S, V) { diff --git a/third-party/log/dp_logger.go b/third-party/log/dp_logger.go index 796adffe..9f892ac7 100644 --- a/third-party/log/dp_logger.go +++ b/third-party/log/dp_logger.go @@ -28,7 +28,7 @@ type dpLogger struct { conf LoggerConfig } -func DefaultDpLogger(dirName string,logLevel Lvl) *dpLogger { +func DefaultDpLogger(dirName string, logLevel Lvl) *dpLogger { conf := DefaultLogConf conf.LogLevel = logLevel conf.DirName = dirName @@ -61,22 +61,22 @@ var ( Pm *dpLogger Middleware *dpLogger P2P *dpLogger - Stack *dpLogger + Stack *dpLogger dpLoggers map[string]*dpLogger ) func init() { - Mpt = DefaultDpLogger("mpt",LvlInfo) - Halt = DefaultDpLogger("ver_halt",LvlInfo) - Health = DefaultDpLogger("health_info",LvlInfo) - PBft = DefaultDpLogger("PBft",LvlInfo) - Witch = DefaultDpLogger("witch",LvlInfo) - Vm = DefaultDpLogger("vm",LvlInfo) - VmMem = DefaultDpLogger("vm_memory",LvlInfo) - Pm = DefaultDpLogger("pm",LvlInfo) - Middleware = DefaultDpLogger("Middleware",LvlError) - P2P = DefaultDpLogger("P2P",LvlInfo) - Stack = DefaultDpLogger("Stack",LvlInfo) + Mpt = DefaultDpLogger("mpt", LvlInfo) + Halt = DefaultDpLogger("ver_halt", LvlInfo) + Health = DefaultDpLogger("health_info", LvlInfo) + PBft = DefaultDpLogger("PBft", LvlInfo) + Witch = DefaultDpLogger("witch", LvlInfo) + Vm = DefaultDpLogger("vm", LvlInfo) + VmMem = DefaultDpLogger("vm_memory", LvlInfo) + Pm = DefaultDpLogger("pm", LvlInfo) + Middleware = DefaultDpLogger("Middleware", LvlError) + P2P = DefaultDpLogger("P2P", LvlInfo) + Stack = DefaultDpLogger("Stack", LvlInfo) dpLoggers = map[string]*dpLogger{ "mpt": Mpt, @@ -89,7 +89,7 @@ func init() { "pm": Pm, "Middleware": Middleware, "P2P": P2P, - "Stack": Stack, + "Stack": Stack, } } @@ -150,7 +150,7 @@ func InitDPLogger(nodeName string) { if os.Getenv("boots_env") == "venus" { switch k { //case "mpt", "health_info", "vm_memory", "witch": - case "mpt", "vm_memory", "witch","Stack","P2P": + case "mpt", "vm_memory", "witch", "Stack", "P2P": v.conf.LogLevel = LvlWarn } } diff --git a/third-party/log/log15_test.go b/third-party/log/log15_test.go index 04702fd1..b8a7a71f 100644 --- a/third-party/log/log15_test.go +++ b/third-party/log/log15_test.go @@ -145,24 +145,24 @@ type testLog struct { l Logger } -func (l testLog) String()string{ +func (l testLog) String() string { //l.l.Info("test lock") fmt.Println("test lock") return "test lock string" } -func Test_LogFormat(t *testing.T){ +func Test_LogFormat(t *testing.T) { l := New() - l.SetHandler(StreamHandler(os.Stdout,LogfmtFormat())) + l.SetHandler(StreamHandler(os.Stdout, LogfmtFormat())) testVar := testLog{ - l:l, + l: l, } - l.Info("the test format log is:","testVar",testVar) + l.Info("the test format log is:", "testVar", testVar) - l.SetHandler(StreamHandler(os.Stdout,TerminalFormat())) + l.SetHandler(StreamHandler(os.Stdout, TerminalFormat())) - l.Info("the test format log is:","testVar",testVar) + l.Info("the test format log is:", "testVar", testVar) } func TestMultiHandler(t *testing.T) { diff --git a/third-party/p2p/dial.go b/third-party/p2p/dial.go index f7012bec..7ad97c32 100644 --- a/third-party/p2p/dial.go +++ b/third-party/p2p/dial.go @@ -231,7 +231,7 @@ func (s *dialstate) newTasks(nRunning int, peers map[enode.ID]*Peer, now time.Ti } // Create dynamic dials from random lookup results, removing tried // items from the result buffer. - log.P2P.Info("newTasks the lookupBuf and needDynDials is:","needDynDials",needDynDials,"lookupBuf",s.lookupBuf) + log.P2P.Info("newTasks the lookupBuf and needDynDials is:", "needDynDials", needDynDials, "lookupBuf", s.lookupBuf) i := 0 for ; i < len(s.lookupBuf) && needDynDials > 0; i++ { if addDial(dynDialedConn, s.lookupBuf[i]) { diff --git a/third-party/p2p/discover/table.go b/third-party/p2p/discover/table.go index ce807eaf..69704d9c 100644 --- a/third-party/p2p/discover/table.go +++ b/third-party/p2p/discover/table.go @@ -339,38 +339,38 @@ func (tab *Table) refresh() <-chan struct{} { } //print tab info for debug -func (tab *Table) printTableInfo(){ +func (tab *Table) printTableInfo() { return log.P2P.Info("") log.P2P.Info("[*********************table info**********************]") - log.P2P.Info("nursery number","number",len(tab.nursery)) - for i,node := range tab.nursery{ - log.P2P.Info(fmt.Sprintf("node%v",i)+":","url",node.String()) - } - log.P2P.Info("bucket number","number",len(tab.buckets)) - for i,bucket := range tab.buckets{ - log.P2P.Info(fmt.Sprintf("[~~bucket%v",i)+":~~]") - log.P2P.Info("the bucket ips is:","ips",bucket.ips) - log.P2P.Info("the bucket entries number:","number",len(bucket.entries)) - for j,node:= range bucket.entries{ - log.P2P.Info(fmt.Sprintf("node%v",j)+":","url",node.String()) + log.P2P.Info("nursery number", "number", len(tab.nursery)) + for i, node := range tab.nursery { + log.P2P.Info(fmt.Sprintf("node%v", i)+":", "url", node.String()) + } + log.P2P.Info("bucket number", "number", len(tab.buckets)) + for i, bucket := range tab.buckets { + log.P2P.Info(fmt.Sprintf("[~~bucket%v", i) + ":~~]") + log.P2P.Info("the bucket ips is:", "ips", bucket.ips) + log.P2P.Info("the bucket entries number:", "number", len(bucket.entries)) + for j, node := range bucket.entries { + log.P2P.Info(fmt.Sprintf("node%v", j)+":", "url", node.String()) } - log.P2P.Info("the bucket replacements number:","number",len(bucket.replacements)) - for j,node:= range bucket.replacements{ - log.P2P.Info(fmt.Sprintf("node%v",j)+":","url",node.String()) + log.P2P.Info("the bucket replacements number:", "number", len(bucket.replacements)) + for j, node := range bucket.replacements { + log.P2P.Info(fmt.Sprintf("node%v", j)+":", "url", node.String()) } } log.P2P.Info("") } -func (tab *Table) debugInfo(){ +func (tab *Table) debugInfo() { tick := time.NewTicker(time.Minute) defer tick.Stop() tab.printTableInfo() for { select { case <-tick.C: - tab.printTableInfo() + tab.printTableInfo() } } } @@ -475,7 +475,7 @@ func (tab *Table) loadSeedNodes() { seed := seeds[i] age := log.Lazy{Fn: func() interface{} { return time.Since(tab.db.LastPongReceived(seed.ID())) }} log.Debug("Found seed node in database", "id", seed.ID(), "addr", seed.addr(), "age", age) - log.P2P.Info("table loadSeedNodes the node is:","seedNode",seed.String()) + log.P2P.Info("table loadSeedNodes the node is:", "seedNode", seed.String()) tab.add(seed) } } @@ -591,7 +591,7 @@ func (tab *Table) add(n *node) { return } - log.P2P.Info("the tab add node~~~","node",n.String()) + log.P2P.Info("the tab add node~~~", "node", n.String()) tab.printTableInfo() tab.mutex.Lock() diff --git a/third-party/p2p/discover/udp.go b/third-party/p2p/discover/udp.go index a70ebb45..67b7746c 100644 --- a/third-party/p2p/discover/udp.go +++ b/third-party/p2p/discover/udp.go @@ -358,8 +358,8 @@ func (t *udp) sendPing(toid enode.ID, toaddr *net.UDPAddr, callback func()) <-ch return ok }) t.localNode.UDPContact(toaddr) - log.P2P.Info("sendPing info to","toAddr",toaddr) - log.P2P.Info("the Ping package netType is","netType",req.NetType) + log.P2P.Info("sendPing info to", "toAddr", toaddr) + log.P2P.Info("the Ping package netType is", "netType", req.NetType) t.write(toaddr, req.name(), packet) return errc } @@ -666,7 +666,7 @@ func decodePacket(buf []byte) (packet, encPubkey, []byte, error) { return req, fromKey, hash, err } - log.P2P.Info("the received package info","type",req.name(),"netType",req.netType(),"localNetType",getNetType()) + log.P2P.Info("the received package info", "type", req.name(), "netType", req.netType(), "localNetType", getNetType()) if req.netType() != getNetType() { log.P2P.Error("the req and local node netType is:", "req", req.netType(), "localNode", getNetType()) return req, fromKey, hash, errors.New("the netType error") @@ -682,14 +682,14 @@ func (req *ping) handle(t *udp, from *net.UDPAddr, fromKey encPubkey, mac []byte if err != nil { return fmt.Errorf("invalid public key: %v", err) } - log.P2P.Info("receive ping package","from",from.String(),"netType",req.NetType) + log.P2P.Info("receive ping package", "from", from.String(), "netType", req.NetType) t.send(from, pongPacket, &pong{ To: makeEndpoint(from, req.From.TCP), ReplyTok: mac, Expiration: uint64(time.Now().Add(expiration).Unix()), NetType: getNetType(), }) - log.P2P.Info("send pong respond","to",from.String(),"netType", getNetType()) + log.P2P.Info("send pong respond", "to", from.String(), "netType", getNetType()) n := wrapNode(enode.NewV4(key, from.IP, int(req.From.TCP), from.Port)) t.handleReply(n.ID(), pingPacket, req) if time.Since(t.db.LastPongReceived(n.ID())) > bondExpiration {