Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
76767e9
feat(trie): Add v2 runtime functions
dimartiro Aug 8, 2023
155cc4b
Merge branch 'development' into diego/trieV1/runtime-functions
dimartiro Aug 9, 2023
f4ad738
chore(trie): version trie functions
dimartiro Aug 10, 2023
b0a36cc
Update tests
dimartiro Aug 10, 2023
3293693
Fix lint errors
dimartiro Aug 10, 2023
634f315
Fix deepsource checks
dimartiro Aug 10, 2023
1015ece
Revisit TODOs
dimartiro Aug 15, 2023
9d828c7
Add more tests
dimartiro Aug 15, 2023
b09f7a5
Fix linter
dimartiro Aug 15, 2023
8c8ed40
Merge remote-tracking branch 'origin/development' into diego/trieV1/v…
dimartiro Aug 15, 2023
5d25644
Fix linter
dimartiro Aug 15, 2023
a625bc4
Get hashed values
dimartiro Aug 16, 2023
40fccff
Check memory db put value error
dimartiro Aug 16, 2023
59107ce
Add memory db lock
dimartiro Aug 16, 2023
ce73de2
Fix linter
dimartiro Aug 16, 2023
e0dd691
Deepsource
dimartiro Aug 16, 2023
7e16064
Add default version
dimartiro Aug 16, 2023
61f0d8d
Fix doc
dimartiro Aug 16, 2023
7974017
Add test to cover case for #2329
dimartiro Aug 16, 2023
494a85b
Fix linter
dimartiro Aug 16, 2023
2703b93
chore(trie): version trie functions
dimartiro Aug 10, 2023
00d4231
Update tests
dimartiro Aug 10, 2023
447ccf5
Fix lint errors
dimartiro Aug 10, 2023
752ce6d
Fix deepsource checks
dimartiro Aug 10, 2023
0514501
Revisit TODOs
dimartiro Aug 15, 2023
a0b8dc1
Add more tests
dimartiro Aug 15, 2023
db45755
Fix linter
dimartiro Aug 15, 2023
5719b28
fix(dot/sync): rework on bootstrap/tip sync (#3227)
EclesioMeloJunior Aug 11, 2023
ae86ad0
chore(deps): bump github.com/multiformats/go-multiaddr from 0.10.1 to…
dependabot[bot] Aug 14, 2023
7046c94
chore(deps): bump github.com/go-playground/validator/v10 from 10.14.1…
dependabot[bot] Aug 15, 2023
9dc3af5
chore(deps): bump github.com/ethereum/go-ethereum from 1.12.0 to 1.12…
dependabot[bot] Aug 15, 2023
970e6aa
chore(deepsource): address Deepsource suggestions (#3436)
EclesioMeloJunior Aug 15, 2023
2ebf184
Fix linter
dimartiro Aug 15, 2023
1761922
Get hashed values
dimartiro Aug 16, 2023
7b4b6d1
Check memory db put value error
dimartiro Aug 16, 2023
5ec4460
Add memory db lock
dimartiro Aug 16, 2023
8d70d77
Fix linter
dimartiro Aug 16, 2023
461596e
Deepsource
dimartiro Aug 16, 2023
c9b42e9
Add default version
dimartiro Aug 16, 2023
503fc27
Fix doc
dimartiro Aug 16, 2023
3f6cdcc
Add test to cover case for #2329
dimartiro Aug 16, 2023
0c5f542
Fix linter
dimartiro Aug 16, 2023
3e3878a
Use state version param in runtime functions
dimartiro Aug 16, 2023
45394d7
Merge branch 'diego/trieV1/versioning' into diego/trieV1/runtime-func…
dimartiro Aug 16, 2023
4f8d81c
PR comments
dimartiro Aug 16, 2023
1b5c0d3
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Aug 16, 2023
2da48d7
Fix merge
dimartiro Aug 16, 2023
c0bda83
Merge branch 'diego/trieV1/versioning' into diego/trieV1/runtime-func…
dimartiro Aug 16, 2023
264ca68
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Aug 17, 2023
7e1e42f
Fix merge
dimartiro Aug 17, 2023
644dc20
Version child tries functions
dimartiro Aug 17, 2023
99626a3
Improve version test cover
dimartiro Aug 22, 2023
376a97e
Remove unused function
dimartiro Aug 22, 2023
130e9bb
Refactor tests
dimartiro Aug 22, 2023
15770b4
Add child storage tests
dimartiro Aug 22, 2023
f00678c
Add more tests to increase coverage
dimartiro Aug 23, 2023
8834add
Fix linters
dimartiro Aug 23, 2023
265c747
Merge branch 'diego/trieV1/versioning' into diego/trieV1/runtime-func…
dimartiro Aug 23, 2023
d4e2ac6
PR comments
dimartiro Aug 23, 2023
024965a
Increase coverage in child storage tests
dimartiro Aug 23, 2023
4f87801
Remove unused functions
dimartiro Aug 23, 2023
bc167e2
Merge branch 'diego/trieV1/versioning' of https://github.com/ChainSaf…
dimartiro Aug 23, 2023
84541d8
Removes todos and skip validations for unused params
dimartiro Aug 24, 2023
884a2ae
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Aug 28, 2023
b765f73
Merge branch 'diego/trieV1/versioning' into diego/trieV1/runtime-func…
dimartiro Aug 28, 2023
793d80c
Add new runtime functions tests
dimartiro Aug 28, 2023
4139160
Improve largest lines to not ignore linter
dimartiro Aug 29, 2023
d02b3d3
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Aug 30, 2023
19ffee8
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Aug 31, 2023
cfcb324
Fix trie snapshot creation copying internal db
dimartiro Sep 1, 2023
3da0d32
Fix DBGetter mock
dimartiro Sep 1, 2023
919468c
Remove comments
dimartiro Sep 4, 2023
b94c622
Fix get version in runtime functions
dimartiro Sep 5, 2023
c088287
Merge branch 'diego/trieV1/versioning' of https://github.com/ChainSaf…
dimartiro Sep 7, 2023
55c51b2
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Sep 7, 2023
19fd637
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Sep 7, 2023
48ccf91
Fix merge
dimartiro Sep 7, 2023
f695530
Improve version parsing and simplify checks
dimartiro Sep 8, 2023
31413a4
lint
dimartiro Sep 8, 2023
fd95c86
Merge branch 'diego/trieV1/versioning' into diego/trieV1/runtime-func…
dimartiro Sep 8, 2023
215d4b3
PR comments
dimartiro Sep 8, 2023
a5a10c4
Add comment
dimartiro Sep 8, 2023
bb1a1c4
Fixes
dimartiro Sep 8, 2023
0043e31
Rollback runtime constants changes
dimartiro Sep 8, 2023
28ee3c9
Remove unused version parse switch case
dimartiro Sep 8, 2023
a8f1d23
Change panic to test fail
dimartiro Sep 8, 2023
da95dd7
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Sep 12, 2023
39c3923
Use sharing db in trie
dimartiro Sep 12, 2023
c481b6a
Fix mocks
dimartiro Sep 12, 2023
8ac581c
Remove old in memory db implementation and replace it to pebble
dimartiro Sep 12, 2023
50f52de
Fix lint
dimartiro Sep 12, 2023
191ff3e
Fix fuzz test
dimartiro Sep 12, 2023
22b4216
Remove value nodes from db when hashed node is deleted
dimartiro Sep 13, 2023
ab2ee18
Merge branch 'diego/trieV1/versioning' of https://github.com/ChainSaf…
dimartiro Sep 13, 2023
8d7c6b6
Add comments
dimartiro Sep 13, 2023
233c2f2
Merge branch 'diego/trieV1/versioning' of https://github.com/ChainSaf…
dimartiro Sep 13, 2023
f32c939
Return empty array instead 0
dimartiro Sep 13, 2023
8e076bb
Fix return zero value
dimartiro Sep 13, 2023
c187943
Revert using pebble as in memory db for tries
dimartiro Sep 13, 2023
ce04c1f
Merge branch 'diego/trieV1/versioning' of https://github.com/ChainSaf…
dimartiro Sep 13, 2023
97ce272
Add more test cases
dimartiro Sep 14, 2023
16ea637
Merge branch 'diego/trieV1/runtime-functions' of https://github.com/C…
dimartiro Sep 14, 2023
26f3eb5
Fix documentations
dimartiro Sep 14, 2023
bf28117
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Sep 25, 2023
dfefbbf
Fix ClearChildStorage with versioning
dimartiro Sep 29, 2023
5f2ad5d
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Sep 29, 2023
1dbf91b
Fix tests
dimartiro Sep 29, 2023
436100c
Add todo reminder
dimartiro Oct 2, 2023
c2bdf2f
Fix merge trie nodes preserve isHashed property
dimartiro Oct 2, 2023
242bba6
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Oct 2, 2023
18c6a22
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Oct 3, 2023
6e1e612
Simplify runtime functions reusing v2 in v1
dimartiro Oct 3, 2023
1096a93
Reuse new root from entries function in ext_ordered_root
dimartiro Oct 3, 2023
4d6434a
Add tests for new root function
dimartiro Oct 3, 2023
d8df35e
Fix lint lll
dimartiro Oct 3, 2023
8c92fbb
Improve trie versions functions
dimartiro Oct 3, 2023
02928a0
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Oct 4, 2023
784f96e
Fix test
dimartiro Oct 4, 2023
f5a67b9
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Oct 8, 2023
a276576
PR comments
dimartiro Oct 8, 2023
0915077
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Oct 31, 2023
8cf3b4a
PR review comments
dimartiro Nov 6, 2023
a9a25e9
Add godoc for exported method and consts
dimartiro Nov 6, 2023
487e1ea
Do not store hashed values
dimartiro Nov 7, 2023
f0478c2
Remove DB
dimartiro Nov 7, 2023
b04de53
Use trie version to calculate hash only
dimartiro Nov 7, 2023
a16d3de
Fix import state command
dimartiro Nov 7, 2023
eda5f6c
Use default state version in helpers test
dimartiro Nov 7, 2023
3ec5be3
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Nov 7, 2023
a3db05c
Use default state version in helpers test
dimartiro Nov 7, 2023
50f9616
Revert import integration tests change
dimartiro Nov 7, 2023
ffa7157
Lint
dimartiro Nov 7, 2023
9ba1bee
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Nov 13, 2023
c72deb8
Change default version to 0
dimartiro Nov 13, 2023
93c29f7
Fix Test_newTrieFromPairs
dimartiro Nov 13, 2023
9f66a11
Add one more test case
dimartiro Nov 13, 2023
a47970a
Fix version test
dimartiro Nov 13, 2023
2970674
Fix deepsource checks
dimartiro Nov 13, 2023
34f4e6b
Fix deepsource checks
dimartiro Nov 13, 2023
39bcb46
Replace max int to constant
dimartiro Nov 13, 2023
0e4ab54
Use default state version in e2e tests
dimartiro Nov 13, 2023
8a7cc08
Change constant
dimartiro Nov 13, 2023
8c49535
Simplify database interface
dimartiro Nov 13, 2023
bd21886
Removes harcoded state trie version
dimartiro Nov 13, 2023
5946baf
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Nov 13, 2023
bc85310
Get state trie version from runtime
dimartiro Nov 13, 2023
1d1bd25
Move comment
dimartiro Nov 13, 2023
2648240
Add import state version
dimartiro Nov 13, 2023
2de3013
Change error message
dimartiro Nov 14, 2023
4181e0b
Merge branch 'development' into diego/trieV1/versioning
dimartiro Nov 14, 2023
6fa58b7
Merge branch 'development' into diego/trieV1/versioning
dimartiro Nov 15, 2023
337ab9c
Merge branch 'development' into diego/trieV1/versioning
dimartiro Nov 16, 2023
c56bd71
Removes Database interface
dimartiro Nov 17, 2023
2ff1a4e
Make GetCurrentStateTrieVersion private
dimartiro Nov 17, 2023
38b4b37
Rename trie version to layout
dimartiro Nov 17, 2023
14ad372
use NoMaxInlineValueSize
dimartiro Nov 17, 2023
2185edb
Fix mocks
dimartiro Nov 17, 2023
f4661c9
Fix tests using new runtime version parameter
dimartiro Nov 20, 2023
2cfbdca
Fix Test_ext_default_child_storage_root_version_2
dimartiro Nov 20, 2023
8f56a8d
Use right test runtime URL
dimartiro Nov 20, 2023
5b08816
Merge branch 'development' of https://github.com/ChainSafe/gossamer i…
dimartiro Nov 20, 2023
a747c37
Add missing err check
dimartiro Nov 20, 2023
8dcca66
Fix commands checks and doc
dimartiro Nov 21, 2023
2ce26f7
Merge branch 'development' into diego/trieV1/versioning
dimartiro Nov 21, 2023
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
Prev Previous commit
Next Next commit
chore(trie): version trie functions
  • Loading branch information
dimartiro committed Aug 16, 2023
commit 2703b93cea4ed4b7eeff047ebf90ef6aacee6fd4
4 changes: 2 additions & 2 deletions dot/core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ func createTestService(t *testing.T, genesisFilePath string,
cfgRuntime, err := wazero_runtime.NewRuntimeFromGenesis(rtCfg)
require.NoError(t, err)

cfgRuntime.Context.Storage.Put(aliceBalanceKey, encodedAccountInfo)
cfgRuntime.Context.Storage.Put(aliceBalanceKey, encodedAccountInfo, trie.V0)
// this key is System.UpgradedToDualRefCount -> set to true since all accounts have been upgraded to v0.9 format
cfgRuntime.Context.Storage.Put(common.UpgradedToDualRefKey, []byte{1})
cfgRuntime.Context.Storage.Put(common.UpgradedToDualRefKey, []byte{1}, trie.V0)

cfgBlockState.StoreRuntime(cfgBlockState.BestBlockHash(), cfgRuntime)

Expand Down
10 changes: 5 additions & 5 deletions dot/rpc/modules/childstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ func createTestTrieState(t *testing.T) (*trie.Trie, common.Hash) {
_, genesisTrie, _ := newWestendLocalGenesisWithTrieAndHeader(t)
tr := rtstorage.NewTrieState(&genesisTrie)

tr.Put([]byte(":first_key"), []byte(":value1"))
tr.Put([]byte(":second_key"), []byte(":second_value"))
tr.Put([]byte(":first_key"), []byte(":value1"), trie.V0)
tr.Put([]byte(":second_key"), []byte(":second_value"), trie.V0)

childTr := trie.NewEmptyTrie()
childTr.Put([]byte(":child_first"), []byte(":child_first_value"))
childTr.Put([]byte(":child_second"), []byte(":child_second_value"))
childTr.Put([]byte(":another_child"), []byte("value"))
childTr.Put([]byte(":child_first"), []byte(":child_first_value"), trie.V0)
childTr.Put([]byte(":child_second"), []byte(":child_second_value"), trie.V0)
childTr.Put([]byte(":another_child"), []byte("value"), trie.V0)

err := tr.SetChild([]byte(":child_storage_key"), childTr)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion dot/state/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestTrie_StoreAndLoadFromDB(t *testing.T) {

for keyString, value := range kv {
key := []byte(keyString)
tt.Put(key, value)
tt.Put(key, value, trie.V0)
}

err := tt.WriteDirty(db)
Expand Down
7 changes: 4 additions & 3 deletions dot/state/storage_notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/ChainSafe/chaindb"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/dgraph-io/badger/v4/pb"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -49,7 +50,7 @@ func TestStorageState_RegisterStorageObserver(t *testing.T) {
ss.RegisterStorageObserver(mockobs)
defer ss.UnregisterStorageObserver(mockobs)

ts.Put([]byte("mackcom"), []byte("wuz here"))
ts.Put([]byte("mackcom"), []byte("wuz here"), trie.V0)
err = ss.StoreTrie(ts, nil)
require.NoError(t, err)

Expand Down Expand Up @@ -86,7 +87,7 @@ func TestStorageState_RegisterStorageObserver_Multi(t *testing.T) {
key1 := []byte("key1")
value1 := []byte("value1")

ts.Put(key1, value1)
ts.Put(key1, value1, trie.V0)

err = ss.StoreTrie(ts, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -125,7 +126,7 @@ func TestStorageState_RegisterStorageObserver_Multi_Filter(t *testing.T) {
ss.RegisterStorageObserver(mockobs)
}

ts.Put(key1, value1)
ts.Put(key1, value1, trie.V0)
err = ss.StoreTrie(ts, nil)
require.NoError(t, err)

Expand Down
10 changes: 5 additions & 5 deletions dot/state/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestStorage_GetStorageByBlockHash(t *testing.T) {

key := []byte("testkey")
value := []byte("testvalue")
ts.Put(key, value)
ts.Put(key, value, trie.V0)

root, err := ts.Root()
require.NoError(t, err)
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestStorage_TrieState(t *testing.T) {
storage := newTestStorageState(t)
ts, err := storage.TrieState(&trie.EmptyHash)
require.NoError(t, err)
ts.Put([]byte("noot"), []byte("washere"))
ts.Put([]byte("noot"), []byte("washere"), trie.V0)

root, err := ts.Root()
require.NoError(t, err)
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestStorage_LoadFromDB(t *testing.T) {
}

for _, kv := range trieKV {
ts.Put(kv.key, kv.value)
ts.Put(kv.key, kv.value, trie.V0)
}

root, err := ts.Root()
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestStorage_StoreTrie_NotSyncing(t *testing.T) {

key := []byte("testkey")
value := []byte("testvalue")
ts.Put(key, value)
ts.Put(key, value, trie.V0)

err = storage.StoreTrie(ts, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestGetStorageChildAndGetStorageFromChild(t *testing.T) {
}
testChildTrie := trie.NewTrie(trieRoot, dbGetter)

testChildTrie.Put([]byte("keyInsidechild"), []byte("voila"))
testChildTrie.Put([]byte("keyInsidechild"), []byte("voila"), trie.V0)

err = genTrie.SetChild([]byte("keyToChild"), testChildTrie)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion dot/state/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func generateBlockWithRandomTrie(t *testing.T, serv *Service,
rand := time.Now().UnixNano()
key := []byte("testKey" + fmt.Sprint(rand))
value := []byte("testValue" + fmt.Sprint(rand))
err = trieState.Put(key, value)
err = trieState.Put(key, value, trie.V0)
require.NoError(t, err)

trieStateRoot, err := trieState.Root()
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// Storage runtime interface.
type Storage interface {
Put(key []byte, value []byte) (err error)
Put(key []byte, value []byte, version trie.Version) (err error)
Get(key []byte) []byte
Root() (common.Hash, error)
SetChild(keyToChild []byte, child *trie.Trie) error
Expand Down
4 changes: 2 additions & 2 deletions lib/runtime/storage/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ func (s *TrieState) RollbackStorageTransaction() {
}

// Put puts a key-value pair in the trie
func (s *TrieState) Put(key, value []byte) (err error) {
func (s *TrieState) Put(key, value []byte, version trie.Version) (err error) {
s.lock.Lock()
defer s.lock.Unlock()
return s.t.Put(key, value)
return s.t.Put(key, value, version)
}

// Get gets a value from the trie
Expand Down
22 changes: 11 additions & 11 deletions lib/runtime/storage/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var testCases = []string{
func TestTrieState_SetGet(t *testing.T) {
testFunc := func(ts *TrieState) {
for _, tc := range testCases {
ts.Put([]byte(tc), []byte(tc))
ts.Put([]byte(tc), []byte(tc), trie.V0)
}

for _, tc := range testCases {
Expand All @@ -43,7 +43,7 @@ func TestTrieState_SetGet(t *testing.T) {
func TestTrieState_Delete(t *testing.T) {
testFunc := func(ts *TrieState) {
for _, tc := range testCases {
ts.Put([]byte(tc), []byte(tc))
ts.Put([]byte(tc), []byte(tc), trie.V0)
}

ts.Delete([]byte(testCases[0]))
Expand All @@ -58,7 +58,7 @@ func TestTrieState_Delete(t *testing.T) {
func TestTrieState_Root(t *testing.T) {
testFunc := func(ts *TrieState) {
for _, tc := range testCases {
ts.Put([]byte(tc), []byte(tc))
ts.Put([]byte(tc), []byte(tc), trie.V0)
}

expected := ts.MustRoot()
Expand All @@ -79,7 +79,7 @@ func TestTrieState_ClearPrefix(t *testing.T) {
}

for i, key := range keys {
ts.Put([]byte(key), []byte{byte(i)})
ts.Put([]byte(key), []byte{byte(i)}, trie.V0)
}

ts.ClearPrefix([]byte("noo"))
Expand All @@ -105,7 +105,7 @@ func TestTrieState_ClearPrefixInChild(t *testing.T) {
}

for i, key := range keys {
child.Put([]byte(key), []byte{byte(i)})
child.Put([]byte(key), []byte{byte(i)}, trie.V0)
}

keyToChild := []byte("keytochild")
Expand All @@ -131,7 +131,7 @@ func TestTrieState_NextKey(t *testing.T) {
ts := &TrieState{t: trie.NewEmptyTrie()}

for _, tc := range testCases {
ts.Put([]byte(tc), []byte(tc))
ts.Put([]byte(tc), []byte(tc), trie.V0)
}

sort.Slice(testCases, func(i, j int) bool {
Expand All @@ -152,12 +152,12 @@ func TestTrieState_CommitStorageTransaction(t *testing.T) {
ts := &TrieState{t: trie.NewEmptyTrie()}

for _, tc := range testCases {
ts.Put([]byte(tc), []byte(tc))
ts.Put([]byte(tc), []byte(tc), trie.V0)
}

ts.BeginStorageTransaction()
testValue := []byte("noot")
ts.Put([]byte(testCases[0]), testValue)
ts.Put([]byte(testCases[0]), testValue, trie.V0)
ts.CommitStorageTransaction()

val := ts.Get([]byte(testCases[0]))
Expand All @@ -168,12 +168,12 @@ func TestTrieState_RollbackStorageTransaction(t *testing.T) {
ts := &TrieState{t: trie.NewEmptyTrie()}

for _, tc := range testCases {
ts.Put([]byte(tc), []byte(tc))
ts.Put([]byte(tc), []byte(tc), trie.V0)
}

ts.BeginStorageTransaction()
testValue := []byte("noot")
ts.Put([]byte(testCases[0]), testValue)
ts.Put([]byte(testCases[0]), testValue, trie.V0)
ts.RollbackStorageTransaction()

val := ts.Get([]byte(testCases[0]))
Expand All @@ -191,7 +191,7 @@ func TestTrieState_DeleteChildLimit(t *testing.T) {
}

for i, key := range keys {
child.Put([]byte(key), []byte{byte(i)})
child.Put([]byte(key), []byte{byte(i)}, trie.V0)
}

keyToChild := []byte("keytochild")
Expand Down
16 changes: 8 additions & 8 deletions lib/runtime/wasmer/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ func TestWestendRuntime_ValidateTransaction(t *testing.T) {
encBal, err := scale.Marshal(accInfo)
require.NoError(t, err)

rt.ctx.Storage.Put(aliceBalanceKey, encBal)
rt.ctx.Storage.Put(aliceBalanceKey, encBal, trie.V0)
// this key is System.UpgradedToDualRefCount -> set to true since all accounts have been upgraded to v0.9 format
rt.ctx.Storage.Put(common.UpgradedToDualRefKey, []byte{1})
rt.ctx.Storage.Put(common.UpgradedToDualRefKey, []byte{1}, trie.V0)

genesisHeader := &types.Header{
Number: 0,
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestInstance_GrandpaAuthorities_NodeRuntime(t *testing.T) {
require.NoError(t, err)

key := common.MustHexToBytes(genesis.GrandpaAuthoritiesKeyHex)
tt.Put(key, value)
tt.Put(key, value, trie.V0)

rt := NewTestInstanceWithTrie(t, runtime.WESTEND_RUNTIME_v0929, tt)

Expand Down Expand Up @@ -265,7 +265,7 @@ func TestInstance_GrandpaAuthorities_PolkadotRuntime(t *testing.T) {
require.NoError(t, err)

key := common.MustHexToBytes(genesis.GrandpaAuthoritiesKeyHex)
tt.Put(key, value)
tt.Put(key, value, trie.V0)

rt := NewTestInstanceWithTrie(t, runtime.POLKADOT_RUNTIME_v0929, tt)

Expand Down Expand Up @@ -312,13 +312,13 @@ func TestInstance_BabeGenerateKeyOwnershipProof(t *testing.T) {
randomnessValue, err := common.HexToHash("0x01")
require.NoError(t, err)
key := common.MustHexToBytes(genesis.BABERandomnessKeyHex)
tt.Put(key, randomnessValue[:])
tt.Put(key, randomnessValue[:], trie.V0)

authorityValue, err := common.HexToBytes("0x08eea1eabcac7d2c8a6459b7322cf997874482bfc3d2ec7a80888a3a7d714103640100000000000000b64994460e59b30364cad3c92e3df6052f9b0ebbb8f88460c194dc5794d6d7170100000000000000") //nolint:lll
require.NoError(t, err)

key = common.MustHexToBytes(genesis.BABEAuthoritiesKeyHex)
tt.Put(key, authorityValue)
tt.Put(key, authorityValue, trie.V0)

rt := NewTestInstanceWithTrie(t, testCase.targetRuntime, tt)

Expand Down Expand Up @@ -399,13 +399,13 @@ func TestInstance_BabeConfiguration_WestendRuntime_WithAuthorities(t *testing.T)
randomnessValue, err := common.HexToHash("0x01")
require.NoError(t, err)
key := common.MustHexToBytes(genesis.BABERandomnessKeyHex)
tt.Put(key, randomnessValue[:])
tt.Put(key, randomnessValue[:], trie.V0)

authorityValue, err := common.HexToBytes("0x08eea1eabcac7d2c8a6459b7322cf997874482bfc3d2ec7a80888a3a7d714103640100000000000000b64994460e59b30364cad3c92e3df6052f9b0ebbb8f88460c194dc5794d6d7170100000000000000") //nolint:lll
require.NoError(t, err)

key = common.MustHexToBytes(genesis.BABEAuthoritiesKeyHex)
tt.Put(key, authorityValue)
tt.Put(key, authorityValue, trie.V0)

rt := NewTestInstanceWithTrie(t, runtime.WESTEND_RUNTIME_v0929, tt)

Expand Down
5 changes: 3 additions & 2 deletions lib/runtime/wasmer/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/ChainSafe/gossamer/lib/common/types"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/pkg/scale"
"github.com/wasmerio/go-ext-wasm/wasmer"
)
Expand Down Expand Up @@ -208,7 +209,7 @@ func toWasmMemoryFixedSizeOptional(context wasmer.InstanceContext, data []byte)
return toWasmMemory(context, encodedOptionalFixedSize)
}

func storageAppend(storage runtime.Storage, key, valueToAppend []byte) (err error) {
func storageAppend(storage runtime.Storage, key, valueToAppend []byte, version trie.Version) (err error) {
// this function assumes the item in storage is a SCALE encoded array of items
// the valueToAppend is a new item, so it appends the item and increases the length prefix by 1
currentValue := storage.Get(key)
Expand Down Expand Up @@ -259,7 +260,7 @@ func storageAppend(storage runtime.Storage, key, valueToAppend []byte) (err erro
}
}

err = storage.Put(key, value)
err = storage.Put(key, value, version)
if err != nil {
return fmt.Errorf("putting key and value in storage: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions lib/runtime/wasmer/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ func ext_trie_blake2_256_root_version_1(context unsafe.Pointer, dataSpan C.int64
}

for _, kv := range kvs {
err := t.Put(kv.Key, kv.Value)
err := t.Put(kv.Key, kv.Value, trie.V0)
if err != nil {
logger.Errorf("failed putting key 0x%x and value 0x%x into trie: %s",
kv.Key, kv.Value, err)
Expand Down Expand Up @@ -873,7 +873,7 @@ func ext_trie_blake2_256_ordered_root_version_1(context unsafe.Pointer, dataSpan
"put key=0x%x and value=0x%x",
key, value)

err = t.Put(key, value)
err = t.Put(key, value, trie.V0)
if err != nil {
logger.Errorf("failed putting key 0x%x and value 0x%x into trie: %s",
key, value, err)
Expand Down Expand Up @@ -1916,7 +1916,7 @@ func ext_storage_append_version_1(context unsafe.Pointer, keySpan, valueSpan C.i
cp := make([]byte, len(valueAppend))
copy(cp, valueAppend)

err := storageAppend(storage, key, cp)
err := storageAppend(storage, key, cp, trie.V0)
if err != nil {
logger.Errorf("failed appending to storage: %s", err)
}
Expand Down Expand Up @@ -2156,7 +2156,7 @@ func ext_storage_set_version_1(context unsafe.Pointer, keySpan, valueSpan C.int6
logger.Debugf(
"key 0x%x has value 0x%x",
key, value)
err := storage.Put(key, cp)
err := storage.Put(key, cp, trie.V0)
panicOnError(err)
}

Expand Down
Loading