If nonReentrant
modifier is used for transfer function, or mint function, and during periods of high volume of transactions if multiple transactions get submitted in one block, then what does nonReentrant
do to subsequent transactions in the same block? Will it revert them? How does nonReentrant
behave for simultaneous transactions?
Transactions are always executed in series, even in the same block.
The single-underscore line ( _;
) in the nonReentrant
modifier ( code ) divides blocks of code that are executed before the function, and after the function.
Each transaction executing a function that uses this modifier validates that the _status
is _NOT_ENTERED
(otherwise throws an exception), sets it as _ENTERED
, then executes the function, and then sets the _status
back to _NOT_ENTERED
.
If the transaction throws an uncaught exception, the contract is reverted back to the state before this transaction. In this case, _status
is reverted back to _NOT_ENTERED
.
In both cases, when another transaction comes in, the value of _status
is always _NOT_ENTERED
.
I think you have a misconception about reentrancy .
Reentrancy happens when a smart contract function calls out to another contract which then calls the original contract ("re-entering"), all within one transaction.
The point of the OpenZeppelin nonReentrant
modifier is to protect a smart contract function from reentrancy, which by definition always happens in the same transaction. It's not meant to block a function from ever being used again in other transactions (regardless of whether they are in the same block or not).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.