Git Product home page Git Product logo

crust's Introduction

Crust · Build Status Substrate version GitHub license

Funded by web3 foundation     

Implementation of a Crust Protocol node with substrate.

🎮 Join to Play

Please go to crust wiki, refer the node overview.

Building

⌨️ Build from source

1. Install rust

If, after installation, running rustc --version in the console fails, refer to it to repair.

curl https://sh.rustup.rs -sSf | sh

2. Initialize your wasm build environment

./scripts/init.sh

3. Build wasm and native code

cargo build --release

*4. Troubleshooting

Depending on different building environments, if you cannot build the source code, please check the detail error message and try to run the corresponding commands to fix it

  • Debian/Ubuntu/Raspbian
sudo apt install gcc-multilib

wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh 10
sudo ln -s /usr/lib/llvm-10/bin/llvm-config /user/bin/llvm-config

sudo apt install gcc
sudo apt install clang
  • Fedora/RedHat/CentOS
sudo yum -y install gcc
sudo yum -y install clang

Also, you can join discord to get help

🐳 Dockerize

Please refer this to see how to build and run crust with docker.

⛰ Live Network

1. Connect to mainnet

The default branch mainnet can be build and connect to mainnet.

./target/release/crust --chain mainnet

To speed up the synchronization process, please add the following parameters.

--execution=wasm --wasm-execution=compiled

2. Connect to maxwell

Please checkout the branch release/0.11.1, then build and connect to maxwell

./target/release/crust --chain maxwell

Get the bootnodes from here.

🍕 Dev Network

1. Connect to rocky

Rocky has the same function and parameters with Mainnet, developers can deploy applications on this free test network. Read more about rocky.

./target/release/crust --chain rocky

2. Run as dev

Purge any existing developer chain state:

./target/release/crust purge-chain --dev

Start a development chain with:

./target/release/crust --dev

Detailed logs may be shown by running the node with the following environment variables set: RUST_LOG=debug RUST_BACKTRACE=1 cargo run -- --dev.

3. Run as local

If you want to see the multi-node consensus algorithm in action locally, then you can create a local testnet with two validator nodes for Alice and Bob, who are the initial authorities of the genesis chain that have been endowed with testnet units.

You'll need two terminal windows open.

We'll start Alice's substrate node first on default TCP port 30333 with her chain database stored locally at /tmp/alice. The bootnode ID of her node is 12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp, which is generated from the --node-key value that we specify below:

./target/release/crust \
  --base-path /tmp/alice \
  --chain local \
  --alice \
  --node-key 0000000000000000000000000000000000000000000000000000000000000001

In the second terminal, we'll start Bob's substrate node on a different TCP port of 30334, and with his chain database stored locally at /tmp/bob. We'll specify a value for the --bootnodes option that will connect his node to Alice's bootnode ID on TCP port 30333:

./target/release/crust \
  --base-path /tmp/bob \
  --chain local \
  --bob \
  --port 30334 \
  --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp

Additional CLI usage options are available and may be shown by running cargo run -- --help.

🙋🏻‍♂️ Contribution

Please follow the contributions guidelines as outlined in docs/CONTRIBUTION.md. In all communications and contributions, this project follows the Contributor Covenant Code of Conduct.

License

Apache 2.0

crust's People

Contributors

andresilva avatar badkk avatar gougougogol avatar lowentropybody avatar mmyyrroonn avatar pangwa avatar wuhaixian1984 avatar yashirooooo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crust's Issues

[MPoW] PubKey should be unique

After recover mode is enable in TEE side, if different accountId can bond same pubkey, it will steal the recovery_file, then different accounts can use the same plot size, it will destroy crust network.

[GPoS] Support guarantor's behaviour

Currently, guarantee only support

  1. nominate a whole butch of candidates;
  2. can nominate even he/she isn't candidates;

It better to provide:

  1. check candidates is real there;
  2. can nominate a single candidate;

Node disconnection influent block time

Step to reproduce

  1. Start 2 validators(connected);
  2. 3nd node connect to them;
  3. 3nd node offline;

Result

The block time will become abnormal, far more than ideal block time(6s).

Change Authority Discovery in a better way

When I using BABE, I found the blocking time was unstable because of the authority peers sometimes be disconnected, How can I make sure the authorities always connected each other?

BABE + AUDI can solve this problem, however, authority_discovery now is in experimental stage, follow polka's change in service.rs code/update substrate in stable 2.0.0 version

[GPoS] Change CurrencyToVote

NPoS to GPoS, the 3nd thing is better stake limitation mechanism.
For now we unlock their stakes forcefully in each era end. However

  1. stake limit calculation bonding with total_issue and total_storage, limit may change periodlly, this may leads unlocking every era
  2. with guarantors voting, the unlock algorithm looks dumb

So we should design a passive checking on calculate the valid currency for whole stakes.

Better nominator stake limit setting mechainism

  1. If one of the nominator's validator reach the limit, the exceeded part should invest into others(or let user can choose)?
  2. After an era, the Phragmen will change nominator' stakes in some algorithm, which will make the last nominator's stake goes less and less;

[Market] Delayed payment

Delayed payment should contains:

  1. 3 status = { Created, Pay to provider, Pay to clientself };
  2. Pay by session change(better by block);

[GPoS] Reward returning mechanism

Currently, rewarding will return by 3 strategies:

  • Stashing account(increase the amount at stake);
  • Stash account (do not increase the amount at stake);
  • Controller account;
    Maybe better strategy inferring newest Kusama

[GPoS] error message is unfriendly

When a guarantor votes a validator, whose valid votes is equal to his stake limit, the error message is EmptyTarget, which is unfriendly to me.

Offline validator won't get slash

Problem description

Now the runtime module did not set slash mechanism, so if validator offline, it won't get slash, even get reward.

Steps to reproduce

  1. Get rotateKey through existing validator's rpc;
  2. Bond with rotateKey;
  3. Set validator;

same problem but different consequences #25

BABE's behaviour is not expected

Background

Started in local mode(2/4 min/all validators).

Reproduce

  1. Start Alice;(She will wait in block#0);✅
  2. Start Full node named watcher;✅
  3. Then Alice started to produce blocks;❌

However, polkadot still have this problem.

Error with block built when epoch expired

Step to reproduce:

  1. Start normally with crust --dev;
  2. Stop normally and wait more than 1 epoch(alphanet is 1m);
  3. Start again;

Error detail:

2020-01-10 10:06:55 Crust ALPHA Node
2020-01-10 10:06:55   version 0.0.1-211c7a5-x86_64-macos
2020-01-10 10:06:55   by crustio, 2019, 2020
2020-01-10 10:06:55 Chain specification: Local Testnet
2020-01-10 10:06:55 Node name: Bob
2020-01-10 10:06:55 Roles: AUTHORITY
2020-01-10 10:06:55 Highest known block at #31
2020-01-10 10:06:55 Using default protocol ID "sup" because none is configured in the chain specs
2020-01-10 10:06:55 Local node identity is: QmRVb12fiybGjStNNHA8318SQFPRV9PHwQkPWkS7DGReZf
2020-01-10 10:06:55 Starting BABE Authorship worker
2020-01-10 10:06:55 Unable to bind grafana data source server to 127.0.0.1:9955. Trying random port.
2020-01-10 10:06:55 Grafana data source server started at 127.0.0.1:0
2020-01-10 10:06:56 Discovered new external address for our node: /ip4/192.168.50.56/tcp/30334/p2p/QmRVb12fiybGjStNNHA8318SQFPRV9PHwQkPWkS7DGReZf
2020-01-10 10:07:00 Idle (0 peers), best: #31 (0xb60e…518c), finalized #30 (0xf108…1d38), ⬇ 0.4kiB/s ⬆ 0.4kiB/s
2020-01-10 10:07:05 Idle (1 peers), best: #31 (0xb60e…518c), finalized #30 (0xf108…1d38), ⬇ 1.2kiB/s ⬆ 1.1kiB/s
2020-01-10 10:07:10 Idle (1 peers), best: #31 (0xb60e…518c), finalized #30 (0xf108…1d38), ⬇ 1.0kiB/s ⬆ 1.0kiB/s
2020-01-10 10:07:12 Starting consensus session on top of parent 0xb60effdb93f2773b9ade15bbb152b3402f68629ff565ebf0a8c40c07a6cc518c
2020-01-10 10:07:12 Prepared block for proposing at 32 [hash: 0x25cfb1f6d34ee9a34c7eb5d581d0e77c58af86c39d1c100e52fffcb6a64148e5; parent_hash: 0xb60e…518c; extrinsics: [0xca73…d404]]
2020-01-10 10:07:12 Pre-sealed block for proposal at 32. Hash now 0xec898038a9b9312b6dacc3a0e636c272844ae58cacdfb0f7b9aed9d380201d09, previously 0x25cfb1f6d34ee9a34c7eb5d581d0e77c58af86c39d1c100e52fffcb6a64148e5.
2020-01-10 10:07:12 Error with block built on 0xb60effdb93f2773b9ade15bbb152b3402f68629ff565ebf0a8c40c07a6cc518c: ClientImport("Expected epoch change to happen at 0xec898038a9b9312b6dacc3a0e636c272844ae58cacdfb0f7b9aed9d380201d09, s263103672")

Stake limitation needs accurate rate of workloads

The stake limitation rate of workloads should consider with economic model, the AlphaNet calculation can be:

v_stake_limit = v_workloads * (total_CRUs * 50%) / total_workloads

which v_workloads is validator's workloads, total_CRUs is the current total currency and the total_workloads is the network workloads.

[Market] Storage slashing

we ONLY slash provider. To apply market slashing, we should record provider's failed time(which can be easily recorded) and slashing according to this data.

CI is so slow

The old library is deleted every time in C I, which is inefficient. Maybe we need to fix this problem.

[GPoS] Slashing

Currently, we use KUSAMA's slashing mechanism, we should apply our own, including:

  1. Offline validator's slash;
  2. V's related guarantor's slash;

[GPoS] stakers may update failed

maybe happens on

// 4. Update next era's snapshot `Stakers` and `Validators`
<Stakers<T>>::remove(v_stash);
if v_ledger.valid == Zero::zero() {
<Validators<T>>::remove(v_stash);
} else {
let v_own_votes = to_votes(v_own_stakes);
// a. total_votes should less than balance max value
let v_total_votes =
(v_own_votes + v_guarantors_votes).min(u64::max_value() as u128);
// b. build struct `Exposure`
let exposure = Exposure {
own: v_own_stakes,
// This might reasonably saturate and we cannot do much about it. The sum of
// someone's stake might exceed the balance type if they have the maximum amount
// of balance and receive some support. This is super unlikely to happen, yet
// we simulate it in some tests.
total: to_balance(v_total_votes),
others,
};
// c. update snapshot
<Stakers<T>>::insert(v_stash, exposure);
// d. UPDATE NODE: `Validator`
let new_validations = Validations {
commission: validations.commission,
guarantors: new_guarantors,
};
<Validators<T>>::insert(v_stash, new_validations);
}

[GPoS] Clear stakers should not remove online validators

Problem

If chain in a danger situation(corner case), it won't update any staking related data structures(minimum validator protection)

<tee::Module<T>>::update_identities();
Self::clear_stakers();
let validators: Vec<(T::AccountId, Validations<T::AccountId>)> =
<Validators<T>>::iter().collect();
let validator_count = validators.len();
let minimum_validator_count = Self::minimum_validator_count().max(1) as usize;
if validator_count < minimum_validator_count {
// There were not enough validators for even our minimal level of functionality.
// This is bad.
// We should probably disable all functionality except for block production
// and let the chain keep producing blocks until we can decide on a sufficiently
// substantial set.
// TODO: #2494(paritytech/substrate)
return None;
}

However, we should not clear online validator's stakers, cause rewards based on staker(snapshot) status:
// 2. Staking payout
let current_era = Self::current_era().unwrap_or(0);
let total_staking_payout = Self::staking_rewards_in_era(current_era);
let total_stakes = Self::total_stakes();
<Stakers<T>>::iter().for_each(|(v, e)| {
let staking_reward = Perbill::from_rational_approximation(to_num(e.total), to_num(total_stakes)) * total_staking_payout;
total_imbalance.subsume(Self::reward_validator(&v, staking_reward));
});

Proposal

We can zip Stakers with Validators, remove those offline validator's staker

[GPoS] Change guarantor's voting pref

NPoS to GPoS, the second thing is changing stake allocating mechanism of guarantors. Guarantors can vote their stake with self-known amount not using backing_stakes to allocate their stakes automatically.

[Market] Provider mortgage

Market, for the storage order, provider should have mortgage to take order's. It plays 2 roles :

  1. Sum(order_price) <= Mortgage;
  2. Mortgage should link to stable coin(like USDT);

[GPoS] Validator set election algorithm

NPoS to GPoS, the 1st thing should enable active voting for guarantors, now we are using phragmen's backing_stake to allocate guarantors' stake. We should design a brand new election algorithm to select validators in an end of era.

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.