From 0559b2029bce8188f225c758039fbc37d6e2fda1 Mon Sep 17 00:00:00 2001 From: Andrew Gross Date: Wed, 15 Aug 2018 10:51:51 -0600 Subject: [PATCH] blockchain app content (#335) * blockchain app content * review changes --- README.md | 1 + apps/blockchain/LICENSE.md | 25 -------- apps/blockchain/README.md | 62 ++----------------- apps/blockchain/lib/blockchain.ex | 10 ++- apps/blockchain/lib/blockchain/account.ex | 2 +- apps/blockchain/lib/blockchain/application.ex | 4 -- apps/blockchain/lib/blockchain/block.ex | 4 +- apps/blockchain/lib/blockchain/bloom.ex | 13 ++++ apps/blockchain/lib/math_helper.ex | 3 +- apps/blockchain/lib/test.ex | 2 +- 10 files changed, 33 insertions(+), 93 deletions(-) delete mode 100644 apps/blockchain/LICENSE.md diff --git a/README.md b/README.md index 88de566ae..0105516e3 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ Ethereum common tests are created for all clients to test against. We plan to pr - [ ] Byzantium - [ ] Constantinople: View the community [Constantinople Project Tracker](https://github.com/ethereum/pm/issues/53). + # Project Status | Functionality | Status | diff --git a/apps/blockchain/LICENSE.md b/apps/blockchain/LICENSE.md deleted file mode 100644 index 28bbb5a6c..000000000 --- a/apps/blockchain/LICENSE.md +++ /dev/null @@ -1,25 +0,0 @@ -The MIT License (MIT) -===================== - -Copyright © 2017 Geoffrey Hayes, Ayrat Badykov, Mason Fischer - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the “Software”), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. diff --git a/apps/blockchain/README.md b/apps/blockchain/README.md index 3ed59bb01..904db9328 100644 --- a/apps/blockchain/README.md +++ b/apps/blockchain/README.md @@ -1,69 +1,17 @@ -# Exthereum Blockchain [![CircleCI](https://circleci.com/gh/exthereum/blockchain.svg?style=svg)](https://circleci.com/gh/exthereum/blockchain) +# Mana-Ethereum Blockchain [![CircleCI](https://circleci.com/gh/exthereum/blockchain.svg?style=svg)](https://circleci.com/gh/exthereum/blockchain) -Elixir implementation of Ethereum's Blockchain. +An Elixir implementation of the Ethereum Blockchain. This includes functionality to build and verify a chain of Ethereum blocks that may be advertised from any peer. We complete the resultant state of the blocktree and form a canonical blockchain based on difficulty. -Exthereum's blocks are specified in a variety of sections throughout [the yellow paper](https://ethereum.github.io/yellowpaper/paper.pdf), -but it's best to start looking under Section 4.3. +Mana-Ethereum's blocks are specified in a variety of sections throughout [the yellow paper](https://ethereum.github.io/yellowpaper/paper.pdf). Blocks, State and Transactions begin in section 4. ## Installation -```bash -export "CFLAGS=-I/usr/local/include -L/usr/local/lib" -cd deps/libsecp256k1 && rebar compile -mix compile -``` +Installation is handled through the bin/setup procedure in the [Mana-Ethereum README](https://github.com/poanetwork/mana). -## Debugging - -To debug a given run of the blockchain, you can set breakpoints on contract addresses by -setting the `BREAKPOINT` environment variable and specifying a contract address to break on. E.g. - -```bash -BREAKPOINT=bc1ffc1620da1468624a596cb841d35e6b2f1fb6 iex -S mix - -... - -00:04:18.739 [warn] Debugger has been enabled. Set breakpoint #1 on contract address 0xbc1ffc1620da1468624a596cb841d35e6b2f1fb6. - -... - --- Breakpoint #1 triggered with conditions contract address 0xbc1ffc1620da1468624a596cb841d35e6b2f1fb6 (start) -- - -gas: 277888 | pc: 0 | memory: 0 | words: 0 | # stack: 0 - -----> [ 0] push2 - [ 1] 0 - [ 2] 4 - [ 3] dup1 - [ 4] push2 - [ 5] 0 - [ 6] 14 - [ 7] push1 - [ 8] 0 - [ 9] codecopy - -Enter a debug command or type `h` for help. - ->> -``` ## Contributing -1. [Fork it!](https://github.com/exthereum/blockchain/fork) -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Add some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create new Pull Request - -## Author - -Geoffrey Hayes (@hayesgm) -Ayrat Badykov (@ayrat555) -Mason Fischer (@masonforest) - -## License +See the [CONTRIBUTING](CONTRIBUTING.md) document for contribution, testing and pull request protocol. -Exthereum's Blockchain is released under the MIT License. -See the LICENSE file for further details. diff --git a/apps/blockchain/lib/blockchain.ex b/apps/blockchain/lib/blockchain.ex index 7e9b8fcc3..703ad2a9f 100644 --- a/apps/blockchain/lib/blockchain.ex +++ b/apps/blockchain/lib/blockchain.ex @@ -1,5 +1,13 @@ defmodule Blockchain do @moduledoc """ - Documentation for Blockchain. + The Blockchain application is responsible for Ethereum blockchain processes and capabilities as defined in the [Ethereum yellow paper](https://ethereum.github.io/yellowpaper/paper.pdf) + + Application functionality includes: + * Block encoding + * Adding blocks to the block tree to form a consistent blockchain + * Chain specific information + * Genesis block generation + * Transaction serialization + * Contract creation and message calls """ end diff --git a/apps/blockchain/lib/blockchain/account.ex b/apps/blockchain/lib/blockchain/account.ex index 517ef078e..ffd5f27a4 100644 --- a/apps/blockchain/lib/blockchain/account.ex +++ b/apps/blockchain/lib/blockchain/account.ex @@ -1,6 +1,6 @@ defmodule Blockchain.Account do @moduledoc """ - Represents the state of an account, + Represents the account state, as defined in Section 4.1 of the Yellow Paper. """ diff --git a/apps/blockchain/lib/blockchain/application.ex b/apps/blockchain/lib/blockchain/application.ex index fead7add1..08e7f652b 100644 --- a/apps/blockchain/lib/blockchain/application.ex +++ b/apps/blockchain/lib/blockchain/application.ex @@ -1,6 +1,4 @@ defmodule Blockchain.Application do - # See http://elixir-lang.org/docs/stable/elixir/Application.html - # for more information on OTP Applications @moduledoc false use Application @@ -32,8 +30,6 @@ defmodule Blockchain.Application do # worker(Blockchain.Worker, [arg1, arg2, arg3]), ] - # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html - # for other strategies and supported options opts = [strategy: :one_for_one, name: Blockchain.Supervisor] Supervisor.start_link(children, opts) end diff --git a/apps/blockchain/lib/blockchain/block.ex b/apps/blockchain/lib/blockchain/block.ex index 61686d056..38b2dfa52 100644 --- a/apps/blockchain/lib/blockchain/block.ex +++ b/apps/blockchain/lib/blockchain/block.ex @@ -1,6 +1,6 @@ defmodule Blockchain.Block do @moduledoc """ - This module effectively encodes a Block, the heart of the blockchain. + This module effectively encodes a block, the heart of the blockchain. A chain is formed when blocks point to previous blocks, either as a parent or an ommer (uncle). For more information, see Section 4.3 of the Yellow Paper. @@ -491,7 +491,7 @@ defmodule Blockchain.Block do @doc """ Set the difficulty of a new block based on Eq.(39), better defined - in Block.Header`. + in `Block.Header`. # TODO: Validate these results diff --git a/apps/blockchain/lib/blockchain/bloom.ex b/apps/blockchain/lib/blockchain/bloom.ex index a21d769d5..5d31cdfc4 100644 --- a/apps/blockchain/lib/blockchain/bloom.ex +++ b/apps/blockchain/lib/blockchain/bloom.ex @@ -1,4 +1,17 @@ defmodule Blockchain.Bloom do + @moduledoc """ + When a block is generated or verified, the contract addresses and fields from the generated logs are added to a bloom filter. This is included in the block header. + + _From Yellow Paper 4.3.1. Transaction Receipt_: The transaction receipt (R) is a tuple of four items comprising the post-transaction state: + + - _Ru:_ the cumulative gas used in the block containing the transaction receipt immediately after the transaction has happened + + - _Rl:_ the set of logs created through execution of the transaction + + - _Rb_: the *bloom filter* composed from information in those logs + + - _Rz_: the status code of the transaction. + """ alias ExthCrypto.Hash.Keccak use Bitwise diff --git a/apps/blockchain/lib/math_helper.ex b/apps/blockchain/lib/math_helper.ex index ceffb8868..645f791bd 100644 --- a/apps/blockchain/lib/math_helper.ex +++ b/apps/blockchain/lib/math_helper.ex @@ -2,8 +2,7 @@ defmodule Blockchain.MathHelper do alias Blockchain.Transaction @doc """ - Caluclates the amount which should be refunded based on the current transactions - final usage. This includes the remaining gas plus refunds from clearing storage. + Calculates the amount amount of gas to refund based on the final usage of the current transaction. This includes the remaining gas plus refunds from clearing storage. The specs calls for capping the refund at half of the total amount of gas used. diff --git a/apps/blockchain/lib/test.ex b/apps/blockchain/lib/test.ex index 79768e70e..ce788b031 100644 --- a/apps/blockchain/lib/test.ex +++ b/apps/blockchain/lib/test.ex @@ -2,7 +2,7 @@ defmodule Blockchain.Test do @moduledoc """ Helper functions related to testing the Blockchain. - NOTE: Remember to recompile test after updading chain configs. + NOTE: Remember to recompile test after updating chain configs. """ @chain Blockchain.Chain.load_chain(:ropsten)