429 Errors When Buying Batches in Parallel
Context
- Bee version: 2.2
Summary
When attempting to buy postage batches, the operation takes a long time and cannot be performed in parallel with other postage post API calls. This results in a 429 status code, indicating that simultaneous on-chain operations are not supported.
Expected behavior
Buying postage batches should be efficient, and it should be possible to perform this operation in parallel with other API calls without receiving 429 status codes.
Actual behavior
When trying to buy postage batches in parallel with other API calls, the system returns a 429 status code. The logs indicate that simultaneous on-chain operations are not supported:
"postage access: simultaneous on-chain operations not supported"
This suggests that the current locking mechanism may be overly restrictive, potentially affecting the performance and scalability of the system.
Steps to reproduce
- Start multiple postage batch purchases in parallel with other postage post API calls.
- Observe that some operations fail with a 429 status code.
- Check the logs for messages indicating that simultaneous on-chain operations are not supported.
Possible solution
Review and possibly redesign the locking mechanism used during the postage batch purchase process. While the nonce handling needs to remain synchronous to prevent duplicate transactions, other parts of the process could potentially be handled in a more concurrent manner. This could improve the responsiveness and scalability of the system.
To clarify, are you suggesting
- Purchase of multiple postage batches in parallel
- Purchase of a single batch and call another API (like topup or dilute) in parallel
- 1 and 2
the first option
I don't think there's much we can do to enable parallel usage of the buy stamp endpoint. It's mostly just
expire limited batches
balance check
send approve tx
send buy tx
save stamp
BTW, it returns an "unuseable" stamp only in a few seconds. The stamp then needs a few minutes to become useable - That's not related to this endpoint.
While this endpoint shouldn't be called in parallel, factoring out the wait period might help to parallelize your flow.