当多个客户试图在坚固的合同中同时更改状态变量时会发生什么?
对于像MySQL这样的数据库,我们有数据一致性的锁,当2个客户端尝试查找值并进行更新时,我可以使用锁来确保第二个客户端始终等待第一个客户端完成其操作。
是否有任何以太坊/坚固性(如锁)的机制?如果没有,如果我在以太坊上签订合同,会发生什么:
contract MyContract{
string name;
function changeName(string memory newName) public view{
name = newName;
}
}
当地址呼叫changeName(“ name1”)和地址B呼叫changeName(“ name2”)时,会发生什么?状态变量“名称”的值是多少?
For databases like MySQL, we have locks for data consistency, when 2 clients try to look up a value and update it, I can use locks to make sure the second client always wait for the first client finish its operation.
Is there any mechanisms for ethereum/solidity like locks for data consistency? If not, what will happen if I have a contract on ethereum:
contract MyContract{
string name;
function changeName(string memory newName) public view{
name = newName;
}
}
When address A calling changeName("name1") and address B calling changeName("name2") at the same time? What will be the value of state variable "name"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EVM串联执行所有交易,而不是并行。
实际顺序是在块中执行的交易取决于该特定块的矿工(POW)或验证器(POS)。但是,在大多数情况下,它们只是从最大的
加斯普里斯
订购至最小。另请注意,
View
修饰符将此功能删除以更改合同状态。但是,如果省略修饰符,则适用上述。The EVM executes all transactions in series, not in parallel.
Actual order in which are the transactions executed within a block depends on the miner (PoW) or validator (PoS) of that specific block. However in most cases they simply order from largest
gasPrice
to smallest.Also note that the
view
modifier disallows this function to change the contract state. But if you omit the modifier, the above applies.