mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
core,eth,internal/cli,internal/ethapi: add --rpc.allow-unprotected-txs flag to allow txs to get replayed (for shadow node)
This commit is contained in:
parent
2ad6dcf53b
commit
cb973283bc
6 changed files with 76 additions and 10 deletions
|
|
@ -174,7 +174,8 @@ type TxPoolConfig struct {
|
|||
AccountQueue uint64 // Maximum number of non-executable transaction slots permitted per account
|
||||
GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts
|
||||
|
||||
Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
|
||||
Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
|
||||
AllowUnprotectedTxs bool // Allow non-EIP-155 transactions
|
||||
}
|
||||
|
||||
// DefaultTxPoolConfig contains the default configurations for the transaction
|
||||
|
|
@ -191,7 +192,8 @@ var DefaultTxPoolConfig = TxPoolConfig{
|
|||
AccountQueue: 64,
|
||||
GlobalQueue: 1024,
|
||||
|
||||
Lifetime: 3 * time.Hour,
|
||||
Lifetime: 3 * time.Hour,
|
||||
AllowUnprotectedTxs: false,
|
||||
}
|
||||
|
||||
// sanitize checks the provided user configurations and changes anything that's
|
||||
|
|
@ -759,7 +761,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
|||
|
||||
// Make sure the transaction is signed properly.
|
||||
from, err := types.Sender(pool.signer, tx)
|
||||
if err != nil {
|
||||
if err != nil && !pool.config.AllowUnprotectedTxs {
|
||||
return ErrInvalidSender
|
||||
}
|
||||
|
||||
|
|
@ -1096,6 +1098,11 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
|
|||
// Exclude transactions with invalid signatures as soon as
|
||||
// possible and cache senders in transactions before
|
||||
// obtaining lock
|
||||
|
||||
if pool.config.AllowUnprotectedTxs {
|
||||
pool.signer = types.NewFakeSigner(tx.ChainId())
|
||||
}
|
||||
|
||||
_, err = types.Sender(pool.signer, tx)
|
||||
if err != nil {
|
||||
errs = append(errs, ErrInvalidSender)
|
||||
|
|
@ -1149,11 +1156,16 @@ func (pool *TxPool) addTx(tx *types.Transaction, local, sync bool) error {
|
|||
// Exclude transactions with invalid signatures as soon as
|
||||
// possible and cache senders in transactions before
|
||||
// obtaining lock
|
||||
if pool.config.AllowUnprotectedTxs {
|
||||
pool.signer = types.NewFakeSigner(tx.ChainId())
|
||||
}
|
||||
|
||||
_, err = types.Sender(pool.signer, tx)
|
||||
if err != nil {
|
||||
invalidTxMeter.Mark(1)
|
||||
|
||||
return
|
||||
} else {
|
||||
err = nil
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -470,6 +470,42 @@ func (fs FrontierSigner) Hash(tx *Transaction) common.Hash {
|
|||
})
|
||||
}
|
||||
|
||||
// FakeSigner implements the Signer interface and accepts unprotected transactions
|
||||
type FakeSigner struct{ londonSigner }
|
||||
|
||||
var _ Signer = FakeSigner{}
|
||||
|
||||
func NewFakeSigner(chainId *big.Int) Signer {
|
||||
signer := NewLondonSigner(chainId)
|
||||
ls, _ := signer.(londonSigner)
|
||||
|
||||
return FakeSigner{londonSigner: ls}
|
||||
}
|
||||
|
||||
func (f FakeSigner) Sender(tx *Transaction) (common.Address, error) {
|
||||
return f.londonSigner.Sender(tx)
|
||||
}
|
||||
|
||||
func (f FakeSigner) SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error) {
|
||||
return f.londonSigner.SignatureValues(tx, sig)
|
||||
}
|
||||
|
||||
func (f FakeSigner) ChainID() *big.Int {
|
||||
return f.londonSigner.ChainID()
|
||||
}
|
||||
|
||||
// Hash returns 'signature hash', i.e. the transaction hash that is signed by the
|
||||
// private key. This hash does not uniquely identify the transaction.
|
||||
func (f FakeSigner) Hash(tx *Transaction) common.Hash {
|
||||
return f.londonSigner.Hash(tx)
|
||||
}
|
||||
|
||||
// Equal returns true if the given signer is the same as the receiver.
|
||||
func (f FakeSigner) Equal(Signer) bool {
|
||||
// Always return true
|
||||
return true
|
||||
}
|
||||
|
||||
func decodeSignature(sig []byte) (r, s, v *big.Int) {
|
||||
if len(sig) != crypto.SignatureLength {
|
||||
panic(fmt.Sprintf("wrong size for signature: got %d, want %d", len(sig), crypto.SignatureLength))
|
||||
|
|
|
|||
|
|
@ -174,7 +174,9 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
// START: Bor changes
|
||||
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
|
||||
if eth.APIBackend.allowUnprotectedTxs {
|
||||
log.Info("Unprotected transactions allowed")
|
||||
log.Debug(" ###########", "Unprotected transactions allowed")
|
||||
|
||||
config.TxPool.AllowUnprotectedTxs = true
|
||||
}
|
||||
gpoParams := config.GPO
|
||||
if gpoParams.Default == nil {
|
||||
|
|
|
|||
|
|
@ -254,6 +254,8 @@ type JsonRPCConfig struct {
|
|||
Graphql *APIConfig `hcl:"graphql,block" toml:"graphql,block"`
|
||||
|
||||
HttpTimeout *HttpTimeouts `hcl:"timeouts,block" toml:"timeouts,block"`
|
||||
|
||||
AllowUnprotectedTxs bool `hcl:"unprotectedtxs,optional" toml:"unprotectedtxs,optional"`
|
||||
}
|
||||
|
||||
type GRPCConfig struct {
|
||||
|
|
@ -504,10 +506,11 @@ func DefaultConfig() *Config {
|
|||
IgnorePrice: gasprice.DefaultIgnorePrice,
|
||||
},
|
||||
JsonRPC: &JsonRPCConfig{
|
||||
IPCDisable: false,
|
||||
IPCPath: "",
|
||||
GasCap: ethconfig.Defaults.RPCGasCap,
|
||||
TxFeeCap: ethconfig.Defaults.RPCTxFeeCap,
|
||||
IPCDisable: false,
|
||||
IPCPath: "",
|
||||
GasCap: ethconfig.Defaults.RPCGasCap,
|
||||
TxFeeCap: ethconfig.Defaults.RPCTxFeeCap,
|
||||
AllowUnprotectedTxs: false,
|
||||
Http: &APIConfig{
|
||||
Enabled: false,
|
||||
Port: 8545,
|
||||
|
|
@ -1049,6 +1052,7 @@ func (c *Config) buildNode() (*node.Config, error) {
|
|||
InsecureUnlockAllowed: c.Accounts.AllowInsecureUnlock,
|
||||
Version: params.VersionWithCommit(gitCommit, gitDate),
|
||||
IPCPath: ipcPath,
|
||||
AllowUnprotectedTxs: c.JsonRPC.AllowUnprotectedTxs,
|
||||
P2P: p2p.Config{
|
||||
MaxPeers: int(c.P2P.MaxPeers),
|
||||
MaxPendingPeers: int(c.P2P.MaxPendPeers),
|
||||
|
|
|
|||
|
|
@ -364,6 +364,13 @@ func (c *Command) Flags() *flagset.Flagset {
|
|||
Default: c.cliConfig.JsonRPC.TxFeeCap,
|
||||
Group: "JsonRPC",
|
||||
})
|
||||
f.BoolFlag(&flagset.BoolFlag{
|
||||
Name: "rpc.allow-unprotected-txs",
|
||||
Usage: "Allow for unprotected (non EIP155 signed) transactions to be submitted via RPC",
|
||||
Value: &c.cliConfig.JsonRPC.AllowUnprotectedTxs,
|
||||
Default: c.cliConfig.JsonRPC.AllowUnprotectedTxs,
|
||||
Group: "JsonRPC",
|
||||
})
|
||||
f.BoolFlag(&flagset.BoolFlag{
|
||||
Name: "ipcdisable",
|
||||
Usage: "Disable the IPC-RPC server",
|
||||
|
|
|
|||
|
|
@ -1856,7 +1856,8 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
|
|||
// Print a log with full tx details for manual investigations and interventions
|
||||
signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number())
|
||||
from, err := types.Sender(signer, tx)
|
||||
if err != nil {
|
||||
|
||||
if err != nil && (!b.UnprotectedAllowed() || (b.UnprotectedAllowed() && err != types.ErrInvalidChainId)) {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
|
||||
|
|
@ -2046,6 +2047,10 @@ func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs Transact
|
|||
for _, p := range pending {
|
||||
wantSigHash := s.signer.Hash(matchTx)
|
||||
pFrom, err := types.Sender(s.signer, p)
|
||||
|
||||
if err != nil && (s.b.UnprotectedAllowed() && err == types.ErrInvalidChainId) {
|
||||
err = nil
|
||||
}
|
||||
if err == nil && pFrom == sendArgs.from() && s.signer.Hash(p) == wantSigHash {
|
||||
// Match. Re-sign and send the transaction.
|
||||
if gasPrice != nil && (*big.Int)(gasPrice).Sign() != 0 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue