Skip to content
5 changes: 3 additions & 2 deletions dot/core/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ func (s *Service) validateTransaction(head *types.Header, rt runtime.Instance,
tx types.Extrinsic) (validity *transaction.Validity, err error) {
s.storageState.Lock()

ts, err := s.storageState.TrieState(&head.StateRoot)
bhash := head.Hash()
ts, err := s.storageState.TrieState(&bhash)
s.storageState.Unlock()
if err != nil {
return nil, fmt.Errorf("cannot get trie state from storage for root %s: %w", head.StateRoot, err)
return nil, fmt.Errorf("cannot get trie state from storage for block hash %s: %w", bhash.String(), err)
}

rt.SetContextStorage(ts)
Expand Down
11 changes: 6 additions & 5 deletions dot/core/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func TestService_TransactionsCount(t *testing.T) {

func TestServiceHandleTransactionMessage(t *testing.T) {
testEmptyHeader := types.NewEmptyHeader()
headerHash := testEmptyHeader.Hash()
testExtrinsic := []types.Extrinsic{{1, 2, 3}}

ctrl := gomock.NewController(t)
Expand Down Expand Up @@ -222,7 +223,7 @@ func TestServiceHandleTransactionMessage(t *testing.T) {
},
},
mockStorageState: &mockStorageState{
input: &common.Hash{},
input: &headerHash,
err: errDummyErr,
},
args: args{
Expand All @@ -232,8 +233,8 @@ func TestServiceHandleTransactionMessage(t *testing.T) {
},
},
expErr: errDummyErr,
expErrMsg: "validating transaction from peerID D1KeRhQ: cannot get trie state from storage" +
" for root 0x0000000000000000000000000000000000000000000000000000000000000000: dummy error for testing",
expErrMsg: "validating transaction from peerID D1KeRhQ: cannot get trie state from storage for block " +
"hash 0xdcdd89927d8a348e00257e1ecc8617f45edb5118efff3ea2f9961b2ad9b7690a: dummy error for testing",
},
{
name: "runtime.ErrInvalidTransaction",
Expand All @@ -257,7 +258,7 @@ func TestServiceHandleTransactionMessage(t *testing.T) {
callsBestBlockHash: true,
},
mockStorageState: &mockStorageState{
input: &common.Hash{},
input: &headerHash,
trieState: &storage.InMemoryTrieState{},
},
mockRuntime: &mockRuntime{
Expand Down Expand Up @@ -301,7 +302,7 @@ func TestServiceHandleTransactionMessage(t *testing.T) {
callsBestBlockHash: true,
},
mockStorageState: &mockStorageState{
input: &common.Hash{},
input: &headerHash,
trieState: &storage.InMemoryTrieState{},
},
mockTxnState: &mockTxnState{
Expand Down
94 changes: 32 additions & 62 deletions dot/core/mock_state_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 3 additions & 22 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,7 @@ func (s *Service) maintainTransactionPool(block *types.Block, bestBlockHash comm
s.transactionState.RemoveExtrinsic(ext)
}

stateRoot, err := s.storageState.GetStateRootFromBlock(&bestBlockHash)
if err != nil {
logger.Errorf("could not get state root from block %s: %w", bestBlockHash, err)
return err
}

ts, err := s.storageState.TrieState(stateRoot)
ts, err := s.storageState.TrieState(&bestBlockHash)
if err != nil {
logger.Errorf(err.Error())
return err
Expand Down Expand Up @@ -586,12 +580,7 @@ func (s *Service) HandleSubmittedExtrinsic(ext types.Extrinsic) error {

bestBlockHash := s.blockState.BestBlockHash()

stateRoot, err := s.storageState.GetStateRootFromBlock(&bestBlockHash)
if err != nil {
return fmt.Errorf("could not get state root from block %s: %w", bestBlockHash, err)
}

ts, err := s.storageState.TrieState(stateRoot)
ts, err := s.storageState.TrieState(&bestBlockHash)
if err != nil {
return err
}
Expand Down Expand Up @@ -679,15 +668,7 @@ func (s *Service) buildExternalTransaction(rt runtime.Instance, ext types.Extrin

func prepareRuntime(blockHash *common.Hash, storageState state.StorageState,
blockState state.BlockState) (instance runtime.Instance, err error) {
var stateRootHash *common.Hash
if blockHash != nil {
stateRootHash, err = storageState.GetStateRootFromBlock(blockHash)
if err != nil {
return nil, fmt.Errorf("getting state root from block hash: %w", err)
}
}

trieState, err := storageState.TrieState(stateRootHash)
trieState, err := storageState.TrieState(blockHash)
if err != nil {
return nil, fmt.Errorf("getting trie state: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions dot/core/service_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,8 @@ func TestService_HandleRuntimeChanges(t *testing.T) {
require.NoError(t, err)

genesisBlockHash := genesisHeader.Hash()
genesisStateRoot := genesisHeader.StateRoot

ts, err := s.storageState.TrieState(&genesisStateRoot) // Pass genesis root
ts, err := s.storageState.TrieState(&genesisBlockHash)
require.NoError(t, err)

firstBlockHash := createBlockUsingOldRuntime(t, genesisBlockHash, ts, s.blockState)
Expand Down
Loading
Loading