aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-06-09 21:53:49 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-06-09 21:53:49 +0800
commit365576620a8230a193570e81e7f296d17b13fede (patch)
treeef7fe2a68ef0b112b7a1eff7d3ac4d27716b9256 /core
parent60b780c21b861766b06b2990b7bb8c41fd6d25f8 (diff)
parentebf2aabd254a4e765b68cdb46b18806fa7e4cb4b (diff)
downloadgo-tangerine-365576620a8230a193570e81e7f296d17b13fede.tar.gz
go-tangerine-365576620a8230a193570e81e7f296d17b13fede.tar.zst
go-tangerine-365576620a8230a193570e81e7f296d17b13fede.zip
Merge pull request #1216 from karalabe/fix-eth-dataraces
Fix various data races in eth and core
Diffstat (limited to 'core')
-rw-r--r--core/chain_manager.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go
index a0ce20006..c69d3a10e 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -56,10 +56,7 @@ func CalcTD(block, parent *types.Block) *big.Int {
if parent == nil {
return block.Difficulty()
}
-
- td := new(big.Int).Add(parent.Td, block.Header().Difficulty)
-
- return td
+ return new(big.Int).Add(parent.Td, block.Header().Difficulty)
}
func CalcGasLimit(parent *types.Block) *big.Int {
@@ -178,7 +175,7 @@ func (self *ChainManager) Td() *big.Int {
self.mu.RLock()
defer self.mu.RUnlock()
- return self.td
+ return new(big.Int).Set(self.td)
}
func (self *ChainManager) GasLimit() *big.Int {
@@ -204,7 +201,7 @@ func (self *ChainManager) Status() (td *big.Int, currentBlock common.Hash, genes
self.mu.RLock()
defer self.mu.RUnlock()
- return self.td, self.currentBlock.Hash(), self.genesisBlock.Hash()
+ return new(big.Int).Set(self.td), self.currentBlock.Hash(), self.genesisBlock.Hash()
}
func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
@@ -382,8 +379,8 @@ func (self *ChainManager) ExportN(w io.Writer, first uint64, last uint64) error
func (bc *ChainManager) insert(block *types.Block) {
key := append(blockNumPre, block.Number().Bytes()...)
bc.blockDb.Put(key, block.Hash().Bytes())
-
bc.blockDb.Put([]byte("LastBlock"), block.Hash().Bytes())
+
bc.currentBlock = block
bc.lastBlockHash = block.Hash()
}
@@ -488,8 +485,7 @@ func (self *ChainManager) GetAncestors(block *types.Block, length int) (blocks [
}
func (bc *ChainManager) setTotalDifficulty(td *big.Int) {
- //bc.blockDb.Put([]byte("LTD"), td.Bytes())
- bc.td = td
+ bc.td = new(big.Int).Set(td)
}
func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) {
@@ -544,6 +540,9 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
self.wg.Add(1)
defer self.wg.Done()
+ self.mu.Lock()
+ defer self.mu.Unlock()
+
self.chainmu.Lock()
defer self.chainmu.Unlock()