Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Sign in
net-liquid
net-liquid
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3
    • Issues 3
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • Wiki
    • Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar

新注册的用户请输入邮箱并保存,随后登录邮箱激活账号。后续可直接使用邮箱登录!

  • chainmaker
  • net-liquidnet-liquid
  • Issues
  • #2

Closed
Open
Opened Jan 19, 2024 by Ramboll Wang@rambollDeveloper

simple.simpleProtocolMgr实现的相关问题

RT,在view代码的过程中发现一些问题:

  1. 声明的sync.Mutex锁没有使用
  2. 所有更改或写操作没有加锁
  3. supportedN和unsupportedN使用开启协程的方式调用不合理,可能会导致乱序执行问题
func (s *simpleProtocolMgr) callNotifyIfChanged(pid peer.ID, news []protocol.ID) {
	if len(news) == 0 {
		return
	}
	// check new
	if s.supportedN != nil {
		for i := range news {
			if !s.protocolBook.ContainsProtocol(pid, news[i]) {
				go s.supportedN(news[i], pid) // 这里应该删除go
			}
		}
	}

	// check drop
	if s.unsupportedN != nil {
		tempMap := make(map[protocol.ID]struct{})
		for i := range news {
			tempMap[news[i]] = struct{}{}
		}
		oldSupported := s.protocolBook.GetProtocols(pid)
		for idx := range oldSupported {
			_, notDrop := tempMap[oldSupported[idx]]
			if !notDrop {
				go s.unsupportedN(oldSupported[idx], pid) // 这里应该删除go
			}
		}
	}
}

改进建议:

ProtocolManager应该是只有在节点连接/断开、新协议注册、旧协议注销时被调用,使用频率并不会特别高,建议使用sync.RWMutex代替sync.Mutex,使用map代替sync.Map

Edited Jan 19, 2024 by Ramboll Wang
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: chainmaker/net-liquid#2

Copyright © 2021 ChainMaker Org. All Rights Reserved. 长安链 版权所有。