Skip to content

Commit

Permalink
Add wg to prevent stopping blockchain in the middle of block processing
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-lashin committed Nov 27, 2018
1 parent 14afd9f commit 1077e62
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Blockchain struct {
validatorsStatuses map[[20]byte]int8

lock sync.RWMutex
wg sync.WaitGroup
}

const (
Expand Down Expand Up @@ -102,6 +103,8 @@ func (app *Blockchain) InitChain(req abciTypes.RequestInitChain) abciTypes.Respo
}

func (app *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTypes.ResponseBeginBlock {
app.wg.Add(1)

atomic.StoreInt64(&app.height, req.Header.Height)
app.rewards = big.NewInt(0)

Expand Down Expand Up @@ -311,6 +314,8 @@ func (app *Blockchain) Commit() abciTypes.ResponseCommit {

atomic.StoreInt64(&app.lastCommittedHeight, app.Height())

app.wg.Done()

return abciTypes.ResponseCommit{
Data: hash,
}
Expand All @@ -321,6 +326,8 @@ func (app *Blockchain) Query(reqQuery abciTypes.RequestQuery) abciTypes.Response
}

func (app *Blockchain) Stop() {
app.wg.Wait()

app.appDB.Close()
app.stateDB.Close()
}
Expand Down

0 comments on commit 1077e62

Please sign in to comment.