Coder Social home page Coder Social logo

darwinia-network / bridger Goto Github PK

View Code? Open in Web Editor NEW
11.0 8.0 10.0 5.96 MB

Relayer client implementation for Darwinia LCMP protocols.

Home Page: https://rust-docs.darwinia.network/bridger

License: GNU General Public License v3.0

Rust 98.79% Dockerfile 0.01% Shell 0.12% HTML 0.01% JavaScript 0.01% Vue 0.70% TypeScript 0.38% SCSS 0.01%
bridge darwinia relayer

bridger's People

Contributors

alexchien avatar aurevoirxavier avatar cinlk avatar clearloop avatar fewensa avatar furoxr avatar hackfisher avatar songtianyi avatar wi1dcard avatar wuminzhe avatar xiaoch05 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bridger's Issues

unreasonable ERROR prompt before shadow catch the lastest block

bridger should receive an answer from shadow about its status such as its latest block when error. not just pop up a json error.

[2021-01-05T09:05:55Z ERROR darwinia_bridger::service::relay] Error {
        context: "Fail to get parcel from shadow when affirming ethereum block 9401625",
        source: Error {
            context: "Fail to parse json to MMRRootJson: https://testnet.shadow.darwinia.network/ethereum/parent_mmr_root/9401626",
            source: reqwest::Error {
                kind: Decode,
                source: Error("missing field `mmr_root`", line: 1, column: 49),
            },
        },
    }

Check extrinsic nonce or wait for previous extrinsic confirm after sending next?

[2020-10-24T09:49:32Z TRACE darwinia_bridger::service::redeem] Looking for redeemable ethereum transactions...
[2020-10-24T09:49:32Z TRACE darwinia_bridger::service::redeem] Currently we have 14 txs might need to be redeemed
[2020-10-24T09:49:39Z INFO  darwinia_bridger::service::redeem] Redeemed tx 0x40f96d27265e851fc8bbd01360a775cf2f278e13a6c5f6c0f38babcd72f475c0
[2020-10-24T09:49:40Z INFO  darwinia_bridger::service::redeem] Redeemed tx 0x1f4da58dd08c2d2370cebbbf1c0705273b15c4223ed3c32a64b7588e39a6dd7e

Better services management

Run bridger in daemon mode

> bridger run -d

Show running status

> bridger status
ID      SERVICE NAME                            STATUS
1       ethereum to darwinia relay              runing
2       ethereum to darwinia redeem             stopped
3       ethereum to darwinia guard              stopped
4       ethereum tracking                       runing
5       darwinia tracking                       runing

Start & stop service

> bridger start 2
> bridger stop 2

Could not run guard even using technical committee

Logs

 ๐บ ./target/debug/bridger keys 
sudo key: d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d (5GrwvaEF...)
technical committee members: [d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d (5GrwvaEF...)]
 ๐บ ./target/debug/bridger guard 
[2020-10-26T16:00:16Z INFO  darwinia_bridger::cmd::guard] Init API succeed!
[2020-10-26T16:00:16Z ERROR darwinia_bridger::cmd::guard] Bridger("Guard service is not running because the relayer is not a member of the technical committee!!!")

And why using !!! here? A bridger is not a technical committee that might be a common situation.

Darwinia Events Logging

  • Relay Pending Header Event
  • Relay Guard Checking Event. (Vote Aye/Nay)
  • Relay Confirmed Header Event.
  • Backing Redeem Event (print origin)
  • Relayer Game Events

No error log even bridger cannot connect to darwinia/eth nodes

For example, change the rpc in [eth] to a non-existent node address:

# ...
[eth]
rpc = 'https://mainnet.infura.ioabcd/v3/...'
start = 11149205
# ...

Bridger should report an error if it's not able to connect to the rpc endpoint. Please do not check the address ourselves, instead, it is better just throwing out the error from the HTTP client, as this is just an example case to let you easily reproduce the issue. We have tons of possibilities of different errors, like connection refused if the port is misconfigured, no route to the host if the IP is misconfigured, or missing CA certificates if we don't have ca-certificates installed, etc...

Affirmed same block multi times

[2020-10-26T08:05:19Z ERROR darwinia_bridger::service::relay] Bridger("The target block 8779869 is pending")
[2020-10-26T08:06:19Z ERROR darwinia_bridger::service::relay] Bridger("The target block 8779869 is pending")
[2020-10-26T08:07:20Z INFO  darwinia_bridger::service::relay] Affirmed ethereum block 8779869 in extrinsic 0x0c097555e3bc30bbe0a25ee903aa44185fa1deb398e19cd4152c6a961f956172
[2020-10-26T08:08:20Z INFO  darwinia_bridger::service::relay] Affirmed ethereum block 8779869 in extrinsic 0x4d79529ddb27026718bb3970697c02feb020bb4429225143aa91b10600013197
[2020-10-26T08:09:20Z ERROR darwinia_bridger::service::relay] Bridger("The target block 8779869 is pending")
[2020-10-26T08:10:21Z ERROR darwinia_bridger::service::relay] Bridger("The target block 8779869 is pending")
[2020-10-26T08:13:23Z ERROR darwinia_bridger::service::relay] Bridger("The target block 8779869 is pending")

Scale codec error: No such variant in enum Phase

When handling the Darwinia event, this error will appear repeatedly, but it will not cause a problem.

[2020-12-30T13:19:19Z ERROR darwinia_bridger::service::subscribe] Encounter error when handle events of block 378287: Scale codec error: No such variant in enum Phase

Importing unnecessary crate hex

Desc

match hex::decode(real) {
Ok(real) => {
let mut data: [u8; 32] = [0u8; 32];
data.copy_from_slice(&real[..]);
let real = <DarwiniaRuntime as System>::AccountId::from(data);
Some(real)
},
Err(_e) => None

The darwinia-bridge-primitives crate already implemented the same function

/// Convert hex string to `Vec<u8>` or `[u8; n]`
#[macro_export]
macro_rules! bytes {
// Convert hex to Vec<u8>
($hex:expr) => {{
let mut h = $hex;
if h.starts_with("0x") {
h = &h[2..];
}
(0..h.len())
.step_by(2)
.map(|i| u8::from_str_radix(&h[i..i + 2], 16))
.collect::<Result<Vec<u8>, _>>()
.unwrap_or_default()
}};

Proxy Config Struct

Currently, there is a relayer key in config which is only used when proxy account is open.

A minor suggestion would be.

  • rename relayer to a more accurate name, e.g. real
  • adding a proxy tag to define keys only for proxy
  • current seed key have different meanings in two cases, if proxy is closed, it means the private key of relayer, if proxy is opened, it means the private key of proxy account.
  • Adding documents explain the config. (@clearloop said that it is auto generated now, but it is not friendly to add docs for it, prefer removing auto generate mechanism)
seed = ""

[proxy]
real = ""

Moving start in config to cache db/file

  • Move start to outside of config, this should not hardcoded in config and config is not for data store.
  • Provide a command for use to query/change the current ethereum scan start block.

User Document

  • Configuration
  • Shadow Service
  • Operation
  • Logging
  • Proxy Document, #15

Print the version when bridger launches

Since I'm using Kubernetes to deploy the bridger, probably adding the version to logs at the time when bridger launches would be nice. That way, operators like me will be able to know the version of current running bridger, by just inspecting log output without running another command in the container.

Build failed with sccache

Desc

Could not build futures-macro using sccache wrapper.

Solution

Stop the sccache backend server solved the problem on my machine temporarily

Transaction has a bad signature after runtime upgrade

[2020-10-29T09:04:41Z TRACE darwinia_bridger::service::ethereum] Scanning on ethereum for new cross-chain transactions...
[2020-10-29T09:05:12Z TRACE darwinia_bridger::service::ethereum] Scanning on ethereum for new cross-chain transactions...
[2020-10-29T09:05:20Z TRACE darwinia_bridger::service::redeem] Looking for redeemable ethereum transactions...
[2020-10-29T09:05:20Z TRACE darwinia_bridger::service::redeem] Currently we have 1 txs might need to be redeemed
[2020-10-29T09:05:20Z INFO  darwinia_bridger::service::guard] Last confirmed ethereum block number is 8968590
[2020-10-29T09:05:20Z TRACE darwinia_bridger::service::guard] Checking pending headers...
[2020-10-29T09:05:21Z TRACE darwinia_bridger::service::relay] Prepare to affirm ethereum block: 8970243
[2020-10-29T09:05:21Z TRACE darwinia_bridger::api::darwinia] Proxy call `affirm` for cec66c9be4c0500c5da90cb87d1d0af693da4d5fc9bf0e43ec6195cf7ee4d650 (5GjpfZkb...)
[2020-10-29T09:05:21Z ERROR darwinia_bridger::service::relay] Subxt("Rpc error: Server responded to our request with an error: Error { code: ServerError(1010), message: \"Invalid Transaction\", data: Some(String(\"Transaction has a bad signature\")) }")

Recommend to run rustfmt after editing files

Desc

This will make the checking of pull requests easier, for example, rustfmt will :

  • Order the dependencies
  • Unify the code style of different developers

Lots of editors will run rustfmt on saving changes.

Husky

This still can be implemented by using husky.

Flag to switch testnet or mainnet

Desc

Our contract addresses are rarely changed, it might be a choice to write it inside and switch by flag, for example bridger run -v --testnet

Or a switcher like the proxy config:

testnet = false;

[ethereum>darwinia]Optimistic Bridge Relayer Behaviors

  • affirm, when received request of header relay into light client, and there are no existing games match requirement (game block number is smaller than the requested block number).

  • dispute_and_affirm, when received affirm event and have different checking result.

  • extend_affirmation, when received event of new round, and continue to follow the right affirmation if necessary. (make sure that last_leaf is using first_affirm_header_number - 1, because protocol is using mm_root in first affirmed header parcel to verify consistency)

  • Check #44

Support Proxy Model

  • proxy support: #16
  • modify proxy config
  • add proxy pallet to node-template
  • test with node-template

Using an embedded database may be a better choice

Now the tx data center is a memory pool, if the program stopped, the tx data will be lost.
When the user restarts the program, he must reset the start param in the config file, or the program will do repeat work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.