Skip to content

Commit

Permalink
Merge pull request #1363 from jakmeier/update-error-v69
Browse files Browse the repository at this point in the history
feat: update RPC error schema for protocol version 69
  • Loading branch information
andy-haynes authored Jul 30, 2024
2 parents cc93136 + 8584206 commit f6b7794
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-books-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@near-js/utils": minor
---

New transaction submission errors: ShardCongested, ShardStuck, ReceiptSizeExceeded
4 changes: 3 additions & 1 deletion packages/utils/src/errors/error_messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
34 changes: 32 additions & 2 deletions packages/utils/src/errors/rpc_error_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -562,7 +564,10 @@
"InvalidChain",
"Expired",
"ActionsValidation",
"TransactionSizeExceeded"
"TransactionSizeExceeded",
"StorageError",
"ShardCongested",
"ShardStuck"
],
"props": {}
},
Expand Down Expand Up @@ -719,6 +724,14 @@
"method_name": ""
}
},
"ReceiptSizeExceeded": {
"name": "ReceiptSizeExceeded",
"subtypes": [],
"props": {
"limit": "",
"size": ""
}
},
"ReceiptValidationError": {
"name": "ReceiptValidationError",
"subtypes": [
Expand All @@ -728,7 +741,8 @@
"InvalidDataReceiverId",
"ReturnedValueLengthExceeded",
"NumberInputDataDependenciesExceeded",
"ActionsValidation"
"ActionsValidation",
"ReceiptSizeExceeded"
],
"props": {}
},
Expand Down Expand Up @@ -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": [],
Expand Down
66 changes: 64 additions & 2 deletions packages/utils/test/rpc-errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('rpc-errors', () => {
TxExecutionError: {
ActionError: {
index: 1,
kind: {AccountAlreadyExists: {account_id: 'bob.near'}}
kind: { AccountAlreadyExists: { account_id: 'bob.near' } }
}
}
};
Expand Down Expand Up @@ -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 }
}
}
}
Expand Down

0 comments on commit f6b7794

Please sign in to comment.