Skip to content

Commit

Permalink
credo
Browse files Browse the repository at this point in the history
  • Loading branch information
InoMurko committed Mar 3, 2021
1 parent 4ceca98 commit 35fd9bf
Show file tree
Hide file tree
Showing 84 changed files with 162 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ jobs:
_counter=$(mix credo --only Credo.Check.Readability.SinglePipe | grep -c "Use a function call when a pipeline is only one function long")
echo "Current Credo.Check.Readability.SinglePipe occurrences:"
echo $_counter
if [ $_counter -gt 283 ]; then
if [ $_counter -gt 280 ]; then
echo "Have you been naughty or nice? Find out if Santa knows."
exit 1
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ defmodule OMG.Conformance.MerkleProofTest do
implementations (currently `elixir-omg` and `plasma-contracts`, Elixir and Solidity)
"""

alias OMG.Merkle
alias OMG.Eth.Encoding
alias OMG.Watcher.Crypto
alias OMG.Watcher.Merkle
alias Support.SnapshotContracts

import Support.Conformance.MerkleProofs, only: [solidity_proof_valid: 5]
Expand All @@ -39,12 +41,12 @@ defmodule OMG.Conformance.MerkleProofTest do

on_exit(exit_fn)

[contract: OMG.Eth.Encoding.from_hex(merkle_wrapper_address_hex)]
[contract: Encoding.from_hex(merkle_wrapper_address_hex)]
end

test "a simple, 3-leaf merkle proof validates fine", %{contract: contract} do
leaves = [<<1>>, <<0>>, <<>>]
root_hash = OMG.Watcher.Merkle.hash(leaves)
root_hash = Merkle.hash(leaves)

leaves
|> Enum.with_index()
Expand All @@ -59,14 +61,14 @@ defmodule OMG.Conformance.MerkleProofTest do
# why?
# 1. we'd like to test all proofs on a full tree
# 2. that's 65K proofs
# 3. so we're pre-building the merkle tree by using raw `MerkleTree` calls instead of `OMG.Merkle`
# 3. so we're pre-building the merkle tree by using raw `MerkleTree` calls instead of `OMG.Watcher.Merkle`
# This is slightly inconsistent, but otherwise the test takes forever
full_leaves = Enum.map(1..@max_block_size, &:binary.encode_unsigned/1)
full_root_hash = OMG.Watcher.Merkle.hash(full_leaves)
full_root_hash = Merkle.hash(full_leaves)

full_tree =
MerkleTree.build(full_leaves,
hash_function: &OMG.Watcher.Crypto.hash/1,
hash_function: &Crypto.hash/1,
height: 16,
default_data_block: <<0::256>>
)
Expand Down
1 change: 1 addition & 0 deletions apps/omg_conformance/test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
ExUnit.configure(exclude: [integration: true, property: true])
{:ok, _} = Application.ensure_all_started(:propcheck)
ExUnit.start()
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule OMG.Eth.ReleaseTasks.SetEthereumEventsCheckInterval do

Config.Reader.merge(config,
omg_eth: [ethereum_events_check_interval_ms: interval_ms],
omg: [ethereum_events_check_interval_ms: interval_ms]
omg_watcher: [ethereum_events_check_interval_ms: interval_ms]
)
end

Expand Down
2 changes: 1 addition & 1 deletion apps/omg_watcher/lib/omg_watcher/api/account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ defmodule OMG.Watcher.API.Account do
"""

alias OMG.DB.Models.PaymentExitInfo
alias OMG.Watcher.Utxo
alias OMG.Watcher.Crypto
alias OMG.Watcher.Utxo
require OMG.Watcher.Utxo

@doc """
Expand Down
4 changes: 2 additions & 2 deletions apps/omg_watcher/lib/omg_watcher/api/in_flight_exit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ defmodule OMG.Watcher.API.InFlightExit do
Module provides API for starting, validating and challenging in-flight exits
"""

alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
alias OMG.Watcher.API
alias OMG.Watcher.ExitProcessor
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo

require Utxo

Expand Down
4 changes: 2 additions & 2 deletions apps/omg_watcher/lib/omg_watcher/api/status_cache/external.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ defmodule OMG.Watcher.API.StatusCache.External do
alias OMG.Eth.Configuration
alias OMG.Eth.EthereumHeight
alias OMG.Eth.RootChain
alias OMG.Watcher.RootChainCoordinator
alias OMG.Watcher.State
alias OMG.Utils.HttpRPC.Encoding
alias OMG.Watcher.BlockGetter
alias OMG.Watcher.Event
alias OMG.Watcher.ExitProcessor
alias OMG.Watcher.RootChainCoordinator
alias OMG.Watcher.State

@type t() :: %{
last_validated_child_block_number: non_neg_integer(),
Expand Down
3 changes: 1 addition & 2 deletions apps/omg_watcher/lib/omg_watcher/api/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ defmodule OMG.Watcher.API.Transaction do
Module provides API for transactions
"""

alias OMG.Watcher.HttpRPC.Client
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
alias OMG.Watcher.HttpRPC.Client

require Utxo

@doc """
Expand Down
2 changes: 1 addition & 1 deletion apps/omg_watcher/lib/omg_watcher/api/utxo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ defmodule OMG.Watcher.API.Utxo do
"""

alias OMG.Eth.Configuration
alias OMG.Watcher.Utxo
alias OMG.Watcher.ExitProcessor
alias OMG.Watcher.Utxo
alias OMG.Watcher.UtxoExit.Core

require Utxo
Expand Down
12 changes: 6 additions & 6 deletions apps/omg_watcher/lib/omg_watcher/block_getter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule OMG.Watcher.BlockGetter do
Responsible for processing all block submissions and processing them once, regardless of the reorg situation.
Note that `BlockGetter` shouldn't have any finality margin configured, i.e. it should be prepared to be served events
from zero-confirmation Ethereum blocks from the `OMG.RootChainCoordinator`.
from zero-confirmation Ethereum blocks from the `OMG.Watcher.RootChainCoordinator`.
The flow of getting blocks is as follows:
- `BlockGetter` tracks the top child block number mined in the root chain contract (by doing `eth_call` on the
Expand All @@ -30,12 +30,12 @@ defmodule OMG.Watcher.BlockGetter do
- if this succeeds it continues to statelessly validate the block (recover transactions, calculate Merkle root)
- if this fails (e.g. timeout) it goes into a `PotentialWithholding` state and tries to see if the problem
resolves. If not it ends up reporting a `block_withholding` byzantine event
- it holds such downloaded block until `OMG.RootChainCoordinator` allows the blocks submitted at given Ethereum
- it holds such downloaded block until `OMG.Watcher.RootChainCoordinator` allows the blocks submitted at given Ethereum
heights to be applied
- Applies the block by statefully validating and executing the txs on `OMG.State`
- after the block is fully validated it gathers all the updates to `OMG.DB` and executes them. This includes marking
a respective Ethereum height (that contained the `BlockSubmitted` event) as processed
- checks in to `OMG.RootChainCoordinator` to let other services know about progress
- checks in to `OMG.Watcher.RootChainCoordinator` to let other services know about progress
The process of downloading and stateless validation of blocks is done in `Task`s for concurrency.
Expand All @@ -46,14 +46,14 @@ defmodule OMG.Watcher.BlockGetter do
use Spandex.Decorators

alias OMG.Eth.RootChain
alias OMG.Watcher.RootChainCoordinator
alias OMG.Watcher.RootChainCoordinator.SyncGuide
alias OMG.Watcher.State
alias OMG.Watcher.BlockGetter.BlockApplication
alias OMG.Watcher.BlockGetter.Core
alias OMG.Watcher.BlockGetter.Status
alias OMG.Watcher.ExitProcessor
alias OMG.Watcher.HttpRPC.Client
alias OMG.Watcher.RootChainCoordinator
alias OMG.Watcher.RootChainCoordinator.SyncGuide
alias OMG.Watcher.State

@doc """
Retrieves the freshest information about `OMG.Watcher.BlockGetter`'s status, as stored by the slave process `Status`.
Expand Down
4 changes: 2 additions & 2 deletions apps/omg_watcher/lib/omg_watcher/block_getter/core.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ defmodule OMG.Watcher.BlockGetter.Core do
"""

alias OMG.Watcher.Block
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.BlockGetter.BlockApplication
alias OMG.Watcher.Event
alias OMG.Watcher.ExitProcessor
alias OMG.Watcher.State.Transaction

require Logger

Expand Down Expand Up @@ -432,7 +432,7 @@ defmodule OMG.Watcher.BlockGetter.Core do
maximum_number_of_pending_blocks >= 1 || {:error, :maximum_number_of_pending_blocks_too_low}
end

# height served as syncable from the `OMG.RootChainCoordinator` is older, nothing we can do about it, so noop
# height served as syncable from the `OMG.Watcher.RootChainCoordinator` is older, nothing we can do about it, so noop
defp do_get_blocks_to_apply(
%__MODULE__{synced_height: synced_height} = state,
_block_submitted_events,
Expand Down
4 changes: 2 additions & 2 deletions apps/omg_watcher/lib/omg_watcher/coordinator_setup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

defmodule OMG.Watcher.CoordinatorSetup do
@moduledoc """
The setup of `OMG.RootChainCoordinator` for the Watcher - configures the relations between different event listeners
The setup of `OMG.Watcher.RootChainCoordinator` for the Watcher - configures the relations between different event listeners
"""

@doc """
The `OMG.RootChainCoordinator` setup for the `OMG.Watcher` app. Summary of the configuration:
The `OMG.Watcher.RootChainCoordinator` setup for the `OMG.Watcher` app. Summary of the configuration:
- deposits are recognized after `deposit_finality_margin`. Should take child chain server's setting into account
- exit-related events are recognized after `exit_finality_margin`
Expand Down
8 changes: 4 additions & 4 deletions apps/omg_watcher/lib/omg_watcher/exit_processor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ defmodule OMG.Watcher.ExitProcessor do
NOTE: Note that all calls return `db_updates` and relay on the caller to do persistence.
"""

alias OMG.Watcher.Block
alias OMG.DB
alias OMG.DB.Models.PaymentExitInfo
alias OMG.Eth
alias OMG.Eth.EthereumHeight
alias OMG.Eth.RootChain
alias OMG.Watcher.State
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
alias OMG.Watcher.Block
alias OMG.Watcher.ExitProcessor
alias OMG.Watcher.ExitProcessor.Core
alias OMG.Watcher.ExitProcessor.ExitInfo
alias OMG.Watcher.ExitProcessor.StandardExit
alias OMG.Watcher.ExitProcessor.Tools
alias OMG.Watcher.State
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo

require Logger
require Utxo
Expand Down
5 changes: 2 additions & 3 deletions apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,18 @@ defmodule OMG.Watcher.ExitProcessor.Canonicity do

alias OMG.Watcher.Block
alias OMG.Watcher.Crypto
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
alias OMG.Watcher.Event
alias OMG.Watcher.ExitProcessor
alias OMG.Watcher.ExitProcessor.Core
alias OMG.Watcher.ExitProcessor.DoubleSpend
alias OMG.Watcher.ExitProcessor.InFlightExitInfo
alias OMG.Watcher.ExitProcessor.KnownTx
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo

import OMG.Watcher.ExitProcessor.Tools

require Utxo

require Logger

@type competitor_data_t :: %{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ defmodule OMG.Watcher.ExitProcessor.CompetitorInfo do
"""

alias OMG.Watcher.Crypto
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.ExitProcessor.InFlightExitInfo
alias OMG.Watcher.State.Transaction

# mapped by tx_hash
defstruct [
Expand Down
4 changes: 2 additions & 2 deletions apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ defmodule OMG.Watcher.ExitProcessor.Core do
"""

alias OMG.Watcher.Block
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
alias OMG.Watcher.Event
alias OMG.Watcher.ExitProcessor
alias OMG.Watcher.ExitProcessor.CompetitorInfo
alias OMG.Watcher.ExitProcessor.ExitInfo
alias OMG.Watcher.ExitProcessor.InFlightExitInfo
alias OMG.Watcher.ExitProcessor.KnownTx
alias OMG.Watcher.ExitProcessor.StandardExit
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo

import OMG.Watcher.ExitProcessor.Tools

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ defmodule OMG.Watcher.ExitProcessor.DoubleSpend do

defstruct [:index, :utxo_pos, :known_spent_index, :known_tx]

alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
alias OMG.Watcher.ExitProcessor.KnownTx
alias OMG.Watcher.ExitProcessor.Tools
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo

@type t() :: %__MODULE__{
index: non_neg_integer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ defmodule OMG.Watcher.ExitProcessor.ExitInfo do
"""

alias OMG.Watcher.Crypto
alias OMG.Watcher.Event
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
alias OMG.Watcher.Event

require Utxo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ defmodule OMG.Watcher.ExitProcessor.Finalizations do
For the imperative shell, see `OMG.Watcher.ExitProcessor`
"""

alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
alias OMG.Watcher.ExitProcessor.Core
alias OMG.Watcher.ExitProcessor.ExitInfo
alias OMG.Watcher.ExitProcessor.InFlightExitInfo
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo

require Logger

Expand Down
4 changes: 2 additions & 2 deletions apps/omg_watcher/lib/omg_watcher/exit_processor/known_tx.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ defmodule OMG.Watcher.ExitProcessor.KnownTx do
defstruct [:signed_tx, :utxo_pos]

alias OMG.Watcher.Block
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
alias OMG.Watcher.ExitProcessor.Core
alias OMG.Watcher.ExitProcessor.TxAppendix
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo

require Utxo

Expand Down
4 changes: 2 additions & 2 deletions apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ defmodule OMG.Watcher.ExitProcessor.Piggyback do
For the imperative shell, see `OMG.Watcher.ExitProcessor`
"""

alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
alias OMG.Watcher.Event
alias OMG.Watcher.ExitProcessor
alias OMG.Watcher.ExitProcessor.Core
alias OMG.Watcher.ExitProcessor.DoubleSpend
alias OMG.Watcher.ExitProcessor.InFlightExitInfo
alias OMG.Watcher.ExitProcessor.KnownTx
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo

import OMG.Watcher.ExitProcessor.Tools

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do
end

alias OMG.Watcher.Block
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
alias OMG.Watcher.ExitProcessor
alias OMG.Watcher.ExitProcessor.Core
alias OMG.Watcher.ExitProcessor.DoubleSpend
alias OMG.Watcher.ExitProcessor.ExitInfo
alias OMG.Watcher.ExitProcessor.KnownTx
alias OMG.Watcher.ExitProcessor.TxAppendix

alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
import OMG.Watcher.ExitProcessor.Tools

require Utxo
Expand Down
4 changes: 2 additions & 2 deletions apps/omg_watcher/lib/omg_watcher/exit_processor/tools.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ defmodule OMG.Watcher.ExitProcessor.Tools do
"""

alias OMG.Watcher.Crypto
alias OMG.Watcher.ExitProcessor.DoubleSpend
alias OMG.Watcher.ExitProcessor.KnownTx
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.TypedDataHash
alias OMG.Watcher.Utxo
alias OMG.Watcher.ExitProcessor.DoubleSpend
alias OMG.Watcher.ExitProcessor.KnownTx

require OMG.Watcher.Utxo

Expand Down

0 comments on commit 35fd9bf

Please sign in to comment.