Commit Graph

99 Commits

Author SHA1 Message Date
Peter van Nostrand aaa5bee49e Problem: no functionality exists to dynamically fetch gas-prices
Currently, gas-prices are set upon bridge startup via the
Users's config TOML file; this value remains constant for the
life of the Bridge.

Solution: create a mechanism that asynchronously queries
gas-prices from an "Oracle" service on a timed interval. This
mechanism should be a stream of gas-prices that can be polled
from the Bridge.
2018-05-23 20:42:13 -04:00
Yurii Rashkovskii d25bea1a93
Problem: integration tests get stuck (most of the time)
Solution: ensure not failing the initial checking of the balance
if it was in fact successful.
2018-05-11 11:02:44 -07:00
Yurii Rashkovskii 40b21ddb7d
Problem: errors do not show their context
If the error like this appears in the logs:
```
INFO:bridge::bridge::withdraw_confirm: waiting for new withdraws that
should get signed
WARN:bridge: Bridge crashed with Error(Transport("Incomplete"), State {
next_error: None, backtrace: None })
Error(Transport("Incomplete"), State { next_error: None, backtrace: None
})
```
it is hard to understand which side of the bridge failed. The message
must contains type of operation (`deposit_relay`, `withdraw_confirm` or
`withdraw_relay`) and side of bridge (URL of RPC channel).

Solution: record error's top level context and print it out if recorded

Addresses #75
2018-05-08 00:48:35 -07:00
Yurii Rashkovskii c3c2461af3
Problem: eth_getLogs returning no logs in some cases
Sometimes there's an event and eth_getLogs returns
nothing.

Solution: trim the nulls from the topic filter's tail

It appears that in some implementations or setups
eth_getLogs topics: [A, null, null, null] won't return
logs when only [A] was there.

This patch is a quick workaround that trims nulls from
that said tail. A proper fix would likely require
an incursion into ethabi to make Topic optional.
2018-05-04 13:58:19 -07:00
Yurii Rashkovskii ce487b34a6
Problem: bridge tests failing
Solution: bring them up to date
2018-05-04 11:02:17 -07:00
Yurii Rashkovskii f98fc49aed
Problem: bridge tests don't compile
Solution: the database format changed, accommodate that
2018-05-04 10:55:30 -07:00
Yurii Rashkovskii 4feca245f1
Problem: home_deploy and foreign_deploy fields
These fields in database are no longer useful outside of
integration testing.

Solution: make them optional

Closes #67
2018-05-04 10:08:12 -07:00
Yurii Rashkovskii fbe77d7359
Problem: bridge sends out transactions slowly
This is because it is limiting them to one at a time
per operation type. This was done so that there's no
gaps in nonces due to undelivered transactions.

Solution: allow concurrent sending of transactions

By default, 100 transactions are allowed.

Note, however, that now there's a chance that nonce
gaps may be formed under cerain circumstances.
2018-05-03 14:14:42 -07:00
Yurii Rashkovskii 6a371cfb46
Merge pull request #58 from yrashk/contract-setting
Problem: `contract` configuration is no longer necessary
2018-05-01 19:10:29 -07:00
Yurii Rashkovskii 6ed056b744
Problem: estimated_gas_cost_of_withdraw setting is no longer useful
Solution: remove it from the default build
2018-05-01 11:58:08 -07:00
Yurii Rashkovskii 633e4a122a
Problem: `contract` configuration is no longer necessary
It is only necessary when deploying

Solution: remove the requirement for this configuration option
but leave it for the `deploy` feature used in integration tests
until they are rewritten to use external deployment mechanics.
2018-05-01 11:40:30 -07:00
Alexander Kolotov f6c6546e77
Merge pull request #56 from yrashk/failing-tests
Problem: bridge crate tests failing to compile
2018-05-01 20:43:15 +03:00
Yurii Rashkovskii 935f6bdc9b
Problem: bridge crate tests failing to compile
Solution: bring them up to date
2018-05-01 10:03:42 -07:00
Yurii Rashkovskii 9a192c1e07
Problem: bridge should not deploy its contracts anymore
Bridge's contracts are now developed in a separate repository
and have their own deployment procedure:

https://github.com/poanetwork/poa-parity-bridge-contracts

However, our integration tests are not yet updated to
use this deployment procedure.

Solution: disable deployment compile-time by default
and only use it in integration tests as a stopgap measure
until the new deployment procedure (or any other viable
alternative) has been used.
2018-05-01 09:43:34 -07:00
Yurii Rashkovskii 385c5885dd
Problem: nonce reuse without error
In cases when the node is backed by a cluster of nodes,
one node will not share the same information with the
other, hence it will not be able to report nonce reuse,
ultimately leading to lost transactions as they are
discarded later.

Solution: combine getTransactionCount with an internal counter
so that validator controls its own nonces, but in case if
something external happens, it can reset itself against
those externalities.
2018-04-29 16:41:03 -07:00
Yurii Rashkovskii a1269272e2
Problem: nonce reuse
Unfortunately, bridge will still reuse nonce very often.
Specifically when trying to send more than one transaction at
a time, clearly a faulty behaviour.

Solution: chain retrieving a nonce with subsequent sending
of the transaction.

However, chaining these is not enough as it'll still fail.

This is happening because bridge module is polling all its components
(deposit_relay, withdraw_confirm, withdraw_relay) sequentially,
 and some of them maybe waiting on their transactions to go through.

However, those transactions are also done as composed futures of nonce
retrieval and transaction sending. This means that it is very often
that first, these futures will go through the nonce acquisition process,
get the same values, and then submit transactions with the same nonce.

This patch makes NonceCheck future check if the transaction failed
with this specific issue of nonce reuse and effectively restarts from
the beginning in that case, repeating nonce acquisition process... until
it succeeeds.
2018-04-29 13:20:42 -07:00
Yurii Rashkovskii 072291813c
Problem: withdraw_confirm failure
If a node configured as Foreign for the bridge and it has no validator
account unlocked the bridge crashes and produces the following message:

```
INFO:bridge::bridge::withdraw_confirm: got 1 new withdraws to sign
INFO:bridge::bridge::withdraw_confirm: withdraw is ready for signature
submission. tx hash 0x6493…4fa8
INFO:bridge::bridge::withdraw_confirm: signing
WARN:bridge: Bridge crashed with Error(Transport("Unexpected response
status code: 405 Method Not Allowed"), State { next_error: None,
backtrace: None })
Error(Transport("Unexpected response status code: 405 Method Not
Allowed"), State { next_error: None, backtrace: None })
```

Solution: sign messages locally

Closes #49
2018-04-28 15:50:25 -07:00
Yurii Rashkovskii c0715dadba
Merge branch 'raw-transactions' into rpc+raw-transactions 2018-04-26 18:21:07 -07:00
Yurii Rashkovskii 58d092f1d4
Merge branch 'rpc' into rpc+raw-transactions-1 2018-04-26 18:13:24 -07:00
Yurii Rashkovskii fe28e335e0
Problem: RPC transport doesn't support HTTPS
Solution: upgrade web3 to the version which has support for TLS
2018-04-26 18:12:01 -07:00
Yurii Rashkovskii e5afb28783
Problem: AsRef implementation of App
It isn't really necessary for anything that I can see.

Solution: remove it
2018-04-26 17:57:29 -07:00
Yurii Rashkovskii 96ecfab2c6
Problem: unlocking account every time to sign a tx
On my computer, this takes approximately 0.3 seconds, which is clearly
a deal-breaker. In retrospect, this is an obvious problem because
of key derivation function use.

Solution: unlock accounts permanently.

This cut down time to sign one transaction is 0.0001 or so.
2018-04-26 17:53:38 -07:00
Yurii Rashkovskii 94b1343594
Problem: sending unsigned transactions over API
This means that the node has to sign the transaction itself.
It might be acceptable in a localized setup, but can't be used
with untrusted setups. For example, once HTTP RPC is supported,
we can't really use infrastructure like INFURA to send transactions.

Solution: switch to signing transactions in bridge

This absolutely requires separating the accounts used by validators
and administrative tasks as this will otherwise interfere with
management of nonces.
2018-04-26 17:50:07 -07:00
Yurii Rashkovskii 4151237c54
Problem: RPC transport change conflated with keystore
As a part of the original feature request, there was a need
for the bridge to be able to sign its own transactions. However,
this didn't fully materialize in the original patch, and only
configuration parameters were implemented.

Solution: remove these last conflated bits
and make this a pure transport change patch.
2018-04-19 10:13:45 -07:00
Yurii Rashkovskii 449c97cf5b
Problem: unnecessarily complicated string formatting
Solution: use format!() macro instead of manual concatenation
2018-04-19 09:51:38 -07:00
Yurii Rashkovskii 39202644b8
Problem: some unnecessary leftovers in the RPC patch
Solution: remove them
2018-04-19 09:51:38 -07:00
Yurii Rashkovskii c04d6a282e
Problem: RPC patch doesn't compile yet
The inner workings of choosing IPC vs RPC haven't been worked out.

Solution: remove IPC in favour of RPC
2018-04-19 09:51:37 -07:00
Edward Mack aacea235bb
Problem: IPC doesn't scale well
Using IPC means bridge has to run alognside the node
on the same machine. This, at times, presents problems
in terms of efficiency or coupling of deployment.

Solution: switch to RPC
2018-04-19 09:51:32 -07:00
Yurii Rashkovskii 976256780b
Problem: unknown balance warning
Upon startup, bridge produces the following warning:

```
WARN:bridge::bridge::deposit_relay: foreign contract balance is unknown
```

This happens because the RPC response from the node might
not come/get processed immediately.

By itself this warning means that the deposit_relay won't
perform any operations.

Solution: don't commence operations until balances are retrieved

Also, indicate when balances are retrieved:

```
INFO:bridge::bridge: Retrieved home contract balance
INFO:bridge::bridge: Retrieved foreign contract balance
```

This shows us that the balances are successfully retrieved and
bridge can commence its operations.
2018-04-16 07:21:31 -07:00
Yurii Rashkovskii 618d3bcb00
Problem: bridge crashes with insufficient balance
Currently there are two possible situations related to low balance on
the account which is used for bridge operations:

1. The account which is used to sign transactions to be addressed by
ForeignBridge contract has low balance. So, the bridge is not able to do
deposit_relay and withdraw_confirm.
2. The account which is used to sign transactions to be addressed by
HomeBridge contract has low balance. So, the bridge is not able to do
withdraw_relay.

In both cases bridges hangs silently at the moment of sending
transactions and does not proceed with further actions even the
operation is intended to be performed in opposite direction (e.g. the
bridge hangs at the moment to perform withdraw_relay, so deposit_relay
cannot be performed either).

Solution: make bridge track its balance and hande insufficient

Bridge will crash with ERR_INSUFFICIENT_FUNDS (code 4) so that
supervisor can decide what should happen next. It will also log the
condition.

P.S.Make sure to run the tests with `--test-threads=1` to avoid
other test conflicting with this one. A better solution to this
issue must be devised later, however.
2018-04-04 10:42:16 +04:00
Yurii Rashkovskii 38e1cac265
Problem: intentional bridge shutdowns
It is impossible to tell whether the bridge
is being shut down intentionally or because of
an error. This is particularly important
for supervising the process, both in development
and production.

Solution: handle SIGINT and SIGTERM as a special case
and designate a separate status code (3) for intentional
shutdowns.

Also, include an example supervisor for development
mode (examples/suprevisor). Simply prepend it before
the invocation of bridge to supervise it.
2018-03-15 21:14:37 +07:00
Alexander Kolotov 9c375cc89b
Merge pull request #25 from yrashk/ipc-lost
Problem: bridge dies when Parity is stopped
2018-03-10 10:13:07 +01:00
Yurii Rashkovskii d9bc432ab8
Problem: integration tests won't compile or pass
Solution: map it to the API used in bridge.sol
2018-03-05 15:23:36 +07:00
Yurii Rashkovskii b8a5b8eeb8
Problem: bridge dies when Parity is stopped
Steps to reproduce:

Run two Parity-based nodes responsible for Home and Foreign chains.
Run bridge: RUST_LOG=info bridge --config ... --database ....
Kill parity process responsible for Foreign chain.
Expected results:
The bridge handles gracefully death of Parity node: warns about the
connection lose, shutdowns all operations (deposit_relay,
withdraw_confirm and withdraw_relay) for a while, waits when the
connection appears and runs all operations after that.

Actual results:
After killing Parity process the following appear in the terminal where
the bridge is running:

WARN:<unknown>: Unexpected IO error: Error { repr: Os { code: 32,
message: "Broken pipe" } }
No messages appear from withdraw_confirm and withdraw_relay.
Then after some time (few seconds or few minutes) the following appear
on the terminal and the bridge dies:

Request eth_blockNumber timed out

Solution: once "Broken pipe" error is caught, attempt to
reconnect repeatedly with a pause of 1 second between attempts.

When other errors are caught, simply restart the bridge,
as there is no indication that the connection has been severed.

Fixes #22
2018-02-28 05:35:18 +07:00
Alexander Kolotov 57bce4579a fixes #23 2018-02-25 00:21:23 +03:00
Maximilian Krüger 0246119518 remove panics. improve error handling for signature.
resolves grumble:
https://github.com/paritytech/parity-bridge/pull/114#discussion_r168406741
2018-02-15 12:49:12 +01:00
Maximilian Krüger 6f13eb4b05 shorten error handling
resolve grumble:
https://github.com/paritytech/parity-bridge/pull/114#discussion_r168433291
2018-02-15 11:33:59 +01:00
Maximilian Krüger ca7f758587 remove unnecessary `.clone()`
resolves grumble:
https://github.com/paritytech/parity-bridge/pull/114#discussion_r168406837
2018-02-15 11:18:26 +01:00
Maximilian Krüger 189d5b2331 remove redundant conversions
resolves grumbles:
https://github.com/paritytech/parity-bridge/pull/114#discussion_r168407959
https://github.com/paritytech/parity-bridge/pull/114#discussion_r168408026
2018-02-15 11:17:42 +01:00
Maximilian Krüger 55192e9830 proper error handling instead of expect 2018-02-14 12:13:49 +01:00
Maximilian Krüger 53e02f4430 add docstrings 2018-02-14 12:13:40 +01:00
Maximilian Krüger 107141e0b7 remove unused imports 2018-02-14 12:13:11 +01:00
Maximilian Krüger 12eea5053f quickcheck test that MessageToMainnet roundtrips from/to bytes and payload 2018-02-12 19:32:09 +01:00
Maximilian Krüger 1de9a53d1e slightly simplify test for signature roundtrips 2018-02-12 19:31:46 +01:00
Maximilian Krüger dfb7fef654 bridge/src/signature.rs: 100% test coverage with quickcheck 2018-02-12 19:14:57 +01:00
Maximilian Krüger 5b446b48a3 remove `use` of symbols that no longer exist 2018-02-12 16:35:36 +01:00
Maximilian Krüger c887668eda remove tests for withdraw confirm payloads
- they test against raw hex strings
  - hard to modify
  - if we me it easier to modify by using ethabi to assemble data
    the tests essentially become useless
- logic should already be covered by both integration test and RPC tests
2018-02-12 15:24:23 +01:00
Maximilian Krüger 4a3b4ba1f0 remove test for function that doesn't exist anymore 2018-02-12 15:23:41 +01:00
Maximilian Krüger be18c96d31 remove conversion (web3 -> ethabi) that is no longer needed (ethereum-types) 2018-02-12 14:58:14 +01:00
Maximilian Krüger 87c57c9963 extract code dealing with signatures into module 2018-02-12 14:57:57 +01:00