Browse Source

Implement an eficient memory storage, Resolve #120

feature/sql-semaphore1
Eduard S 4 years ago
parent
commit
96ceb014bf
1 changed files with 17 additions and 2 deletions
  1. +17
    -2
      db/statedb/txprocessors.go

+ 17
- 2
db/statedb/txprocessors.go

@ -2,14 +2,16 @@ package statedb
import ( import (
"errors" "errors"
"io/ioutil"
"math/big" "math/big"
"os"
"github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/common"
"github.com/hermeznetwork/hermez-node/log" "github.com/hermeznetwork/hermez-node/log"
"github.com/iden3/go-iden3-crypto/babyjub" "github.com/iden3/go-iden3-crypto/babyjub"
"github.com/iden3/go-merkletree" "github.com/iden3/go-merkletree"
"github.com/iden3/go-merkletree/db" "github.com/iden3/go-merkletree/db"
"github.com/iden3/go-merkletree/db/memory"
"github.com/iden3/go-merkletree/db/pebble"
) )
var ( var (
@ -61,7 +63,20 @@ func (s *StateDB) ProcessTxs(l1usertxs, l1coordinatortxs []common.L1Tx, l2txs []
// TBD if ExitTree is only in memory or stored in disk, for the moment // TBD if ExitTree is only in memory or stored in disk, for the moment
// only needed in memory // only needed in memory
if s.typ == TypeSynchronizer || s.typ == TypeBatchBuilder { if s.typ == TypeSynchronizer || s.typ == TypeBatchBuilder {
exitTree, err = merkletree.NewMerkleTree(memory.NewMemoryStorage(), s.mt.MaxLevels())
tmpDir, err := ioutil.TempDir("", "hermez-statedb-exittree")
if err != nil {
return nil, nil, err
}
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
log.Errorw("Dleting statedb temp exit tree", "err", err)
}
}()
sto, err := pebble.NewPebbleStorage(tmpDir, false)
if err != nil {
return nil, nil, err
}
exitTree, err = merkletree.NewMerkleTree(sto, s.mt.MaxLevels())
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

Loading…
Cancel
Save