-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
soft delete nonce in s_consumers so that request IDs do not repeat #12405
Changes from 5 commits
4aca8af
7326acb
cef7a63
75361ea
74d44a1
91717d9
7f34448
f89c9fc
80feabe
8dd28f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,8 +60,13 @@ abstract contract SubscriptionAPI is ConfirmedOwner, IERC677Receiver, IVRFSubscr | |
// consumer is valid without reading all the consumers from storage. | ||
address[] consumers; | ||
} | ||
struct ConsumerConfig { | ||
bool active; | ||
uint64 nonce; | ||
} | ||
// Note a nonce of 0 indicates an the consumer is not assigned to that subscription. | ||
mapping(address => mapping(uint256 => uint64)) /* consumer */ /* subId */ /* nonce */ internal s_consumers; | ||
mapping(address => mapping(uint256 => ConsumerConfig)) /* consumerAddress */ /* subId */ /* consumerConfig */ | ||
internal s_consumers; | ||
mapping(uint256 => SubscriptionConfig) /* subId */ /* subscriptionConfig */ internal s_subscriptionConfigs; | ||
mapping(uint256 => Subscription) /* subId */ /* subscription */ internal s_subscriptions; | ||
// subscription nonce used to construct subId. Rises monotonically | ||
|
@@ -405,14 +410,16 @@ abstract contract SubscriptionAPI is ConfirmedOwner, IERC677Receiver, IVRFSubscr | |
if (consumers.length == MAX_CONSUMERS) { | ||
revert TooManyConsumers(); | ||
} | ||
mapping(uint256 => uint64) storage nonces = s_consumers[consumer]; | ||
if (nonces[subId] != 0) { | ||
ConsumerConfig storage consumerConfig = s_consumers[consumer][subId]; | ||
if (consumerConfig.active) { | ||
// Idempotence - do nothing if already added. | ||
// Ensures uniqueness in s_subscriptions[subId].consumers. | ||
return; | ||
} | ||
// Initialize the nonce to 1, indicating the consumer is allocated. | ||
nonces[subId] = 1; | ||
// consumerConfig.nonce is 0 if the consumer had never sent a request to this subscription | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we consider starting nonce at 1, to maintain parity with previous implementation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think 0 makes more sense because previously 0 indicated inactive consumer but now, we have a Also, we increment nonce before generating the first requestID here. So if we start the nonce at 1 here, first requestID will be generated with nonce 2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, as long as the boolean is |
||
// otherwise, consumerConfig.nonce is non-zero | ||
// in both cases, use consumerConfig.nonce as is and set active status to true | ||
consumerConfig.active = true; | ||
consumers.push(consumer); | ||
|
||
emit SubscriptionConsumerAdded(subId, consumer); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this check before
if (consumers.length == MAX_CONSUMERS) {
, since attempting to add same consumer again should be an idempotent operation instead of revertingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense technically. Can change it