Skip to content

Commit

Permalink
Fix issue in which transaction appeared in /api/transaction before …
Browse files Browse the repository at this point in the history
…actual execution
  • Loading branch information
danil-lashin committed Nov 22, 2018
1 parent c7d96b3 commit 0098026
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.7.5
*Nov 22th, 2018*

BUG FIXES

- [api] Fix issue in which transaction appeared in `/api/transaction` before actual execution

## 0.7.4
*Nov 20th, 2018*

Expand Down
4 changes: 2 additions & 2 deletions api/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func Transaction(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "application/json; charset=UTF-8")

if err != nil {
if err != nil || tx.Height > blockchain.LastCommittedHeight() {
w.WriteHeader(http.StatusBadRequest)
err = json.NewEncoder(w).Encode(Response{
Code: 0,
Code: 404,
Result: err.Error(),
})

Expand Down
28 changes: 18 additions & 10 deletions core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import (
type Blockchain struct {
abciTypes.BaseApplication

stateDB db.DB
appDB *appdb.AppDB
stateDeliver *state.StateDB
stateCheck *state.StateDB
height int64
rewards *big.Int
validatorsStatuses map[[20]byte]int8
stateDB db.DB
appDB *appdb.AppDB
stateDeliver *state.StateDB
stateCheck *state.StateDB
height int64
lastCommittedHeight int64
rewards *big.Int
validatorsStatuses map[[20]byte]int8

lock sync.RWMutex
}
Expand All @@ -53,9 +54,10 @@ func NewMinterBlockchain() *Blockchain {
applicationDB := appdb.NewAppDB()

blockchain = &Blockchain{
stateDB: ldb,
appDB: applicationDB,
height: applicationDB.GetLastHeight(),
stateDB: ldb,
appDB: applicationDB,
height: applicationDB.GetLastHeight(),
lastCommittedHeight: applicationDB.GetLastHeight(),
}

blockchain.stateDeliver, err = state.New(int64(blockchain.height), blockchain.stateDB)
Expand Down Expand Up @@ -307,6 +309,8 @@ func (app *Blockchain) Commit() abciTypes.ResponseCommit {

app.updateCurrentState()

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

return abciTypes.ResponseCommit{
Data: hash,
}
Expand Down Expand Up @@ -346,6 +350,10 @@ func (app *Blockchain) Height() int64 {
return atomic.LoadInt64(&app.height)
}

func (app *Blockchain) LastCommittedHeight() int64 {
return atomic.LoadInt64(&app.lastCommittedHeight)
}

func (app *Blockchain) getCurrentValidators() abciTypes.ValidatorUpdates {
return app.appDB.GetValidators()
}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.4"
services:
minter:
image: minterteam/minter:0.7.4
image: minterteam/minter:0.7.5
volumes:
- ~/.minter:/minter
ports:
Expand Down
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ package version
const (
Maj = "0"
Min = "7"
Fix = "4"
Fix = "5"
)

var (
// Must be a string because scripts like dist.sh read this file.
Version = "0.7.4"
Version = "0.7.5"

// GitCommit is the current HEAD set using ldflags.
GitCommit string
Expand Down

0 comments on commit 0098026

Please sign in to comment.