Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] add a way to switch between RLP and Protobuf for substateDB decoding #86

Closed
wants to merge 157 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
79265d7
actually add protobuf
rpl-ffl Aug 14, 2024
8838baa
Fix incorrect message transition (#82)
cabrador Aug 23, 2024
c4231f2
added protobuf
rpl-ffl Sep 2, 2024
676b0a6
more decode
rpl-ffl Sep 3, 2024
b2f9017
remove swp
rpl-ffl Sep 3, 2024
613b93d
alloc done
rpl-ffl Sep 3, 2024
56b43b6
finish result
rpl-ffl Sep 4, 2024
0dbde61
finish message
rpl-ffl Sep 4, 2024
1f627cb
substate iterator now uses pb decode
rpl-ffl Sep 4, 2024
700223c
remove cyclical import in decode
rpl-ffl Sep 4, 2024
a0b6e83
decode bugfix
rpl-ffl Sep 4, 2024
9aad265
fix big int assignment
rpl-ffl Sep 4, 2024
5339c05
using newMessage instead of constructor
rpl-ffl Sep 4, 2024
6a55190
*big.Int now directly assigned
rpl-ffl Sep 4, 2024
5992162
decode bugfix
rpl-ffl Sep 4, 2024
0c53db7
pTo replaces toAddr
rpl-ffl Sep 4, 2024
6aaa194
predefine err
rpl-ffl Sep 4, 2024
da95437
try using empty bytes as address
rpl-ffl Sep 4, 2024
3c4190a
bytes->byte
rpl-ffl Sep 4, 2024
5adb6b0
try using NewResult instead
rpl-ffl Sep 4, 2024
a61ff96
{} -> ()
rpl-ffl Sep 4, 2024
dc183a8
try using all [20]bytes{}
rpl-ffl Sep 4, 2024
c9366d6
using var instead
rpl-ffl Sep 4, 2024
7ba04ea
add addr as intermediate value
rpl-ffl Sep 4, 2024
6ed87a7
for now remove rlp
rpl-ffl Sep 4, 2024
1fec2a4
GetSubstate now uses protobuf
rpl-ffl Sep 4, 2024
e525473
substate_db bugfix
rpl-ffl Sep 4, 2024
25aa7aa
added contract address logic
rpl-ffl Sep 4, 2024
6d4e857
common.Address instead of types.Address
rpl-ffl Sep 4, 2024
64858e7
types.Address->common.Address
rpl-ffl Sep 4, 2024
929cc25
another injection of contract address
rpl-ffl Sep 4, 2024
83610e3
add printer to substate_db.go
rpl-ffl Sep 4, 2024
f1c75e9
print using generic go
rpl-ffl Sep 4, 2024
cb0a261
more printer
rpl-ffl Sep 4, 2024
daa7cfa
give up on single line pointer
rpl-ffl Sep 4, 2024
334f437
turns out single line worked
rpl-ffl Sep 4, 2024
d46d6e0
what
rpl-ffl Sep 4, 2024
ff41839
empty codehash
rpl-ffl Sep 4, 2024
6ace404
added more debug
rpl-ffl Sep 5, 2024
5731302
remove debug
rpl-ffl Sep 5, 2024
7b99eb4
now uses code instead of codehash when creating world state
rpl-ffl Sep 5, 2024
f86f14a
gasfeecap, gastipcap now defaults to gasprice
rpl-ffl Sep 9, 2024
72b56a0
message is now a new constructor
rpl-ffl Sep 9, 2024
0e6adfc
removed dataHash temporarily
rpl-ffl Sep 9, 2024
0dc0bf4
data now switches between data/initcodehash
rpl-ffl Sep 9, 2024
5656431
correct switch syntax
rpl-ffl Sep 9, 2024
1c79c4a
data now defaults to blank bytes[]
rpl-ffl Sep 9, 2024
ddb2d26
add debug for data
rpl-ffl Sep 9, 2024
1b441a8
msg.Input now msg.GetInput()
rpl-ffl Sep 9, 2024
cf941b0
revert to rr04convert method to populate data
rpl-ffl Sep 9, 2024
aab3b28
add debug for tx message decode
rpl-ffl Sep 9, 2024
969ec53
add debug for tx message decode
rpl-ffl Sep 9, 2024
f2cbc25
try something plain
rpl-ffl Sep 9, 2024
c7745b4
one more
rpl-ffl Sep 9, 2024
cea2962
one more
rpl-ffl Sep 9, 2024
0b8f1e7
add also nonce
rpl-ffl Sep 9, 2024
13f3bbb
add also block, tx
rpl-ffl Sep 9, 2024
a2b5005
do a proper dump
rpl-ffl Sep 9, 2024
48a20fa
do a proper dump +log
rpl-ffl Sep 9, 2024
d1d7f61
test lookup
rpl-ffl Sep 9, 2024
3b5d141
fix bug
rpl-ffl Sep 9, 2024
36b7dea
fix bug2
rpl-ffl Sep 9, 2024
7c5d214
fix bug2
rpl-ffl Sep 9, 2024
73b4872
fix bug3
rpl-ffl Sep 9, 2024
21f4055
fix bug4
rpl-ffl Sep 9, 2024
28e3ca2
remove codehash from worldstate
rpl-ffl Sep 9, 2024
ec327ad
remove codehash from worldstate2
rpl-ffl Sep 9, 2024
1dc09e2
remove codehash from worldstate3
rpl-ffl Sep 9, 2024
645cc25
remove codehash from worldstate4
rpl-ffl Sep 9, 2024
aef723b
remove debug
rpl-ffl Sep 9, 2024
1fedcdd
getblocksubstates now protobuf
rpl-ffl Sep 9, 2024
dbfc19d
debug code db
rpl-ffl Sep 10, 2024
6861765
added lookup for worldstate
rpl-ffl Sep 10, 2024
5a24f19
fix bug
rpl-ffl Sep 10, 2024
d539e8f
added storage
rpl-ffl Sep 10, 2024
d74e2d9
bugfix1
rpl-ffl Sep 10, 2024
9ee83c7
bugfix2
rpl-ffl Sep 10, 2024
7ad034b
remove code_db debug
rpl-ffl Sep 10, 2024
15186b1
starting on random
rpl-ffl Sep 10, 2024
b56909c
random is now hash
rpl-ffl Sep 10, 2024
f92dd00
introduced uint256, changed difficulty, balance -> uint256
rpl-ffl Sep 10, 2024
457d2fe
bugfix
rpl-ffl Sep 10, 2024
70dbe18
bugfix2
rpl-ffl Sep 10, 2024
fd2e80f
bugfix3
rpl-ffl Sep 10, 2024
a40d995
account now accepts uint256
rpl-ffl Sep 10, 2024
a0a7cc1
bugfix
rpl-ffl Sep 10, 2024
2f34ea6
bugfix2
rpl-ffl Sep 10, 2024
ae05f39
bugfix3
rpl-ffl Sep 10, 2024
30153aa
bugfix4
rpl-ffl Sep 10, 2024
aed0349
bugfix5
rpl-ffl Sep 10, 2024
df500b7
updateset now uses uint256
rpl-ffl Sep 10, 2024
63bbde1
debug
rpl-ffl Sep 10, 2024
a29f69b
debug2
rpl-ffl Sep 10, 2024
4e5fdb8
debug3
rpl-ffl Sep 10, 2024
32e026a
also dump substate.Substate
rpl-ffl Sep 10, 2024
f5481c6
also dump substate.Substate2
rpl-ffl Sep 10, 2024
7ad5f56
also dump substate.Substate3
rpl-ffl Sep 10, 2024
95af711
dump using string did not work
rpl-ffl Sep 10, 2024
03553c3
encoding/json
rpl-ffl Sep 10, 2024
b46a819
uint 256 from byte now direct
rpl-ffl Sep 11, 2024
922e136
remove debug, blockhashes now nil if pb is nil
rpl-ffl Sep 11, 2024
9ba49e1
difficulty now nil if pb is nil
rpl-ffl Sep 11, 2024
050ea67
difficulty now *big.Int
rpl-ffl Sep 11, 2024
258ec06
gasfeecap, gastipcap now uses txMsg, utils
rpl-ffl Sep 12, 2024
750da03
switch txType
rpl-ffl Sep 12, 2024
173385c
blobgasfeecap now uses bytesvalue
rpl-ffl Sep 12, 2024
00967de
blobhashes now uses txType
rpl-ffl Sep 12, 2024
ffbfc83
remove extraneous =
rpl-ffl Sep 12, 2024
cbd5dfe
debug gfc, gtp
rpl-ffl Sep 12, 2024
3f3afcb
debug gfc, gtp2
rpl-ffl Sep 12, 2024
9cf590f
debug gfc, gtp3
rpl-ffl Sep 12, 2024
e5568f7
debug gfc, gtp4
rpl-ffl Sep 12, 2024
b18308b
debug gfc, gtp5
rpl-ffl Sep 12, 2024
e8a3ec0
debug gfc, gtp6
rpl-ffl Sep 12, 2024
43b6cad
debug gfc, gtp7
rpl-ffl Sep 12, 2024
238c27e
debug gfc, gtp7
rpl-ffl Sep 12, 2024
cf057b3
debug gfc, gtp8
rpl-ffl Sep 12, 2024
655e839
debug txtype
rpl-ffl Sep 12, 2024
fdd8ee4
debug txtype2
rpl-ffl Sep 12, 2024
b83802b
debug txtype3
rpl-ffl Sep 12, 2024
f0248b2
txtype now uint8
rpl-ffl Sep 12, 2024
e25f400
gtp, blobhashes now uses uint8 txtype
rpl-ffl Sep 12, 2024
f13cc9e
accessList now also uses txType
rpl-ffl Sep 12, 2024
c447c59
accessList debug
rpl-ffl Sep 12, 2024
bbc8fa1
accessList debug2
rpl-ffl Sep 12, 2024
f749dd2
accessList debug3
rpl-ffl Sep 12, 2024
7d05def
message confirmed exactly the same
rpl-ffl Sep 12, 2024
e0954ab
random now using bytesvaluetohash
rpl-ffl Sep 12, 2024
027a877
Random is now pHash
rpl-ffl Sep 12, 2024
504e2e5
difficulty now nil if random exists
rpl-ffl Sep 12, 2024
ad8235f
add debug for blobhashes
rpl-ffl Sep 17, 2024
8f3f4cd
debug blobhashes len
rpl-ffl Sep 17, 2024
9f81e08
debug blobhashes len2
rpl-ffl Sep 17, 2024
0adce33
debug blobhashes len3
rpl-ffl Sep 17, 2024
a92ac80
debug blobhashes len4
rpl-ffl Sep 17, 2024
1b20bed
blobhashes
rpl-ffl Sep 17, 2024
63c1ff0
blockhashes
rpl-ffl Sep 17, 2024
3650b46
remove debug
rpl-ffl Sep 18, 2024
fc089b8
blobhash refactoring
rpl-ffl Sep 18, 2024
7cba457
remove intermediate swtich
rpl-ffl Sep 18, 2024
7362264
add missing len()
rpl-ffl Sep 18, 2024
92df181
add missing getTxType
rpl-ffl Sep 18, 2024
23f71f4
difficulty now directly parsed
rpl-ffl Sep 19, 2024
5f79cfc
debug2
rpl-ffl Sep 19, 2024
78b534a
DbGetCode -> dBGetCode
rpl-ffl Sep 19, 2024
7df05ce
difficulty now no longer depended on random
rpl-ffl Sep 19, 2024
4845d6b
debug2
rpl-ffl Sep 19, 2024
1c869b5
test original difficulty instead
rpl-ffl Sep 19, 2024
ce980a3
difficulty now using direct expr again
rpl-ffl Sep 19, 2024
8891cdb
difficulty now working, remove debug
rpl-ffl Sep 19, 2024
8850e6c
basefee, blobbasefee now uses BytesValueToBigInt
rpl-ffl Sep 19, 2024
b63251f
added decodeUsing
rpl-ffl Sep 19, 2024
fb268a4
Decode->DecodeSubstate, decodeSubstate now pointers
rpl-ffl Sep 19, 2024
4af65f7
removed unused packages, decodeSubstate no longer pointer
rpl-ffl Sep 19, 2024
ffde78d
decodeSubstate now directly func
rpl-ffl Sep 19, 2024
00c8cfd
add nil to constructor
rpl-ffl Sep 19, 2024
5251e44
Squash Debug
rpl-ffl Sep 19, 2024
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
1 change: 1 addition & 0 deletions db/code_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (db *codeDB) GetCode(codeHash types.Hash) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("cannot get code %s: %w", codeHash, err)
}

return code, nil
}

Expand Down
28 changes: 11 additions & 17 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 All @@ -57,11 +60,11 @@ func NewSubstateDB(path string, o *opt.Options, wo *opt.WriteOptions, ro *opt.Re
}

func MakeDefaultSubstateDB(db *leveldb.DB) SubstateDB {
return &substateDB{&codeDB{&baseDB{backend: db}}}
return &substateDB{&codeDB{&baseDB{backend: db}}, nil}
}

func MakeDefaultSubstateDBFromBaseDB(db BaseDB) SubstateDB {
return &substateDB{&codeDB{&baseDB{backend: db.getBackend()}}}
return &substateDB{&codeDB{&baseDB{backend: db.getBackend()}}, nil}
}

// NewReadOnlySubstateDB creates a new instance of read-only SubstateDB.
Expand All @@ -70,19 +73,20 @@ func NewReadOnlySubstateDB(path string) (SubstateDB, error) {
}

func MakeSubstateDB(db *leveldb.DB, wo *opt.WriteOptions, ro *opt.ReadOptions) SubstateDB {
return &substateDB{&codeDB{&baseDB{backend: db, wo: wo, ro: ro}}}
return &substateDB{&codeDB{&baseDB{backend: db, wo: wo, ro: ro}}, nil}
}

func newSubstateDB(path string, o *opt.Options, wo *opt.WriteOptions, ro *opt.ReadOptions) (*substateDB, error) {
base, err := newCodeDB(path, o, wo, ro)
if err != nil {
return nil, err
}
return &substateDB{base}, nil
return &substateDB{base, nil}, nil
}

type substateDB struct {
*codeDB
decodeSubstate decoderFunc
}

func (db *substateDB) GetFirstSubstate() *substate.Substate {
Expand All @@ -108,12 +112,7 @@ func (db *substateDB) GetSubstate(block uint64, tx int) (*substate.Substate, err
return nil, fmt.Errorf("cannot get substate block: %v, tx: %v from db; %w", block, tx, err)
}

rlpSubstate, err := rlp.Decode(val)
if err != nil {
return nil, fmt.Errorf("cannot decode data into rlp block: %v, tx %v; %w", block, tx, err)
}

return rlpSubstate.ToSubstate(db.GetCode, block, tx)
return db.DecodeSubstate(val, block, tx)
}

// GetBlockSubstates returns substates for given block if exists within DB.
Expand All @@ -138,14 +137,9 @@ func (db *substateDB) GetBlockSubstates(block uint64) (map[int]*substate.Substat
return nil, fmt.Errorf("record-replay: GetBlockSubstates(%v) iterated substates from block %v", block, b)
}

rlpSubstate, err := rlp.Decode(value)
if err != nil {
return nil, fmt.Errorf("cannot decode data into rlp block: %v, tx %v; %w", block, tx, err)
}

sbstt, err := rlpSubstate.ToSubstate(db.GetCode, block, tx)
sbstt, err := db.DecodeSubstate(value, block, tx)
if err != nil {
return nil, fmt.Errorf("cannot decode data into substate: %w", err)
return nil, fmt.Errorf("Error decoding block %d, tx %d; %w", block, tx, err)
}

txSubstate[tx] = sbstt
Expand Down
76 changes: 76 additions & 0 deletions db/substate_decoder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package db

import (
"fmt"

pb "github.com/Fantom-foundation/Substate/protobuf"
"github.com/Fantom-foundation/Substate/rlp"
"github.com/Fantom-foundation/Substate/substate"
"github.com/Fantom-foundation/Substate/types"
"github.com/golang/protobuf/proto"
)

// SetDecoder sets the runtime parsing behavior of substateDB
// intended usage:
//
// 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
}

type substateDecoder interface {
DecodeSubstate(bytes []byte, block uint64, tx int) (*substate.Substate, error)
}

func (db *substateDB) DecodeSubstate(bytes []byte, block uint64, tx int) (*substate.Substate, error) {
if db.decodeSubstate == nil {
db.SetDecoder("default")
}
return db.decodeSubstate(bytes, block, tx)
}

// decoderFunc aliases the common function used to decode substate
type decoderFunc func([]byte, uint64, int) (*substate.Substate, error)

func (decode decoderFunc) DecodeSubstate(bytes []byte, block uint64, tx int) {
decode(bytes, block, tx)
}

type codeLookup = func(types.Hash) ([]byte, error)

func getDecoderFunc(encoding string, lookup codeLookup) decoderFunc {
switch encoding {
case "protobuf", "pb":
return func(bytes []byte, block uint64, tx int) (*substate.Substate, error) {
return decodeProtobuf(bytes, lookup, block, tx)
}
default:
fallthrough
case "rlp":
return func(bytes []byte, block uint64, tx int) (*substate.Substate, error) {
return decodeRlp(bytes, lookup, block, tx)
}
}
}

// decodeRlp decodes into substate the provided rlp-encoded bytecode
func decodeRlp(bytes []byte, lookup codeLookup, block uint64, tx int) (*substate.Substate, error) {
rlpSubstate, err := rlp.Decode(bytes)
if err != nil {
return nil, fmt.Errorf("cannot decode data into rlp block: %v, tx %v; %w", block, tx, err)
}

return rlpSubstate.ToSubstate(lookup, block, tx)
}

// decodeProtobuf decodes into substate the provided protobuf-encoded bytecode
func decodeProtobuf(bytes []byte, lookup codeLookup, block uint64, tx int) (*substate.Substate, error) {
pbSubstate := &pb.Substate{}
if err := proto.Unmarshal(bytes, pbSubstate); err != nil {
return nil, fmt.Errorf("cannot decode data into protobuf block: %v, tx %v; %w", block, tx, err)
}

return pbSubstate.Decode(lookup, block, tx)
}
11 changes: 2 additions & 9 deletions db/substate_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package db
import (
"fmt"

"github.com/syndtr/goleveldb/leveldb/util"

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

func newSubstateIterator(db *substateDB, start []byte) *substateIterator {
Expand All @@ -33,12 +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)
if err != nil {
return nil, err
}

return rlpSubstate.ToSubstate(i.db.GetCode, block, tx)
return i.db.DecodeSubstate(value, block, tx)
}

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