From 00980265c3d351f3ee91120a2cacbfce314b35c9 Mon Sep 17 00:00:00 2001 From: Daniil Lashin Date: Thu, 22 Nov 2018 11:41:46 +0300 Subject: [PATCH] Fix issue in which transaction appeared in `/api/transaction` before actual execution --- CHANGELOG.md | 7 +++++++ api/transaction.go | 4 ++-- core/minter/minter.go | 28 ++++++++++++++++++---------- docker-compose.yml | 2 +- version/version.go | 4 ++-- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dc456223..4546f70ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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* diff --git a/api/transaction.go b/api/transaction.go index 930496abc..5c96a9077 100644 --- a/api/transaction.go +++ b/api/transaction.go @@ -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(), }) diff --git a/core/minter/minter.go b/core/minter/minter.go index 6a8dde6d8..2500d0f96 100644 --- a/core/minter/minter.go +++ b/core/minter/minter.go @@ -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 } @@ -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) @@ -307,6 +309,8 @@ func (app *Blockchain) Commit() abciTypes.ResponseCommit { app.updateCurrentState() + atomic.StoreInt64(&app.lastCommittedHeight, app.Height()) + return abciTypes.ResponseCommit{ Data: hash, } @@ -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() } diff --git a/docker-compose.yml b/docker-compose.yml index f151fd71b..0337a6b07 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/version/version.go b/version/version.go index 552bba8ed..ab0ecf91e 100755 --- a/version/version.go +++ b/version/version.go @@ -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