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
This commit is contained in:
jesse snyder 2023-04-20 13:55:36 -06:00 committed by GitHub
parent e19690c976
commit c2d33eb566
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 83 additions and 3 deletions

View file

@ -185,6 +185,11 @@ var (
utils.GRPCPortFlag, utils.GRPCPortFlag,
} }
metroFlags = []cli.Flag{
utils.MetroGRPCHostFlag,
utils.MetroGRPCPortFlag,
}
metricsFlags = []cli.Flag{ metricsFlags = []cli.Flag{
utils.MetricsEnabledFlag, utils.MetricsEnabledFlag,
utils.MetricsEnabledExpensiveFlag, utils.MetricsEnabledExpensiveFlag,
@ -248,6 +253,7 @@ func init() {
app.Flags = flags.Merge( app.Flags = flags.Merge(
nodeFlags, nodeFlags,
rpcFlags, rpcFlags,
metroFlags,
consoleFlags, consoleFlags,
debug.Flags, debug.Flags,
metricsFlags, metricsFlags,

View file

@ -811,6 +811,20 @@ var (
Category: flags.APICategory, 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 // Network Settings
MaxPeersFlag = &cli.IntFlag{ MaxPeersFlag = &cli.IntFlag{
Name: "maxpeers", Name: "maxpeers",
@ -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. // Override any default configs for hard coded networks.
switch { switch {
case ctx.Bool(MainnetFlag.Name): case ctx.Bool(MainnetFlag.Name):

View file

@ -1043,6 +1043,14 @@ func (pool *TxPool) AddRemotesSync(txs []*types.Transaction) []error {
return pool.addTxs(txs, false, true) 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. // 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 { func (pool *TxPool) addRemoteSync(tx *types.Transaction) error {
errs := pool.AddRemotesSync([]*types.Transaction{tx}) errs := pool.AddRemotesSync([]*types.Transaction{tx})

View file

@ -19,6 +19,7 @@ package eth
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"math/big" "math/big"
"time" "time"
@ -351,6 +352,10 @@ func (b *EthAPIBackend) UnprotectedAllowed() bool {
return b.allowUnprotectedTxs 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 { func (b *EthAPIBackend) RPCGasCap() uint64 {
return b.eth.config.RPCGasCap return b.eth.config.RPCGasCap
} }

View file

@ -90,6 +90,10 @@ var Defaults = Config{
RPCEVMTimeout: 5 * time.Second, RPCEVMTimeout: 5 * time.Second,
GPO: FullNodeGPO, GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether RPCTxFeeCap: 1, // 1 ether
// Metro GRPC
MetroGRPCHost: "localhost",
MetroGRPCPort: 9090,
} }
func init() { func init() {
@ -207,6 +211,10 @@ type Config struct {
// OverrideShanghai (TODO: remove after the fork) // OverrideShanghai (TODO: remove after the fork)
OverrideShanghai *uint64 `toml:",omitempty"` 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. // CreateConsensusEngine creates a consensus engine for the given chain configuration.

View file

@ -92,6 +92,11 @@ func (s *ExecutionServiceServer) DoBlock(ctx context.Context, req *executionv1.D
return nil, fmt.Errorf("failed to insert block into blockchain (n=%d)", n) return nil, fmt.Errorf("failed to insert block into blockchain (n=%d)", n)
} }
// remove txs from original mempool
for _, tx := range block.Transactions() {
s.eth.TxPool().RemoveTx(tx.Hash())
}
newForkChoice := &engine.ForkchoiceStateV1{ newForkChoice := &engine.ForkchoiceStateV1{
HeadBlockHash: block.Hash(), HeadBlockHash: block.Hash(),
SafeBlockHash: block.Hash(), SafeBlockHash: block.Hash(),

View file

@ -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") 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 // send to metro instead of eth mempool
txBytes, err := tx.MarshalBinary() txBytes, err := tx.MarshalBinary()
if err != nil { if err != nil {
return common.Hash{}, err return common.Hash{}, err
} }
if err := submitMetroTransaction(txBytes); err != nil {
metroAPI := NewMetroAPI(b.MetroGRPCEndpoint())
if err := metroAPI.SubmitTransaction(txBytes); err != nil {
return common.Hash{}, err return common.Hash{}, err
} }

View file

@ -97,6 +97,9 @@ type Backend interface {
SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription
BloomStatus() (uint64, uint64) BloomStatus() (uint64, uint64)
ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
// Metro GRPC endpoint
MetroGRPCEndpoint() string
} }
func GetAPIs(apiBackend Backend) []rpc.API { func GetAPIs(apiBackend Backend) []rpc.API {

View file

@ -2,10 +2,20 @@ package ethapi
import ( import (
metrotx "github.com/astriaorg/metro-transactions/tx" metrotx "github.com/astriaorg/metro-transactions/tx"
"github.com/ethereum/go-ethereum/log"
) )
const secondaryChainID = "ethereum" const secondaryChainID = "ethereum"
func submitMetroTransaction(tx []byte) error { type MetroAPI struct {
return metrotx.BuildAndSendSecondaryTransaction(metrotx.DefaultGRPCEndpoint, secondaryChainID, tx) 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)
} }

View file

@ -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) ChainDb() ethdb.Database { return nil }
func (b *backendMock) AccountManager() *accounts.Manager { return nil } func (b *backendMock) AccountManager() *accounts.Manager { return nil }
func (b *backendMock) ExtRPCEnabled() bool { return false } func (b *backendMock) ExtRPCEnabled() bool { return false }
func (b *backendMock) MetroGRPCEndpoint() string { return "" }
func (b *backendMock) RPCGasCap() uint64 { return 0 } func (b *backendMock) RPCGasCap() uint64 { return 0 }
func (b *backendMock) RPCEVMTimeout() time.Duration { return time.Second } func (b *backendMock) RPCEVMTimeout() time.Duration { return time.Second }
func (b *backendMock) RPCTxFeeCap() float64 { return 0 } func (b *backendMock) RPCTxFeeCap() float64 { return 0 }

View file

@ -19,6 +19,7 @@ package les
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"math/big" "math/big"
"time" "time"
@ -292,6 +293,10 @@ func (b *LesApiBackend) UnprotectedAllowed() bool {
return b.allowUnprotectedTxs 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 { func (b *LesApiBackend) RPCGasCap() uint64 {
return b.eth.config.RPCGasCap return b.eth.config.RPCGasCap
} }