简体   繁体   English

以太坊 BC 智能合约执行重复

[英]Ethereum BC Smart Contract Execution Duplicates

I am currently learning solidity for writing smart contracts.我目前正在学习编写智能合约的可靠性。 I understand smart contracts are stored on the Ethereum block chain and broadcast and exectued by all the nodes on the.network.我了解智能合约存储在以太坊区块链上,并由 .network 上的所有节点广播和执行。 google: A smart contract refers to a piece of computer program that gets executed by a quorum of blockchain nodes independently in order to record the latest program state.谷歌:智能合约是指由一定数量的区块链节点独立执行的一段计算机程序,以记录最新的程序 state。

This is where I am having a bit of problem understanding the execution cycle.这是我在理解执行周期时遇到一些问题的地方。 Let's say we are doing something that happens only once, exchanging an ERC20 token for ETH for example.假设我们正在做只发生一次的事情,例如用 ERC20 代币交换 ETH。 Take Node A and B. Node A exectues the transfer and does the transfer, say for example.以节点 A 和 B 为例。节点 A 执行传输并进行传输,例如。 When Node B executes the code, there will be a check on the balance in the smart contract or something, but does it even get to this point. B节点在执行代码的时候,会检查智能合约里面的余额什么的,但是到底有没有到这个地步。 Is the actual smart contract really executed more than once or is it done once and the other executions are somehow different?实际的智能合约是否真的执行了不止一次,还是只执行了一次而其他执行却有所不同?

confused since we are writing a contract which does an action one time but gets executed multiple times, thanks for links to other readings.很困惑,因为我们正在编写一个执行一次操作但多次执行的合同,感谢其他阅读材料的链接。

Node A exectues the transfer and does the transfer, say for example.例如,节点 A 执行传输并进行传输。 When Node B executes the code, there will be a check on the balance in the smart contract or something, but does it even get to this point. B节点在执行代码的时候,会检查智能合约里面的余额什么的,但是到底有没有到这个地步。 Is the actual smart contract really executed more than once or is it done once and the other executions are somehow different?实际的智能合约是否真的执行了不止一次,还是只执行了一次而其他执行却有所不同?

Currently all Ethereum nodes in the world execute all transactions in a blockchain.目前世界上所有的以太坊节点都执行区块链中的所有交易。 The node that is a mining node produces a block that contains the state transition from state 1 -> state 2. This is so called "transaction is included in a block".作为挖掘节点的节点产生一个块,该块包含从 state 1 -> state 2 的 state 转换。这就是所谓的“交易包含在一个块中”。 Then all other nodes that download the block will check that all transactions in this node were correctly executed.然后下载该块的所有其他节点将检查该节点中的所有交易是否已正确执行。

To get a better grasp of how it all comes together, I recommend checking out http://ethviewer.live/ .为了更好地了解这一切是如何组合在一起的,我建议查看http://ethviewer.live/ When you write your smart contract, you need to deploy it to the Ethereum blockchain first.当您编写智能合约时,您需要先将其部署到以太坊区块链。 This deploy costs gas, and is transmitted to the chain as a transaction just as it would for a typical token transfer.这种部署会消耗 gas,并作为交易传输到链上,就像典型的代币转移一样。 You can observer contract creations / contract-calls being pooled into the transaction queue before they are pushed into blocks.您可以观察到合约创建/合约调用在被推入区块之前被汇集到交易队列中。

If Node A is only deploying the contract once (to be executed say, thousands of times by other people), Node A ONLY pays the gas cost of deploying that contract to the blockchain.如果节点 A 只部署一次合约(比如说,被其他人执行数千次),节点 A 只支付将该合约部署到区块链的 gas 成本。 Whoever wishes to interact with Node A's contract at a future time (say, Node B), would have to pay the associated gas cost in order to execute those contract calls.无论谁希望在未来某个时间与节点 A 的合约进行交互(比如节点 B),都必须支付相关的 gas 成本才能执行这些合约调用。

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

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