Skip to content

Commit 82e52c4

Browse files
committed
rpcsrv: fix RPC error codes proposal compatibility
mempool.ErrInsufficientFunds is used when sender doesn't have enough balance to pay the submitted transaction fees (-511 code according to neo-project/proposals#156). mempool.ErrConflict is used when sender is not able to pay the overall transactions fee sum in the pool (generic -500 error according to the proposal). This bugfix is kind of breaking change for those users who relied on the old -511 code previously returning "insufficient funds" error. Signed-off-by: Anna Shaleva <[email protected]>
1 parent 335550f commit 82e52c4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

pkg/services/rpcsrv/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2657,7 +2657,7 @@ func getRelayResult(err error, hash util.Uint256) (any, *neorpc.Error) {
26572657
return nil, neorpc.WrapErrorWithData(neorpc.ErrInsufficientNetworkFee, err.Error())
26582658
case errors.Is(err, core.ErrInvalidAttribute):
26592659
return nil, neorpc.WrapErrorWithData(neorpc.ErrInvalidAttribute, err.Error())
2660-
case errors.Is(err, core.ErrInsufficientFunds):
2660+
case errors.Is(err, core.ErrMemPoolConflict):
26612661
return nil, neorpc.WrapErrorWithData(neorpc.ErrInsufficientFunds, err.Error())
26622662
case errors.Is(err, core.ErrInvalidSignature):
26632663
return nil, neorpc.WrapErrorWithData(neorpc.ErrInvalidSignature, err.Error())

pkg/services/rpcsrv/server_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2659,7 +2659,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
26592659
t.Run("insufficient funds", func(t *testing.T) {
26602660
b := testchain.NewBlock(t, chain, 1, 0, newTxWithParams(t, chain, opcode.PUSH1, 10, 899999999999, 1, false))
26612661
body := doRPCCall(fmt.Sprintf(rpc, encodeBinaryToString(t, b)), httpSrv.URL, t)
2662-
checkErrGetResult(t, body, true, neorpc.ErrInsufficientFundsCode)
2662+
checkErrGetResult(t, body, true, neorpc.ErrVerificationFailedCode)
26632663
})
26642664
t.Run("positive", func(t *testing.T) {
26652665
b := testchain.NewBlock(t, chain, 1, 0, newTxWithParams(t, chain, opcode.PUSH1, 10, 0, 1, false))
@@ -3341,6 +3341,23 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
33413341
body2 := doRPCCall(fmt.Sprintf(rpc, rawTx2), httpSrv.URL, t)
33423342
checkErrGetResult(t, body2, true, neorpc.ErrMempoolCapReachedCode)
33433343
})
3344+
t.Run("mempool conflict", func(t *testing.T) {
3345+
chain, _, httpSrv := initClearServerWithCustomConfig(t, func(c *config.Config) {
3346+
c.ProtocolConfiguration.MemPoolSize = 2
3347+
})
3348+
3349+
// Create and push the first transaction with large network fee.
3350+
tx := newTxWithParams(t, chain, opcode.PUSH1, 10, 1, 25, false)
3351+
rawTx := encodeBinaryToString(t, tx)
3352+
body := doRPCCall(fmt.Sprintf(rpc, rawTx), httpSrv.URL, t)
3353+
checkErrGetResult(t, body, false, 0)
3354+
3355+
// Create and push the second transaction, sender doesn't have enough balance to pay for two transactions.
3356+
tx2 := newTxWithParams(t, chain, opcode.PUSH1, 10, 1, 25, false)
3357+
rawTx2 := encodeBinaryToString(t, tx2)
3358+
body2 := doRPCCall(fmt.Sprintf(rpc, rawTx2), httpSrv.URL, t)
3359+
checkErrGetResult(t, body2, true, neorpc.ErrInsufficientFundsCode)
3360+
})
33443361
})
33453362
t.Run("test functions with unsupported states", func(t *testing.T) {
33463363
chain, _, httpSrv := initClearServerWithCustomConfig(t, func(c *config.Config) {

0 commit comments

Comments
 (0)