diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 2bb20863d..c4e7b631f 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -408,8 +408,12 @@ func (bc *Blockchain) notificationDispatcher() { // Close stops Blockchain's internal loop, syncs changes to persistent storage // and closes it. The Blockchain is no longer functional after the call to Close. func (bc *Blockchain) Close() { + // If there is a block addition in progress, wait for it to finish and + // don't allow new ones. + bc.addLock.Lock() close(bc.stopCh) <-bc.runToExitCh + bc.addLock.Unlock() } // AddBlock accepts successive block for the Blockchain, verifies it and