File mempool.go
has 898 lines of code (exceeds 500 allowed). Consider refactoring. Open
/**
* @file
* @copyright defined in aergo/LICENSE.txt
*/
Method MemPool.validateTx
has a Cognitive Complexity of 68 (exceeds 20 allowed). Consider refactoring. Open
func (mp *MemPool) validateTx(tx types.Transaction, account types.Address) error {
if !mp.whitelist.Check(types.EncodeAddress(account)) {
return types.ErrTxNotAllowedAccount
}
ns, err := mp.getAccountState(account)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
MemPool
has 33 methods (exceeds 20 allowed). Consider refactoring. Open
type MemPool struct {
*component.BaseComponent
sync.RWMutex
cfg *cfg.Config
Method MemPool.validateTx
has 118 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (mp *MemPool) validateTx(tx types.Transaction, account types.Address) error {
if !mp.whitelist.Check(types.EncodeAddress(account)) {
return types.ErrTxNotAllowedAccount
}
ns, err := mp.getAccountState(account)
Method MemPool.validateTx
has 24 return statements (exceeds 4 allowed). Open
func (mp *MemPool) validateTx(tx types.Transaction, account types.Address) error {
if !mp.whitelist.Check(types.EncodeAddress(account)) {
return types.ErrTxNotAllowedAccount
}
ns, err := mp.getAccountState(account)
Method MemPool.setStateDB
has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring. Open
func (mp *MemPool) setStateDB(block *types.Block) (bool, bool) {
if mp.testConfig {
return true, false
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method MemPool.Receive
has 58 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (mp *MemPool) Receive(context actor.Context) {
switch msg := context.Message().(type) {
case *message.MemPoolPut:
mp.verifier.Request(msg.Tx, context.Sender())
Method MemPool.removeOnBlockArrival
has 56 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (mp *MemPool) removeOnBlockArrival(block *types.Block) error {
var ag [2]time.Duration
start := time.Now()
mp.Lock()
defer mp.Unlock()
Method MemPool.dumpTxsToFile
has 52 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (mp *MemPool) dumpTxsToFile() {
if !mp.isRunning() {
return
}
mp.Info().Msg("start mempool dump")
Method MemPool.setStateDB
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (mp *MemPool) setStateDB(block *types.Block) (bool, bool) {
if mp.testConfig {
return true, false
}
Method MemPool.getUnconfirmed
has 7 return statements (exceeds 4 allowed). Open
func (mp *MemPool) getUnconfirmed(accounts []types.Address, countOnly bool) []*unconfirmedTxs {
mp.RLock()
defer mp.RUnlock()
getTxList := func(acc types.Address) (*txList, *time.Time) {
Avoid deeply nested control flow statements. Open
if err != nil {
mp.Warn().Err(err).Msg("failed to get whitelist")
}
Avoid deeply nested control flow statements. Open
if err != nil {
mp.Warn().Err(err).Msg("failed to init whitelist")
}
Method MemPool.getNameDest
has 5 return statements (exceeds 4 allowed). Open
func (mp *MemPool) getNameDest(account []byte, owner bool) []byte {
if mp.testConfig {
return account
}
Method MemPool.put
has 5 return statements (exceeds 4 allowed). Open
func (mp *MemPool) put(tx types.Transaction) error {
id := types.ToTxID(tx.GetHash())
acc := tx.GetBody().GetAccount()
if tx.HasVerifedAccount() {
acc = tx.GetVerifedAccount()
Method MemPool.dumpTxsToFile
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Open
func (mp *MemPool) dumpTxsToFile() {
if !mp.isRunning() {
return
}
mp.Info().Msg("start mempool dump")
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"