Skip to content

Commit

Permalink
Squash Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
rpl-ffl committed Sep 19, 2024
1 parent 00c8cfd commit 5251e44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
3 changes: 3 additions & 0 deletions db/substate_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type SubstateDB interface {

// GetLastSubstate returns last substate (block and transaction wise) inside given DB.
GetLastSubstate() (*substate.Substate, error)

// SetDecoder sets the decoder func to the provided encoding
SetDecoder(encoding string) *substateDB
}

// NewDefaultSubstateDB creates new instance of SubstateDB with default options.
Expand Down
11 changes: 5 additions & 6 deletions db/substate_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/golang/protobuf/proto"
)

// decodeUsing sets the runtime parsing behavior of substateDB
// SetDecoder sets the runtime parsing behavior of substateDB
// intended usage:
//
// db := &substateDB{..} // initializing db
// db.DecodeSubstateUsing(<encoding>) // end of init, or right before decoding
func (db *substateDB) DecodeSubstateUsing(encoding string) *substateDB {
// db := &substateDB{..} // initializing db
// .SetDecoder(<encoding>) // end of init, or right before decoding
func (db *substateDB) SetDecoder(encoding string) *substateDB {
db.decodeSubstate = getDecoderFunc(encoding, db.GetCode)
return db
}
Expand All @@ -26,7 +26,7 @@ type substateDecoder interface {

func (db *substateDB) DecodeSubstate(bytes []byte, block uint64, tx int) (*substate.Substate, error) {
if db.decodeSubstate == nil {
db.decodeUsing("default")
db.SetDecoder("default")
}
return db.decodeSubstate(bytes, block, tx)
}
Expand All @@ -47,7 +47,6 @@ func getDecoderFunc(encoding string, lookup codeLookup) decoderFunc {
return decodeProtobuf(bytes, lookup, block, tx)
}
default:
fmt.Println("Defaulting getDecoderFunc")
fallthrough
case "rlp":
return func(bytes []byte, block uint64, tx int) (*substate.Substate, error) {
Expand Down
15 changes: 2 additions & 13 deletions db/substate_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package db
import (
"fmt"

"github.com/golang/protobuf/proto"
"github.com/syndtr/goleveldb/leveldb/util"

pb "github.com/Fantom-foundation/Substate/protobuf"
"github.com/Fantom-foundation/Substate/substate"
"github.com/syndtr/goleveldb/leveldb/util"
)

func newSubstateIterator(db *substateDB, start []byte) *substateIterator {
Expand All @@ -34,15 +31,7 @@ func (i *substateIterator) decode(data rawEntry) (*substate.Substate, error) {
return nil, fmt.Errorf("invalid substate key: %v; %w", key, err)
}

//rlpSubstate, err := rlp.Decode(value)
//return rlpSubstate.ToSubstate(i.db.GetCode, block, tx)

pbSubstate := &pb.Substate{}
if err := proto.Unmarshal(value, pbSubstate); err != nil {
return nil, err
}

return pbSubstate.Decode(i.db.GetCode, block, tx)
return i.db.DecodeSubstate(value, block, tx)
}

func (i *substateIterator) start(numWorkers int) {
Expand Down

0 comments on commit 5251e44

Please sign in to comment.