Skip to content

Commit

Permalink
Merge pull request #204 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v0.12.1
  • Loading branch information
danil-lashin authored Feb 8, 2019
2 parents d9e8f46 + 8c1aa96 commit 11aa720
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.12.1

BUG FIXES

- [core] Fix "No info about LastBlocksTimeDelta is available" issue

## 0.12.0

BREAKING CHANGES
Expand Down
29 changes: 26 additions & 3 deletions cmd/minter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/MinterTeam/minter-go-node/genesis"
"github.com/MinterTeam/minter-go-node/gui"
"github.com/MinterTeam/minter-go-node/log"
bc "github.com/tendermint/tendermint/blockchain"
tmCfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/common"
tmNode "github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/p2p"
Expand All @@ -29,7 +31,29 @@ func main() {
}

app := minter.NewMinterBlockchain()
node := startTendermintNode(app)

tmCfg := config.GetTmConfig()

// update BlocksTimeDelta
// TODO: refactor
blockStoreDB, err := tmNode.DefaultDBProvider(&tmNode.DBContext{ID: "blockstore", Config: tmCfg})
if err != nil {
panic(err)
}
blockStore := bc.NewBlockStore(blockStoreDB)
height := blockStore.Height()
count := int64(3)
if _, err := app.GetBlocksTimeDelta(height, count); err != nil {
blockA := blockStore.LoadBlockMeta(height - count - 1)
blockB := blockStore.LoadBlockMeta(height - 1)

delta := int(blockB.Header.Time.Sub(blockA.Header.Time).Seconds())
app.SetBlocksTimeDelta(height, delta)
}
blockStoreDB.Close()

// start TM node
node := startTendermintNode(app, tmCfg)

client := rpc.NewLocal(node)
status, _ := client.Status()
Expand All @@ -53,8 +77,7 @@ func main() {
})
}

func startTendermintNode(app *minter.Blockchain) *tmNode.Node {
cfg := config.GetTmConfig()
func startTendermintNode(app *minter.Blockchain, cfg *tmCfg.Config) *tmNode.Node {
nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())

if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions core/appdb/appdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package appdb

import (
"encoding/binary"
"errors"
"github.com/MinterTeam/minter-go-node/cmd/utils"
"github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -92,7 +93,7 @@ type LastBlocksTimeDelta struct {
Delta int
}

func (appDB *AppDB) GetLastBlocksTimeDelta(height int64) int {
func (appDB *AppDB) GetLastBlocksTimeDelta(height int64) (int, error) {
result := appDB.db.Get([]byte(blockTimeDeltaPath))
if result == nil {
panic("No info about LastBlocksTimeDelta is available")
Expand All @@ -105,10 +106,10 @@ func (appDB *AppDB) GetLastBlocksTimeDelta(height int64) int {
}

if data.Height != height {
panic("No info about LastBlocksTimeDelta is available")
return 0, errors.New("no info about LastBlocksTimeDelta is available")
}

return data.Delta
return data.Delta, nil
}

func (appDB *AppDB) SetLastBlocksTimeDelta(height int64, delta int) {
Expand Down
17 changes: 10 additions & 7 deletions core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ func (app *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTypes.Res
panic("Application stopped")
}

// compute max gas
app.updateBlocksTimeDelta(req.Header.Height, 3)
maxGas := app.calcMaxGas(req.Header.Height)
app.stateDeliver.SetMaxGas(maxGas)

atomic.StoreInt64(&app.height, req.Header.Height)
app.rewards = big.NewInt(0)
Expand Down Expand Up @@ -315,16 +318,12 @@ func (app *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.Respons

_ = eventsdb.GetCurrent().FlushEvents(req.Height)

// compute max gas
maxGas := app.calcMaxGas(req.Height)
app.stateDeliver.SetMaxGas(maxGas)

return abciTypes.ResponseEndBlock{
ValidatorUpdates: updates,
ConsensusParamUpdates: &abciTypes.ConsensusParams{
BlockSize: &abciTypes.BlockSizeParams{
MaxBytes: BlockMaxBytes,
MaxGas: int64(maxGas),
MaxGas: int64(app.stateDeliver.GetMaxGas()),
},
},
}
Expand Down Expand Up @@ -518,7 +517,11 @@ func (app *Blockchain) updateBlocksTimeDelta(height, count int64) {
app.appDB.SetLastBlocksTimeDelta(height, delta)
}

func (app *Blockchain) getBlocksTimeDelta(height, count int64) int {
func (app *Blockchain) SetBlocksTimeDelta(height int64, value int) {
app.appDB.SetLastBlocksTimeDelta(height, value)
}

func (app *Blockchain) GetBlocksTimeDelta(height, count int64) (int, error) {
return app.appDB.GetLastBlocksTimeDelta(height)
}

Expand All @@ -535,7 +538,7 @@ func (app *Blockchain) calcMaxGas(height int64) uint64 {
newMaxGas := app.stateCheck.GetCurrentMaxGas()

// check if blocks are created in time
if app.getBlocksTimeDelta(height, blockDelta) > targetTime*blockDelta {
if delta, _ := app.GetBlocksTimeDelta(height, blockDelta); delta > targetTime*blockDelta {
newMaxGas = newMaxGas * 7 / 10 // decrease by 30%
} else {
newMaxGas = newMaxGas * 105 / 100 // increase by 5%
Expand Down
6 changes: 6 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1472,3 +1472,9 @@ func (s *StateDB) SetMaxGas(maxGas uint64) {

s.iavl.Set(maxGasKey, bs)
}

func (s *StateDB) GetMaxGas() uint64 {
_, b := s.iavl.Get(maxGasKey)

return binary.BigEndian.Uint64(b)
}
2 changes: 1 addition & 1 deletion core/transaction/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func RunTx(context *state.StateDB, isCheck bool, rawTx []byte, rewardPool *big.I
if len(rawTx) > maxTxLength {
return Response{
Code: code.TxTooLarge,
Log: "TX length is over 1024 bytes"}
Log: fmt.Sprintf("TX length is over %d bytes", maxTxLength)}
}

tx, err := TxDecoder.DecodeFromBytes(rawTx)
Expand Down

0 comments on commit 11aa720

Please sign in to comment.