Skip to content

Commit

Permalink
fix test bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Timmy-crypto committed Oct 9, 2019
1 parent 09414c5 commit d2cca0e
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 65 deletions.
2 changes: 0 additions & 2 deletions common/util/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@ func WriteDebugStack(toFile string) error {
buf = buf[:runtime.Stack(buf, true)]
return ioutil.WriteFile(toFile, buf, 0755)
}


1 change: 0 additions & 1 deletion core/chain-communication/cs_protocol_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/chain-config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/chain-config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion core/dipperin/miner_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 7 additions & 8 deletions core/dipperin/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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)]
Expand All @@ -61,17 +61,16 @@ 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()
}
}
}


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)
Expand Down
2 changes: 1 addition & 1 deletion core/dipperin/node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/dipperin/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion core/model/transactionsign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 15 additions & 15 deletions third-party/log/dp_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -89,7 +89,7 @@ func init() {
"pm": Pm,
"Middleware": Middleware,
"P2P": P2P,
"Stack": Stack,
"Stack": Stack,
}
}

Expand Down Expand Up @@ -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
}
}
Expand Down
14 changes: 7 additions & 7 deletions third-party/log/log15_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion third-party/p2p/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
38 changes: 19 additions & 19 deletions third-party/p2p/discover/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions third-party/p2p/discover/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand Down

0 comments on commit d2cca0e

Please sign in to comment.