Skip to content

Commit

Permalink
Merge pull request #248 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v0.20.5
  • Loading branch information
danil-lashin authored May 6, 2019
2 parents f671f1e + 79cff9f commit bc23845
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 20 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.20.5

IMPROVEMENT

- [api] Speed up state history

## 0.20.4

BUG FIXES
Expand Down
10 changes: 5 additions & 5 deletions core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewMinterBlockchain(cfg *config.Config) *Blockchain {
panic(err)
}

blockchain.stateCheck = state.NewForCheck(blockchain.stateDeliver)
blockchain.stateCheck = state.NewForCheckFromDeliver(blockchain.stateDeliver)

// Set start height for rewards and validators
rewards.SetStartHeight(applicationDB.GetStartHeight())
Expand Down Expand Up @@ -428,7 +428,7 @@ func (app *Blockchain) Commit() abciTypes.ResponseCommit {
// Check invariants
if app.height%720 == 0 && app.tmNode != nil {
genesis, _ := client.NewLocal(app.tmNode).Genesis()
if err := state.NewForCheck(app.stateCheck).CheckForInvariants(genesis.Genesis); err != nil {
if err := state.NewForCheckFromDeliver(app.stateCheck).CheckForInvariants(genesis.Genesis); err != nil {
log.With("module", "invariants").Error("Invariants error", "msg", err.Error(), "height", app.height)
}
}
Expand Down Expand Up @@ -465,15 +465,15 @@ func (app *Blockchain) CurrentState() *state.StateDB {
app.lock.RLock()
defer app.lock.RUnlock()

return state.NewForCheck(app.stateCheck)
return state.NewForCheckFromDeliver(app.stateCheck)
}

// Get immutable state of Minter Blockchain for given height
func (app *Blockchain) GetStateForHeight(height uint64) (*state.StateDB, error) {
app.lock.RLock()
defer app.lock.RUnlock()

s, err := state.New(height, app.stateDB, false)
s, err := state.NewForCheck(height, app.stateDB)
if err != nil {
return nil, rpctypes.RPCError{Code: 404, Message: "State at given height not found", Data: err.Error()}
}
Expand Down Expand Up @@ -523,7 +523,7 @@ func (app *Blockchain) resetCheckState() {
app.lock.Lock()
defer app.lock.Unlock()

app.stateCheck = state.NewForCheck(app.stateDeliver)
app.stateCheck = state.NewForCheckFromDeliver(app.stateDeliver)
}

func (app *Blockchain) getCurrentValidators() abciTypes.ValidatorUpdates {
Expand Down
34 changes: 33 additions & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,35 @@ type StakeCache struct {
BipValue *big.Int
}

func NewForCheck(s *StateDB) *StateDB {
func NewForCheck(height uint64, db dbm.DB) (*StateDB, error) {
tree := NewMutableTree(db)

t, err := tree.GetImmutableAtHeight(int64(height))
if err != nil {
return nil, err
}

return &StateDB{
db: db,
iavl: t,
height: height,
stateAccounts: make(map[types.Address]*stateAccount),
stateAccountsDirty: make(map[types.Address]struct{}),
stateCoins: make(map[types.CoinSymbol]*stateCoin),
stateCoinsDirty: make(map[types.CoinSymbol]struct{}),
stateFrozenFunds: make(map[uint64]*stateFrozenFund),
stateFrozenFundsDirty: make(map[uint64]struct{}),
stateCandidates: nil,
stateCandidatesDirty: false,
stateValidators: nil,
stateValidatorsDirty: false,
totalSlashed: nil,
totalSlashedDirty: false,
stakeCache: make(map[types.CoinSymbol]StakeCache),
}, nil
}

func NewForCheckFromDeliver(s *StateDB) *StateDB {
return &StateDB{
db: s.db,
iavl: s.iavl.GetImmutable(),
Expand Down Expand Up @@ -2071,3 +2099,7 @@ func (s *StateDB) CheckForInvariants(genesis *tmTypes.GenesisDoc) error {
func (s *StateDB) Height() uint64 {
return s.height
}

func (s *StateDB) DB() dbm.DB {
return s.db
}
34 changes: 22 additions & 12 deletions core/state/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ type Tree interface {
Set(key, value []byte) bool
Remove(key []byte) ([]byte, bool)
LoadVersion(targetVersion int64) (int64, error)
Load() (int64, error)
SaveVersion() ([]byte, int64, error)
DeleteVersion(version int64) error
GetImmutable() *ImmutableTree
GetImmutableAtHeight(version int64) (*ImmutableTree, error)
Version() int64
Hash() []byte
Iterate(fn func(key []byte, value []byte) bool) (stopped bool)
Expand All @@ -32,6 +32,17 @@ type MutableTree struct {
lock sync.RWMutex
}

func (t *MutableTree) GetImmutableAtHeight(version int64) (*ImmutableTree, error) {
tree, err := t.tree.GetImmutable(version)
if err != nil {
return nil, err
}

return &ImmutableTree{
tree: tree,
}, nil
}

func (t *MutableTree) Iterate(fn func(key []byte, value []byte) bool) (stopped bool) {
return t.tree.Iterate(fn)
}
Expand All @@ -50,13 +61,6 @@ func (t *MutableTree) Version() int64 {
return t.tree.Version()
}

func (t *MutableTree) Load() (int64, error) {
t.lock.Lock()
defer t.lock.Unlock()

return t.tree.Load()
}

func (t *MutableTree) GetImmutable() *ImmutableTree {
t.lock.RLock()
defer t.lock.RUnlock()
Expand Down Expand Up @@ -108,6 +112,12 @@ func (t *MutableTree) DeleteVersion(version int64) error {
return t.tree.DeleteVersion(version)
}

func NewImmutableTree(db dbm.DB) *ImmutableTree {
return &ImmutableTree{
tree: iavl.NewImmutableTree(db, 1024),
}
}

type ImmutableTree struct {
tree *iavl.ImmutableTree
}
Expand All @@ -124,10 +134,6 @@ func (t *ImmutableTree) Version() int64 {
return t.tree.Version()
}

func (t *ImmutableTree) Load() (int64, error) {
panic("Not implemented")
}

func (t *ImmutableTree) GetImmutable() *ImmutableTree {
return t
}
Expand All @@ -136,6 +142,10 @@ func (t *ImmutableTree) Get(key []byte) (index int64, value []byte) {
return t.tree.Get(key)
}

func (t *ImmutableTree) GetImmutableAtHeight(version int64) (*ImmutableTree, error) {
panic("Not implemented")
}

func (t *ImmutableTree) Set(key, value []byte) bool {
panic("Not implemented")
}
Expand Down
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package version
const (
Maj = "0"
Min = "20"
Fix = "4"
Fix = "5"

AppVer = 4
)

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

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

0 comments on commit bc23845

Please sign in to comment.