Idx to 6 bytes (48 bits)

This commit is contained in:
arnaucube
2020-09-22 16:24:40 +02:00
parent c0336f485f
commit 06703aecad
11 changed files with 172 additions and 111 deletions

View File

@@ -235,7 +235,11 @@ func (s *StateDB) GetAccount(idx common.Idx) (*common.Account, error) {
// getAccountInTreeDB is abstracted from StateDB to be used from StateDB and
// from ExitTree. GetAccount returns the account for the given Idx
func getAccountInTreeDB(sto db.Storage, idx common.Idx) (*common.Account, error) {
vBytes, err := sto.Get(idx.Bytes())
idxBytes, err := idx.Bytes()
if err != nil {
return nil, err
}
vBytes, err := sto.Get(idxBytes[:])
if err != nil {
return nil, err
}
@@ -282,7 +286,11 @@ func createAccountInTreeDB(sto db.Storage, mt *merkletree.MerkleTree, idx common
return nil, err
}
_, err = tx.Get(idx.Bytes())
idxBytes, err := idx.Bytes()
if err != nil {
return nil, err
}
_, err = tx.Get(idxBytes[:])
if err != db.ErrNotFound {
return nil, ErrAccountAlreadyExists
}
@@ -291,7 +299,7 @@ func createAccountInTreeDB(sto db.Storage, mt *merkletree.MerkleTree, idx common
if err != nil {
return nil, err
}
err = tx.Put(idx.Bytes(), v.Bytes())
err = tx.Put(idxBytes[:], v.Bytes())
if err != nil {
return nil, err
}
@@ -337,7 +345,11 @@ func updateAccountInTreeDB(sto db.Storage, mt *merkletree.MerkleTree, idx common
if err != nil {
return nil, err
}
err = tx.Put(idx.Bytes(), v.Bytes())
idxBytes, err := idx.Bytes()
if err != nil {
return nil, err
}
err = tx.Put(idxBytes[:], v.Bytes())
if err != nil {
return nil, err
}

View File

@@ -678,7 +678,11 @@ func (s *StateDB) setIdx(idx common.Idx) error {
if err != nil {
return err
}
err = tx.Put(keyidx, idx.Bytes())
idxBytes, err := idx.Bytes()
if err != nil {
return err
}
err = tx.Put(keyidx, idxBytes[:])
if err != nil {
return err
}

View File

@@ -46,12 +46,16 @@ func (s *StateDB) setIdxByEthAddrBJJ(idx common.Idx, addr ethCommon.Address, pk
}
k := concatEthAddrBJJ(addr, pk)
// store Addr&BJJ-idx
err = tx.Put(k, idx.Bytes())
idxBytes, err := idx.Bytes()
if err != nil {
return err
}
err = tx.Put(k, idxBytes[:])
if err != nil {
return err
}
// store Addr-idx
err = tx.Put(addr.Bytes(), idx.Bytes())
err = tx.Put(addr.Bytes(), idxBytes[:])
if err != nil {
return err
}