mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
TxSel integrated with L2DB, Add L1CoordTx creation
- GetL2TxSelection & GetL1L2TxSelection integrated with dbs - Create L1CoordinatorTx of type CreateAccountDeposit when a L2 requires it (and the AccountCreationAuth exists)
This commit is contained in:
@@ -65,6 +65,12 @@ func NewL2DB(
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DB returns a pointer to the L2DB.db. This method should be used only for
|
||||
// internal testing purposes.
|
||||
func (l2db *L2DB) DB() *sqlx.DB {
|
||||
return l2db.db
|
||||
}
|
||||
|
||||
// AddTx inserts a tx into the L2DB
|
||||
func (l2db *L2DB) AddTx(tx *common.PoolL2Tx) error {
|
||||
return meddler.Insert(l2db.db, "tx_pool", tx)
|
||||
|
||||
@@ -64,9 +64,11 @@ func (s *StateDB) ProcessTxs(cmpExitTree, cmpZKInputs bool, l1usertxs, l1coordin
|
||||
|
||||
// TBD if ExitTree is only in memory or stored in disk, for the moment
|
||||
// only needed in memory
|
||||
exitTree, err = merkletree.NewMerkleTree(memory.NewMemoryStorage(), s.mt.MaxLevels())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
if cmpExitTree {
|
||||
exitTree, err = merkletree.NewMerkleTree(memory.NewMemoryStorage(), s.mt.MaxLevels())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// assumption: l1usertx are sorted by L1Tx.Position
|
||||
@@ -333,12 +335,12 @@ func (s *StateDB) processL2Tx(exitTree *merkletree.MerkleTree, tx *common.PoolL2
|
||||
// Idx not set in the Tx, get it from DB through ToEthAddr or ToBJJ
|
||||
var idx common.Idx
|
||||
if !bytes.Equal(tx.ToEthAddr.Bytes(), ffAddr.Bytes()) {
|
||||
idx = s.getIdxByEthAddr(tx.ToEthAddr)
|
||||
idx = s.GetIdxByEthAddr(tx.ToEthAddr)
|
||||
if idx == common.Idx(0) {
|
||||
return nil, nil, false, fmt.Errorf("Idx can not be found for given tx.FromEthAddr")
|
||||
}
|
||||
} else {
|
||||
idx = s.getIdxByBJJ(tx.ToBJJ)
|
||||
idx = s.GetIdxByBJJ(tx.ToBJJ)
|
||||
if idx == common.Idx(0) {
|
||||
return nil, nil, false, fmt.Errorf("Idx can not be found for given tx.FromBJJ")
|
||||
}
|
||||
@@ -629,6 +631,9 @@ func (s *StateDB) applyExit(exitTree *merkletree.MerkleTree, tx *common.Tx) (*co
|
||||
s.zki.Siblings1[s.i] = siblingsToZKInputFormat(p.Siblings)
|
||||
}
|
||||
|
||||
if exitTree == nil {
|
||||
return nil, false, nil
|
||||
}
|
||||
exitAccount, err := getAccountInTreeDB(exitTree.DB(), tx.FromIdx)
|
||||
if err == db.ErrNotFound {
|
||||
// 1a. if idx does not exist in exitTree:
|
||||
|
||||
@@ -9,13 +9,27 @@ import (
|
||||
"github.com/iden3/go-merkletree"
|
||||
)
|
||||
|
||||
// TODO
|
||||
func (s *StateDB) getIdxByEthAddr(addr ethCommon.Address) common.Idx {
|
||||
// GetIdxByEthAddr returns the smallest Idx in the StateDB for the given
|
||||
// Ethereum Address. Will return 0 in case that Idx is not found in the
|
||||
// StateDB.
|
||||
func (s *StateDB) GetIdxByEthAddr(addr ethCommon.Address) common.Idx {
|
||||
// TODO
|
||||
return common.Idx(0)
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (s *StateDB) getIdxByBJJ(pk *babyjub.PublicKey) common.Idx {
|
||||
// GetIdxByBJJ returns the smallest Idx in the StateDB for the given BabyJubJub
|
||||
// PublicKey. Will return 0 in case that Idx is not found in the StateDB.
|
||||
func (s *StateDB) GetIdxByBJJ(pk *babyjub.PublicKey) common.Idx {
|
||||
// TODO
|
||||
return common.Idx(0)
|
||||
}
|
||||
|
||||
// GetIdxByEthAddrBJJ returns the smallest Idx in the StateDB for the given
|
||||
// Ethereum Address AND the given BabyJubJub PublicKey. If `addr` is the zero
|
||||
// address, it's ignored in the query. If `pk` is nil, it's ignored in the
|
||||
// query. Will return 0 in case that Idx is not found in the StateDB.
|
||||
func (s *StateDB) GetIdxByEthAddrBJJ(addr ethCommon.Address, pk *babyjub.PublicKey) common.Idx {
|
||||
// TODO
|
||||
return common.Idx(0)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user