aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-26 09:57:08 +0800
committerGitHub <noreply@github.com>2018-10-26 09:57:08 +0800
commit1aa61d3287f63222a6cac8a49be0080a37cad8d6 (patch)
tree2f6141aa97615178978aac9e2b9db1d894171137
parent1e84ff2da76534b7b2412d2f4e862090dc31192c (diff)
downloaddexon-consensus-1aa61d3287f63222a6cac8a49be0080a37cad8d6.tar
dexon-consensus-1aa61d3287f63222a6cac8a49be0080a37cad8d6.tar.gz
dexon-consensus-1aa61d3287f63222a6cac8a49be0080a37cad8d6.tar.bz2
dexon-consensus-1aa61d3287f63222a6cac8a49be0080a37cad8d6.tar.lz
dexon-consensus-1aa61d3287f63222a6cac8a49be0080a37cad8d6.tar.xz
dexon-consensus-1aa61d3287f63222a6cac8a49be0080a37cad8d6.tar.zst
dexon-consensus-1aa61d3287f63222a6cac8a49be0080a37cad8d6.zip
core: Lock entire lattice.ProcessBlock (#259)
* Lock entire ProcessBlock * Lock Consensus.processBlock
-rw-r--r--core/consensus.go4
-rw-r--r--core/lattice.go5
2 files changed, 7 insertions, 2 deletions
diff --git a/core/consensus.go b/core/consensus.go
index ab59a67..05f93e1 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -830,6 +830,10 @@ func (con *Consensus) processBlock(block *types.Block) (err error) {
if err = con.db.Put(*block); err != nil && err != blockdb.ErrBlockExists {
return
}
+ con.lock.Lock()
+ defer con.lock.Unlock()
+ // Block processed by lattice can be out-of-order. But the output of lattice
+ // (deliveredBlocks) cannot.
deliveredBlocks, err := con.lattice.ProcessBlock(block)
if err != nil {
return
diff --git a/core/lattice.go b/core/lattice.go
index 69ad51c..06005c1 100644
--- a/core/lattice.go
+++ b/core/lattice.go
@@ -161,8 +161,6 @@ func (s *Lattice) SanityCheck(b *types.Block) (err error) {
// NOTE: assume the block passed sanity check.
func (s *Lattice) addBlockToLattice(
input *types.Block) (outputBlocks []*types.Block, err error) {
- s.lock.Lock()
- defer s.lock.Unlock()
if tip := s.data.chains[input.Position.ChainID].tip; tip != nil {
if !input.Position.Newer(&tip.Position) {
return
@@ -226,6 +224,9 @@ func (s *Lattice) ProcessBlock(
deliveredMode uint32
)
+ s.lock.Lock()
+ defer s.lock.Unlock()
+
if inLattice, err = s.addBlockToLattice(input); err != nil {
return
}