From 9836fde68031e311dffc231b56bc444d8371dc4a Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Wed, 4 Sep 2024 15:35:48 +0300 Subject: [PATCH] fixes after review --- epochStart/metachain/systemSCs_test.go | 2 +- factory/processing/blockProcessorCreator_test.go | 2 +- process/transaction/shardProcess.go | 1 + state/accountsDB.go | 7 ++++--- state/accountsDBApi.go | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index d203a2c1075..4d2b5d466a7 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -764,7 +764,7 @@ func createAccountsDB( StoragePruningManager: spm, AddressConverter: &testscommon.PubkeyConverterMock{}, SnapshotsManager: disabledState.NewDisabledSnapshotsManager(), - StateChangesCollector: state.NewStateChangesCollector(), + StateChangesCollector: disabledState.NewDisabledStateChangesCollector(), } adb, _ := state.NewAccountsDB(args) return adb diff --git a/factory/processing/blockProcessorCreator_test.go b/factory/processing/blockProcessorCreator_test.go index 92941e4778e..938e1f65ac1 100644 --- a/factory/processing/blockProcessorCreator_test.go +++ b/factory/processing/blockProcessorCreator_test.go @@ -208,7 +208,7 @@ func createAccountAdapter( StoragePruningManager: disabled.NewDisabledStoragePruningManager(), AddressConverter: &testscommon.PubkeyConverterMock{}, SnapshotsManager: disabledState.NewDisabledSnapshotsManager(), - StateChangesCollector: state.NewStateChangesCollector(), + StateChangesCollector: disabledState.NewDisabledStateChangesCollector(), } adb, err := state.NewAccountsDB(args) if err != nil { diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 43c5b4878bf..a3242861f92 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -195,6 +195,7 @@ func (txProc *txProcessor) ProcessTransaction(tx *transaction.Transaction) (vmco txProc.pubkeyConv, ) + // TODO refactor to set the tx hash for the following state changes before the processing occurs defer txProc.accounts.SetTxHashForLatestStateChanges(txHash) txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(tx) diff --git a/state/accountsDB.go b/state/accountsDB.go index ce450bdcb95..fe92920e383 100644 --- a/state/accountsDB.go +++ b/state/accountsDB.go @@ -280,7 +280,7 @@ func (adb *AccountsDB) SaveAccount(account vmcommon.AccountHandler) error { } adb.stateChangesCollector.AddStateChange(stateChange) - return err + return nil } func (adb *AccountsDB) saveCodeAndDataTrie(oldAcc, newAcc vmcommon.AccountHandler) ([]DataTrieChange, error) { @@ -288,7 +288,7 @@ func (adb *AccountsDB) saveCodeAndDataTrie(oldAcc, newAcc vmcommon.AccountHandle baseOldAccount, _ := oldAcc.(baseAccountHandler) if !newAccOk { - return make([]DataTrieChange, 0), nil + return nil, nil } newValues, err := adb.saveDataTrie(baseNewAcc) @@ -301,7 +301,7 @@ func (adb *AccountsDB) saveCodeAndDataTrie(oldAcc, newAcc vmcommon.AccountHandle return nil, err } - return newValues, err + return newValues, nil } func (adb *AccountsDB) saveCode(newAcc, oldAcc baseAccountHandler) error { @@ -384,6 +384,7 @@ func (adb *AccountsDB) updateOldCodeEntry(oldCodeHash []byte) (*CodeEntry, error return nil, err } + // TODO refactor this after remove code leaf is merged stateChange := StateChangeDTO{ MainTrieKey: oldCodeHash, MainTrieVal: codeEntryBytes, diff --git a/state/accountsDBApi.go b/state/accountsDBApi.go index 2d07d99e818..b548901f167 100644 --- a/state/accountsDBApi.go +++ b/state/accountsDBApi.go @@ -244,7 +244,7 @@ func (accountsDB *accountsDBApi) SetTxHashForLatestStateChanges(txHash []byte) { // ResetStateChangesCollector returns nil func (accountsDB *accountsDBApi) ResetStateChangesCollector() []StateChangesForTx { - return nil + return accountsDB.innerAccountsAdapter.ResetStateChangesCollector() } // Close will handle the closing of the underlying components