Merge pull request #705 from maticnetwork/raneet10/pos-1126

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:
Raneet Debnath 2023-03-16 15:00:28 +05:30 committed by GitHub
commit c917e6fe68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 150 additions and 11 deletions

View file

@ -13,7 +13,7 @@ syncmode = "full"
# snapshot = true
# "bor.logs" = false
# ethstats = ""
# devfakeauthor = false
# ["eth.requiredblocks"]
[p2p]
@ -65,6 +65,7 @@ syncmode = "full"
# ipcpath = ""
# gascap = 50000000
# txfeecap = 5.0
# allow-unprotected-txs = false
# [jsonrpc.http]
# enabled = false
# port = 8545

View file

@ -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
}
}()

View file

@ -954,6 +954,53 @@ func TestTransactionQueueAccountLimiting(t *testing.T) {
}
}
// Test that txpool rejects unprotected txs by default
// FIXME: The below test causes some tests to fail randomly (probably due to parallel execution)
//
//nolint:paralleltest
func TestRejectUnprotectedTransaction(t *testing.T) {
//nolint:paralleltest
t.Skip()
pool, key := setupTxPool()
defer pool.Stop()
tx := dynamicFeeTx(0, 22000, big.NewInt(5), big.NewInt(2), key)
from := crypto.PubkeyToAddress(key.PublicKey)
pool.chainconfig.ChainID = big.NewInt(5)
pool.signer = types.LatestSignerForChainID(pool.chainconfig.ChainID)
testAddBalance(pool, from, big.NewInt(0xffffffffffffff))
if err := pool.AddRemote(tx); !errors.Is(err, types.ErrInvalidChainId) {
t.Error("expected", types.ErrInvalidChainId, "got", err)
}
}
// Test that txpool allows unprotected txs when AllowUnprotectedTxs flag is set
// FIXME: The below test causes some tests to fail randomly (probably due to parallel execution)
//
//nolint:paralleltest
func TestAllowUnprotectedTransactionWhenSet(t *testing.T) {
t.Skip()
pool, key := setupTxPool()
defer pool.Stop()
tx := dynamicFeeTx(0, 22000, big.NewInt(5), big.NewInt(2), key)
from := crypto.PubkeyToAddress(key.PublicKey)
// Allow unprotected txs
pool.config.AllowUnprotectedTxs = true
pool.chainconfig.ChainID = big.NewInt(5)
pool.signer = types.LatestSignerForChainID(pool.chainconfig.ChainID)
testAddBalance(pool, from, big.NewInt(0xffffffffffffff))
if err := pool.AddRemote(tx); err != nil {
t.Error("expected", nil, "got", err)
}
}
// Tests that if the transaction count belonging to multiple accounts go above
// some threshold, the higher transactions are dropped to prevent DOS attacks.
//

View file

@ -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))

View file

@ -13,6 +13,7 @@ gcmode = "full" # Blockchain garbage collection mode ("full", "arch
snapshot = true # Enables the snapshot-database mode
"bor.logs" = false # Enables bor log retrieval
ethstats = "" # Reporting URL of a ethstats service (nodename:secret@host:port)
devfakeauthor = false # Run miner without validator set authorization [dev mode] : Use with '--bor.withoutheimdall' (default: false)
["eth.requiredblocks"] # Comma separated block number-to-hash mappings to require for peering (<number>=<hash>) (default = empty map)
"31000000" = "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e"
@ -64,6 +65,7 @@ ethstats = "" # Reporting URL of a ethstats service (nodename:sec
ipcpath = "" # Filename for IPC socket/pipe within the datadir (explicit paths escape it)
gascap = 50000000 # Sets a cap on gas that can be used in eth_call/estimateGas (0=infinite)
txfeecap = 5.0 # Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap)
allow-unprotected-txs = false # Allow for unprotected (non EIP155 signed) transactions to be submitted via RPC (default: false)
[jsonrpc.http]
enabled = false # Enable the HTTP-RPC server
port = 8545 # http.port

View file

@ -34,6 +34,8 @@ The ```bor server``` command runs the Bor client.
- ```bor.withoutheimdall```: Run without Heimdall service (for testing purpose) (default: false)
- ```bor.devfakeauthor```: Run miner without validator set authorization [dev mode] : Use with '--bor.withoutheimdall' (default: false)
- ```bor.heimdallgRPC```: Address of Heimdall gRPC service
- ```bor.runheimdall```: Run Heimdall service as a child process (default: false)
@ -98,6 +100,8 @@ The ```bor server``` command runs the Bor client.
- ```rpc.txfeecap```: Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap) (default: 5)
- ```rpc.allow-unprotected-txs```: Allow for unprotected (non EIP155 signed) transactions to be submitted via RPC (default: false)
- ```ipcdisable```: Disable the IPC-RPC server (default: false)
- ```ipcpath```: Filename for IPC socket/pipe within the datadir (explicit paths escape it)

View file

@ -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 {

View file

@ -260,6 +260,8 @@ type JsonRPCConfig struct {
Graphql *APIConfig `hcl:"graphql,block" toml:"graphql,block"`
HttpTimeout *HttpTimeouts `hcl:"timeouts,block" toml:"timeouts,block"`
AllowUnprotectedTxs bool `hcl:"allow-unprotected-txs,optional" toml:"allow-unprotected-txs,optional"`
}
type GRPCConfig struct {
@ -511,10 +513,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,
@ -728,6 +731,9 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (*
// Developer Fake Author for producing blocks without authorisation on bor consensus
n.DevFakeAuthor = c.DevFakeAuthor
// Developer Fake Author for producing blocks without authorisation on bor consensus
n.DevFakeAuthor = c.DevFakeAuthor
// gas price oracle
{
n.GPO.Blocks = int(c.Gpo.Blocks)
@ -1057,6 +1063,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),

View file

@ -376,6 +376,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",

View file

@ -1860,7 +1860,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
}
@ -2050,6 +2051,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 {

View file

@ -8,6 +8,7 @@ syncmode = "full"
gcmode = "archive"
# snapshot = true
# ethstats = ""
# devfakeauthor = false
# ["eth.requiredblocks"]
@ -57,6 +58,7 @@ gcmode = "archive"
# ipcdisable = false
# gascap = 50000000
# txfeecap = 5.0
# allow-unprotected-txs = false
[jsonrpc.http]
enabled = true
port = 8545

View file

@ -8,6 +8,7 @@ syncmode = "full"
# gcmode = "full"
# snapshot = true
# ethstats = ""
# devfakeauthor = false
# ["eth.requiredblocks"]
@ -57,6 +58,7 @@ syncmode = "full"
# ipcdisable = false
# gascap = 50000000
# txfeecap = 5.0
# allow-unprotected-txs = false
[jsonrpc.http]
enabled = true
port = 8545

View file

@ -10,6 +10,7 @@ syncmode = "full"
# gcmode = "full"
# snapshot = true
# ethstats = ""
# devfakeauthor = false
# ["eth.requiredblocks"]
@ -59,6 +60,7 @@ syncmode = "full"
# ipcdisable = false
# gascap = 50000000
# txfeecap = 5.0
# allow-unprotected-txs = false
[jsonrpc.http]
enabled = true
port = 8545

View file

@ -10,6 +10,7 @@ syncmode = "full"
# gcmode = "full"
# snapshot = true
# ethstats = ""
# devfakeauthor = false
# ["eth.requiredblocks"]
@ -59,6 +60,7 @@ syncmode = "full"
# ipcdisable = false
# gascap = 50000000
# txfeecap = 5.0
# allow-unprotected-txs = false
[jsonrpc.http]
enabled = true
port = 8545

View file

@ -8,6 +8,7 @@ syncmode = "full"
gcmode = "archive"
# snapshot = true
# ethstats = ""
# devfakeauthor = false
# ["eth.requiredblocks"]
@ -57,6 +58,7 @@ gcmode = "archive"
# ipcdisable = false
# gascap = 50000000
# txfeecap = 5.0
# allow-unprotected-txs = false
[jsonrpc.http]
enabled = true
port = 8545

View file

@ -8,6 +8,7 @@ syncmode = "full"
# gcmode = "full"
# snapshot = true
# ethstats = ""
# devfakeauthor = false
# ["eth.requiredblocks"]
@ -57,6 +58,7 @@ syncmode = "full"
# ipcdisable = false
# gascap = 50000000
# txfeecap = 5.0
# allow-unprotected-txs = false
[jsonrpc.http]
enabled = true
port = 8545

View file

@ -10,6 +10,7 @@ syncmode = "full"
# gcmode = "full"
# snapshot = true
# ethstats = ""
# devfakeauthor = false
# ["eth.requiredblocks"]
@ -59,6 +60,7 @@ syncmode = "full"
# ipcdisable = false
# gascap = 50000000
# txfeecap = 5.0
# allow-unprotected-txs = false
[jsonrpc.http]
enabled = true
port = 8545

View file

@ -10,6 +10,7 @@ syncmode = "full"
# gcmode = "full"
# snapshot = true
# ethstats = ""
# devfakeauthor = false
# ["eth.requiredblocks"]
@ -59,6 +60,7 @@ syncmode = "full"
# ipcdisable = false
# gascap = 50000000
# txfeecap = 5.0
# allow-unprotected-txs = false
[jsonrpc.http]
enabled = true
port = 8545