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

Merge develop to main #78

Merged
merged 69 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
5dfc689
DB package (#30)
cabrador Dec 22, 2023
da15acd
New alloc (#31)
cabrador Dec 25, 2023
b7957b3
Add env with tests. (#33)
cabrador Dec 25, 2023
98902eb
Add message with tests. (#34)
cabrador Dec 25, 2023
d936eb9
Add result with tests. (#35)
cabrador Dec 25, 2023
0496d12
New rlp (#37)
cabrador Dec 25, 2023
53e6233
Add string functions to new_substate (#38)
cabrador Dec 27, 2023
266b518
Create substate_db tests (#39)
cabrador Dec 27, 2023
fa7d010
Create substate Iterator divided from classic low level iterator (#40)
cabrador Dec 29, 2023
56e5d97
Update db (#41)
cabrador Jan 2, 2024
1cb3ca0
Add generic iterator (#42)
cabrador Jan 2, 2024
2f2a7c7
Add updateset iterator. (#43)
cabrador Jan 2, 2024
a8e0430
Remove Transaction type. Add block and tx number to substate type. (#44)
cabrador Jan 2, 2024
eb5c2ac
New_substate -> substate (#45)
cabrador Jan 12, 2024
7d2b77a
Change name of const (#46)
cabrador Jan 17, 2024
3ffd9c3
First wait to close all threads. Then release low level iterator. (#47)
cabrador Jan 17, 2024
ad594f6
Naming refactor
evgensheff Mar 18, 2024
b45a026
Naming refactor
evgensheff Mar 18, 2024
d35375d
unused code cleaned
evgensheff Mar 18, 2024
db9c2bc
Update README.md
evgensheff Mar 19, 2024
53d5733
Merge remote-tracking branch 'personal/refactor' into refactor
evgensheff Mar 19, 2024
279bb4e
Merge pull request #48 from evgensheff/refactor
evgensheff Mar 19, 2024
fa20756
common hash and address refactor
evgensheff Mar 20, 2024
8fc6d91
further optimizing of internal types
evgensheff Mar 20, 2024
36ae557
changed common to simple types
evgensheff Mar 20, 2024
9d33692
naming
evgensheff Mar 20, 2024
5c241c9
Update db/code_db.go
evgensheff Mar 21, 2024
dfad463
Merge pull request #50 from Fantom-foundation/refactor
evgensheff Mar 21, 2024
ee4de13
added unit tests for rlp decoding
evgensheff Mar 22, 2024
b30ec91
Rename variables back to what it was.
cabrador Mar 22, 2024
fa2cc90
Add tests for each cross encoding/decoding.
cabrador Mar 25, 2024
42e7948
Remove incorrect comment. Add data to test log.
cabrador Mar 25, 2024
a38458b
Fix Iterator (#51)
cabrador Mar 26, 2024
af84ebb
Merge branch 'develop' into eugene/decode
cabrador Mar 26, 2024
4829f5e
added rlp methods for types.Log
evgensheff Mar 26, 2024
2162a4f
refactor and debug of Decoding
evgensheff Mar 27, 2024
64afe2b
unit test fix
evgensheff Mar 27, 2024
067f5ff
Merge pull request #53 from Fantom-foundation/eugene/decode
evgensheff Mar 27, 2024
e02ea3b
Uncomment incorrectly merged code. (#54)
cabrador Mar 27, 2024
cb22995
removed go-ethereum from dependencies
evgensheff Mar 28, 2024
7f8dedd
Merge branch 'develop' into eugene/geth
evgensheff Mar 28, 2024
0f97566
removed panics and comment added
evgensheff Mar 28, 2024
4abefca
Merge pull request #55 from Fantom-foundation/eugene/geth
evgensheff Mar 28, 2024
2e4e807
Account.Code bug found and fixed. Tests are updated
evgensheff Apr 2, 2024
4dea10a
test added
evgensheff Apr 2, 2024
a7d9327
fix
evgensheff Apr 2, 2024
3327231
fix of lost data
evgensheff Apr 3, 2024
4871ed8
Add test after bug-fix
cabrador Apr 3, 2024
c30f242
Merge pull request #57 from Fantom-foundation/eugene/fix-test
evgensheff Apr 3, 2024
fd8604a
returns back RecordReplay
evgensheff Apr 4, 2024
2cd3752
Merge pull request #59 from Fantom-foundation/eugene/rr
evgensheff Apr 4, 2024
4161d4d
Fixed iterator issue and added some unit tests
evgensheff Apr 5, 2024
ab1848b
Merge pull request #61 from Fantom-foundation/eugene/fix-issue-60
evgensheff Apr 5, 2024
4a891d5
fix formatting
wsodsong Apr 9, 2024
b11389b
Merge pull request #62 from Fantom-foundation/wasuwee/fix-format
wsodsong Apr 9, 2024
da3f446
Use go 1.21 (#65)
wsodsong Apr 9, 2024
6d51459
Github actions (#36)
cabrador Apr 9, 2024
bc2f8f8
Extend address type (#67)
cabrador Apr 11, 2024
8e88c18
Add missing functions from db package. (#63)
cabrador Apr 12, 2024
255eab4
Fix baseFee nilptr dereference. (#64)
cabrador Apr 12, 2024
de1e380
Fix incorrect slice assignment (#68)
cabrador Apr 12, 2024
f5a1d46
Add missing hash functionality. (#69)
cabrador Apr 19, 2024
d646d5f
Create bloom type (#66)
cabrador Apr 19, 2024
301648e
added hash and address MarshallText() (#72)
evgensheff Apr 22, 2024
2772ef3
Sort errors (#73)
cabrador Apr 22, 2024
570203f
Allow stopping even if workers result channel is full. (#74)
cabrador Apr 22, 2024
60d9336
Create read-only factory functions for databases. (#75)
cabrador Apr 22, 2024
cc6c29f
Correctly return error. (#77)
cabrador May 20, 2024
0d28864
Open existing db (#76)
cabrador Jun 6, 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
Prev Previous commit
Next Next commit
removed go-ethereum from dependencies
  • Loading branch information
evgensheff committed Mar 28, 2024
commit cb22995ef2fda7863c993af1ea8c3dac558af1a7
27 changes: 0 additions & 27 deletions db.go

This file was deleted.

35 changes: 18 additions & 17 deletions destroyed_account_db.go → db/destroyed_account_db.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
package substate
package db

import (
"encoding/binary"
"fmt"
"log"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/rlp"
"github.com/syndtr/goleveldb/leveldb/opt"

"github.com/Fantom-foundation/Substate/types"
"github.com/Fantom-foundation/Substate/types/rlp"
)

type DestroyedAccountDB struct {
backend BackendDatabase
backend BaseDB
}

func NewDestroyedAccountDB(backend BackendDatabase) *DestroyedAccountDB {
func NewDestroyedAccountDB(backend BaseDB) *DestroyedAccountDB {
return &DestroyedAccountDB{backend: backend}
}

func OpenDestroyedAccountDB(destroyedAccountDir string) (*DestroyedAccountDB, error) {
return openDestroyedAccountDB(destroyedAccountDir, false)
return openDestroyedAccountDB(destroyedAccountDir, &opt.Options{ReadOnly: false}, nil, nil)
}

func OpenDestroyedAccountDBReadOnly(destroyedAccountDir string) (*DestroyedAccountDB, error) {
return openDestroyedAccountDB(destroyedAccountDir, true)
return openDestroyedAccountDB(destroyedAccountDir, &opt.Options{ReadOnly: true}, nil, nil)
}

func openDestroyedAccountDB(destroyedAccountDir string, readOnly bool) (*DestroyedAccountDB, error) {
func openDestroyedAccountDB(destroyedAccountDir string, o *opt.Options, wo *opt.WriteOptions, ro *opt.ReadOptions) (*DestroyedAccountDB, error) {
log.Println("substate: OpenDestroyedAccountDB")
backend, err := rawdb.NewLevelDBDatabase(destroyedAccountDir, 1024, 100, "destroyed_accounts", readOnly)
backend, err := newBaseDB(destroyedAccountDir, o, wo, ro)
if err != nil {
return nil, fmt.Errorf("error opening deletion-db %s: %v", destroyedAccountDir, err)
}
Expand All @@ -40,11 +41,11 @@ func (db *DestroyedAccountDB) Close() error {
}

type SuicidedAccountLists struct {
DestroyedAccounts []common.Address
ResurrectedAccounts []common.Address
DestroyedAccounts []types.Address
ResurrectedAccounts []types.Address
}

func (db *DestroyedAccountDB) SetDestroyedAccounts(block uint64, tx int, des []common.Address, res []common.Address) error {
func (db *DestroyedAccountDB) SetDestroyedAccounts(block uint64, tx int, des []types.Address, res []types.Address) error {
accountList := SuicidedAccountLists{DestroyedAccounts: des, ResurrectedAccounts: res}
value, err := rlp.EncodeToBytes(accountList)
if err != nil {
Expand All @@ -53,7 +54,7 @@ func (db *DestroyedAccountDB) SetDestroyedAccounts(block uint64, tx int, des []c
return db.backend.Put(encodeDestroyedAccountKey(block, tx), value)
}

func (db *DestroyedAccountDB) GetDestroyedAccounts(block uint64, tx int) ([]common.Address, []common.Address, error) {
func (db *DestroyedAccountDB) GetDestroyedAccounts(block uint64, tx int) ([]types.Address, []types.Address, error) {
data, err := db.backend.Get(encodeDestroyedAccountKey(block, tx))
if err != nil {
return nil, nil, err
Expand All @@ -63,13 +64,13 @@ func (db *DestroyedAccountDB) GetDestroyedAccounts(block uint64, tx int) ([]comm
}

// GetAccountsDestroyedInRange get list of all accounts between block from and to (including from and to).
func (db *DestroyedAccountDB) GetAccountsDestroyedInRange(from, to uint64) ([]common.Address, error) {
func (db *DestroyedAccountDB) GetAccountsDestroyedInRange(from, to uint64) ([]types.Address, error) {
startingBlockBytes := make([]byte, 8)
binary.BigEndian.PutUint64(startingBlockBytes, from)

iter := db.backend.NewIterator([]byte(DestroyedAccountPrefix), startingBlockBytes)
defer iter.Release()
isDestroyed := make(map[common.Address]bool)
isDestroyed := make(map[types.Address]bool)
for iter.Next() {
block, _, err := DecodeDestroyedAccountKey(iter.Key())
if err != nil {
Expand All @@ -90,7 +91,7 @@ func (db *DestroyedAccountDB) GetAccountsDestroyedInRange(from, to uint64) ([]co
}
}

var accountList []common.Address
var accountList []types.Address
for addr, isDeleted := range isDestroyed {
if isDeleted {
accountList = append(accountList, addr)
Expand Down
14 changes: 7 additions & 7 deletions metadata.go → db/metadata.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package substate
package db

import (
"encoding/binary"
Expand All @@ -12,33 +12,33 @@ const (
)

// PutMetadata into db
func (db *UpdateDB) PutMetadata(interval, size uint64) error {
func (db *updateDB) PutMetadata(interval, size uint64) error {

byteInterval := make([]byte, 8)
binary.BigEndian.PutUint64(byteInterval, interval)

if err := db.backend.Put([]byte(UpdatesetIntervalKey), byteInterval); err != nil {
if err := db.backend.Put([]byte(UpdatesetIntervalKey), byteInterval, db.wo); err != nil {
return err
}

sizeInterval := make([]byte, 8)
binary.BigEndian.PutUint64(sizeInterval, size)

if err := db.backend.Put([]byte(UpdatesetSizeKey), sizeInterval); err != nil {
if err := db.backend.Put([]byte(UpdatesetSizeKey), sizeInterval, db.wo); err != nil {
return err
}

return nil
}

// GetMetadata from db
func (db *UpdateDB) GetMetadata() (uint64, uint64, error) {
byteInterval, err := db.backend.Get([]byte(UpdatesetIntervalKey))
func (db *updateDB) GetMetadata() (uint64, uint64, error) {
byteInterval, err := db.backend.Get([]byte(UpdatesetIntervalKey), db.ro)
if err != nil {
return 0, 0, err
}

byteSize, err := db.backend.Get([]byte(UpdatesetSizeKey))
byteSize, err := db.backend.Get([]byte(UpdatesetSizeKey), db.ro)
if err != nil {
return 0, 0, err
}
Expand Down
45 changes: 45 additions & 0 deletions db/substate_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package db
import (
"encoding/binary"
"fmt"
"github.com/syndtr/goleveldb/leveldb/util"

"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
Expand All @@ -24,6 +25,8 @@ type SubstateDB interface {
// GetSubstate gets the Substate for given block and tx number.
GetSubstate(block uint64, tx int) (*substate.Substate, error)

GetBlockSubstates(block uint64) map[int]*substate.Substate

// PutSubstate inserts given substate to DB.
PutSubstate(substate *substate.Substate) error

Expand Down Expand Up @@ -88,6 +91,48 @@ func (db *substateDB) GetSubstate(block uint64, tx int) (*substate.Substate, err
return rlpSubstate.ToSubstate(db.GetCode, block, tx)
}

func (db *substateDB) GetBlockSubstates(block uint64) map[int]*substate.Substate {
var err error

txSubstate := make(map[int]*substate.Substate)

prefix := SubstateDBBlockPrefix(block)

iter := db.backend.NewIterator(util.BytesPrefix(prefix), nil)
for iter.Next() {
key := iter.Key()
value := iter.Value()

b, tx, err := DecodeSubstateDBKey(key)
if err != nil {
panic(fmt.Errorf("record-replay: invalid substate key found for block %v: %v", block, err))
}

if block != b {
panic(fmt.Errorf("record-replay: GetBlockSubstates(%v) iterated substates from block %v", block, b))
}

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

sbstt, err := rlpSubstate.ToSubstate(db.GetCode, block, tx)
if err != nil {
panic(fmt.Errorf("cannot decode data into substate: %v", err))
}

txSubstate[tx] = sbstt
}
iter.Release()
err = iter.Error()
if err != nil {
panic(err)
}

return txSubstate
}

func (db *substateDB) PutSubstate(ss *substate.Substate) error {
for i, account := range ss.InputSubstate {
err := db.PutCode(account.Code)
Expand Down
15 changes: 8 additions & 7 deletions substate_task.go → db/substate_task.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package substate
package db

import (
"fmt"
"github.com/Fantom-foundation/Substate/substate"
"runtime"
"sort"
"sync"
Expand Down Expand Up @@ -31,8 +32,8 @@ var (
}
)

type SubstateBlockFunc func(block uint64, transactions map[int]*Substate, taskPool *SubstateTaskPool) error
type SubstateTaskFunc func(block uint64, tx int, substate *Substate, taskPool *SubstateTaskPool) error
type SubstateBlockFunc func(block uint64, transactions map[int]*substate.Substate, taskPool *SubstateTaskPool) error
type SubstateTaskFunc func(block uint64, tx int, substate *substate.Substate, taskPool *SubstateTaskPool) error

type SubstateTaskPool struct {
Name string
Expand All @@ -49,10 +50,10 @@ type SubstateTaskPool struct {

Ctx *cli.Context // CLI context required to read additional flags

DB *DB
DB SubstateDB
}

func NewSubstateTaskPool(name string, taskFunc SubstateTaskFunc, first, last uint64, ctx *cli.Context) *SubstateTaskPool {
func NewSubstateTaskPool(name string, taskFunc SubstateTaskFunc, first, last uint64, ctx *cli.Context, database SubstateDB) *SubstateTaskPool {
return &SubstateTaskPool{
Name: name,
TaskFunc: taskFunc,
Expand All @@ -67,7 +68,7 @@ func NewSubstateTaskPool(name string, taskFunc SubstateTaskFunc, first, last uin

Ctx: ctx,

DB: staticSubstateDB,
DB: database,
}
}

Expand Down Expand Up @@ -95,7 +96,7 @@ func (pool *SubstateTaskPool) ExecuteBlock(block uint64) (numTx int64, gas int64

for _, tx := range txNumbers {
substate := transactions[tx]
alloc := substate.InputAlloc
alloc := substate.InputSubstate
msg := substate.Message

to := msg.To
Expand Down
30 changes: 0 additions & 30 deletions geth/common/big.go

This file was deleted.

Loading