Skip to content

Commit

Permalink
reduce diff
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjbrettj committed Sep 20, 2024
1 parent 3a826db commit 74d7433
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 13 deletions.
1 change: 0 additions & 1 deletion lib/runtime/storage/storagediff.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func (cs *storageDiff) clearPrefixInChild(keyToChild string, prefix []byte,
// optional limit. It returns the number of keys deleted and a boolean
// indicating if all keys with the prefix were removed.
func (cs *storageDiff) clearPrefix(prefix []byte, trieKeys []string, limit int) (deleted uint32, allDeleted bool) {
//newKeys := maps.Keys(cs.upserts)
keysToClear := maps.Keys(cs.upserts)
for _, k := range trieKeys {
if _, ok := cs.upserts[k]; !ok {
Expand Down
5 changes: 0 additions & 5 deletions lib/runtime/storage/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@ func (t *TrieState) Delete(key []byte) (err error) {
return nil
}

err = t.state.Delete(key)
if err != nil {
return err
}

return t.state.Delete(key)
}

Expand Down
4 changes: 4 additions & 0 deletions lib/runtime/wazero/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func ext_logging_log_version_1(_ context.Context, m api.Module, level int32, tar
msg := string(read(m, msgData))

line := fmt.Sprintf("target=%s message=%s", target, msg)

switch int(level) {
case 0:
logger.Critical(line)
Expand Down Expand Up @@ -858,6 +859,7 @@ func ext_trie_blake2_256_ordered_root_version_2(
}

var entries trie.Entries

for i, value := range values {
key, err := scale.Marshal(big.NewInt(int64(i)))
if err != nil {
Expand Down Expand Up @@ -2048,6 +2050,7 @@ func ext_storage_clear_version_1(ctx context.Context, m api.Module, keySpan uint
storage := rtCtx.Storage

key := read(m, keySpan)

logger.Debugf("key: 0x%x", key)
err := storage.Delete(key)
if err != nil {
Expand Down Expand Up @@ -2202,6 +2205,7 @@ func ext_storage_next_key_version_1(ctx context.Context, m api.Module, keySpan u
storage := rtCtx.Storage

key := read(m, keySpan)

next := storage.NextKey(key)
logger.Debugf(
"key: 0x%x; next key 0x%x",
Expand Down
4 changes: 0 additions & 4 deletions pkg/trie/inmemory/child_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package inmemory

import (
"bytes"
"errors"
"fmt"

Expand Down Expand Up @@ -70,9 +69,6 @@ func (t *InMemoryTrie) GetChildTries() map[common.Hash]trie.Trie {

// PutIntoChild puts a key-value pair into the child trie located in the main trie at key :child_storage:[keyToChild]
func (t *InMemoryTrie) PutIntoChild(keyToChild, key, value []byte) error {
if bytes.Equal(common.MustHexToBytes("0x0000000007a9b3851a0966360500"), value) {
fmt.Println("INSERTING OUR VALUE INTO CHILD")
}
child, err := t.getInternalChildTrie(keyToChild)
if err != nil {
if errors.Is(err, trie.ErrChildTrieDoesNotExist) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/trie/inmemory/in_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ package inmemory
import (
"bytes"
"fmt"
"reflect"

"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/pkg/trie"
"github.com/ChainSafe/gossamer/pkg/trie/codec"
"github.com/ChainSafe/gossamer/pkg/trie/db"
"github.com/ChainSafe/gossamer/pkg/trie/node"
"github.com/ChainSafe/gossamer/pkg/trie/tracking"
"reflect"
)

// InMemoryTrie is a base 16 modified Merkle Patricia trie.
Expand Down Expand Up @@ -463,6 +464,7 @@ func (t *InMemoryTrie) insertInBranch(parentBranch *node.Node, key, value []byte
}

if bytes.HasPrefix(key, parentBranch.PartialKey) {
// key is included in parent branch key
commonPrefixLength := lenCommonPrefix(key, parentBranch.PartialKey)
childIndex := key[commonPrefixLength]
remainingKey := key[commonPrefixLength+1:]
Expand Down
1 change: 1 addition & 0 deletions pkg/trie/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (v TrieLayout) Root(t Trie, entries Entries) (common.Hash, error) {
// TODO: is there any way to calculate the hash without building a trie?
// Eg: https://github.com/paritytech/trie/blob/542829a8195c12b67eef05e9020ec7a6d9313c3f/trie-root/src/lib.rs#L273-L388
t.SetVersion(v)

for _, kv := range entries {
err := t.Put(kv.Key, kv.Value)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions scripts/retrieve_state/retrieve_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ func (s *StateRequestProvider) buildTrie(expectedStorageRootHash common.Hash, de
return err
}

// go run ./scripts/retrieve_state/retrieve_state.go 0x00ab8c6e55a9951698052d9d999eb0c440c525af05867df39cb55863632b4ad9 0x804403dad405e595bdca5f068ae91a75d455c90f3e7672a2ee62d3b506a93c21 ./chain/paseo/chain-spec-raw.json ./lib/runtime/test_data/paseo/block1789153.out

func main() {
if len(os.Args) != 5 {
log.Fatalf(`
Expand Down

0 comments on commit 74d7433

Please sign in to comment.