OSDN Git Service

add fast sync func (#204)
[bytom/vapor.git] / protocol / protocol.go
index ee3114e..cb31fe3 100644 (file)
@@ -3,9 +3,9 @@ package protocol
 import (
        "sync"
 
-       "github.com/golang/groupcache/lru"
        log "github.com/sirupsen/logrus"
 
+       "github.com/vapor/common"
        "github.com/vapor/config"
        "github.com/vapor/event"
        "github.com/vapor/protocol/bc"
@@ -24,7 +24,7 @@ type Chain struct {
        processBlockCh chan *processBlockMsg
 
        consensusNodeManager *consensusNodeManager
-       signatureCache       *lru.Cache
+       signatureCache       *common.Cache
        eventDispatcher      *event.Dispatcher
 
        cond                 sync.Cond
@@ -38,7 +38,7 @@ func NewChain(store Store, txPool *TxPool, eventDispatcher *event.Dispatcher) (*
                orphanManage:    NewOrphanManage(),
                txPool:          txPool,
                store:           store,
-               signatureCache:  lru.New(maxSignatureCacheSize),
+               signatureCache:  common.NewCache(maxSignatureCacheSize),
                eventDispatcher: eventDispatcher,
                processBlockCh:  make(chan *processBlockMsg, maxProcessBlockChSize),
        }
@@ -112,7 +112,11 @@ func (c *Chain) BestBlockHash() *bc.Hash {
        return &c.bestNode.Hash
 }
 
-// BestBlockHeader returns the chain tail block
+// BestIrreversibleHeader returns the chain best irreversible block
+func (c *Chain) BestIrreversibleHeader() *types.BlockHeader {
+       return c.bestIrreversibleNode.BlockHeader()
+}
+
 func (c *Chain) BestBlockHeader() *types.BlockHeader {
        node := c.index.BestNode()
        return node.BlockHeader()