Giter Club home page Giter Club logo

caravand-fullnode's Introduction

caravand

Build Status MIT License docs

Logo of caravand

Bitcoin fullnode OCaml implementation. Caravand will be usable as a standalone bitcoin node with a REST api interface.

Caravand is directly connected to other 3 projects:

Features

  • Chain syncronization for Bitcoin, Bitcoin testnet and Bitcoincash
  • Header-first syncronization
  • Block storage
  • UTXO storage
  • Account storage (balance, sent, txs, utxo)
  • JSON REST api interface
  • Prune-mode for low disk footprint
  • Segregated witness
  • Caravand-as-a-library for applications who need blockchain data
  • Lazy evaluation for block parsing which reduces memory footprint

We are planning to integrate other cool features:

  • JSON-RPC api compatible with Bitcoind
  • Bloom filtering and compactblock
  • Side-chain
  • Pluggable script systems

Documentation

An updated documentation is available here.

Supported chains

At the moment caravand supports these chains:

  • XTN - Bitcoin testnet
  • BTC - Bitcoin mainnet
  • BCH - BitcoinCash mainnet

License

Copyright (c) 2016-2018 Davide Gessa

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Donations

Feel free to donate bitcoin to the developer: 13TRVwiqLMveg9aPAmZgcAix5ogKVgpe4T

caravand-fullnode's People

Contributors

dakk avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

caravand-fullnode's Issues

Exception on branch parsing

Thread 1 killed on uncaught exception Pervasives.Exit
Raised at file "src/blockchain/branch.ml", line 75, characters 13-355
Called from file "_none_", line 0, characters 254-1023
Called from file "list.ml", line 59, characters 20-23
Called from file "src/blockchain/storage.ml", line 149, characters 28-78
Called from file "src/blockchain/storage.ml", line 208, characters 9-48
Called from file "src/blockchain/storage.ml" (inlined), line 249, characters 1-16
Called from file "src/blockchain/chain.ml", line 191, characters 5-51
Called from file "src/blockchain/chain.ml", line 262, characters 5-27
Called from file "src/blockchain/chain.ml", line 284, characters 14-44
Called from file "src/blockchain/chain.ml", line 299, characters 2-12
Called from file "thread.ml", line 39, characters 8-14

Library decoupling

Offer the blockchain parsing/serializing code in an external library useful for other projects.

Block categories

The "actual" blockchain state include also:

- A. blocks in the main branch: the transactions in these blocks are considered at least tentatively confirmed

- B. blocks on side branches off the main branch: these blocks have at least tentatively lost the race to be in the main branch

- C. orphan blocks: these are blocks which don't link into the main branch, normally because of a missing predecessor or nth-level predecessor



We need to save them, they are used for fork-detection and data verification. A better abstraction for the storage code could help storing A/B blocks, while we can prune orphan blocks.



https://en.bitcoin.it/wiki/Protocol_rules#Blocks

Secure shutdown

The shutdown procedure should avoid data corruption; we need to handle the exit signal and execute this procedure:

  • Empty the blockchain queue
  • Finish the current step of the blockchain loop
  • Close the database
  • Disconnect all peers

Better handling of serialize / parsing

Serialize and parsing should never fail; If fail even for one Tx in a block, there is a problem. A block / tx parsing could fail only for new block, new tx

Test coverage

  • Create an empty test suite
  • Chain fork situation handling

Unit tests

  • Branch parsing / serialization

Ideas

  • Check for bitcoin-core test suite

Half parsing of blocks

Don't parse the full block when received, parse it only if the the header is valid and only when the node need this data

Pruning

Implement pruning by:

  • specifying a prune interval in blocks (IE 4096)
  • saving the pruning window in the chainstate
  • removing blocks outside the pruning window

Header sync status

If last n received headers messages are empty, assume that the node is in sync

Blocks, Headers and Tx validation

#We need to integrate these validity tests for blocks, headers and txs:
https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages
https://en.bitcoin.it/wiki/Protocol_rules#.22block.22_messages

  • Header validation
  • Header validation - prev block
  • Header validation - nbits pow
  • Header validation - nbits and diff
  • Header validation - median timestamp
  • Header validation - future timestamp
  • Header validation - checkpoints
  • Block validation
  • Block validation - Header validation (optional)
  • Block validation - Txs > 0 validation
  • Block validation - Coinbase validation
  • Block validation - Merkle root
  • Tx validation
  • Loggable assert function (atm if the verification fail, it didn't display any hint about the problem)

Mempool

  • Base structure
  • Insert new tx
  • Remove tx
  • Push tx api
  • Tx broadcast to all
  • Api for mempool stats
  • Handle gettx message

Better storage abstraction for branches handling

Related to #33 , letchain needs a better storage abstraction to handle main branch and other branchs. A git-like model could be a good idea, but still using leveldb as data backend.
The snapshot feature of leveldb could help storing and handling different branches.

API coverage

  • Network info
  • Tx push
  • Raw tx api
  • Block info
  • Header info
  • Last blocks summary
  • Mempool status on chainstate call

Data provider abstraction

Network is just a data provider; we can abstract from this by providing other data sources, like bindings to another node softwares. Data sources should implement a threading instance which reads and write in the request / response queues.
Another useful datasource could be a torrent backup of first years of chain

Reduce IO operations

The IO is always at 99% when receiving blocks; try to reduce the amount of r/w by using caching and batch operations

Branch handling and fork detection

The last part of the fork detector, is the branch handler; at every step of the blockchain thread:

  • Check if a branch is too old (to many blocks behind), then delete it
  • Check if a branch need updates (some blocks behind) (HBLOCKS)
  • Check if a branch is longer than the best chain
  • Revert block from the last to the fork block
  • Move old main and put them in a branch
  • Push branch headers to the main branch
  • Delete the old branch

Random crash (without exception)

The crash occurs with a 100% cpu usage (maybe from the network thread).

It could be a problem with the find_peer during a WAITPING operation; a possible fix could be to check the available peer number before trying the find_peer.

Crash occurs only on certain PING

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.