Skip to content

Commit

Permalink
fix(runtime/storage): support nested storage transactions (#3670)
Browse files Browse the repository at this point in the history
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Kirill <[email protected]>
Co-authored-by: Diego Romero <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Jan 15, 2024
1 parent f7e690f commit 3e99f6d
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 163 deletions.
16 changes: 8 additions & 8 deletions dot/core/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func generateExtrinsic(t *testing.T) (extrinsic, externalExtrinsic types.Extrins
func Test_Service_StorageRoot(t *testing.T) {
t.Parallel()

ts := rtstorage.NewTrieState(nil)
ts := rtstorage.NewTrieState(trie.NewEmptyTrie())

tests := []struct {
name string
Expand Down Expand Up @@ -378,7 +378,7 @@ func Test_Service_handleBlock(t *testing.T) {

t.Run("storeTrie_error", func(t *testing.T) {
t.Parallel()
trieState := rtstorage.NewTrieState(nil)
trieState := rtstorage.NewTrieState(trie.NewEmptyTrie())

testHeader := types.NewEmptyHeader()
block := types.NewBlock(*testHeader, *types.NewBody([]types.Extrinsic{[]byte{21}}))
Expand All @@ -394,7 +394,7 @@ func Test_Service_handleBlock(t *testing.T) {

t.Run("addBlock_quit_error", func(t *testing.T) {
t.Parallel()
trieState := rtstorage.NewTrieState(nil)
trieState := rtstorage.NewTrieState(trie.NewEmptyTrie())

testHeader := types.NewEmptyHeader()
block := types.NewBlock(*testHeader, *types.NewBody([]types.Extrinsic{[]byte{21}}))
Expand All @@ -415,7 +415,7 @@ func Test_Service_handleBlock(t *testing.T) {

t.Run("addBlock_parent_not_found_error", func(t *testing.T) {
t.Parallel()
trieState := rtstorage.NewTrieState(nil)
trieState := rtstorage.NewTrieState(trie.NewEmptyTrie())

testHeader := types.NewEmptyHeader()
block := types.NewBlock(*testHeader, *types.NewBody([]types.Extrinsic{[]byte{21}}))
Expand All @@ -436,7 +436,7 @@ func Test_Service_handleBlock(t *testing.T) {

t.Run("addBlock_error_continue", func(t *testing.T) {
t.Parallel()
trieState := rtstorage.NewTrieState(nil)
trieState := rtstorage.NewTrieState(trie.NewEmptyTrie())

testHeader := types.NewEmptyHeader()
block := types.NewBlock(*testHeader, *types.NewBody([]types.Extrinsic{[]byte{21}}))
Expand Down Expand Up @@ -465,7 +465,7 @@ func Test_Service_handleBlock(t *testing.T) {

t.Run("handle_runtime_changes_error", func(t *testing.T) {
t.Parallel()
trieState := rtstorage.NewTrieState(nil)
trieState := rtstorage.NewTrieState(trie.NewEmptyTrie())

testHeader := types.NewEmptyHeader()
block := types.NewBlock(*testHeader, *types.NewBody([]types.Extrinsic{[]byte{21}}))
Expand Down Expand Up @@ -497,7 +497,7 @@ func Test_Service_handleBlock(t *testing.T) {

t.Run("code_substitution_ok", func(t *testing.T) {
t.Parallel()
trieState := rtstorage.NewTrieState(nil)
trieState := rtstorage.NewTrieState(trie.NewEmptyTrie())

testHeader := types.NewEmptyHeader()
block := types.NewBlock(*testHeader, *types.NewBody([]types.Extrinsic{[]byte{21}}))
Expand Down Expand Up @@ -544,7 +544,7 @@ func Test_Service_HandleBlockProduced(t *testing.T) {

t.Run("happy_path", func(t *testing.T) {
t.Parallel()
trieState := rtstorage.NewTrieState(nil)
trieState := rtstorage.NewTrieState(trie.NewEmptyTrie())

digest := types.NewDigest()
err := digest.Add(
Expand Down
8 changes: 4 additions & 4 deletions dot/sync/chain_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func Test_chainSync_onBlockAnnounce(t *testing.T) {
const somePeer = peer.ID("abc")

errTest := errors.New("test error")
emptyTrieState := storage.NewTrieState(nil)
emptyTrieState := storage.NewTrieState(trie.NewEmptyTrie())
block1AnnounceHeader := types.NewHeader(common.Hash{}, emptyTrieState.MustRoot(trie.NoMaxInlineValueSize),
common.Hash{}, 1, scale.VaryingDataTypeSlice{})
block2AnnounceHeader := types.NewHeader(block1AnnounceHeader.Hash(),
Expand Down Expand Up @@ -242,7 +242,7 @@ func Test_chainSync_onBlockAnnounceHandshake_tipModeNeedToCatchup(t *testing.T)
ctrl := gomock.NewController(t)
const somePeer = peer.ID("abc")

emptyTrieState := storage.NewTrieState(nil)
emptyTrieState := storage.NewTrieState(trie.NewEmptyTrie())
block1AnnounceHeader := types.NewHeader(common.Hash{}, emptyTrieState.MustRoot(trie.NoMaxInlineValueSize),
common.Hash{}, 1, scale.VaryingDataTypeSlice{})
block2AnnounceHeader := types.NewHeader(block1AnnounceHeader.Hash(),
Expand Down Expand Up @@ -1250,7 +1250,7 @@ func createSuccesfullBlockResponse(t *testing.T, parentHeader common.Hash,
response := new(network.BlockResponseMessage)
response.BlockData = make([]*types.BlockData, numBlocks)

emptyTrieState := storage.NewTrieState(nil)
emptyTrieState := storage.NewTrieState(trie.NewEmptyTrie())
tsRoot := emptyTrieState.MustRoot(trie.NoMaxInlineValueSize)

firstHeader := types.NewHeader(parentHeader, tsRoot, common.Hash{},
Expand Down Expand Up @@ -1303,7 +1303,7 @@ func ensureSuccessfulBlockImportFlow(t *testing.T, parentHeader *types.Header,
mockStorageState.EXPECT().Lock()
mockStorageState.EXPECT().Unlock()

emptyTrieState := storage.NewTrieState(nil)
emptyTrieState := storage.NewTrieState(trie.NewEmptyTrie())
parentStateRoot := previousHeader.StateRoot
mockStorageState.EXPECT().TrieState(&parentStateRoot).
Return(emptyTrieState, nil)
Expand Down
6 changes: 3 additions & 3 deletions lib/runtime/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ type Storage interface {
ClearPrefix(prefix []byte) (err error)
ClearPrefixLimit(prefix []byte, limit uint32) (
deleted uint32, allDeleted bool, err error)
BeginStorageTransaction()
CommitStorageTransaction()
RollbackStorageTransaction()
StartTransaction()
CommitTransaction()
RollbackTransaction()
LoadCode() []byte
}

Expand Down
Loading

0 comments on commit 3e99f6d

Please sign in to comment.