mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Update StateDB to new & ExitInfo struct & BatchNum
Update StateDB to new & ExitInfo struct & BatchNum Also a small fix at txselector & log packages
This commit is contained in:
@@ -130,7 +130,7 @@ func (s *StateDB) MakeCheckpoint() error {
|
||||
}
|
||||
|
||||
// DeleteCheckpoint removes if exist the checkpoint of the given batchNum
|
||||
func (s *StateDB) DeleteCheckpoint(batchNum uint64) error {
|
||||
func (s *StateDB) DeleteCheckpoint(batchNum common.BatchNum) error {
|
||||
checkpointPath := s.path + PATHBATCHNUM + strconv.Itoa(int(batchNum))
|
||||
|
||||
if _, err := os.Stat(checkpointPath); os.IsNotExist(err) {
|
||||
@@ -144,7 +144,7 @@ func (s *StateDB) DeleteCheckpoint(batchNum uint64) error {
|
||||
// does not delete the checkpoints between old current and the new current,
|
||||
// those checkpoints will remain in the storage, and eventually will be
|
||||
// deleted when MakeCheckpoint overwrites them.
|
||||
func (s *StateDB) Reset(batchNum uint64) error {
|
||||
func (s *StateDB) Reset(batchNum common.BatchNum) error {
|
||||
if batchNum == 0 {
|
||||
s.idx = 0
|
||||
return nil
|
||||
@@ -331,7 +331,7 @@ func NewLocalStateDB(path string, synchronizerDB *StateDB, withMT bool, nLevels
|
||||
|
||||
// Reset performs a reset in the LocaStateDB. If fromSynchronizer is true, it
|
||||
// gets the state from LocalStateDB.synchronizerStateDB for the given batchNum. If fromSynchronizer is false, get the state from LocalStateDB checkpoints.
|
||||
func (l *LocalStateDB) Reset(batchNum uint64, fromSynchronizer bool) error {
|
||||
func (l *LocalStateDB) Reset(batchNum common.BatchNum, fromSynchronizer bool) error {
|
||||
if batchNum == 0 {
|
||||
l.idx = 0
|
||||
return nil
|
||||
|
||||
@@ -193,13 +193,13 @@ func TestCheckpoints(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, common.BatchNum(4), cb)
|
||||
|
||||
err = sdb.DeleteCheckpoint(uint64(9))
|
||||
err = sdb.DeleteCheckpoint(common.BatchNum(9))
|
||||
assert.Nil(t, err)
|
||||
err = sdb.DeleteCheckpoint(uint64(10))
|
||||
err = sdb.DeleteCheckpoint(common.BatchNum(10))
|
||||
assert.Nil(t, err)
|
||||
err = sdb.DeleteCheckpoint(uint64(9)) // does not exist, should return err
|
||||
err = sdb.DeleteCheckpoint(common.BatchNum(9)) // does not exist, should return err
|
||||
assert.NotNil(t, err)
|
||||
err = sdb.DeleteCheckpoint(uint64(11)) // does not exist, should return err
|
||||
err = sdb.DeleteCheckpoint(common.BatchNum(11)) // does not exist, should return err
|
||||
assert.NotNil(t, err)
|
||||
|
||||
// Create a LocalStateDB from the initial StateDB
|
||||
|
||||
@@ -13,20 +13,12 @@ import (
|
||||
// keyidx is used as key in the db to store the current Idx
|
||||
var keyidx = []byte("idx")
|
||||
|
||||
// FUTURE This will be used from common once pending PR is merged
|
||||
type ExitInfo struct {
|
||||
Idx *common.Idx
|
||||
Proof *merkletree.CircomVerifierProof
|
||||
Nullifier *big.Int
|
||||
Balance *big.Int
|
||||
}
|
||||
|
||||
// ProcessTxs process the given L1Txs & L2Txs applying the needed updates to
|
||||
// the StateDB depending on the transaction Type. Returns the common.ZKInputs
|
||||
// to generate the SnarkProof later used by the BatchBuilder, and if
|
||||
// cmpExitTree is set to true, returns common.ExitTreeLeaf that is later used
|
||||
// by the Synchronizer to update the HistoryDB.
|
||||
func (s *StateDB) ProcessTxs(cmpExitTree bool, l1usertxs, l1coordinatortxs []*common.L1Tx, l2txs []*common.L2Tx) (*common.ZKInputs, []*ExitInfo, error) {
|
||||
func (s *StateDB) ProcessTxs(cmpExitTree bool, l1usertxs, l1coordinatortxs []*common.L1Tx, l2txs []*common.L2Tx) (*common.ZKInputs, []*common.ExitInfo, error) {
|
||||
var err error
|
||||
var exitTree *merkletree.MerkleTree
|
||||
exits := make(map[common.Idx]common.Account)
|
||||
@@ -71,8 +63,8 @@ func (s *StateDB) ProcessTxs(cmpExitTree bool, l1usertxs, l1coordinatortxs []*co
|
||||
}
|
||||
|
||||
// once all txs processed (exitTree root frozen), for each leaf
|
||||
// generate ExitInfo data
|
||||
var exitInfos []*ExitInfo
|
||||
// generate common.ExitInfo data
|
||||
var exitInfos []*common.ExitInfo
|
||||
for exitIdx, exitAccount := range exits {
|
||||
// 0. generate MerkleProof
|
||||
p, err := exitTree.GenerateCircomVerifierProof(exitIdx.BigInt(), nil)
|
||||
@@ -92,12 +84,12 @@ func (s *StateDB) ProcessTxs(cmpExitTree bool, l1usertxs, l1coordinatortxs []*co
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
// 2. generate ExitInfo
|
||||
ei := &ExitInfo{
|
||||
Idx: &exitIdx,
|
||||
Proof: p,
|
||||
Nullifier: nullifier,
|
||||
Balance: exitAccount.Balance,
|
||||
// 2. generate common.ExitInfo
|
||||
ei := &common.ExitInfo{
|
||||
AccountIdx: exitIdx,
|
||||
MerkleProof: p,
|
||||
Nullifier: nullifier,
|
||||
Balance: exitAccount.Balance,
|
||||
}
|
||||
exitInfos = append(exitInfos, ei)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user