Giter Club home page Giter Club logo

nearcore's Introduction





Reference implementation of NEAR Protocol

Buildkite Stable Status Prerelease Status codecov Discord chat Telegram Group

About NEAR

NEAR's purpose is to enable community-driven innovation to benefit people around the world.

To achieve this purpose, NEAR provides a developer platform where developers and entrepreneurs can create apps that put users back in control of their data and assets, which is the foundation of "Open Web" movement.

One of the components of NEAR is the NEAR Protocol, an infrastructure for server-less applications and smart contracts powered by a blockchain. NEAR Protocol is built to deliver usability and scalability of modern PaaS like Firebase at fraction of the prices that blockchains like Ethereum charge.

Overall, NEAR provides a wide range of tools for developers to easily build applications:

Join the Network

The easiest way to join the network, is by using the nearup command, which you can install as follows:

pip3 install --user nearup

You can join all the active networks:

  • mainnet: nearup run mainnet
  • testnet: nearup run testnet
  • betanet: nearup run betanet

Check the nearup repository for more details on how to run with or without docker.

To learn how to become validator, checkout documentation.

Contributing

The workflow and details of setup to contribute are described in CONTRIBUTING.md, and security policy is described in SECURITY.md. To propose new protocol changes or standards use Specification & Standards repository.

Getting in Touch

We use Zulip for semi-synchronous technical discussion, feel free to chime in:

https://near.zulipchat.com/

For non-technical discussion and overall direction of the project, see our Discourse forum:

https://gov.near.org

nearcore's People

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  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

nearcore's Issues

Invalid state transition on shard chains

If shard chain is taken over (>2/3 of validators controlled by an adversary), the shard chain can produce invalid state transition. Through receipts, this transition may be acted upon in the other shards.

better RPC api

we can have more ergonomic API endpoints, right now, we are basically jamming everything under a transaction

Network protocol

Protocol for communicating between nodes (where P2P is abstracted out)

Implement TxFlow

  • Epoch, endorsement, approval computation
  • Fetching
  • Handling of missing messages
  • Message and transaction bundling

TxFlow Gossip Optimization

Current gossip is not optimized, specifically the fetching part and the rate at which we gossip.

  • When one witness fetches DAG from another witness it does it in a BFS fashion one layer of missing messages at a time. We might want to optimistically ask several layers of messages at a time. This would require some heuristics.

  • Currently when witness A receives an unsolicited gossip from B containing message X, if message's parents are all known to A it will add X to its DAG and send an gossip reply back to B (which helps with congestions). However, if X has missing parents A will reply to B later after all parents are known. However if while A waits for parents some other witness C gossips the same message to A, A will not reply to B anymore, and will only reply to C. This should be done better somehow.

  • TxFlowTask should be able to detect when someone repeatedly spams it. This however is not a malicious behavior since it cannot be proved to be malicious so it cannot be addressed with MisbehaviorReporter, see: #118
    It should be solved with some struct we could call "SuspiciousBehaviorReporter" which we would report to and which our network layer would use to determine whether we want to bounce the messages.

messages

We should define the set of messages we want to send through and receive from network. Maybe we should have a spec for this.

VM for smart contracts

  • WebAssembly
  • Interaction with state
  • Transaction format for running functions
  • Example of payment contract

remove testing only functionality

using this as a parent issue to keep track of places where we have code that should live in a test-utils module.

  • primitives::types::SignedTransaction.empty
  • primitives::signature::default_signature

Bring rustfmt back to pre-commit

i don't know if we are always gonna line up with rustfmt rfc's and it would be good to have an option to define our own style but also get a formatting tool.

options:

  • fork rustfmt
  • use non-rust specific formatter that you can tune well

this issue will also be used for discussions about style preferences we have that don't align with our current configuration.

Node should be using message-passing concurrency

In order to be more aligned with the interface of libp2p and other Rust libraries that use futures we need to replace some of our state-sharing concurrency with message-passing concurrency. Which would also allow us to get rid of some thread-safety primitives and hopefully be faster.

The following things should be run as tasks:

  1. network_listener. Listens to the stream of network messages from libp2p and spawns network_messages_handler's;
  2. network_messages_handler (currently called Protocol). We spawn a new instance of handler for every new network message received just shown in the last example here: https://tokio.rs/docs/getting-started/echo/ so that we can benefit from the concurrency.
  3. TxFlowTask is as designed should run as a task.
  4. A pool of Runtimes that execute the contracts.
  5. RPC server.
  • CLI would be on the main thread, and spawn tasks 1, 3, 4, 5, and provide them with the channels that they would use to communicate.

consider different name for transaction

i think this has been cargo culted from bitcoin (where all records on each block are financial transactions).. and i think it becomes confusing when we can define transaction as the following:

  1. data that is being written to blocks (sending money, contract deployment, creating an account, etc.)
  2. financial transaction
  3. database transaction/commit

Three failures in txflow tests

There are three generated tests failing. Here are the tests and the reasons:

bob_fork

Alice approves two messages from Bob, neither shall be considered an endorsements. Carol and Dave only approve one, both such approvals shall be endorsements.

bob_second_msg_in_kickout_epoch

Bob has a message that approves his own kickout message in the same epoch. Rust implementation mistakenly marks such message as kickout as well.

generated_kickouts_and_epoch_blocks_1

For some reason Carol's message is not a representative, even though it approves the previous representative, and its own kickout message has sufficient number of endorsements.

Reimplemented functionality of the Rust futures should go

Here we keep track of the things in our current code base that reimplement the already existing functionality of the Rust futures crate. Most of them will go away once we close: #121

  • tx_pool and import_queue in Client will become not needed once transactions, blocks and other things are going to be communicated using channels between the tasks, because channel is a FIFO queue itself, see: https://doc.rust-lang.org/std/sync/mpsc/

  • The handshaking_peers in Protocol reimplements Future as it waits on a certain task to complete by re-implementing the polling mechanism of the futures using maintain_peers that is being regularly called on a timer, see generate_service_task.

  • Currently block_production in Protocol does not reimplement the polling mechanism, because it simply calls prod_block of the Protocol which immediately provides a fake block. However, if it was not fake, it would need to wait for a consensus to finish, which would turn into the same re-implementation of the polling mechanism as discussed above.

CI too slow

We shouldn't wait 20 minutes for CI to finish. It seems that the cache is not working properly.

Beacon chain

For MVB we use beacon chain to keep state:

  • Implement blockchain tracking (storing into DB blocks and headers)
  • Block production
  • Block validation
  • Network catch up
  • Witness staking, selection and accounting for block production

Cross shard payments

If each account can have a custom smart contract to control the access to funds (multi sign, rules, etc), how can we ensure that the sent money came from a "valid" contract?

Few ideas:

  • Amount is outside of the "account" contract
  • send/deposit functions are standard and non-overridable.
  • have library contract Account that others must inherit to be trusted. This implements standard functions and provides interface for extension.

One failure in txflow test

There is a tricky case failing, and as far as I see can be unrelated to tests tracked on #99

generated_endorse_kickout_fork

Bob create two messages (a fork) B1 and B2.

  • B1 approve representative message from Alice A in epoch 0 and becomes representative message in epoch 1.
  • B2 don't approve message A but is in epoch 1 so its a kickout message.

Further messages approving both B1 and B2 must discard B2 kickout message and endorse representative B1.

refactor network client

should probably be moved out of the network and it definitely needs to be renamed, because it is prohibitively confusing to implement Client for Client, and actually causes conflicts on IDE understanding what is going on when there are naming conflicts when they are both supposed to be in scope.

it seems like this is a trait for a blockchain, that network should rely on.

cc: @bowenwang1996 @ilblackdragon

Chain specification

Implement way of specifying the chain:

  • genesis state -> map of AccountId -> DBValue or Runtime::Account?
  • for now -> list of public keys who are first authorities
  • genesis beacon block (can be constructed automatically, not sure if we need to specify)
  • any other parameters we need

TxFlow DAG performance optimization

The current version of TxFlow DAG works, but was implemented using inefficient data structures in an inefficient way. The following optimizations could improve its speed and memory usage by several times or even an order of magnitude.

  • Replace u64 with more efficient and appropriate types. Current TxFlow DAG structs Message, Group, GroupApproval, GroupsPerEpoch, GroupApprovalPerEpoch, use u64 in most cases, because it was easy to write fast, this should be replaced. Note that most of these fields are only for internal usage and not going to be send across the network (except maybe epoch which is the part of the message) so it might make sense to use u8 for memory reasons, but it might not be faster CPU-wise with than u32.

  • Message, Group, GroupApproval, GroupsPerEpoch, GroupApprovalPerEpoch are currently returning entire datastructures in their methods, which of course creates unnecessary allocation and deallocation. Instead they should be returning iterators wherever it is possible;

  • Replace HashMap/HashSet usages, because we don't really need their flexibility of adding/removing elements at any time. Most of our mutations of these containers are limited to the construction time and therefore they can be replaced with simpler but more cost-efficient containers. Also some of our containers have limited number of elements so we might be able to use some bitmasks.

  • Keeping track only of the relevant epochs. The tracking containers inside Message struct, like approved_epochs, approved_complete_epochs, etc. keep track of all past messages. It makes sense to not keep track of very old messages. This issue might become irrelevant once we implement pruning.

  • Pruning. See separate issue: #116

TxFlow Missing Components

  • Currently TxFlow does not output consensus. They are partially computed inside TxFlow DAG but not exposed to the outside. We should compute them and stream them in the output stream of TxFlowTask.

  • MisbehaviorVerifier. TxFlow should should be able to report misbehavior as soon as it detects it, which can happen in the different parts of our infrastructure: in Message, DAG, TxFlowTask structs. For now MisbehaviorVerifier does not need to send it for slashing but can simply print it or write to a file for testing.

  • Replace hash with real crypto hash. We should be using crypto hash instead of the hashmap hash is some places.

  • Replace signature with real signature. TxFlow might need to link to the component that does the signing, since TxFlow should not have access to private keys.

Node and NodeTask

  • NodeTask has the ability to start, wait, and stop.
  • Node should be able to track the epoch blocks and schedule the NodeTasks.
  • Node should have a mechanism to cancel NodeTasks.
  • Node should be able to schedule NodeTasks.
  • NodeTask should allow communication between TxFlow and Verifiers.
  • NodeTask and TxFlow should handle the catch-up.
  • NodeTask should have some logic for when it is lagging way behind.

TxFlow DAG pruning

In the current implementation, once TxFlow message is constructed and added to DAG it is never modified, which allows safety and efficiency. However, each TxFlow message carries heavy "aggregators" -- containers that aggregate information from the parents of the message -- which we use to compute properties of the message in near-constant time without traversing the DAG, see approved_* and computed_* fields in message/mod.rs. Since these containers grow with the number of past messages the current memory usage of the DAG grows quadratically. We can solve it by pruning the aggregators of the very old messages in the DAG. It requires several changes:

  • The aggregators should be wrapped in RefCell. This will allow to have a mutable access to them even for the messages that are deep down in DAG (note, these messages are linked to their children through immutable references, so we cannot avoid RefCel).

  • The aggregators should be prunable and restorable. Meaning the containers should have function prune or some such that erases its content. If later this message is used again (e.g. a new message comes in that refers to it as parent) then we should be able to "restore" the content by recomputing it from the parents.

  • Implement "pruner" a struct that will monitor the usage of the DAG and prune rarely used messages.

Note, we might not need to implement this for MVB, because TxFlow is getting restarted for each BeaconChain block.

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.