-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
"net/rpc" | ||
|
||
"cosmossdk.io/log" | ||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core" | ||
ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/core/vm" | ||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/evmos/ethermint/x/evm/statedb" | ||
) | ||
|
||
type sgxRPCClient struct { | ||
logger log.Logger | ||
cl *rpc.Client | ||
} | ||
|
||
// newSgxRPCClient creates a new RPC client to communicate with the SGX binary. | ||
func newSgxRPCClient(logger log.Logger) (*sgxRPCClient, error) { | ||
// TODO Make ports configurable | ||
cl, err := rpc.DialHTTP("tcp", "localhost"+":9092") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &sgxRPCClient{ | ||
logger: logger, | ||
cl: cl, | ||
}, nil | ||
} | ||
|
||
func (c *sgxRPCClient) doCall(method string, req any) (any, error) { | ||
c.logger.Debug(fmt.Sprintf("RPC call %s", method), "args", args) | ||
resp, err := c.cl.Call(method, req) | ||
c.logger.Debug(fmt.Sprintf("RPC call %s", method), "reply", resp) | ||
return resp, err | ||
} | ||
|
||
func (c *sgxRPCClient) StartEVM(req *sgx.StartEVMRequest) (*sgx.StartEVMResponse, error) { | ||
Check failure on line 44 in x/evm/keeper/rpc_client.go
|
||
return c.doCall("SgxRpcServer.StartEVM", req) | ||
} | ||
|
||
func (c *sgxRPCClient) InitFhevm(req *sgx.InitFhevmRequest) (*sgx.InitFhevmResponse, error) { | ||
Check failure on line 48 in x/evm/keeper/rpc_client.go
|
||
return c.doCall("SgxRpcServer.InitFhevm", req) | ||
} | ||
|
||
func (c *sgxRPCClient) Create(req *sgx.CreateRequest) (*sgx.CreateResponse, error) { | ||
Check failure on line 52 in x/evm/keeper/rpc_client.go
|
||
return c.doCall("SgxRpcServer.Create", args, reply) | ||
} | ||
|
||
func (c *sgxRPCClient) Call(req *sgx.CallRequest) (*sgx.CallResponse, error) { | ||
Check failure on line 56 in x/evm/keeper/rpc_client.go
|
||
return c.doCall("SgxRpcServer.Call", req) | ||
} | ||
|
||
func (c *sgxRPCClient) Commit(req *sgx.CommitRequest) (*sgx.CommitResponse, error) { | ||
Check failure on line 60 in x/evm/keeper/rpc_client.go
|
||
return c.doCall("SgxRpcServer.Commit", req) | ||
} | ||
|
||
func (c *sgxRPCClient) StateDBAddBalance(req *sgx.StateDBAddBalanceRequest) (*sgx.StateDBAddBalanceResponse, error) { | ||
Check failure on line 64 in x/evm/keeper/rpc_client.go
|
||
return c.doCall("SgxRpcServer.StateDBAddBalance", req) | ||
} | ||
|
||
func (c *sgxRPCClient) StateDBSubBalance(req *sgx.StateDBSubBalanceRequest) (*sgx.StateDBSubBalanceResponse, error) { | ||
Check failure on line 68 in x/evm/keeper/rpc_client.go
|
||
return c.doCall("SgxRpcServer.StateDBSubBalance", req) | ||
} | ||
|
||
func (c *sgxRPCClient) StateDBSetNonce(req *sgx.StateDBSetNonceRequest) (*sgx.StateDBSetNonceResponse, error) { | ||
Check failure on line 72 in x/evm/keeper/rpc_client.go
|
||
return c.doCall("SgxRpcServer.StateDBSetNonce", req) | ||
} | ||
|
||
func (c *sgxRPCClient) StateDBIncreaseNonce(req *sgx.StateDBIncreaseNonceRequest) (*sgx.StateDBIncreaseNonceResponse, error) { | ||
Check failure on line 76 in x/evm/keeper/rpc_client.go
|
||
return c.doCall("SgxRpcServer.StateDBIncreaseNonce", req) | ||
} | ||
|
||
func (c *sgxRPCClient) StateDBPrepare(req *sgx.StateDBPrepareRequest) (*sgx.StateDBPrepareResponse, error) { | ||
Check failure on line 80 in x/evm/keeper/rpc_client.go
|
||
return c.doCall("SgxRpcServer.StateDBPrepare", req) | ||
} | ||
|
||
func (c *sgxRPCClient) StateDBGetRefund(req *sgx.StateDBGetRefundRequest) (*sgx.StateDBGetRefundResponse, error) { | ||
return c.doCall("SgxRpcServer.StateDBGetRefund", req) | ||
} | ||
|
||
func (c *sgxRPCClient) StateDBGetLogs(req *sgx.StateDBGetLogsRequest) (*sgx.StateDBGetLogsResponse, error) { | ||
return c.doCall("SgxRpcServer.StateDBGetLogs", req) | ||
} | ||
|
||
// PrepareTxEVMConfig only contains the fields from EVMConfig that are needed | ||
// to create a new EVM instance. This is used to pass the EVM configuration | ||
// over RPC to the SGX binary. | ||
type PrepareTxEVMConfig struct { | ||
// ChainConfig is the EVM chain configuration in JSON format. Since the | ||
// underlying params.ChainConfig struct contains pointer fields, they are | ||
// not serializable over RPC with gob. Instead, the JSON representation is | ||
// used. | ||
ChainConfigJson []byte | ||
|
||
// Fields from EVMConfig | ||
CoinBase common.Address | ||
BaseFee *big.Int | ||
TxConfig statedb.TxConfig | ||
DebugTrace bool | ||
|
||
// Fields from EVMConfig.FeeMarketParams struct | ||
NoBaseFee bool | ||
|
||
// Fields from EVMConfig.Params struct | ||
EvmDenom string | ||
ExtraEips []int | ||
// *rpctypes.StateOverride : original type | ||
Overrides string | ||
} | ||
|
||
// PrepareTxArgs is the argument struct for the SgxRpcServer.PrepareTx RPC method. | ||
type PrepareTxArgs struct { | ||
TxHash []byte | ||
// Header is the Tendermint header of the block in which the transaction | ||
// will be executed. | ||
Header cmtproto.Header | ||
// Msg is the EVM transaction message to run on the EVM. | ||
Msg core.Message | ||
// EvmConfig is the EVM configuration to set. | ||
EvmConfig PrepareTxEVMConfig | ||
} |