Skip to content

Commit

Permalink
remove ethereum tasks migration (#1828)
Browse files Browse the repository at this point in the history
* remove ethereum tasks migration

* backwards compatibility with OMG.OUTPUTs

* lint
  • Loading branch information
InoMurko committed Mar 23, 2021
1 parent 870eefd commit 2c68973
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 286 deletions.
1 change: 0 additions & 1 deletion Makefile
Expand Up @@ -436,7 +436,6 @@ start-watcher_info:
_build/${BAREBUILD_ENV}/rel/watcher_info/bin/watcher_info eval "OMG.DB.ReleaseTasks.InitKeyValueDB.run()" && \
_build/${BAREBUILD_ENV}/rel/watcher_info/bin/watcher_info eval "OMG.DB.ReleaseTasks.InitKeysWithValues.run()" && \
_build/${BAREBUILD_ENV}/rel/watcher_info/bin/watcher_info eval "OMG.WatcherInfo.ReleaseTasks.InitPostgresqlDB.migrate()" && \
_build/${BAREBUILD_ENV}/rel/watcher_info/bin/watcher_info eval "OMG.WatcherInfo.ReleaseTasks.EthereumTasks.run()" && \
echo "Run Watcher Info" && \
. ${OVERRIDING_VARIABLES} && \
PORT=${WATCHER_INFO_PORT} _build/${BAREBUILD_ENV}/rel/watcher_info/bin/watcher_info $(OVERRIDING_START)
Expand Down
Expand Up @@ -19,7 +19,7 @@ defmodule OMG.Watcher.MergeTransactionValidator do
to know by the child chain to not require the transaction fees.
"""

alias OMG.Watcher.Output
alias OMG.Output
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo

Expand Down
15 changes: 13 additions & 2 deletions apps/omg_watcher/lib/omg_watcher/output.ex
Expand Up @@ -12,12 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

defmodule OMG.Watcher.Output do
defmodule OMG.Output do
@moduledoc """
`OMG.Watcher.Output` and `OMG.Watcher.Output.Protocol` represent the outputs of transactions, i.e. the valuables or other pieces of
`OMG.Output` and `OMG.Output.Protocol` represent the outputs of transactions, i.e. the valuables or other pieces of
data spendable via transactions on the child chain, and/or exitable to the root chain.
This module specificially dispatches generic calls to the various specific types
THIS IS WHAT HAPPENS IF YOU STORE ELIXIR STRUCTS IN A DATABASE
This struct is binary encoded into RocksDB, so when we call `:erlang.binary_to_term(encoded, [:safe])`
for old outputs stored, it expects this struct to exist.
Just make sure they do the same thing!!!
"""
alias OMG.Watcher.Crypto
alias OMG.Watcher.RawData
Expand Down
2 changes: 1 addition & 1 deletion apps/omg_watcher/lib/omg_watcher/state/core.ex
Expand Up @@ -61,10 +61,10 @@ defmodule OMG.Watcher.State.Core do
fee_claiming_started: false
]

alias OMG.Output
alias OMG.Watcher.Block
alias OMG.Watcher.Crypto
alias OMG.Watcher.Fees
alias OMG.Watcher.Output
alias OMG.Watcher.State.Core
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.State.Transaction.Validator
Expand Down
2 changes: 1 addition & 1 deletion apps/omg_watcher/lib/omg_watcher/state/transaction.ex
Expand Up @@ -131,7 +131,7 @@ defprotocol OMG.Watcher.State.Transaction.Protocol do
Should be implemented for any type of transaction processed in the system
"""

alias OMG.Watcher.Output
alias OMG.Output
alias OMG.Watcher.State.Transaction

@doc """
Expand Down
6 changes: 3 additions & 3 deletions apps/omg_watcher/lib/omg_watcher/state/transaction/fee.ex
Expand Up @@ -16,8 +16,8 @@ defmodule OMG.Watcher.State.Transaction.Fee do
@moduledoc """
Internal representation of a fee claiming transaction in plasma chain.
"""
alias OMG.Output
alias OMG.Watcher.Crypto
alias OMG.Watcher.Output
alias OMG.Watcher.State.Transaction

require Transaction
Expand Down Expand Up @@ -99,7 +99,7 @@ defmodule OMG.Watcher.State.Transaction.Fee do
end

defimpl OMG.Watcher.State.Transaction.Protocol, for: OMG.Watcher.State.Transaction.Fee do
alias OMG.Watcher.Output
alias OMG.Output
alias OMG.Watcher.State.Transaction

@doc """
Expand All @@ -109,7 +109,7 @@ defimpl OMG.Watcher.State.Transaction.Protocol, for: OMG.Watcher.State.Transacti
def get_data_for_rlp(%Transaction.Fee{tx_type: tx_type, outputs: outputs, nonce: nonce}) do
[
tx_type,
Enum.map(outputs, &OMG.Watcher.Output.get_data_for_rlp/1),
Enum.map(outputs, &Output.get_data_for_rlp/1),
nonce
]
end
Expand Down
6 changes: 3 additions & 3 deletions apps/omg_watcher/lib/omg_watcher/state/transaction/payment.ex
Expand Up @@ -20,7 +20,7 @@ defmodule OMG.Watcher.State.Transaction.Payment do
"""
alias OMG.Watcher.Crypto

alias OMG.Watcher.Output
alias OMG.Output
alias OMG.Watcher.RawData
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
Expand Down Expand Up @@ -155,7 +155,7 @@ defmodule OMG.Watcher.State.Transaction.Payment do
end

defimpl OMG.Watcher.State.Transaction.Protocol, for: OMG.Watcher.State.Transaction.Payment do
alias OMG.Watcher.Output
alias OMG.Output
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo

Expand All @@ -173,7 +173,7 @@ defimpl OMG.Watcher.State.Transaction.Protocol, for: OMG.Watcher.State.Transacti
do: [
tx_type,
Enum.map(inputs, &OMG.Watcher.Utxo.Position.get_data_for_rlp/1),
Enum.map(outputs, &OMG.Watcher.Output.get_data_for_rlp/1),
Enum.map(outputs, &Output.get_data_for_rlp/1),
# used to be optional and as such was `if`-appended if not null here
# When it is not optional, and there's the if, dialyzer complains about the if
0,
Expand Down
Expand Up @@ -18,8 +18,8 @@ defmodule OMG.Watcher.State.Transaction.Validator.Payment do
Specific transaction type's validation is passed to `Transaction.Protocol.can_apply?`
"""

alias OMG.Output
alias OMG.Watcher.Fees
alias OMG.Watcher.Output
alias OMG.Watcher.State.Core
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.State.UtxoSet
Expand Down Expand Up @@ -71,5 +71,5 @@ defmodule OMG.Watcher.State.Transaction.Validator.Payment do
|> if(do: :ok, else: {:error, :unauthorized_spend})
end

defp can_spend?(%OMG.Watcher.Output{owner: owner}, witness), do: owner == witness
defp can_spend?(%Output{owner: owner}, witness), do: owner == witness
end
2 changes: 1 addition & 1 deletion apps/omg_watcher/lib/omg_watcher/state/utxo_set.ex
Expand Up @@ -26,7 +26,7 @@ defmodule OMG.Watcher.State.UtxoSet do

alias OMG.Watcher.Crypto

alias OMG.Watcher.Output
alias OMG.Output
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo

Expand Down
2 changes: 1 addition & 1 deletion apps/omg_watcher/lib/omg_watcher/typed_data_hash.ex
Expand Up @@ -18,8 +18,8 @@ defmodule OMG.Watcher.TypedDataHash do
for structured transaction data. These `struct_txhash`es are later used as digest to sign and recover signatures.
"""

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

Expand Down
2 changes: 1 addition & 1 deletion apps/omg_watcher/lib/omg_watcher/typed_data_hash/tools.ex
Expand Up @@ -18,8 +18,8 @@ defmodule OMG.Watcher.TypedDataHash.Tools do
See also: http://eips.ethereum.org/EIPS/eip-712
"""

alias OMG.Output
alias OMG.Watcher.Crypto
alias OMG.Watcher.Output
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.TypedDataHash.Types
alias OMG.Watcher.Utxo
Expand Down
10 changes: 5 additions & 5 deletions apps/omg_watcher/lib/omg_watcher/utxo.ex
Expand Up @@ -17,7 +17,7 @@ defmodule OMG.Watcher.Utxo do
Manipulates a single unspent transaction output (UTXO) held be the child chain state.
"""

alias OMG.Watcher.Output
alias OMG.Output
alias OMG.Watcher.State.Transaction

defstruct [:output, :creating_txhash]
Expand All @@ -42,26 +42,26 @@ defmodule OMG.Watcher.Utxo do
def to_db_value(%__MODULE__{output: output, creating_txhash: creating_txhash})
when is_nil_or_binary(creating_txhash) do
%{creating_txhash: creating_txhash}
|> Map.put(:output, OMG.Watcher.Output.to_db_value(output))
|> Map.put(:output, Output.to_db_value(output))
end

def from_db_value(%{output: output, creating_txhash: creating_txhash})
when is_nil_or_binary(creating_txhash) do
value = %{
output: OMG.Watcher.Output.from_db_value(output),
output: Output.from_db_value(output),
creating_txhash: creating_txhash
}

struct!(__MODULE__, value)
end

# Reading from old db format, only `OMG.Watcher.Output.FungibleMoreVPToken`
# Reading from old db format, only `OMG.Output.FungibleMoreVPToken`
def from_db_value(%{owner: owner, currency: currency, amount: amount, creating_txhash: creating_txhash})
when is_nil_or_binary(creating_txhash) do
output = %{owner: owner, currency: currency, amount: amount}

value = %{
output: OMG.Watcher.Output.from_db_value(output),
output: Output.from_db_value(output),
creating_txhash: creating_txhash
}

Expand Down
4 changes: 2 additions & 2 deletions apps/omg_watcher/lib/omg_watcher/utxo_exit/core.ex
Expand Up @@ -17,6 +17,7 @@ defmodule OMG.Watcher.UtxoExit.Core do
Module provides API for compose exit
"""

alias OMG.Output
alias OMG.Watcher.Block
alias OMG.Watcher.State.Transaction
alias OMG.Watcher.Utxo
Expand Down Expand Up @@ -47,8 +48,7 @@ defmodule OMG.Watcher.UtxoExit.Core do
def compose_deposit_standard_exit({:ok, {db_utxo_pos, db_utxo_value}}) do
utxo_pos = Position.from_db_key(db_utxo_pos)

%Utxo{output: %OMG.Watcher.Output{amount: amount, currency: currency, owner: owner}} =
Utxo.from_db_value(db_utxo_value)
%Utxo{output: %Output{amount: amount, currency: currency, owner: owner}} = Utxo.from_db_value(db_utxo_value)

tx = Transaction.Payment.new([], [{owner, currency, amount}])
txs = [Transaction.Signed.encode(%Transaction.Signed{raw_tx: tx, sigs: []})]
Expand Down
4 changes: 2 additions & 2 deletions apps/omg_watcher/lib/omg_watcher/wire_format_types.ex
Expand Up @@ -44,8 +44,8 @@ defmodule OMG.Watcher.WireFormatTypes do
}

@output_type_modules %{
1 => OMG.Watcher.Output,
2 => OMG.Watcher.Output
1 => OMG.Output,
2 => OMG.Output
}

@known_tx_types Map.keys(@tx_type_values)
Expand Down
9 changes: 5 additions & 4 deletions apps/omg_watcher/test/omg_watcher/output_test.exs
Expand Up @@ -11,11 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
defmodule OMG.Watcher.OutputTest do
defmodule OMG.OutputTest do
@moduledoc false

use ExUnit.Case, async: true
doctest OMG.Watcher.Output
alias OMG.Output
doctest OMG.Output

describe "reconstruct/1" do
test "returns an error if the output guard is invalid" do
Expand All @@ -28,12 +29,12 @@ defmodule OMG.Watcher.OutputTest do
]
]

assert {:error, :output_guard_cant_be_zero} = OMG.Watcher.Output.reconstruct(rlp_data)
assert {:error, :output_guard_cant_be_zero} = Output.reconstruct(rlp_data)
end

test "returns an error if the output is malformed" do
rlp_data = []
assert {:error, :malformed_outputs} = OMG.Watcher.Output.reconstruct(rlp_data)
assert {:error, :malformed_outputs} = Output.reconstruct(rlp_data)
end
end
end
3 changes: 2 additions & 1 deletion apps/omg_watcher/test/omg_watcher/state/core_test.exs
Expand Up @@ -25,6 +25,7 @@ defmodule OMG.Watcher.State.CoreTest do
require OMG.Watcher.Utxo

alias OMG.Eth.Configuration
alias OMG.Output
alias OMG.Watcher.Block
alias OMG.Watcher.Fees
alias OMG.Watcher.State.Core
Expand Down Expand Up @@ -1120,6 +1121,6 @@ defmodule OMG.Watcher.State.CoreTest do
defp to_utxo_kv({blknum, txindex, oindex, owner, currency, amount}),
do: {
Utxo.position(blknum, txindex, oindex),
%Utxo{output: %OMG.Watcher.Output{amount: amount, currency: currency, owner: owner.addr}}
%Utxo{output: %Output{amount: amount, currency: currency, owner: owner.addr}}
}
end
Expand Up @@ -20,6 +20,7 @@ defmodule OMG.Watcher.State.MeasurementCalculationTest do
use ExUnit.Case, async: true

alias OMG.Eth.Encoding
alias OMG.Output
alias OMG.Watcher.State.Core
alias OMG.Watcher.Utxo

Expand All @@ -32,16 +33,16 @@ defmodule OMG.Watcher.State.MeasurementCalculationTest do
test "calculate metrics from state", %{alice: alice, bob: bob, carol: carol} do
utxos = %{
Utxo.position(2_000, 4076, 3) => %OMG.Watcher.Utxo{
output: %OMG.Watcher.Output{amount: 700_000_000, currency: @eth, owner: alice}
output: %Output{amount: 700_000_000, currency: @eth, owner: alice}
},
Utxo.position(1_000, 2559, 0) => %OMG.Watcher.Utxo{
output: %OMG.Watcher.Output{amount: 111_111_111, currency: @not_eth, owner: alice}
output: %Output{amount: 111_111_111, currency: @not_eth, owner: alice}
},
Utxo.position(8_000, 4854, 2) => %OMG.Watcher.Utxo{
output: %OMG.Watcher.Output{amount: 77_000_000, currency: @eth, owner: bob}
output: %Output{amount: 77_000_000, currency: @eth, owner: bob}
},
Utxo.position(7_000, 4057, 3) => %OMG.Watcher.Utxo{
output: %OMG.Watcher.Output{amount: 222_222_222, currency: @not_eth, owner: carol}
output: %Output{amount: 222_222_222, currency: @not_eth, owner: carol}
},
Utxo.position(7_000, 4057, 4) => %OMG.Watcher.Utxo{output: %{}}
}
Expand Down

This file was deleted.

0 comments on commit 2c68973

Please sign in to comment.