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

Features and fixes needed for contract deployment test #13

Merged
merged 4 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ var (
utils.GRPCPortFlag,
}

metroFlags = []cli.Flag{
utils.MetroGRPCHostFlag,
utils.MetroGRPCPortFlag,
}

metricsFlags = []cli.Flag{
utils.MetricsEnabledFlag,
utils.MetricsEnabledExpensiveFlag,
Expand Down Expand Up @@ -248,6 +253,7 @@ func init() {
app.Flags = flags.Merge(
nodeFlags,
rpcFlags,
metroFlags,
consoleFlags,
debug.Flags,
metricsFlags,
Expand Down
22 changes: 22 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,20 @@ var (
Category: flags.APICategory,
}

// Metro grpc address and port overrides
MetroGRPCHostFlag = &cli.StringFlag{
Name: "metro.addr",
Usage: "Metro gRPC server listening interface",
Value: ethconfig.Defaults.MetroGRPCHost,
Category: flags.APICategory,
}
MetroGRPCPortFlag = &cli.IntFlag{
Name: "metro.port",
Usage: "Metro gRPC server listening port",
Value: ethconfig.Defaults.MetroGRPCPort,
Category: flags.APICategory,
}

// Network Settings
MaxPeersFlag = &cli.IntFlag{
Name: "maxpeers",
Expand Down Expand Up @@ -1891,6 +1905,14 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
}

// metro
if ctx.IsSet(MetroGRPCHostFlag.Name) {
cfg.MetroGRPCHost = ctx.String(MetroGRPCHostFlag.Name)
}
if ctx.IsSet(MetroGRPCPortFlag.Name) {
cfg.MetroGRPCPort = ctx.Int(MetroGRPCPortFlag.Name)
}

// Override any default configs for hard coded networks.
switch {
case ctx.Bool(MainnetFlag.Name):
Expand Down
8 changes: 8 additions & 0 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,14 @@ func (pool *TxPool) AddRemotesSync(txs []*types.Transaction) []error {
return pool.addTxs(txs, false, true)
}

// Remove a single transaction from the mempool.
func (pool *TxPool) RemoveTx(hash common.Hash) {
pool.mu.Lock()
defer pool.mu.Unlock()

pool.removeTx(hash, false)
}

// This is like AddRemotes with a single transaction, but waits for pool reorganization. Tests use this method.
func (pool *TxPool) addRemoteSync(tx *types.Transaction) error {
errs := pool.AddRemotesSync([]*types.Transaction{tx})
Expand Down
5 changes: 5 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package eth
import (
"context"
"errors"
"fmt"
"math/big"
"time"

Expand Down Expand Up @@ -351,6 +352,10 @@ func (b *EthAPIBackend) UnprotectedAllowed() bool {
return b.allowUnprotectedTxs
}

func (b *EthAPIBackend) MetroGRPCEndpoint() string {
return fmt.Sprintf("%s:%d", b.eth.config.MetroGRPCHost, b.eth.config.MetroGRPCPort)
}

func (b *EthAPIBackend) RPCGasCap() uint64 {
return b.eth.config.RPCGasCap
}
Expand Down
8 changes: 8 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ var Defaults = Config{
RPCEVMTimeout: 5 * time.Second,
GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether

// Metro GRPC
MetroGRPCHost: "localhost",
MetroGRPCPort: 9090,
}

func init() {
Expand Down Expand Up @@ -207,6 +211,10 @@ type Config struct {

// OverrideShanghai (TODO: remove after the fork)
OverrideShanghai *uint64 `toml:",omitempty"`

// Metro GRPC Host and Port
MetroGRPCHost string `toml:",omitempty"`
MetroGRPCPort int `toml:",omitempty"`
}

// CreateConsensusEngine creates a consensus engine for the given chain configuration.
Expand Down
7 changes: 7 additions & 0 deletions grpc/execution/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ func (s *ExecutionServiceServer) DoBlock(ctx context.Context, req *executionv1.D
return nil, fmt.Errorf("failed to insert block into blockchain (n=%d)", n)
}

// remove txs from original mempool
for _, block := range blocks {
for _, tx := range block.Transactions() {
s.eth.TxPool().RemoveTx(tx.Hash())
}
}
steezeburger marked this conversation as resolved.
Show resolved Hide resolved

newForkChoice := &engine.ForkchoiceStateV1{
HeadBlockHash: block.Hash(),
SafeBlockHash: block.Hash(),
Expand Down
9 changes: 8 additions & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1694,12 +1694,19 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
return common.Hash{}, errors.New("only replay-protected (EIP-155) transactions allowed over RPC")
}

// save transaction in geth mempool as well, so things like forge can look it up
if err := b.SendTx(ctx, tx); err != nil {
return common.Hash{}, err
}

// send to metro instead of eth mempool
txBytes, err := tx.MarshalBinary()
if err != nil {
return common.Hash{}, err
}
if err := submitMetroTransaction(txBytes); err != nil {

metro_api := NewMetroAPI(b.MetroGRPCEndpoint())
if err := metro_api.SubmitTransaction(txBytes); err != nil {
steezeburger marked this conversation as resolved.
Show resolved Hide resolved
return common.Hash{}, err
}

Expand Down
3 changes: 3 additions & 0 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ type Backend interface {
SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription
BloomStatus() (uint64, uint64)
ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)

// Metro GRPC endpoint
MetroGRPCEndpoint() string
}

func GetAPIs(apiBackend Backend) []rpc.API {
Expand Down
14 changes: 12 additions & 2 deletions internal/ethapi/metro.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ package ethapi

import (
metrotx "github.com/astriaorg/metro-transactions/tx"
"github.com/ethereum/go-ethereum/log"
)

const secondaryChainID = "ethereum"

func submitMetroTransaction(tx []byte) error {
return metrotx.BuildAndSendSecondaryTransaction(metrotx.DefaultGRPCEndpoint, secondaryChainID, tx)
type MetroAPI struct {
endpoint string
}

func NewMetroAPI(endpoint string) *MetroAPI {
log.Info("NewMetroAPI", "endpoint", endpoint)
return &MetroAPI{endpoint: endpoint}
}

func (api *MetroAPI) SubmitTransaction(tx []byte) error {
return metrotx.BuildAndSendSecondaryTransaction(api.endpoint, secondaryChainID, tx)
}
1 change: 1 addition & 0 deletions internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func (b *backendMock) FeeHistory(ctx context.Context, blockCount uint64, lastBlo
func (b *backendMock) ChainDb() ethdb.Database { return nil }
func (b *backendMock) AccountManager() *accounts.Manager { return nil }
func (b *backendMock) ExtRPCEnabled() bool { return false }
func (b *backendMock) MetroGRPCEndpoint() string { return "" }
func (b *backendMock) RPCGasCap() uint64 { return 0 }
func (b *backendMock) RPCEVMTimeout() time.Duration { return time.Second }
func (b *backendMock) RPCTxFeeCap() float64 { return 0 }
Expand Down
5 changes: 5 additions & 0 deletions les/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package les
import (
"context"
"errors"
"fmt"
"math/big"
"time"

Expand Down Expand Up @@ -292,6 +293,10 @@ func (b *LesApiBackend) UnprotectedAllowed() bool {
return b.allowUnprotectedTxs
}

func (b *LesApiBackend) MetroGRPCEndpoint() string {
return fmt.Sprintf("%s:%d", b.eth.config.MetroGRPCHost, b.eth.config.MetroGRPCPort)
}

func (b *LesApiBackend) RPCGasCap() uint64 {
return b.eth.config.RPCGasCap
}
Expand Down
5 changes: 5 additions & 0 deletions node/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ const (
DefaultGraphQLPort = 8547 // Default TCP port for the GraphQL server
DefaultAuthHost = "localhost" // Default host interface for the authenticated apis
DefaultAuthPort = 8551 // Default port for the authenticated apis

// grpc
DefaultGRPCHost = "[::1]" // Default host interface for the gRPC server
DefaultGRPCPort = 50051 // Default port for the gRPC server

// metro
DefaultMetroGRPCHost = "127.0.0.1" // Default host interface for the metro gRPC server
DefaultMetroGRPCPort = 9090 // Default port for the metro gRPC server
steezeburger marked this conversation as resolved.
Show resolved Hide resolved
)

var (
Expand Down