From 39694bc9d5ed52a73d91a286f2f61bef4a7a69f4 Mon Sep 17 00:00:00 2001 From: Roberto Bayardo Date: Tue, 17 Jan 2023 23:38:47 -0800 Subject: [PATCH] nit: tweak error handling for rlp too big (#834) I believe ValidateSerializedTxn should be returning (or at least wrapping) types.RlpTooBig instead of creating a new error when the transaction exceeds max size, since this is the error the txpool actually checks for: https://github.com/ledgerwatch/erigon-lib/blob/61706714c391a85922d0486ec8bf8c49385fc029/txpool/txpool_grpc_server.go#L204 Before this change the ImportResult for an oversized tx would be INTERNAL_ERROR; after this change it will be INVALID, which seems more appropriate. Co-authored-by: Alex Sharov --- txpool/pool.go | 2 +- txpool/txpool_grpc_server.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/txpool/pool.go b/txpool/pool.go index 7dec14895..791298679 100644 --- a/txpool/pool.go +++ b/txpool/pool.go @@ -822,7 +822,7 @@ func (p *TxPool) ValidateSerializedTxn(serializedTxn []byte) error { txMaxSize = 4 * txSlotSize // 128KB ) if len(serializedTxn) > txMaxSize { - return fmt.Errorf(RLPTooLong.String()) + return types.ErrRlpTooBig } return nil } diff --git a/txpool/txpool_grpc_server.go b/txpool/txpool_grpc_server.go index fd12a9235..4484ea325 100644 --- a/txpool/txpool_grpc_server.go +++ b/txpool/txpool_grpc_server.go @@ -240,7 +240,7 @@ func mapDiscardReasonToProto(reason DiscardReason) txpool_proto.ImportResult { return txpool_proto.ImportResult_ALREADY_EXISTS case UnderPriced, ReplaceUnderpriced, FeeTooLow: return txpool_proto.ImportResult_FEE_TOO_LOW - case InvalidSender, NegativeValue, OversizedData, InitCodeTooLarge: + case InvalidSender, NegativeValue, OversizedData, InitCodeTooLarge, RLPTooLong: return txpool_proto.ImportResult_INVALID default: return txpool_proto.ImportResult_INTERNAL_ERROR