Add DebugAPI to Node, fix StateDB

- Allow starting the DebugAPI from the node via config
- In StateDB:
    - Make checkpoints when ProcessTxs() succeeds
    - Remove extra hardcoded `statedb` path that was redundant
    - Replace hardcoded `[:4]` by `[:]` when parsing idx, which failed because
      idx is 6 bytes length now.
- Extra: In node, use waitgroup instead of `stoppedXXX` channels to wait for
syncrhonizer goroutines to finish.
This commit is contained in:
Eduard S
2020-11-06 11:48:16 +01:00
parent fd9b247120
commit 5b6639a947
6 changed files with 58 additions and 21 deletions

View File

@@ -48,8 +48,6 @@ var (
)
const (
// PathStateDB defines the subpath of the StateDB
PathStateDB = "/statedb"
// PathBatchNum defines the subpath of the Batch Checkpoint in the
// subpath of the StateDB
PathBatchNum = "/BatchNum"
@@ -88,7 +86,7 @@ type StateDB struct {
func NewStateDB(path string, typ TypeStateDB, nLevels int) (*StateDB, error) {
var sto *pebble.PebbleStorage
var err error
sto, err = pebble.NewPebbleStorage(path+PathStateDB+PathCurrent, false)
sto, err = pebble.NewPebbleStorage(path+PathCurrent, false)
if err != nil {
return nil, err
}
@@ -105,7 +103,7 @@ func NewStateDB(path string, typ TypeStateDB, nLevels int) (*StateDB, error) {
}
sdb := &StateDB{
path: path + PathStateDB,
path: path,
db: sto,
mt: mt,
typ: typ,
@@ -163,6 +161,7 @@ func (s *StateDB) setCurrentBatch() error {
func (s *StateDB) MakeCheckpoint() error {
// advance currentBatch
s.currentBatch++
log.Debugw("Making StateDB checkpoint", "batch", s.currentBatch, "type", s.typ)
checkpointPath := s.path + PathBatchNum + strconv.Itoa(int(s.currentBatch))

View File

@@ -49,8 +49,13 @@ type ProcessTxOutput struct {
// the HistoryDB, and adds Nonce & TokenID to the L2Txs.
// And if TypeSynchronizer returns an array of common.Account with all the
// created accounts.
func (s *StateDB) ProcessTxs(coordIdxs []common.Idx, l1usertxs, l1coordinatortxs []common.L1Tx, l2txs []common.PoolL2Tx) (*ProcessTxOutput, error) {
var err error
func (s *StateDB) ProcessTxs(coordIdxs []common.Idx, l1usertxs, l1coordinatortxs []common.L1Tx, l2txs []common.PoolL2Tx) (ptOut *ProcessTxOutput, err error) {
defer func() {
if err == nil {
err = s.MakeCheckpoint()
}
}()
var exitTree *merkletree.MerkleTree
var createdAccounts []common.Account
@@ -829,7 +834,7 @@ func (s *StateDB) getIdx() (common.Idx, error) {
if err != nil {
return 0, err
}
return common.IdxFromBytes(idxBytes[:4])
return common.IdxFromBytes(idxBytes[:])
}
// setIdx stores Idx in the localStateDB