Skip to content

Commit c2d33eb

Browse files
authored
Features and fixes needed for contract deployment test (#13)
* add and remove tx from geth mempool so forge can deploy a contract * pass metro addr and port by flag * fixes from pr feedback * formatting
1 parent e19690c commit c2d33eb

File tree

11 files changed

+83
-3
lines changed

11 files changed

+83
-3
lines changed

cmd/geth/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ var (
185185
utils.GRPCPortFlag,
186186
}
187187

188+
metroFlags = []cli.Flag{
189+
utils.MetroGRPCHostFlag,
190+
utils.MetroGRPCPortFlag,
191+
}
192+
188193
metricsFlags = []cli.Flag{
189194
utils.MetricsEnabledFlag,
190195
utils.MetricsEnabledExpensiveFlag,
@@ -248,6 +253,7 @@ func init() {
248253
app.Flags = flags.Merge(
249254
nodeFlags,
250255
rpcFlags,
256+
metroFlags,
251257
consoleFlags,
252258
debug.Flags,
253259
metricsFlags,

cmd/utils/flags.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,20 @@ var (
811811
Category: flags.APICategory,
812812
}
813813

814+
// Metro grpc address and port overrides
815+
MetroGRPCHostFlag = &cli.StringFlag{
816+
Name: "metro.addr",
817+
Usage: "Metro gRPC server listening interface",
818+
Value: ethconfig.Defaults.MetroGRPCHost,
819+
Category: flags.APICategory,
820+
}
821+
MetroGRPCPortFlag = &cli.IntFlag{
822+
Name: "metro.port",
823+
Usage: "Metro gRPC server listening port",
824+
Value: ethconfig.Defaults.MetroGRPCPort,
825+
Category: flags.APICategory,
826+
}
827+
814828
// Network Settings
815829
MaxPeersFlag = &cli.IntFlag{
816830
Name: "maxpeers",
@@ -1891,6 +1905,14 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18911905
}
18921906
}
18931907

1908+
// metro
1909+
if ctx.IsSet(MetroGRPCHostFlag.Name) {
1910+
cfg.MetroGRPCHost = ctx.String(MetroGRPCHostFlag.Name)
1911+
}
1912+
if ctx.IsSet(MetroGRPCPortFlag.Name) {
1913+
cfg.MetroGRPCPort = ctx.Int(MetroGRPCPortFlag.Name)
1914+
}
1915+
18941916
// Override any default configs for hard coded networks.
18951917
switch {
18961918
case ctx.Bool(MainnetFlag.Name):

core/txpool/txpool.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,14 @@ func (pool *TxPool) AddRemotesSync(txs []*types.Transaction) []error {
10431043
return pool.addTxs(txs, false, true)
10441044
}
10451045

1046+
// Remove a single transaction from the mempool.
1047+
func (pool *TxPool) RemoveTx(hash common.Hash) {
1048+
pool.mu.Lock()
1049+
defer pool.mu.Unlock()
1050+
1051+
pool.removeTx(hash, false)
1052+
}
1053+
10461054
// This is like AddRemotes with a single transaction, but waits for pool reorganization. Tests use this method.
10471055
func (pool *TxPool) addRemoteSync(tx *types.Transaction) error {
10481056
errs := pool.AddRemotesSync([]*types.Transaction{tx})

eth/api_backend.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package eth
1919
import (
2020
"context"
2121
"errors"
22+
"fmt"
2223
"math/big"
2324
"time"
2425

@@ -351,6 +352,10 @@ func (b *EthAPIBackend) UnprotectedAllowed() bool {
351352
return b.allowUnprotectedTxs
352353
}
353354

355+
func (b *EthAPIBackend) MetroGRPCEndpoint() string {
356+
return fmt.Sprintf("%s:%d", b.eth.config.MetroGRPCHost, b.eth.config.MetroGRPCPort)
357+
}
358+
354359
func (b *EthAPIBackend) RPCGasCap() uint64 {
355360
return b.eth.config.RPCGasCap
356361
}

eth/ethconfig/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ var Defaults = Config{
9090
RPCEVMTimeout: 5 * time.Second,
9191
GPO: FullNodeGPO,
9292
RPCTxFeeCap: 1, // 1 ether
93+
94+
// Metro GRPC
95+
MetroGRPCHost: "localhost",
96+
MetroGRPCPort: 9090,
9397
}
9498

9599
func init() {
@@ -207,6 +211,10 @@ type Config struct {
207211

208212
// OverrideShanghai (TODO: remove after the fork)
209213
OverrideShanghai *uint64 `toml:",omitempty"`
214+
215+
// Metro GRPC Host and Port
216+
MetroGRPCHost string `toml:",omitempty"`
217+
MetroGRPCPort int `toml:",omitempty"`
210218
}
211219

212220
// CreateConsensusEngine creates a consensus engine for the given chain configuration.

grpc/execution/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ func (s *ExecutionServiceServer) DoBlock(ctx context.Context, req *executionv1.D
9292
return nil, fmt.Errorf("failed to insert block into blockchain (n=%d)", n)
9393
}
9494

95+
// remove txs from original mempool
96+
for _, tx := range block.Transactions() {
97+
s.eth.TxPool().RemoveTx(tx.Hash())
98+
}
99+
95100
newForkChoice := &engine.ForkchoiceStateV1{
96101
HeadBlockHash: block.Hash(),
97102
SafeBlockHash: block.Hash(),

internal/ethapi/api.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,12 +1694,19 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
16941694
return common.Hash{}, errors.New("only replay-protected (EIP-155) transactions allowed over RPC")
16951695
}
16961696

1697+
// save transaction in geth mempool as well, so things like forge can look it up
1698+
if err := b.SendTx(ctx, tx); err != nil {
1699+
return common.Hash{}, err
1700+
}
1701+
16971702
// send to metro instead of eth mempool
16981703
txBytes, err := tx.MarshalBinary()
16991704
if err != nil {
17001705
return common.Hash{}, err
17011706
}
1702-
if err := submitMetroTransaction(txBytes); err != nil {
1707+
1708+
metroAPI := NewMetroAPI(b.MetroGRPCEndpoint())
1709+
if err := metroAPI.SubmitTransaction(txBytes); err != nil {
17031710
return common.Hash{}, err
17041711
}
17051712

internal/ethapi/backend.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ type Backend interface {
9797
SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription
9898
BloomStatus() (uint64, uint64)
9999
ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
100+
101+
// Metro GRPC endpoint
102+
MetroGRPCEndpoint() string
100103
}
101104

102105
func GetAPIs(apiBackend Backend) []rpc.API {

internal/ethapi/metro.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@ package ethapi
22

33
import (
44
metrotx "github.com/astriaorg/metro-transactions/tx"
5+
"github.com/ethereum/go-ethereum/log"
56
)
67

78
const secondaryChainID = "ethereum"
89

9-
func submitMetroTransaction(tx []byte) error {
10-
return metrotx.BuildAndSendSecondaryTransaction(metrotx.DefaultGRPCEndpoint, secondaryChainID, tx)
10+
type MetroAPI struct {
11+
endpoint string
12+
}
13+
14+
func NewMetroAPI(endpoint string) *MetroAPI {
15+
log.Info("NewMetroAPI", "endpoint", endpoint)
16+
return &MetroAPI{endpoint: endpoint}
17+
}
18+
19+
func (api *MetroAPI) SubmitTransaction(tx []byte) error {
20+
return metrotx.BuildAndSendSecondaryTransaction(api.endpoint, secondaryChainID, tx)
1121
}

internal/ethapi/transaction_args_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ func (b *backendMock) FeeHistory(ctx context.Context, blockCount uint64, lastBlo
264264
func (b *backendMock) ChainDb() ethdb.Database { return nil }
265265
func (b *backendMock) AccountManager() *accounts.Manager { return nil }
266266
func (b *backendMock) ExtRPCEnabled() bool { return false }
267+
func (b *backendMock) MetroGRPCEndpoint() string { return "" }
267268
func (b *backendMock) RPCGasCap() uint64 { return 0 }
268269
func (b *backendMock) RPCEVMTimeout() time.Duration { return time.Second }
269270
func (b *backendMock) RPCTxFeeCap() float64 { return 0 }

0 commit comments

Comments
 (0)