aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-17 23:12:55 +0800
committerobscuren <geffobscura@gmail.com>2015-02-17 23:12:55 +0800
commit567428fb3489d639cd7fdcd50e4362be52745ec4 (patch)
tree99e4353cc44bb392ef6583bb82a4e386ead6587c /core
parent815ead71078d63c6d07cdee8b91679e307bedcb2 (diff)
downloaddexon-567428fb3489d639cd7fdcd50e4362be52745ec4.tar
dexon-567428fb3489d639cd7fdcd50e4362be52745ec4.tar.gz
dexon-567428fb3489d639cd7fdcd50e4362be52745ec4.tar.bz2
dexon-567428fb3489d639cd7fdcd50e4362be52745ec4.tar.lz
dexon-567428fb3489d639cd7fdcd50e4362be52745ec4.tar.xz
dexon-567428fb3489d639cd7fdcd50e4362be52745ec4.tar.zst
dexon-567428fb3489d639cd7fdcd50e4362be52745ec4.zip
Filter and mutex locks added
Diffstat (limited to 'core')
-rw-r--r--core/chain_manager.go13
-rw-r--r--core/filter.go23
2 files changed, 29 insertions, 7 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go
index c28e901c6..025615676 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -79,6 +79,7 @@ type ChainManager struct {
genesisBlock *types.Block
// Last known total difficulty
mu sync.RWMutex
+ tsmu sync.RWMutex
td *big.Int
currentBlock *types.Block
lastBlockHash []byte
@@ -131,9 +132,19 @@ func (self *ChainManager) State() *state.StateDB {
}
func (self *ChainManager) TransState() *state.StateDB {
+ self.tsmu.RLock()
+ defer self.tsmu.RUnlock()
+ //tmp := self.transState
+
return self.transState
}
+func (self *ChainManager) setTransState(statedb *state.StateDB) {
+ self.tsmu.Lock()
+ defer self.tsmu.Unlock()
+ self.transState = statedb
+}
+
func (bc *ChainManager) setLastBlock() {
data, _ := bc.db.Get([]byte("LastBlock"))
if len(data) != 0 {
@@ -376,7 +387,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
self.setTotalDifficulty(td)
self.insert(block)
- self.transState = state.New(cblock.Root(), self.db)
+ self.setTransState(state.New(cblock.Root(), self.db))
self.eventMux.Post(ChainEvent{block, td})
}
diff --git a/core/filter.go b/core/filter.go
index 234fa3316..88f12a67c 100644
--- a/core/filter.go
+++ b/core/filter.go
@@ -16,7 +16,7 @@ type FilterOptions struct {
Earliest int64
Latest int64
- Address []byte
+ Address [][]byte
Topics [][]byte
Skip int
@@ -29,7 +29,7 @@ type Filter struct {
earliest int64
latest int64
skip int
- address []byte
+ address [][]byte
max int
topics [][]byte
@@ -65,7 +65,7 @@ func (self *Filter) SetLatestBlock(latest int64) {
self.latest = latest
}
-func (self *Filter) SetAddress(addr []byte) {
+func (self *Filter) SetAddress(addr [][]byte) {
self.address = addr
}
@@ -145,7 +145,8 @@ func (self *Filter) FilterLogs(logs state.Logs) state.Logs {
// Filter the logs for interesting stuff
Logs:
for _, log := range logs {
- if !bytes.Equal(self.address, log.Address()) {
+ if !includes(self.address, log.Address()) {
+ //if !bytes.Equal(self.address, log.Address()) {
continue
}
@@ -163,8 +164,18 @@ Logs:
}
func (self *Filter) bloomFilter(block *types.Block) bool {
- if len(self.address) > 0 && !types.BloomLookup(block.Bloom(), self.address) {
- return false
+ if len(self.address) > 0 {
+ var included bool
+ for _, addr := range self.address {
+ if types.BloomLookup(block.Bloom(), addr) {
+ included = true
+ break
+ }
+ }
+
+ if !included {
+ return false
+ }
}
for _, topic := range self.topics {