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

Fixes and refactors for use in ipld-eth-server #18

Merged
merged 8 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
90 changes: 0 additions & 90 deletions config.go

This file was deleted.

28 changes: 0 additions & 28 deletions database.go

This file was deleted.

2 changes: 1 addition & 1 deletion access_list.go → direct_by_leaf/access_list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ipld_eth_statedb
package state

import (
"github.com/ethereum/go-ethereum/common"
Expand Down
2 changes: 1 addition & 1 deletion journal.go → direct_by_leaf/journal.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ipld_eth_statedb
package state

import (
"math/big"
Expand Down
2 changes: 1 addition & 1 deletion sql.go → direct_by_leaf/sql.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ipld_eth_statedb
package state

const (
GetContractCodePgStr = `SELECT data FROM ipld.blocks WHERE key = $1`
Expand Down
25 changes: 7 additions & 18 deletions state_database.go → direct_by_leaf/state_database.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ipld_eth_statedb
package state

import (
"context"
Expand All @@ -8,14 +8,13 @@ import (

"github.com/VictoriaMetrics/fastcache"
lru "github.com/hashicorp/golang-lru"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/jmoiron/sqlx"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"

util "github.com/cerc-io/ipld-eth-statedb/internal"
"github.com/cerc-io/ipld-eth-statedb/sql"
)

const (
Expand Down Expand Up @@ -43,29 +42,19 @@ type StateDatabase interface {
var _ StateDatabase = &stateDatabase{}

type stateDatabase struct {
db Database
db sql.Database
codeSizeCache *lru.Cache
codeCache *fastcache.Cache
}

// NewStateDatabaseWithPgxPool returns a new Database implementation using the provided postgres connection pool
func NewStateDatabaseWithPgxPool(pgDb *pgxpool.Pool) (*stateDatabase, error) {
// NewStateDatabase returns a new Database implementation using the passed parameters
func NewStateDatabase(db sql.Database) *stateDatabase {
csc, _ := lru.New(codeSizeCacheSize)
return &stateDatabase{
db: NewPostgresDB(&PGXDriver{db: pgDb}),
db: db,
codeSizeCache: csc,
codeCache: fastcache.New(codeCacheSize),
}, nil
}

// NewStateDatabaseWithSqlxPool returns a new Database implementation using the passed parameters
func NewStateDatabaseWithSqlxPool(db *sqlx.DB) (*stateDatabase, error) {
csc, _ := lru.New(codeSizeCacheSize)
return &stateDatabase{
db: NewPostgresDB(&SQLXDriver{db: db}),
codeSizeCache: csc,
codeCache: fastcache.New(codeCacheSize),
}, nil
}
}

// ContractCode satisfies Database, it returns the contract code for a given codehash
Expand Down
5 changes: 3 additions & 2 deletions state_object.go → direct_by_leaf/state_object.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ipld_eth_statedb
package state

import (
"bytes"
Expand Down Expand Up @@ -159,7 +159,8 @@ func (s *stateObject) GetCommittedState(db StateDatabase, key common.Hash) commo
}
// If no live objects are available, load from database
start := time.Now()
enc, err := db.StorageValue(s.addrHash, key, s.blockHash)
keyHash := crypto.Keccak256Hash(key[:])
enc, err := db.StorageValue(s.addrHash, keyHash, s.blockHash)
if metrics.EnabledExpensive {
s.db.StorageReads += time.Since(start)
}
Expand Down
2 changes: 1 addition & 1 deletion statedb.go → direct_by_leaf/statedb.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ipld_eth_statedb
package state

import (
"fmt"
Expand Down
Loading