@@ -26,9 +26,9 @@ type Bfter struct {
2626 broadcast BroadcastFns
2727
2828 // Message Cache
29- knownVotes * lru.ARCCache
30- knownSyncInfos * lru.ARCCache
31- knownTimeouts * lru.ARCCache
29+ knownVotes * lru.Cache
30+ knownSyncInfos * lru.Cache
31+ knownTimeouts * lru.Cache
3232}
3333
3434type ConsensusFns struct {
@@ -49,9 +49,9 @@ type BroadcastFns struct {
4949}
5050
5151func New (broadcasts BroadcastFns , blockCahinReader * core.BlockChain ) * Bfter {
52- knownVotes , _ := lru .NewARC (messageLimit )
53- knownSyncInfos , _ := lru .NewARC (messageLimit )
54- knownTimeouts , _ := lru .NewARC (messageLimit )
52+ knownVotes , _ := lru .New (messageLimit )
53+ knownSyncInfos , _ := lru .New (messageLimit )
54+ knownTimeouts , _ := lru .New (messageLimit )
5555 return & Bfter {
5656 quit : make (chan struct {}),
5757 broadcastCh : make (chan interface {}),
@@ -79,9 +79,9 @@ func (b *Bfter) SetConsensusFuns(engine consensus.Engine) {
7979
8080// TODO: rename
8181func (b * Bfter ) Vote (vote * utils.Vote ) error {
82- log .Info ("Receive Vote" , "voted block hash" , vote .ProposedBlockInfo .Hash .Hex (), "number" , vote .ProposedBlockInfo .Number , "round" , vote .ProposedBlockInfo .Round )
83- if b .knownVotes .Contains (vote .Hash ()) {
84- log .Info ("Discarded vote, known vote" , "voted block hash" , vote .ProposedBlockInfo .Hash .Hex (), "number" , vote .ProposedBlockInfo .Number , "round" , vote .ProposedBlockInfo .Round )
82+ log .Trace ("Receive Vote" , "vote hash" , vote . Hash (), " voted block hash" , vote .ProposedBlockInfo .Hash .Hex (), "number" , vote .ProposedBlockInfo .Number , "round" , vote .ProposedBlockInfo .Round , "signature" , vote . Signature )
83+ if exist , _ := b .knownVotes .ContainsOrAdd (vote .Hash (), true ); exist {
84+ log .Info ("Discarded vote, known vote" , "vote hash" , vote . Hash (), " voted block hash" , vote .ProposedBlockInfo .Hash .Hex (), "number" , vote .ProposedBlockInfo .Number , "round" , vote .ProposedBlockInfo .Round )
8585 return nil
8686 }
8787
@@ -90,7 +90,6 @@ func (b *Bfter) Vote(vote *utils.Vote) error {
9090 log .Error ("Verify BFT Vote" , "error" , err )
9191 return err
9292 }
93- b .knownVotes .Add (vote .Hash (), true )
9493 b .broadcastCh <- vote
9594
9695 err = b .consensus .voteHandler (b .blockCahinReader , vote )
@@ -102,7 +101,7 @@ func (b *Bfter) Vote(vote *utils.Vote) error {
102101}
103102func (b * Bfter ) Timeout (timeout * utils.Timeout ) error {
104103 log .Trace ("Receive Timeout" , "timeout" , timeout )
105- if b . knownVotes . Contains (timeout .Hash ()) {
104+ if exist , _ := b . knownTimeouts . ContainsOrAdd (timeout .Hash (), true ); exist {
106105 log .Trace ("Discarded Timeout, known Timeout" , "Signature" , timeout .Signature , "hash" , timeout .Hash (), "round" , timeout .Round )
107106 return nil
108107 }
@@ -111,7 +110,6 @@ func (b *Bfter) Timeout(timeout *utils.Timeout) error {
111110 log .Error ("Verify BFT Timeout" , "error" , err )
112111 return err
113112 }
114- b .knownTimeouts .Add (timeout .Hash (), true )
115113 b .broadcastCh <- timeout
116114
117115 err = b .consensus .timeoutHandler (timeout )
@@ -127,7 +125,7 @@ func (b *Bfter) Timeout(timeout *utils.Timeout) error {
127125}
128126func (b * Bfter ) SyncInfo (syncInfo * utils.SyncInfo ) error {
129127 log .Trace ("Receive SyncInfo" , "syncInfo" , syncInfo )
130- if b . knownVotes . Contains (syncInfo .Hash ()) {
128+ if exist , _ := b . knownSyncInfos . ContainsOrAdd (syncInfo .Hash (), true ); exist {
131129 log .Trace ("Discarded SyncInfo, known SyncInfo" , "hash" , syncInfo .Hash ())
132130 return nil
133131 }
@@ -137,7 +135,6 @@ func (b *Bfter) SyncInfo(syncInfo *utils.SyncInfo) error {
137135 return err
138136 }
139137
140- b .knownSyncInfos .Add (syncInfo .Hash (), true )
141138 b .broadcastCh <- syncInfo
142139
143140 err = b .consensus .syncInfoHandler (b .blockCahinReader , syncInfo )
0 commit comments