From a9401e2ec781bd8c74e813b7c49dd042c6a5e98c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 13 Dec 2019 18:47:45 +0300 Subject: [PATCH] core: do not write new dao elements into DB It's useless work being done before it's actually needed. These (updated with new values) are going to be written with some kind of Put anyway, so writing them here is just a waste of time. --- pkg/core/dao.go | 12 ------------ pkg/core/dao_test.go | 12 ------------ 2 files changed, 24 deletions(-) diff --git a/pkg/core/dao.go b/pkg/core/dao.go index 846847b7d..d570d5e3e 100644 --- a/pkg/core/dao.go +++ b/pkg/core/dao.go @@ -55,9 +55,6 @@ func (dao *dao) GetAccountStateOrNew(hash util.Uint160) (*state.Account, error) return nil, err } account = state.NewAccount(hash) - if err = dao.PutAccountState(account); err != nil { - return nil, err - } } return account, nil } @@ -151,9 +148,6 @@ func (dao *dao) GetUnspentCoinStateOrNew(hash util.Uint256) (*UnspentCoinState, unspent = &UnspentCoinState{ states: []state.Coin{}, } - if err = dao.PutUnspentCoinState(hash, unspent); err != nil { - return nil, err - } } return unspent, nil } @@ -189,9 +183,6 @@ func (dao *dao) GetSpentCoinsOrNew(hash util.Uint256) (*SpentCoinState, error) { spent = &SpentCoinState{ items: make(map[uint16]uint32), } - if err = dao.PutSpentCoinState(hash, spent); err != nil { - return nil, err - } } return spent, nil } @@ -231,9 +222,6 @@ func (dao *dao) GetValidatorStateOrNew(publicKey *keys.PublicKey) (*state.Valida return nil, err } validatorState = &state.Validator{PublicKey: publicKey} - if err = dao.PutValidatorState(validatorState); err != nil { - return nil, err - } } return validatorState, nil diff --git a/pkg/core/dao_test.go b/pkg/core/dao_test.go index e9b3e610e..d747ddf19 100644 --- a/pkg/core/dao_test.go +++ b/pkg/core/dao_test.go @@ -45,9 +45,6 @@ func TestGetAccountStateOrNew_New(t *testing.T) { createdAccount, err := dao.GetAccountStateOrNew(hash) require.NoError(t, err) require.NotNil(t, createdAccount) - gotAccount, err := dao.GetAccountState(hash) - require.NoError(t, err) - require.Equal(t, createdAccount, gotAccount) } func TestPutAndGetAccountStateOrNew(t *testing.T) { @@ -102,9 +99,6 @@ func TestGetUnspentCoinStateOrNew_New(t *testing.T) { unspentCoinState, err := dao.GetUnspentCoinStateOrNew(hash) require.NoError(t, err) require.NotNil(t, unspentCoinState) - gotUnspentCoinState, err := dao.GetUnspentCoinState(hash) - require.NoError(t, err) - require.Equal(t, unspentCoinState, gotUnspentCoinState) } func TestGetUnspentCoinState_Err(t *testing.T) { @@ -132,9 +126,6 @@ func TestGetSpentCoinStateOrNew_New(t *testing.T) { spentCoinState, err := dao.GetSpentCoinsOrNew(hash) require.NoError(t, err) require.NotNil(t, spentCoinState) - gotSpentCoinState, err := dao.GetSpentCoinState(hash) - require.NoError(t, err) - require.Equal(t, spentCoinState, gotSpentCoinState) } func TestPutAndGetSpentCoinState(t *testing.T) { @@ -175,9 +166,6 @@ func TestGetValidatorStateOrNew_New(t *testing.T) { validatorState, err := dao.GetValidatorStateOrNew(publicKey) require.NoError(t, err) require.NotNil(t, validatorState) - gotValidatorState, err := dao.GetValidatorState(publicKey) - require.NoError(t, err) - require.Equal(t, validatorState, gotValidatorState) } func TestPutGetValidatorState(t *testing.T) {