From d4fc7167666c05198fec5467813a37f2d5f3048e Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 22 Jul 2024 12:21:26 +0200 Subject: [PATCH 1/2] feat: update RPC error schema for protocol version 69 With protocol version 68, cross-shard congestion control is introduced that adds two new errors on the RPC endpoints for submitting transactions. (ShardCongested, ShardStuck) Protocol version 69 introduces stateless validation and also adds a new error for submitted transactions. (ReceiptSizeExceeded) Technically, there are additional errors in nearcore's version of the rpc schema. But those are from nightly features that have not been masked properly. (NonRefundableTransferToExistingAccount and InvalidTransactionVersion are waiting for NEP-491 and NEP-541 respectively.) Aside from updating the schema, I also added human readable error messages and tests for the new errors. --- packages/utils/src/errors/error_messages.json | 4 +- .../utils/src/errors/rpc_error_schema.json | 34 +++++++++- packages/utils/test/rpc-errors.test.js | 66 ++++++++++++++++++- 3 files changed, 99 insertions(+), 5 deletions(-) diff --git a/packages/utils/src/errors/error_messages.json b/packages/utils/src/errors/error_messages.json index be5bafaf7b..587954b0e3 100644 --- a/packages/utils/src/errors/error_messages.json +++ b/packages/utils/src/errors/error_messages.json @@ -63,5 +63,7 @@ "InvalidReceiver": "Invalid receiver account ID {{receiver_id}} according to requirements", "DeleteKeyDoesNotExist": "Account {{account_id}} tries to remove an access key that doesn't exist", "Timeout": "Timeout exceeded", - "Closed": "Connection closed" + "Closed": "Connection closed", + "ShardCongested": "Shard {{shard_id}} rejected the transaction due to congestion level {{congestion_level}}, try again later", + "ShardStuck": "Shard {{shard_id}} rejected the transaction because it missed {{missed_chunks}} chunks and needs to recover before accepting new transactions, try again later" } diff --git a/packages/utils/src/errors/rpc_error_schema.json b/packages/utils/src/errors/rpc_error_schema.json index 1279c61751..aa08373fed 100644 --- a/packages/utils/src/errors/rpc_error_schema.json +++ b/packages/utils/src/errors/rpc_error_schema.json @@ -132,10 +132,12 @@ "props": { "final_accounts_balance": "", "final_postponed_receipts_balance": "", + "forwarded_buffered_receipts_balance": "", "incoming_receipts_balance": "", "incoming_validator_rewards": "", "initial_accounts_balance": "", "initial_postponed_receipts_balance": "", + "new_buffered_receipts_balance": "", "new_delayed_receipts_balance": "", "other_burnt_amount": "", "outgoing_receipts_balance": "", @@ -562,7 +564,10 @@ "InvalidChain", "Expired", "ActionsValidation", - "TransactionSizeExceeded" + "TransactionSizeExceeded", + "StorageError", + "ShardCongested", + "ShardStuck" ], "props": {} }, @@ -719,6 +724,14 @@ "method_name": "" } }, + "ReceiptSizeExceeded": { + "name": "ReceiptSizeExceeded", + "subtypes": [], + "props": { + "limit": "", + "size": "" + } + }, "ReceiptValidationError": { "name": "ReceiptValidationError", "subtypes": [ @@ -728,7 +741,8 @@ "InvalidDataReceiverId", "ReturnedValueLengthExceeded", "NumberInputDataDependenciesExceeded", - "ActionsValidation" + "ActionsValidation", + "ReceiptSizeExceeded" ], "props": {} }, @@ -758,6 +772,22 @@ "subtypes": [], "props": {} }, + "ShardCongested": { + "name": "ShardCongested", + "subtypes": [], + "props": { + "congestion_level": "", + "shard_id": "" + } + }, + "ShardStuck": { + "name": "ShardStuck", + "subtypes": [], + "props": { + "missed_chunks": "", + "shard_id": "" + } + }, "SignerDoesNotExist": { "name": "SignerDoesNotExist", "subtypes": [], diff --git a/packages/utils/test/rpc-errors.test.js b/packages/utils/test/rpc-errors.test.js index 33c5a6c6a3..2f8e989f84 100644 --- a/packages/utils/test/rpc-errors.test.js +++ b/packages/utils/test/rpc-errors.test.js @@ -6,7 +6,7 @@ describe('rpc-errors', () => { TxExecutionError: { ActionError: { index: 1, - kind: {AccountAlreadyExists: {account_id: 'bob.near'}} + kind: { AccountAlreadyExists: { account_id: 'bob.near' } } } } }; @@ -39,13 +39,75 @@ describe('rpc-errors', () => { ); }); + test('test ShardCongested error', async () => { + let rpc_error = { + TxExecutionError: { + InvalidTxError: { + ShardCongested: { + shard_id: 2, + congestion_level: 0.4 + } + } + } + }; + let error = parseRpcError(rpc_error); + expect(error.type === 'ShardCongested').toBe(true); + expect(error.shard_id).toBe(2); + expect(error.congestion_level).toBe(0.4); + expect(formatError(error.type, error)).toBe( + 'Shard 2 rejected the transaction due to congestion level 0.4, try again later' + ); + }); + + test('test ShardStuck error', async () => { + let rpc_error = { + TxExecutionError: { + InvalidTxError: { + ShardStuck: { + shard_id: 2, + missed_chunks: 5 + } + } + } + }; + let error = parseRpcError(rpc_error); + expect(error.type === 'ShardStuck').toBe(true); + expect(error.shard_id).toBe(2); + expect(error.missed_chunks).toBe(5); + expect(formatError(error.type, error)).toBe( + 'Shard 2 rejected the transaction because it missed 5 chunks and needs to recover before accepting new transactions, try again later' + ); + }); + + test('test ReceiptSizeExceeded error', async () => { + let rpc_error = { + TxExecutionError: { + InvalidTxError: { + ReceiptValidationError: { + ReceiptSizeExceeded: { + limit: 100, + size: 101 + } + } + } + } + }; + let error = parseRpcError(rpc_error); + expect(error.type === 'ReceiptSizeExceeded').toBe(true); + expect(error.limit).toBe(100); + expect(error.size).toBe(101); + expect(formatError(error.type, error)).toBe( + '{\"type\":\"ReceiptSizeExceeded\",\"limit\":100,\"size\":101,\"kind\":{\"limit\":100,\"size\":101}}' + ); + }); + test('test InvalidIteratorIndex error', async () => { let rpc_error = { TxExecutionError: { ActionError: { FunctionCallError: { HostError: { - InvalidIteratorIndex: {iterator_index: 42} + InvalidIteratorIndex: { iterator_index: 42 } } } } From bad95007edde4ed9d5989ded7f2032b9f15f5c23 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 22 Jul 2024 12:42:34 +0200 Subject: [PATCH 2/2] chore: add changeset --- .changeset/fast-books-stare.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fast-books-stare.md diff --git a/.changeset/fast-books-stare.md b/.changeset/fast-books-stare.md new file mode 100644 index 0000000000..35924c905b --- /dev/null +++ b/.changeset/fast-books-stare.md @@ -0,0 +1,5 @@ +--- +"@near-js/utils": minor +--- + +New transaction submission errors: ShardCongested, ShardStuck, ReceiptSizeExceeded