Git Product home page Git Product logo

lodestar's Introduction

Lodestar Ethereum Consensus Implementation

GitHub release (latest by date) Docker Image Version (latest by date) Eth Consensus Spec v1.4.0 ES Version Node Version codecov gitpoap badge

Lodestar is a TypeScript implementation of the Ethereum Consensus specification developed by ChainSafe Systems.

Getting started

Prerequisites

Developer Quickstart:
yarn install
yarn build
./lodestar --help

Architecture Overview

  • πŸ“¦ This mono-repository contains a suite of Ethereum Consensus packages.
  • βš–οΈ The mono-repository is released under LGPLv3 license. Note, that the packages contain their own licenses.
Package Version License Docs Description
@lodestar/beacon-node npm License: LGPL v3 documentation 🚨 Beacon-chain client
@lodestar/validator npm License: LGPL v3 documentation 🏦 Validator client
@lodestar/light-client npm License documentation 🐦 Ethereum Light client
@lodestar/api npm License documentation πŸ“‹ REST Client for the Ethereum Beacon API
@chainsafe/lodestar npm License: LGPL v3 documentation πŸ’» Command-line tool for Lodestar
@lodestar/state-transition npm License: LGPL v3 documentation πŸ”Ž Eth Consensus beacon-state transition
@lodestar/types npm License documentation πŸ—’οΈ Eth Consensus TypeScript and SSZ types
@lodestar/params npm License documentation πŸ•ΈοΈ Eth Consensus network parameters
@lodestar/utils npm License documentation 🧰 Miscellaneous utility functions used across Lodestar
@lodestar/config npm License documentation πŸ—’οΈ Eth Consensus types and params bundled together
@lodestar/spec-test-util npm License documentation πŸ§ͺ Test harness for Eth Consensus spec tests
@lodestar/db npm License documentation πŸ’Ύ Read/write persistent Eth Consensus data
@lodestar/fork-choice npm License documentation 🍴 Beacon-chain fork choice

Contributors

Read our contributors document, submit an issue or talk to us on our Discord!

Meetings

Weekly contributor meetings are public and announced on Discord. Feel free to check out our meeting notes and documents on HackMD. Post-September 2021, meeting notes can be found on the Lodestar Wiki Page.

Donations

We are a local group of Toronto open-source developers. As such, all of our open-source work is funded by grants. We all take the time out of our hectic lives to contribute to the Ethereum ecosystem. If you want to donate, you can send us ETH at the following address: lodestar.chainsafe.eth

lodestar's People

Contributors

3xtr4t3rr3str14l avatar ajoydas avatar ansermino avatar aunyks avatar austinabell avatar chainsafesystems avatar dadepo avatar dapplion avatar darrenlangley avatar dependabot[bot] avatar ec2 avatar ensi321 avatar g11tech avatar gregthegreek avatar jeluard avatar jonathanlorimer avatar matthewkeil avatar mikerah avatar mpetrunic avatar nazarhussain avatar nflaig avatar noot avatar philknows avatar protolambda avatar q9f avatar ryry79261 avatar sadiq1971 avatar tueric avatar twoeths avatar wemeetagain 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lodestar's Issues

Using Lerna for package management

As we are converting this repository to typescript (and our other repos) and as we continue to build out the tooling necessary to implement our client, we will see an increase in the usage of packages in this repository. Currently, the repo is small and we have few (if any) outside packages in use and is not much of a concern. However, I think starting a discussion and thinking about what tools we can use to improve managing libraries early is important so that we have less surprises down the road.

I discovered this tool called Lerna that is being used for js-libp2p for managing JS projects with multiple packages.

Any thoughts?

CC'ing @GregTheGreek, @priom, @ansermino

Startup function

Is your feature request related to a problem? Please describe.
By creating the startup functionality we will be able to begin testing the whole system as the pieces come together.

Describe the solution you'd like
Realistically, some functionalities will need to be stubbed, as we are still having some type related issues (primarily bytes #59).

How to
I am working on creating a start function (i.e the main entry point for the beacon chain) that will add an event listener to the deposit contract on ETH1.0. I'll have to get the old logs from the contract, and the continue to look for the new contracts. When the ChainStart log is emitted then my function will need to execute the get_initial_beacon_state function (not implemented, but I will have it implemented for my PR). At this point we will have the base state for the beacon chain and to avoid submitting an extensive pr i will stop at this point.

Classes for startup

Is your feature request related to a problem? Please describe.
The current state from #71 and #73 would require us to pass around the state object on functions that mutate state which could become a bit difficult. If we switched to a class based approach we could access and manage state much easier.

Describe the solution you'd like
Ideally, if we have something like class BeaconChain {} then we can get acccess to state via this.state and guarantee we're mutating the correct state (you can imagine, if we have async and non async actions flying around then theres a chance we would mutate state in the incorrect order). That being said the actual startup functionality should probably be changed over to a command line argument based setup.

EDIT: expanded on the correct one.

Guidlines and templates

In addition to #40 we should set up issue, feature request and PR templates for the repo. Would also be good to setup a contributors guidelines.

Tests for state transition helpers

We need to complete tests before starting on the state transition functions. This will enable use to set up a flow for tests in this repo. Currently, there are (as of this writing) 2 helper functions that have tests.

Drop the "alternative" part in the headlines

Hi @Mikerah, every time I am looking at this repo, I am irritated by the "alternative" parts in the headlines, as it suggests to me that you are doing an alternative implementation in the sense of "an alternative/different approach" - similar to the Casper FFG vs CBC research directions.

I assume that is not what you are intending and you just try to implement the (evolving) specifications in JavaScript (or do you want to indeed follow different paths than e.g. done in the Prysmatic Labs repo)?

Then I would suggest to drop the "alternative" in the header title and the initial section of the README and just state "provide an implementation of the beacon chain in JavaScript".

Cheers
Holger

empty bitfield init error

Issue

getEmptyBitfield in bitfield.js is return an incorrect value. The following code returns strings like "x00x00x00x00x00".
https://github.com/ChainSafeSystems/lodestar_chain/blob/a270c7a577a3deda88f96cebb41bc3f173e26b1d/lodestar_chain/utils/bitfield.js#L19
The intention here is to initialize a byte array or some sort of bytes representation with the correct number of 0 bytes.

Proposed Implementation

Not sure the best way to represent bytes in javascript. Will need to dig around for best practices on this.

Find proper types

We need to find proper typescript types for (or write them ourselves):

  • [ x ] uint's
  • [ x ] bits
  • [ x ] hash32

David's library should do the trick for uints. As for hash32 bits and bytes unsure.

Style guide for Typescript

In order to increase readability, minimize errors and onboarding outside contributions, we need to set up tools that can fix and check the formatting of the code that gets pushed to this repo. We can easily set up tslint for now but in the future, we should aim to have a tool like standard.js for typescript.

Custom logger

Is your feature request related to a problem? Please describe.
Currently there is no standardized way to log anything.

Describe the solution you'd like
We should implement a custom logger.

Representing bytes in Javascript

While implementing ssz in JS, I have been representing bytes as arrays. Currently, in this repository, bytes are represented using strings.

I would like to start a discussion as to what is a good way to represent bytes so that while implementing both ssz and the beacon chain spec, we are consistent.

Migrate to Typescript

There seems to be some good discussion around this in the ethereumjs organization, as well as other JS blockchain projects. There is an additional barrier of entry, but it would seem that the benefits are worth it. We would have a huge advantage by making the switch now, although it would certainly could be reconsidered further down the road.

ethereumjs/organization#28
ethereumjs/ethereumjs-client#10
https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html

Add DB

Is your feature request related to a problem? Please describe.
In order to keep track of the state we should add support for a DB.

Describe the solution you'd like
One option would be to implement level-js which is a key-value pairing that is an implementation of the google leveldb.

EDIT: Clarified this is a discussion.

Import / Export constants

Per @wemeetagain:

This may be a good opportunity to remove the uint/bytes duplicate types/vars from types/block.ts and types/state.ts and import/export these instead.
[...] it would be nice to import/export constants and enums from constants/index.ts like we're now doing with types/index.ts.

TODO:

  • Consolidate and Remove duplicate alias types (probably move into constants) (PR: #91 )
  • Import / Export constants/enums

@wemeetagain Assigned, you because im not sure if you already started or not, otherwise happy to take it on myself.

Implementing ECC and BN128 curve operations in Javascript

The main beacon chain reference in Python makes heavy use of the py_ecc library that was written by Vitalik Buterian and Piper Merriam. Javascript doesn't have a robust library like this. The closest thing I found was rustbn.js but it's still not enough.

I am currently undertaking research on whether we should just implement this from scratch in Javascript or using WebAssembly/asm.js, take py_ecc and compile it to Javascript.

Remove deprecated code from previous Spec

As was pointed out in #7, the repository currently contains code from previous specifications of the beacon chain.

We will need to compare and contrast what is in this repository, what is in the current specification and what is implemented in the reference python beacon chain.

Project Structure

@Mikerah and I had a chat with the team at ethereum-js/Shasper-js on moving forward and/or any collaboration. We came to the conclusion to migrate to typescript as per #24 and look into mimicking project structures from the ethereum-js client. Rational behind this is so contributors in the ecosystem should be able to easily navigate the javascript client codebases.

Byte representation

Related to #35
Is your feature request related to a problem? Please describe.
We are somewhat restricted in regards to what we can do with bytes.

Describe the solution you'd like
Ideally something native to vanilla JS, C/C++ bridge or WASM.

Describe alternatives you've considered
Webpack so we can use class Buffer() from node. Not ideal.

bug in `aggregateVote.numAggregateSig`

Issue

aggregateVote.numAggregateSig currently incorrectly uses the length of aggregate_sig to get the number of aggregate signatures.
https://github.com/ChainSafeSystems/lodestar_chain/blob/a270c7a577a3deda88f96cebb41bc3f173e26b1d/lodestar_chain/state/aggregateVote.js#L36-L38

aggregate_sig is in fact always just the length of 2 so this fails.

Proposed Implementation

You can use the number of 1s in the bitfield to get the length. If you need the length often, you might consider some sort of helper attribute that caches this results.

Add Licence Headers

Is your feature request related to a problem? Please describe.
Licence is arguably invalid without proper instruction.

Describe the solution you'd like
Add GPL3 headers to every source code file.

Describe alternatives you've considered
N/A

Additional context
Suggested template:

Lodestar Chain
Copyright (C) 2019 ChainSafe Systems

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Using Renovate for keeping packages up to date

This isn't much of an issue at the moment, but any dependencies that we will be adding to this repo will need to be updated regularly. The Prysmatic Labs team uses Renovate to keep their packages up to date. The main issue I have with this is that it may break the code due to API changes,etc of a particular package.

Should we manually update packages in order to easily spot code breaks or should we use something like Renovate to automatically do it for us?

CC'ing @GregTheGreek, @priom, @ansermino

Convert core/state to typescript

While converting the code to typescript I will also be checking to ensure that we are still up-to-date with the current spec.

EDIT :: 25/11/18 - Since the spec has been changed quite a bit (noted by: @Mikerah & @ansermino) the primary focus will be to ensure that the spec is up-to-date as stated above, while also converting to typescript.

Note:
- I will be working alphabetically (descending) through core/state.
- Checked items are currently being worked on in the branch greg/typescript-conversion.

Currently working on:

- [x] Interfaces :: A collection of all the eth2.0 data structures

Completed:
none

Just going through the spec and re-implementing ground up!

Update and test the helper functions

Before implementing the state transition function, the helper functions that I badly implemented need to be updated and tested. It will need to be compatible with any choices made with regards to using buffers/bignumber.js and arrays and work in the browser.

Update the spec

This is apart of our bi-weekly spec update.

I've update the spec fork here and we can use this as our "source of truth" for verifying PR's etc... Unless major breaking changes occur then we should only reference our fork for consistency.

Note: Per last call -- they are only updating the spec on a weekly basis.

ReferenceError: artifacts is not defined

I've just cloned the repository, installed the dependencies and I'm getting this error when I run npm test:

[lodestar_chain](master)$ npm test

> [email protected] test /home/hugo/workspace/Sharding/lodestar_chain
> mocha --recursive

/home/hugo/workspace/Sharding/lodestar_chain/test/test_validator_registration.js:1
(function (exports, require, module, __filename, __dirname) { var ValidatorRegistration = artifacts.require('ValidatorRegistration');
                                                                                                    ^

ReferenceError: artifacts is not defined
    at Object.<anonymous> (/home/hugo/workspace/Sharding/lodestar_chain/test/test_validator_registration.js:1:101)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at /home/hugo/workspace/Sharding/lodestar_chain/node_modules/mocha/lib/mocha.js:250:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/home/hugo/workspace/Sharding/lodestar_chain/node_modules/mocha/lib/mocha.js:247:14)
    at Mocha.run (/home/hugo/workspace/Sharding/lodestar_chain/node_modules/mocha/lib/mocha.js:576:10)
    at Object.<anonymous> (/home/hugo/workspace/Sharding/lodestar_chain/node_modules/mocha/bin/_mocha:637:18)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:607:3
npm ERR! Test failed.  See above for more details. 

I couldn't find information about this error which is related to mocha, all the information I found is related to truffle.

Create run-time type definitions of our interfaces

Unfortunately, typescript interfaces do not appear to be available/exist at run time.
This means that we don't have access to the type information necessary to properly serialize the data.

There is a dependency here, between our "types" and our ssz library that we should be aware of.
Our ssz library assumes a type object with a fields key, which it uses to serialize each field. (See here)

Here is an example that can show the issue:

interface ProposalSignedData {
  // Slot number
  slot: uint64;
  // Shard number (`BEACON_CHAIN_SHARD_NUMBER` for beacon chain)
  shard: uint64;
  // Block hash
  blockHash: hash32;
}

const data: ProposalSignedData = {
  slot: 0,
  shard: 0,
  blockHash: 0,
};

const serializedData: Uint8Array = ssz.serialize(data, ???); // <--- problem here

Perhaps a way forward would be to create a "type" object for each interface.
Something that would play nicely with ssz-js:

const ProposalSignedData = {
  fields: [
    ['slot', 'uint64'],
    ['shard', 'uint64'],
    ['blockHash', 'hash32'],
  ],
};

// from above, problem fixed
const serializedData: Uint8Array = ssz.serialize(data, ProposalSignedData);

See also how the python implementation deals with this, eg: here

Complete helper functions

I browsed through the spec/our code, and found a few helper functions that are not yet implemented. I won't get to these for a bit as I'm currently working on writing further tests.

If you plan to work on one of the following please comment.

(Does not include validator helpers)

  • hash
  • hashTreeRoot
  • slotToEpoch
  • getPreviousEpoch
  • getCurrentEpoch
  • getEpochStartSlot
  • isActiveValidator
  • getActiveValidatorIndices
  • getPermutedIndex
  • split
  • getEpochCommitteeCount
  • getShuffling
  • getPreviousEpochCommitteeCount
  • getCurrentEpochCommitteeCount
  • getNextEpochCommitteeCount
  • getCrosslinkCommittessAtSlot
  • getBlockRoot
  • getRandaoMix
  • getActiveIndexRoot
  • generateRoot
  • getBeaconProposerIndex
  • merkleRoot
  • getAttestationParticipants
  • isPowerOfTwo
  • intToBytes1, intToBytes2... (to be handled by Buffer)
  • bytesToInt (to be handled by Buffer)
  • getEffectiveBalance
  • getTotalBalance
  • getForkVersion
  • getDomain
  • getBitfieldBit
  • verifyBitfield
  • verifySlashableAttestation
  • isDoubleVote
  • isSurroundVote
  • integerSquareRoot (intSqrt)
  • getEntryExitEffectEpoch
  • blsVerify
  • blsVerifyMultiple
  • blsAggregatePubkeys
  • validateProofOfPossession
  • processDeposit

Add CI

We should get a basic CI going, probably just to lint right now. Should enforce checks for PRs.

Milestones

We have a few different milestones we can start assigning to this project.

I was thinking of having 2 for now:

  • Beacon Chain POC
  • Project Structure Cleanup (relation to #24 and #31)

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.