github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/store/orgchain/votepool/vote_pool.go (about) 1 package votepool 2 3 import ( 4 "sync" 5 6 "github.com/sixexorg/magnetic-ring/common" 7 ) 8 9 var VotePool = &votePool{ 10 pool: make(map[uint64]map[common.Hash]struct{}, 1024), 11 prepare: make(map[uint64][]common.Hash, 3), 12 } 13 14 //it only pushes in votes that require a response to a failed result 15 type votePool struct { 16 //Key:endHeight val:txHash 17 pool map[uint64]map[common.Hash]struct{} 18 prepare map[uint64][]common.Hash 19 m sync.Mutex 20 } 21 22 func (this *votePool) naturalDeath(height uint64) []common.Hash { 23 this.m.Lock() 24 defer this.m.Unlock() 25 res := this.pool[height] 26 hs := make([]common.Hash, 0, len(res)) 27 for k, _ := range res { 28 hs = append(hs, k) 29 } 30 delete(this.pool, height) 31 return hs 32 } 33 34 func (this *votePool) pushNewVote(height uint64, blockHash common.Hash, txHashes []common.Hash) { 35 this.m.Lock() 36 defer this.m.Unlock() 37 hs := make([]common.Hash, 0, len(txHashes)+1) 38 hs = append(hs, blockHash) 39 hs = append(hs, txHashes...) 40 this.prepare[height] = hs 41 } 42 func (this *votePool) commit(height uint64, blockHash common.Hash) { 43 this.m.Lock() 44 defer this.m.Unlock() 45 46 } 47 48 func (this *votePool) removeHash(hash common.Hash, height uint64) { 49 this.m.Lock() 50 defer this.m.Unlock() 51 delete(this.pool[height], hash) 52 }