Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions cmd/XDC/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ var (
utils.IPCDisabledFlag,
utils.IPCPathFlag,
utils.RPCGlobalTxFeeCap,
utils.AllowUnprotectedTxs,
}

metricsFlags = []cli.Flag{
Expand Down
8 changes: 8 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,11 @@ var (
Usage: "Comma separated list of JavaScript files to preload into the console",
Category: flags.APICategory,
}
AllowUnprotectedTxs = &cli.BoolFlag{
Name: "rpc.allow-unprotected-txs",
Usage: "Allow for unprotected (non EIP155 signed) transactions to be submitted via RPC",
Category: flags.APICategory,
}

// Network Settings
MaxPeersFlag = &cli.IntFlag{
Expand Down Expand Up @@ -1014,6 +1019,9 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
if ctx.IsSet(HTTPIdleTimeoutFlag.Name) {
cfg.HTTPTimeouts.IdleTimeout = ctx.Duration(HTTPIdleTimeoutFlag.Name)
}
if ctx.IsSet(AllowUnprotectedTxs.Name) {
cfg.AllowUnprotectedTxs = ctx.Bool(AllowUnprotectedTxs.Name)
}
cfg.HTTPCors = SplitAndTrim(ctx.String(HTTPCORSDomainFlag.Name))
cfg.HTTPModules = SplitAndTrim(ctx.String(HTTPApiFlag.Name))
cfg.HTTPVirtualHosts = SplitAndTrim(ctx.String(HTTPVirtualHostsFlag.Name))
Expand Down
11 changes: 8 additions & 3 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ import (

// EthAPIBackend implements ethapi.Backend for full nodes
type EthAPIBackend struct {
eth *Ethereum
gpo *gasprice.Oracle
XDPoS *XDPoS.XDPoS
allowUnprotectedTxs bool
eth *Ethereum
gpo *gasprice.Oracle
XDPoS *XDPoS.XDPoS
}

func (b *EthAPIBackend) ChainConfig() *params.ChainConfig {
Expand Down Expand Up @@ -369,6 +370,10 @@ func (b *EthAPIBackend) EventMux() *event.TypeMux {
return b.eth.EventMux()
}

func (b *EthAPIBackend) UnprotectedAllowed() bool {
return b.allowUnprotectedTxs
}

func (b *EthAPIBackend) RPCGasCap() uint64 {
return b.eth.config.RPCGasCap
}
Expand Down
15 changes: 12 additions & 3 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,19 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, stack.Config().AnnounceTxs)
eth.miner.SetExtra(makeExtraData(config.ExtraData))

var xdPoS *XDPoS.XDPoS = nil
if eth.chainConfig.XDPoS != nil {
eth.ApiBackend = &EthAPIBackend{eth, nil, eth.engine.(*XDPoS.XDPoS)}
} else {
eth.ApiBackend = &EthAPIBackend{eth, nil, nil}
xdPoS = eth.engine.(*XDPoS.XDPoS)
}
eth.ApiBackend = &EthAPIBackend{
allowUnprotectedTxs: stack.Config().AllowUnprotectedTxs,
eth: eth,
gpo: nil,
XDPoS: xdPoS,
}

if eth.ApiBackend.allowUnprotectedTxs {
Comment thread
JukLee0ira marked this conversation as resolved.
Outdated
log.Info("Unprotected transactions allowed")
}
eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, config.GPO, config.GasPrice)

Expand Down
4 changes: 4 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,10 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
if err := checkTxFee(tx.GasPrice(), tx.Gas(), b.RPCTxFeeCap()); err != nil {
return common.Hash{}, err
}
if !b.UnprotectedAllowed() && !tx.Protected() {
// Ensure only eip155 signed transactions are submitted if EIP155Required is set.
return common.Hash{}, errors.New("only replay-protected (EIP-155) transactions allowed over RPC")
}
if err := b.SendTx(ctx, tx); err != nil {
return common.Hash{}, err
}
Expand Down
6 changes: 4 additions & 2 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ type Backend interface {
BlobBaseFee(ctx context.Context) *big.Int
ChainDb() ethdb.Database
AccountManager() *accounts.Manager
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs
UnprotectedAllowed() bool // allows only for EIP155 transactions.

XDCxService() *XDCx.XDCX
LendingService() *XDCxlending.Lending

Expand Down
3 changes: 3 additions & 0 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ type Config struct {
oldGethResourceWarning bool

AnnounceTxs bool `toml:",omitempty"`

// AllowUnprotectedTxs allows non EIP-155 protected transactions to be send over RPC.
AllowUnprotectedTxs bool `toml:",omitempty"`
}

// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
Expand Down
2 changes: 1 addition & 1 deletion node/rpcstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func baseRpcRequest(t *testing.T, url, bodyStr string, extraHeaders ...string) *

// Create the request.
body := bytes.NewReader([]byte(bodyStr))
req, err := http.NewRequest("POST", url, body)
req, err := http.NewRequest(http.MethodPost, url, body)
if err != nil {
t.Fatal("could not create http request:", err)
}
Expand Down