Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d58db5d
define StorageProvider interface
haikoschol May 29, 2025
8738a48
implement StorageProvider on ClientAdapter
haikoschol May 29, 2025
0adb5c9
implement read-only StorageState methods on ClientAdapter
haikoschol May 29, 2025
9dda3ce
lint
haikoschol Jun 12, 2025
a05706a
Merge branch 'development' into haiko/read-only-storage-state
haikoschol Jun 12, 2025
a5dd729
Merge branch 'development' into haiko/read-only-storage-state
haikoschol Jun 18, 2025
ad9e065
address some review feedback
haikoschol Jun 18, 2025
80028fa
correctly set IterArgs.StartAtExclusive
haikoschol Jun 18, 2025
9ddac63
Merge branch 'development' into haiko/read-only-storage-state
haikoschol Jun 20, 2025
c3e7a71
use updated TrieLayout types/API
haikoschol Jun 20, 2025
2cd321d
use storage.StorageKey instead of statemachine.StorageKey in StorageP…
haikoschol Jun 20, 2025
37dd38d
use local KeysIter/PairsIter in StorageProvider
haikoschol Jun 20, 2025
2b5ef15
remove unused methods from BlockState and ClientAdapter
haikoschol Jun 20, 2025
ec5f7d0
move StorageProvider impl from ClientAdapter to Client
haikoschol Jun 20, 2025
545acd8
Merge branch 'development' into haiko/read-only-storage-state
haikoschol Jun 21, 2025
d05af3e
remove another unused method from BlockState
haikoschol Jun 21, 2025
5b016e5
implement ClientAdapter.Leaves()
haikoschol Jun 21, 2025
e6f4a0e
implement ClientAdapter.TrieState()
haikoschol Jun 21, 2025
2196b5d
Revert "remove another unused method from BlockState"
haikoschol Jun 21, 2025
c9c2bb0
maybe fix mock
haikoschol Jun 21, 2025
9aa715c
more mock fixery
haikoschol Jun 21, 2025
96a0c2e
update a bazillion BlockState mocks
haikoschol Jun 21, 2025
9ee8088
WIP GenerateTrieProof()
haikoschol Jun 25, 2025
65615ce
use statemachine.KeysIter in StorageProvider
haikoschol Jun 26, 2025
3a71c45
fix(state): Change StorageState methods to always expect a block hash…
haikoschol Jul 5, 2025
9026510
update StorageState impl on ClientAdapter
haikoschol Jul 5, 2025
20c6080
Merge branch 'development' into haiko/read-only-storage-state
haikoschol Jul 5, 2025
f7fc05e
remove duplicate StorageProvider definition
haikoschol Jul 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
124 changes: 32 additions & 92 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