mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
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:
parent
e19690c976
commit
c2d33eb566
11 changed files with 83 additions and 3 deletions
|
|
@ -185,6 +185,11 @@ var (
|
|||
utils.GRPCPortFlag,
|
||||
}
|
||||
|
||||
metroFlags = []cli.Flag{
|
||||
utils.MetroGRPCHostFlag,
|
||||
utils.MetroGRPCPortFlag,
|
||||
}
|
||||
|
||||
metricsFlags = []cli.Flag{
|
||||
utils.MetricsEnabledFlag,
|
||||
utils.MetricsEnabledExpensiveFlag,
|
||||
|
|
@ -248,6 +253,7 @@ func init() {
|
|||
app.Flags = flags.Merge(
|
||||
nodeFlags,
|
||||
rpcFlags,
|
||||
metroFlags,
|
||||
consoleFlags,
|
||||
debug.Flags,
|
||||
metricsFlags,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package eth
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
// remove txs from original mempool
|
||||
for _, tx := range block.Transactions() {
|
||||
s.eth.TxPool().RemoveTx(tx.Hash())
|
||||
}
|
||||
|
||||
newForkChoice := &engine.ForkchoiceStateV1{
|
||||
HeadBlockHash: block.Hash(),
|
||||
SafeBlockHash: block.Hash(),
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
metroAPI := NewMetroAPI(b.MetroGRPCEndpoint())
|
||||
if err := metroAPI.SubmitTransaction(txBytes); err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package les
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue