Skip to content
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
10 changes: 5 additions & 5 deletions ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/eth/tracers"
"math/big"
"strings"
"time"
Expand All @@ -36,10 +35,10 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params"
Expand All @@ -50,6 +49,7 @@ import (

"github.com/Fantom-foundation/go-opera/evmcore"
"github.com/Fantom-foundation/go-opera/gossip/gasprice"
"github.com/Fantom-foundation/go-opera/inter/state"
"github.com/Fantom-foundation/go-opera/opera"
"github.com/Fantom-foundation/go-opera/utils/signers/gsignercache"
"github.com/Fantom-foundation/go-opera/utils/signers/internaltx"
Expand Down Expand Up @@ -922,7 +922,7 @@ type OverrideAccount struct {
type StateOverride map[common.Address]OverrideAccount

// Apply overrides the fields of specified accounts into the given state.
func (diff *StateOverride) Apply(state state.StateDbInterface) error {
func (diff *StateOverride) Apply(state state.StateDB) error {
if diff == nil {
return nil
}
Expand Down Expand Up @@ -2113,7 +2113,7 @@ func (api *PublicDebugAPI) TraceTransaction(ctx context.Context, hash common.Has
// traceTx configures a new tracer according to the provided configuration, and
// executes the given message in the provided environment. The return value will
// be tracer dependent.
func (api *PublicDebugAPI) traceTx(ctx context.Context, message evmcore.Message, txctx *tracers.Context, blockHeader *evmcore.EvmHeader, statedb state.StateDbInterface, config *TraceConfig) (interface{}, error) {
func (api *PublicDebugAPI) traceTx(ctx context.Context, message evmcore.Message, txctx *tracers.Context, blockHeader *evmcore.EvmHeader, statedb state.StateDB, config *TraceConfig) (interface{}, error) {
// Assemble the structured logger or the JavaScript tracer
var (
tracer vm.Tracer
Expand Down Expand Up @@ -2280,7 +2280,7 @@ func (api *PublicDebugAPI) traceBlock(ctx context.Context, block *evmcore.EvmBlo
}

// stateAtTransaction returns the execution environment of a certain transaction.
func (api *PublicDebugAPI) stateAtTransaction(ctx context.Context, block *evmcore.EvmBlock, txIndex int) (evmcore.Message, state.StateDbInterface, error) {
func (api *PublicDebugAPI) stateAtTransaction(ctx context.Context, block *evmcore.EvmBlock, txIndex int) (evmcore.Message, state.StateDB, error) {
// Short circuit if it's genesis block.
if block.NumberU64() == 0 {
return nil, nil, errors.New("no transaction in genesis")
Expand Down
6 changes: 3 additions & 3 deletions ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
notify "github.com/ethereum/go-ethereum/event"
Expand All @@ -36,6 +35,7 @@ import (
"github.com/Fantom-foundation/go-opera/evmcore"
"github.com/Fantom-foundation/go-opera/inter"
"github.com/Fantom-foundation/go-opera/inter/iblockproc"
"github.com/Fantom-foundation/go-opera/inter/state"
)

// PeerProgress is synchronization status of a peer
Expand Down Expand Up @@ -67,12 +67,12 @@ type Backend interface {
HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*evmcore.EvmHeader, error)
HeaderByHash(ctx context.Context, hash common.Hash) (*evmcore.EvmHeader, error)
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*evmcore.EvmBlock, error)
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (state.StateDbInterface, *evmcore.EvmHeader, error)
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (state.StateDB, *evmcore.EvmHeader, error)
ResolveRpcBlockNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (idx.Block, error)
BlockByHash(ctx context.Context, hash common.Hash) (*evmcore.EvmBlock, error)
GetReceiptsByNumber(ctx context.Context, number rpc.BlockNumber) (types.Receipts, error)
GetTd(hash common.Hash) *big.Int
GetEVM(ctx context.Context, msg evmcore.Message, state state.StateDbInterface, header *evmcore.EvmHeader, vmConfig *vm.Config) (*vm.EVM, func() error, error)
GetEVM(ctx context.Context, msg evmcore.Message, state vm.StateDB, header *evmcore.EvmHeader, vmConfig *vm.Config) (*vm.EVM, func() error, error)
MinGasPrice() *big.Int
MaxGasLimit() uint64

Expand Down
4 changes: 2 additions & 2 deletions ethapi/tx_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"

"github.com/Fantom-foundation/go-opera/evmcore"
"github.com/Fantom-foundation/go-opera/inter/state"
"github.com/Fantom-foundation/go-opera/opera"
"github.com/Fantom-foundation/go-opera/txtrace"
"github.com/Fantom-foundation/go-opera/utils/signers/gsignercache"
Expand Down Expand Up @@ -204,7 +204,7 @@ func (s *PublicTxTraceAPI) replayBlock(ctx context.Context, block *evmcore.EvmBl
// traceTx trace transaction with EVM replay and return processed result
func (s *PublicTxTraceAPI) traceTx(
ctx context.Context, b Backend, header *evmcore.EvmHeader, msg types.Message,
state state.StateDbInterface, block *evmcore.EvmBlock, tx *types.Transaction, index uint64,
state state.StateDB, block *evmcore.EvmBlock, tx *types.Transaction, index uint64,
status uint64) (*[]txtrace.ActionTrace, error) {

// Providing default config with tracer
Expand Down
66 changes: 1 addition & 65 deletions evmcore/apply_fake_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,79 +19,15 @@ package evmcore
import (
"crypto/ecdsa"
"errors"
"math"
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/Fantom-foundation/go-opera/inter"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"

"github.com/Fantom-foundation/go-opera/inter"
)

var FakeGenesisTime = inter.Timestamp(1608600000 * time.Second)

// ApplyFakeGenesis writes or updates the genesis block in db.
func ApplyFakeGenesis(statedb state.StateDbInterface, time inter.Timestamp, balances map[common.Address]*big.Int) (*EvmBlock, error) {
for acc, balance := range balances {
statedb.SetBalance(acc, balance)
}

// initial block
root, err := flush(statedb, true)
if err != nil {
return nil, err
}
block := genesisBlock(time, root)

return block, nil
}

func flush(statedb state.StateDbInterface, clean bool) (root common.Hash, err error) {
root, err = statedb.Commit(clean)
if err != nil {
return
}
err = statedb.Database().TrieDB().Commit(root, false, nil)
if err != nil {
return
}

if !clean {
err = statedb.Database().TrieDB().Cap(0)
}

return
}

// genesisBlock makes genesis block with pretty hash.
func genesisBlock(time inter.Timestamp, root common.Hash) *EvmBlock {
block := &EvmBlock{
EvmHeader: EvmHeader{
Number: big.NewInt(0),
Time: time,
GasLimit: math.MaxUint64,
Root: root,
TxHash: types.EmptyRootHash,
},
}

return block
}

// MustApplyFakeGenesis writes the genesis block and state to db, panicking on error.
func MustApplyFakeGenesis(statedb state.StateDbInterface, time inter.Timestamp, balances map[common.Address]*big.Int) *EvmBlock {
block, err := ApplyFakeGenesis(statedb, time, balances)
if err != nil {
log.Crit("ApplyFakeGenesis", "err", err)
}
return block
}

// FakeKey gets n-th fake private key.
func FakeKey(n uint32) *ecdsa.PrivateKey {
var keys = [100]string{
Expand Down
166 changes: 0 additions & 166 deletions evmcore/bench_test.go

This file was deleted.

Loading