Skip to content

Commit

Permalink
add geth rpc fork and wire it with the host (#1840)
Browse files Browse the repository at this point in the history
* add geth rpc fork and wire it with the host

* clarifications

* lint

* lint

* fix
  • Loading branch information
tudor-malene authored Mar 19, 2024
1 parent 67b94d0 commit 85097d6
Show file tree
Hide file tree
Showing 74 changed files with 7,046 additions and 143 deletions.
2 changes: 1 addition & 1 deletion go/common/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/ten-protocol/go-ten/go/common/errutil"

"github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common/tracers"
"github.com/ten-protocol/go-ten/go/responses"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"

gethcommon "github.com/ethereum/go-ethereum/common"
)
Expand Down
2 changes: 1 addition & 1 deletion go/common/gethencoding/geth_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/ten-protocol/go-ten/go/common/gethapi"

gethcommon "github.com/ethereum/go-ethereum/common"
gethrpc "github.com/ethereum/go-ethereum/rpc"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion go/common/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package host

import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/config"
"github.com/ten-protocol/go-ten/go/host/db"
"github.com/ten-protocol/go-ten/go/responses"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

// Host is the half of the Obscuro node that lives outside the enclave.
Expand Down
2 changes: 1 addition & 1 deletion go/common/host/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package host
import (
"math/big"

"github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/responses"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"

gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down
2 changes: 1 addition & 1 deletion go/common/log_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common/viewingkey"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

// LogSubscription is an authenticated subscription to logs.
Expand Down
2 changes: 1 addition & 1 deletion go/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/contracts/generated/MessageBus"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/components/batch_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (

"github.com/ethereum/go-ethereum/core/state"
gethlog "github.com/ethereum/go-ethereum/log"
gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common/async"
"github.com/ten-protocol/go-ten/go/common/errutil"
"github.com/ten-protocol/go-ten/go/common/log"
"github.com/ten-protocol/go-ten/go/common/measure"
"github.com/ten-protocol/go-ten/go/enclave/core"
"github.com/ten-protocol/go-ten/go/enclave/limiters"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

type batchRegistry struct {
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/components/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/enclave/core"
"github.com/ten-protocol/go-ten/go/enclave/limiters"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

var ErrDuplicateRollup = errors.New("duplicate rollup received")
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
gethcommon "github.com/ethereum/go-ethereum/common"
gethcore "github.com/ethereum/go-ethereum/core"
gethlog "github.com/ethereum/go-ethereum/log"
gethrpc "github.com/ethereum/go-ethereum/rpc"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

var _noHeadBatch = big.NewInt(0)
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/events/subscription_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"math/big"
"sync"

gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/enclave/vkhandler"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"

"github.com/ten-protocol/go-ten/go/common/log"

Expand Down
2 changes: 1 addition & 1 deletion go/enclave/evm/evm_facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
gethcommon "github.com/ethereum/go-ethereum/common"
gethcore "github.com/ethereum/go-ethereum/core"
gethlog "github.com/ethereum/go-ethereum/log"
gethrpc "github.com/ethereum/go-ethereum/rpc"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

// ExecuteTransactions
Expand Down
10 changes: 5 additions & 5 deletions go/enclave/evm/no_op_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ type ObscuroNoOpConsensusEngine struct {
logger gethlog.Logger
}

func (e *ObscuroNoOpConsensusEngine) Finalize(_ consensus.ChainHeaderReader, _ *types.Header, _ *state.StateDB, _ []*types.Transaction, _ []*types.Header, _ []*types.Withdrawal) {
// TODO implement me
panic("implement me")
}

// Author is used to determine where to send the gas collected from the fees.
func (e *ObscuroNoOpConsensusEngine) Author(_ *types.Header) (common.Address, error) {
return PoolAddress, nil
Expand All @@ -52,6 +47,11 @@ func (e *ObscuroNoOpConsensusEngine) Prepare(_ consensus.ChainHeaderReader, _ *t
return nil
}

func (e *ObscuroNoOpConsensusEngine) Finalize(_ consensus.ChainHeaderReader, _ *types.Header, _ *state.StateDB, _ []*types.Transaction, _ []*types.Header, _ []*types.Withdrawal) {
// TODO implement me
panic("implement me")
}

func (e *ObscuroNoOpConsensusEngine) FinalizeAndAssemble(_ consensus.ChainHeaderReader, _ *types.Header, _ *state.StateDB, _ []*types.Transaction,
_ []*types.Header, _ []*types.Receipt, _ []*types.Withdrawal,
) (*types.Block, error) {
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/l2chain/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
gethcore "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/vm"
gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common/gethapi"
"github.com/ten-protocol/go-ten/go/enclave/core"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

// ObscuroChain - the interface that provides the data access layer to the obscuro l2.
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/l2chain/l2_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
gethlog "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/status-im/keycard-go/hexutils"
"github.com/ten-protocol/go-ten/go/common/gethapi"
"github.com/ten-protocol/go-ten/go/common/gethencoding"
Expand All @@ -24,6 +23,7 @@ import (
"github.com/ten-protocol/go-ten/go/enclave/core"
"github.com/ten-protocol/go-ten/go/enclave/evm"
"github.com/ten-protocol/go-ten/go/enclave/genesis"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

type obscuroChain struct {
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/rpc/EstimateGas.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
gethcore "github.com/ethereum/go-ethereum/core"
gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common/gethapi"
"github.com/ten-protocol/go-ten/go/common/gethencoding"
"github.com/ten-protocol/go-ten/go/common/syserr"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

func EstimateGasValidate(reqParams []any, builder *CallBuilder[CallParamsWithBlock, hexutil.Uint64], _ *EncryptionManager) error {
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/rpc/GetBalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/ethereum/go-ethereum/common"

"github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ten-protocol/go-ten/go/common/gethencoding"
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/rpc/rpc_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package rpc
import (
"fmt"

gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common/gethapi"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"

gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ten-protocol/go-ten/go/common"
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

gethcommon "github.com/ethereum/go-ethereum/common"
gethlog "github.com/ethereum/go-ethereum/log"
gethrpc "github.com/ethereum/go-ethereum/rpc"
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

// RPCServer receives RPC calls to the enclave process and relays them to the enclave.Enclave.
Expand Down
33 changes: 12 additions & 21 deletions go/host/container/host_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"fmt"
"time"

"github.com/ten-protocol/go-ten/lib/gethfork/node"

gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ten-protocol/go-ten/go/host/l1"

"github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/common/log"
"github.com/ten-protocol/go-ten/go/common/metrics"
Expand All @@ -17,9 +18,9 @@ import (
"github.com/ten-protocol/go-ten/go/host"
"github.com/ten-protocol/go-ten/go/host/p2p"
"github.com/ten-protocol/go-ten/go/host/rpc/clientapi"
"github.com/ten-protocol/go-ten/go/host/rpc/clientrpc"
"github.com/ten-protocol/go-ten/go/host/rpc/enclaverpc"
"github.com/ten-protocol/go-ten/go/wallet"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"

gethlog "github.com/ethereum/go-ethereum/log"
hostcommon "github.com/ten-protocol/go-ten/go/common/host"
Expand All @@ -40,7 +41,7 @@ type HostContainer struct {
host hostcommon.Host
logger gethlog.Logger
metricsService *metrics.Service
rpcServer clientrpc.Server
rpcServer node.Server
}

func (h *HostContainer) Start() error {
Expand Down Expand Up @@ -137,7 +138,13 @@ func NewHostContainerFromConfig(parsedConfig *config.HostInputConfig, logger get

aggP2P := p2p.NewSocketP2PLayer(cfg, services, p2pLogger, metricsService.Registry())

rpcServer := clientrpc.NewServer(cfg, logger)
rpcServer := node.NewServer(&node.RPCConfig{
EnableHTTP: cfg.HasClientRPCHTTP,
HTTPPort: int(cfg.ClientRPCPortHTTP),
EnableWs: cfg.HasClientRPCWebsockets,
WsPort: int(cfg.ClientRPCPortWS),
Host: cfg.ClientRPCHost,
}, logger)

mgmtContractLib := mgmtcontractlib.NewMgmtContractLib(&cfg.ManagementContractAddress, logger)
obscuroRelevantContracts := []gethcommon.Address{cfg.ManagementContractAddress, cfg.MessageBusAddress}
Expand All @@ -148,7 +155,7 @@ func NewHostContainerFromConfig(parsedConfig *config.HostInputConfig, logger get

// NewHostContainer builds a host container with dependency injection rather than from config.
// Useful for testing etc. (want to be able to pass in logger, and also have option to mock out dependencies)
func NewHostContainer(cfg *config.HostConfig, services *host.ServicesRegistry, p2p hostcommon.P2PHostService, l1Client ethadapter.EthClient, l1Repo hostcommon.L1RepoService, enclaveClient common.Enclave, contractLib mgmtcontractlib.MgmtContractLib, hostWallet wallet.Wallet, rpcServer clientrpc.Server, logger gethlog.Logger, metricsService *metrics.Service) *HostContainer {
func NewHostContainer(cfg *config.HostConfig, services *host.ServicesRegistry, p2p hostcommon.P2PHostService, l1Client ethadapter.EthClient, l1Repo hostcommon.L1RepoService, enclaveClient common.Enclave, contractLib mgmtcontractlib.MgmtContractLib, hostWallet wallet.Wallet, rpcServer node.Server, logger gethlog.Logger, metricsService *metrics.Service) *HostContainer {
h := host.NewHost(cfg, services, p2p, l1Client, l1Repo, enclaveClient, hostWallet, contractLib, logger, metricsService.Registry())

hostContainer := &HostContainer{
Expand All @@ -162,55 +169,39 @@ func NewHostContainer(cfg *config.HostConfig, services *host.ServicesRegistry, p
rpcServer.RegisterAPIs([]rpc.API{
{
Namespace: APINamespaceObscuro,
Version: APIVersion1,
Service: clientapi.NewObscuroAPI(h),
Public: true,
},
{
Namespace: APINamespaceEth,
Version: APIVersion1,
Service: clientapi.NewEthereumAPI(h, logger),
Public: true,
},
{
Namespace: APINamespaceTenScan,
Version: APIVersion1,
Service: clientapi.NewTenScanAPI(h),
Public: true,
},
{
Namespace: APINamespaceNetwork,
Version: APIVersion1,
Service: clientapi.NewNetworkAPI(h),
Public: true,
},
{
Namespace: APINamespaceTest,
Version: APIVersion1,
Service: clientapi.NewTestAPI(hostContainer),
Public: true,
},
{
Namespace: APINamespaceEth,
Version: APIVersion1,
Service: clientapi.NewFilterAPI(h, logger),
Public: true,
},
{
Namespace: APINamespaceScan,
Version: APIVersion1,
Service: clientapi.NewScanAPI(h, logger),
Public: true,
},
})

if cfg.DebugNamespaceEnabled {
rpcServer.RegisterAPIs([]rpc.API{
{
Namespace: APINamespaceDebug,
Version: APIVersion1,
Service: clientapi.NewNetworkDebug(h),
Public: true,
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion go/host/enclave/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"sync/atomic"

gethlog "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/common/errutil"
"github.com/ten-protocol/go-ten/go/common/host"
"github.com/ten-protocol/go-ten/go/common/log"
"github.com/ten-protocol/go-ten/go/responses"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

// This private interface enforces the services that the enclaves service depends on
Expand Down
2 changes: 1 addition & 1 deletion go/host/events/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/ten-protocol/go-ten/go/common/log"

gethlog "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

type logSubsServiceLocator interface {
Expand Down
2 changes: 1 addition & 1 deletion go/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/ten-protocol/go-ten/go/host/enclave"
"github.com/ten-protocol/go-ten/go/host/l1"

"github.com/ethereum/go-ethereum/rpc"
"github.com/naoina/toml"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/common/log"
Expand All @@ -24,6 +23,7 @@ import (
"github.com/ten-protocol/go-ten/go/host/events"
"github.com/ten-protocol/go-ten/go/responses"
"github.com/ten-protocol/go-ten/go/wallet"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"

gethlog "github.com/ethereum/go-ethereum/log"
gethmetrics "github.com/ethereum/go-ethereum/metrics"
Expand Down
2 changes: 1 addition & 1 deletion go/host/rpc/clientapi/client_api_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/common/host"
"github.com/ten-protocol/go-ten/go/common/log"
"github.com/ten-protocol/go-ten/go/responses"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"

gethcommon "github.com/ethereum/go-ethereum/common"
gethlog "github.com/ethereum/go-ethereum/log"
Expand Down
2 changes: 1 addition & 1 deletion go/host/rpc/clientapi/client_api_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/ten-protocol/go-ten/go/common"

"github.com/ethereum/go-ethereum/rpc"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

// FilterAPI exposes a subset of Geth's PublicFilterAPI operations.
Expand Down
Loading

0 comments on commit 85097d6

Please sign in to comment.