Skip to content

Commit

Permalink
chore: rollback deltas to core/service.go
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Feb 7, 2024
1 parent 32fb14d commit 0069a00
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
17 changes: 8 additions & 9 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,14 @@ func (s *Service) handleBlock(block *types.Block, state *rtstorage.TrieState) er
return ErrNilBlockHandlerParameter
}

// store updates state trie nodes in database
// err := s.storageState.StoreTrie(state, &block.Header)
// if err != nil {
// logger.Warnf("failed to store state trie for imported block %s: %s",
// block.Header.Hash(), err)
// return err
// }

var err error
//store updates state trie nodes in database
err := s.storageState.StoreTrie(state, &block.Header)
if err != nil {
logger.Warnf("failed to store state trie for imported block %s: %s",
block.Header.Hash(), err)
return err
}

// store block in database
if err = s.blockState.AddBlock(block); err != nil {
if errors.Is(err, blocktree.ErrParentNotFound) && block.Header.Number != 0 {
Expand Down
4 changes: 2 additions & 2 deletions dot/state/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (s *StorageState) TrieState(root *common.Hash) (*rtstorage.TrieState, error
if root == nil {
sr, err := s.blockState.BestBlockStateRoot()
if err != nil {
return nil, err
return nil, fmt.Errorf("while getting best block state root: %w", err)
}
root = &sr
}
Expand All @@ -102,7 +102,7 @@ func (s *StorageState) TrieState(root *common.Hash) (*rtstorage.TrieState, error
var err error
t, err = s.LoadFromDB(*root)
if err != nil {
return nil, err
return nil, fmt.Errorf("while loading from database: %w", err)
}

s.tries.softSet(*root, t)
Expand Down
6 changes: 0 additions & 6 deletions lib/runtime/wazero/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -2273,24 +2273,18 @@ func ext_storage_root_version_2(ctx context.Context, m api.Module, version uint3
}
storage := rtCtx.Storage

fmt.Printf("ext_storage_root_version_2 with pre parsed: %v\n", version)

stateVersion, err := trie.ParseVersion(version)
if err != nil {
logger.Errorf("failed parsing state version: %s", err)
return mustWrite(m, rtCtx.Allocator, emptyByteVectorEncoded)
}

fmt.Printf("ext_storage_root_version_2 with pos parsed: %s\n", stateVersion.String())

root, err := storage.Root(stateVersion.MaxInlineValue())
if err != nil {
logger.Errorf("failed to get storage root: %s", err)
panic(err)
}

fmt.Printf("root v1 hash is: %s\n", root.String())

rootSpan, err := write(m, rtCtx.Allocator, root[:])
if err != nil {
logger.Errorf("failed to allocate: %s", err)
Expand Down
3 changes: 2 additions & 1 deletion lib/runtime/wazero/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func NewInstanceFromTrie(t *trie.Trie, cfg Config) (*Instance, error) {

// NewInstance instantiates a runtime from raw wasm bytecode
func NewInstance(code []byte, cfg Config) (instance *Instance, err error) {
logger.Info("instantiating a runtime!")
logger.Patch(log.SetLevel(cfg.LogLvl), log.SetCallerFunc(true))

ctx := context.Background()
Expand Down Expand Up @@ -434,6 +435,7 @@ func NewInstance(code []byte, cfg Config) (instance *Instance, err error) {
codeHash: cfg.CodeHash,
}

instance.version()
return instance, nil
}

Expand Down Expand Up @@ -515,7 +517,6 @@ func (in *Instance) version() error { //skipcq: RVV-B0001
fmt.Println("state version", version.StateVersion)

in.Context.Version = &version

return nil
}

Expand Down
1 change: 0 additions & 1 deletion lib/trie/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func (t *Trie) Load(db db.DBGetter, rootHash common.Hash) error {
return nil
}
rootHashBytes := rootHash.ToBytes()

encodedNode, err := db.Get(rootHashBytes)
if err != nil {
return fmt.Errorf("failed to find root key %s: %w", rootHash, err)
Expand Down

0 comments on commit 0069a00

Please sign in to comment.