简体   繁体   English

nonReentrant 修饰符对一个块中的多个事务有什么作用

[英]What does nonReentrant modifier do for multiple transactions in one block

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?如果nonReentrant修饰符用于传输 function 或 mint function,并且在交易量大的时期,如果多个交易在一个块中提交,那么nonReentrant对同一块中的后续交易做了什么? Will it revert them?它会还原它们吗? How does nonReentrant behave for simultaneous transactions? nonReentrant对同时事务的表现如何?

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. nonReentrant修饰符 ( code ) 中的单下划线 ( _; ) 将在 function 之前和 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 .每个事务执行使用此修饰符的 function 验证_status_NOT_ENTERED (否则引发异常),将其设置为_ENTERED ,然后执行 function,然后将_status设置回_NOT_ENTERED

If the transaction throws an uncaught exception, the contract is reverted back to the state before this transaction.如果交易抛出未捕获的异常,则合约将恢复到此交易之前的 state。 In this case, _status is reverted back to _NOT_ENTERED .在这种情况下, _status恢复为_NOT_ENTERED

In both cases, when another transaction comes in, the value of _status is always _NOT_ENTERED .在这两种情况下,当另一个事务进入时, _status的值总是_NOT_ENTERED

I think you have a misconception about reentrancy .我认为您对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.当智能合约 function 调用另一个合约然后调用原始合约(“重新进入”)时,就会发生重入,所有这些都在一个事务中。

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. OpenZeppelin nonReentrant修饰符的目的是保护智能合约 function 免受重入,根据定义,重入总是发生在同一交易中。 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).这并不意味着阻止 function 在其他交易中再次使用(无论它们是否在同一个块中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM