Coder Social home page Coder Social logo

lnp-bp / rust-lnpbp Goto Github PK

View Code? Open in Web Editor NEW
79.0 79.0 38.0 2.76 MB

Library implementing LNPBP standards related to client-side-validation paradigm

Home Page: https://lnp-bp.org

License: MIT License

Rust 99.03% Shell 0.97%
bitcoin bitcoin-blockchain bitcoin-protocols client-side-validation lightning-network lnp-bp rust-library single-use-seals smart-contracts

rust-lnpbp's People

Contributors

afilini avatar btcparadigm avatar crisdut avatar dependabot[bot] avatar dr-orlovsky avatar fedsten avatar inaltoasinistra avatar kixunil avatar nicbus avatar philmartin2525 avatar rajarshimaitra avatar ukolovaolga avatar yancyribbens avatar zoedberg 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-lnpbp's Issues

Use 32-bit integers for transaction output indexes in single-use seals

Bitcoin normally uses VarInt to represent the number of transaction outputs that may be contained in a given transaction and 32-bit integer to reference specific transaction output from other's transaction input. While with the given block size limit transaction containing more than 2^16 outputs can't fit the block, it's better not to diverge from bitcoin data structure. The original reason why 16-bit integers were introduced is to save some storage space for RGB client-validated data; however bitcoin transaction output single-use seals are more generic standard and RGB consensus commitment encoding does not require storage space optimization. RGB P2P protocols and vendor-specific RGB storage may still use 16-bit integers; however this should not be required by the LNP/BP standards.

Consider running `cargo fmt`

Running cargo fmt on the current (bd1bd41) master produces a huge diff:

48 files changed, 936 insertions(+), 666 deletions(-)

I won't make a PR now because it would make merging stuff a mess, but we should consider running it when we don't have any big PR open

Versioning for non-commitment RGB data structures

While with those data structures that participate in commitments we can't use versioning without risking complex hard-fork issues under client-side validation paradigm, we can (and should) have versioning for network/storage serialized data, like consignments and disclosures.

TODO: Add version field to consignments and disclosures, defaulting now to 1

Adopt TORv2 addresses

@afilini was right #24 (comment) that we need to add support of TORv2 addresses additionally to TORv3: at least they are a part of Lightning Network gossip protocol https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#the-node_announcement-message and we have to support them in LNP part of the library.

Basically, we need to duplicate all TORv3-related code and adjust it to TORv2-specific types in here: https://github.com/LNP-BP/rust-lnpbp/blob/master/src/common/internet.rs. Also there is a need to add feature requirement to Cargo.toml torut crate as pointed out here: #24 (comment)

Refactor: Move `enum ScriptPubkeyComposition` to `dbc/types.rs`

If this has been already discussed or kept here for future purposes, feel free to close this issue.

ScriptPubkeyComposition is a major input in the high level TxCoinatianer, which is subsequently passed down into smaller containers. So it feels to me that a better location for ScriptPubkeyComposition is with the other protocol level primitive types like Proof and ScriptInfo. Currently, its located in dbc/scriptpubkey.rs.

Thus proposing to reallocate this enum with other primitive types.

Refactor CSV mod

Make serialize its root structure, remove old unnecessary data types; move multimessage commitments to CMT

Abstract BOLT-1 into `lnp::peer` mod

BOLT-1 defines messages that peer nodes exchange before any channel establishment. The data related to these messages are scattered throughout rust-lightning library. It will be useful to abstract them into a single mod in the lnp mod of the library

Refactor bp::Network into ChainParams

We need to support wide range of networks (including Liquid, LN) and create a foundation for generic asset concept (that includes chain-based assets and RGB assets).

Draft concept:

/// P2P network magic number: prefix identifying network on which node operates
pub type P2pMagic = u32;
/// Magic number prefixing Pubkey or Prvkey data according to BIP32 spec
pub type Bip32Magic = u32;

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
#[repr(u8)]
pub enum ChainFormat {
    Bitcoin = 0,
    Elements = 1,
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum AssetLayer {
    Layer1and2,
    Layer2and3,
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct AssetParams {
    pub ticker: &'static str,
    pub unit_of_accounting: &'static str,
    pub indivisible_unit: &'static str,
    pub divisibility: u64,
    pub asset_id: AssetId,
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ChainParams {
    pub name: &'static str,
    pub p2p_magic: P2pMagic,
    pub genesis_hash: BlockHash,
    pub bip32_pubkey: Bip32Magic,
    pub bip32_prvkey: Bip32Magic,
    pub bip70_name: &'static str,
    pub bip173_prefix: &'static str,
    pub p2p_port: u16,
    pub rpc_port: u16,
    pub ln_height: u32,
    pub format: ChainFormat,
    pub dust_limit: u64,
    pub native_asset: AssetParams,
    pub testnet: bool,
    pub pow: bool,
}

/// A set of recommended standard networks. Differs from bitcoin::Network in
/// ability to support non-standard and non-predefined networks
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
#[repr(u32)]
pub enum Chains {
    Mainnet,
    Testnet3,
    Regtest(BlockHash),
    Signet,
    SignetPrivate(BlockHash),
    LiquidV1,
    Other(ChainParams),
}

Consider decreasing use of wildcards in use statements

Use statements containing wildcards (e.g. use foo::*) have a significant disadvantage: it makes it very hard to understand where an item is coming from, especially for new people.

For example, when written as:

use foo::*;
use bar::*;

let baz = Baz::new();

It's impossible to know where Baz comes from without using search tool. However from:

use foo::Something;
use bar::Baz;

let baz = Baz::new();

We can easily see Baz is in bar.

Further, this could cause various issues like two developers adding an item with same name in different modules causing conflict in a third module after merge, which can not happen with explicit use statements.

As an alternative, limit the scope of asterisks to where they're needed. Eg.g sometimes it's useful to use LongEnumNameWithManyVariants::*; at the top of a function containing a huge match.

Add support for bech32 encoding of tagged hash types

// TODO: Remove once the default `Display` implementation for
// hash-derived types is removed
#[derive_from(::bitcoin_hashes::hex::Error)]
HexError,

// TODO: Enable after removal of the default `Display` implementation for
// hash-derived types
/*
impl Display for seal::Confidential {
fn fmt(&self, f: &mut Formatter<'_>) -> ::core::fmt::Result {
Bech32::Outpoint(self.clone()).fmt(f)
}
}
impl Display for ContractId {
fn fmt(&self, f: &mut Formatter<'_>) -> ::core::fmt::Result {
Bech32::ContractId(self.clone()).fmt(f)
}
}
impl Display for SchemaId {
fn fmt(&self, f: &mut Formatter<'_>) -> ::core::fmt::Result {
Bech32::SchemaId(self.clone()).fmt(f)
}
}
*/

Is `stringify!` what we really want here?

https://github.com/LNP-BP/rust-lnpbp/blob/master/src/bp/tagged256.rs#L36

The macro is unused so I can't say for sure what it's meant to do, but that looks wrong to me. From the docs: "This macro will yield an expression of type &'static str which is the stringification of all the tokens passed to the macro. No restrictions are placed on the syntax of the macro invocation itself.".

Kinda dangerous because it wouldn't make anything fail in an obvious way, but it would be a mess to remove in the future.

I would just remove the stringify and concat $prefix and $tag.

Move network field from Schema to Genesis

When we have network in Schema, this will result in that the same schema will have a different SchemaId on different networks (mainnet, testnet), which is undesirable. In fact, network is an asset-specific thing (i.e. genesis is more natural place), and not smart contract category-specific.

Next, Genesis must include full ChainParams data structure, not just a network ID. This will allow RGB to operate on top of any future chain (like new federated sidechains) without requiring library updates.

Related issues:

  • #102 Refactor bp::Network into ChainParams
  • #95 Use ChainParams instead of Network

Use more "rusty" Error types

I noticed that InetAddr as well as other types use String to report errors. This is generally viewed as anti-pattern, especially in library code. I suggest to use custom error types.

We can decrease boilerplate in the early stage of development by using crates thiserror and anyhow using this pattern:

#[derive(Debug, Error)]
#[thiserror(transparent)] // NOT to be confused with repr(transparent)!!! completely different things
struct InetAddrError(anyhow::Error);

This way we will not waste time writing custom enums that we aren't confident about, but avoid running into technical debt of rewriting code to use something else than strings later. The dependencies can be removed at any point and replaced with manual implementation without loss of features or compatibility.

Important: we must not impl From<anyhow::Error> for InetAddrError as that would make the type forward-incompatible.

I might be able to help with this.

Network serialization for Genesis chain parameters

Genesis commits to ChainHash (hash of the genesis block of the underlying blockchain), however it contains (for P2P networking purposes) information about the target blockchain (name etc) called ChainParam. This allows not to hardcore list of supported blockchains (main, test, signet, regtest, sidechains, test sidechains...) into each and all client-level software. However, ChainParam may evolve, so to avoid compatibility issues and allow extensibility w/o RGB contract change we
will serialize chain parameters in all known/legacy formats for compatibility:

genesis := some_data, chain_params, rest_of_data
chain_params := no_of_encodins, chain_param_encoding*
chain_param_encoding := len, bytes*

Make upstream PRs accepted & publish v0.1.0 release on crates.io

TODOs

  • Make all PRs in upstream crates merged
  • Get version bump in upstream crates after the last PR released
  • Complete code docs #81
  • Remove all dead code
    // TODO: when we will be ready for the release #![deny(dead_code)]
  • Remove re-exporting of bitcoin crates
    // TODO: Remove re-exporting of bitcoin crates on release

Upstream dependencies requiring attention

  • grin_secp256k1zkp
  • bitcoin_hashes
  • rust-bitcoin
  • rust-lightning
  • miniscript

List of opened upstream PRs

Possible Refactoring in `schema::types` module

There seems to be an awkward import here with pub use elliptic_curve::EllipticCurve;

pub use elliptic_curve::EllipticCurve;
mod strict_encoding {
use super::*;
use crate::strict_encoding::{Error, StrictDecode, StrictEncode};
impl_enum_strict_encoding!(DigestAlgorithm);
impl_enum_strict_encoding!(Bits);
impl_enum_strict_encoding!(EllipticCurve);

Was this intentional? Why specifically import EllipticCurve like this and not do the same for SignatureAlgorithm and PointSerialization?

Broken consignment validation test

Recent commits with updates to upstream dependencies has broken consignment test: it now leads to rust compiler stack overflow. We need to investigate and test this issue

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.