mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-08 03:46:52 +01:00
Unify StateDB MT{Create/Update}Account
Previously as the txprocessor.go methods were specific for the BatchBuilder, the MTCreateAccount & CreateAccount and MTUpdateAccount & UpdateAccount were also designed to be used by BatchBuilder and TxSelector depending on the MerkleTree usage calling one kind of method or anotherone. But now that this methods are being called directly by the StateDB (through the methods in txprocessors.go), to allow also the methods usage from the Synchronizer, there can not be the MT and no-MT methods separated, so this commit unifies MTCreateAccount with CreateAccount, and MTUpdateAccount with UpdateAccount, which internally will update the MerkleTree depending if the specific StateDB in usage has the MerkleTree defined or not.
This commit is contained in:
@@ -89,7 +89,7 @@ func (s *StateDB) applyCreateAccount(tx *common.L1Tx) error {
|
||||
EthAddr: tx.FromEthAddr,
|
||||
}
|
||||
|
||||
err := s.CreateAccount(common.Idx(s.idx+1), account)
|
||||
_, err := s.CreateAccount(common.Idx(s.idx+1), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -120,13 +120,13 @@ func (s *StateDB) applyDeposit(tx *common.L1Tx, transfer bool) error {
|
||||
// add amount to the receiver
|
||||
accReceiver.Balance = new(big.Int).Add(accReceiver.Balance, tx.Amount)
|
||||
// update receiver account in localStateDB
|
||||
err = s.UpdateAccount(tx.ToIdx, accReceiver)
|
||||
_, err = s.UpdateAccount(tx.ToIdx, accReceiver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// update sender account in localStateDB
|
||||
err = s.UpdateAccount(tx.FromIdx, accSender)
|
||||
_, err = s.UpdateAccount(tx.FromIdx, accSender)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -146,18 +146,21 @@ func (s *StateDB) applyTransfer(tx *common.Tx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// increment nonce
|
||||
accSender.Nonce++
|
||||
|
||||
// substract amount to the sender
|
||||
accSender.Balance = new(big.Int).Sub(accSender.Balance, tx.Amount)
|
||||
// add amount to the receiver
|
||||
accReceiver.Balance = new(big.Int).Add(accReceiver.Balance, tx.Amount)
|
||||
|
||||
// update receiver account in localStateDB
|
||||
err = s.UpdateAccount(tx.ToIdx, accReceiver)
|
||||
_, err = s.UpdateAccount(tx.ToIdx, accReceiver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// update sender account in localStateDB
|
||||
err = s.UpdateAccount(tx.FromIdx, accSender)
|
||||
_, err = s.UpdateAccount(tx.FromIdx, accSender)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user