OSDN Git Service

add broadcast block signature (#139)
[bytom/vapor.git] / protocol / orphan_manage.go
index 52c6a87..e0ed49f 100644 (file)
@@ -13,6 +13,7 @@ import (
 var (
        orphanBlockTTL           = 60 * time.Minute
        orphanExpireWorkInterval = 3 * time.Minute
+       numOrphanBlockLimit      = 256
 )
 
 type orphanBlock struct {
@@ -56,10 +57,15 @@ func (o *OrphanManage) Add(block *types.Block) {
                return
        }
 
+       if len(o.orphan) >= numOrphanBlockLimit {
+               log.WithFields(log.Fields{"module": logModule, "hash": blockHash.String(), "height": block.Height}).Info("the number of orphan blocks exceeds the limit")
+               return
+       }
+
        o.orphan[blockHash] = &orphanBlock{block, time.Now().Add(orphanBlockTTL)}
        o.prevOrphans[block.PreviousBlockHash] = append(o.prevOrphans[block.PreviousBlockHash], &blockHash)
 
-       log.WithFields(log.Fields{"hash": blockHash.String(), "height": block.Height}).Info("add block to orphan")
+       log.WithFields(log.Fields{"module": logModule, "hash": blockHash.String(), "height": block.Height}).Info("add block to orphan")
 }
 
 // Delete will delete the block from OrphanManage