Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix utxo fetching in current block #22

Merged
merged 8 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@

Subcoin is a full node implementation of Bitcoin in Rust, built using the Substrate framework.
By leveraging Substrate's modular and flexible architecture, Subcoin aims to offer a robust
and performant implementation of Bitcoin protocol.
and performant implementation of Bitcoin protocol. It is the first Bitcoin client that
introduces the snap (fast) sync into the Bitcoin ecosystem, a syncing strategy common in
newer blockchains (Ethereum, Polkadot, Near, etc) with a global chain state.

Currently, Subcoin only implements the feature of syncing as a full node. It is not yet capable
of participating in the Bitcoin consensus as a miner node. Additional features are in the
planning stages.
## Features

## Pros
- 🔄 **Snap Sync**. Employs Substrate's advanced state sync strategy, enabling Bitcoin snap sync
by downloading all headers and the state at a specific block, in decentralized manner. This allows
new users to quickly sync to the latest state of the Bitcoin chain by running a Subcoin node.
<!-- TODO: add a rough snap syncing time later -->

- 🔄 **Fast Sync**. Employs Substrate's advanced state sync strategy, enabling Bitcoin fast sync
by downloading all headers and the state at a specific block, in decentralized manner.
- 🔗 **Substrate Integration**: Utilizes Substrate framework to provide production-level blockchain infrastructures.
- 🔗 **Substrate Integration**. Utilizes Substrate framework to provide production-level blockchain infrastructures.

## Development Status

Currently, Subcoin tentatively implements the feature of syncing as a Bitcoin full node. It is not yet
capable of participating in the Bitcoin consensus as a miner node. Please note that Subcoin is not stable
and is still under active development. Additional features and improvements are in the planning stages.

## Run Tests

Expand Down
20 changes: 1 addition & 19 deletions crates/pallet-bitcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ use scale_info::TypeInfo;
use sp_core::H256;
use sp_std::prelude::*;
use sp_std::vec::Vec;
use subcoin_runtime_primitives::Coin;

// Re-export pallet items so that they can be accessed from the crate namespace.
pub use pallet::*;

const MAX_SCRIPT_SIZE: usize = 10_000;

/// Transaction output index.
pub type Vout = u32;

Expand Down Expand Up @@ -63,23 +62,6 @@ impl core::fmt::Debug for Txid {
}
}

/// Unspent transaction output.
#[derive(Debug, TypeInfo, Encode, Decode)]
pub struct Coin {
/// Whether the coin is from a coinbase transaction.
pub is_coinbase: bool,
/// Transfer value in satoshis.
pub amount: u64,
/// Spending condition of the output.
pub script_pubkey: Vec<u8>,
}

impl MaxEncodedLen for Coin {
fn max_encoded_len() -> usize {
bool::max_encoded_len() + u64::max_encoded_len() + MAX_SCRIPT_SIZE
}
}

#[derive(Debug, TypeInfo, Encode, Decode, MaxEncodedLen)]
struct OutPointInner {
txid: Txid,
Expand Down
3 changes: 1 addition & 2 deletions crates/sc-consensus-nakamoto/src/block_executor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::verification::Coin;
use async_trait::async_trait;
use bitcoin::OutPoint;
use sc_client_api::{AuxStore, Backend, BlockBackend, HeaderBackend, StorageProvider};
Expand All @@ -8,7 +7,7 @@ use sp_runtime::traits::{Block as BlockT, HashingFor, Header as HeaderT};
use sp_state_machine::{StorageKey, StorageValue};
use std::marker::PhantomData;
use std::sync::Arc;
use subcoin_primitives::runtime::Subcoin;
use subcoin_primitives::runtime::{Coin, Subcoin};
use subcoin_primitives::{BitcoinTransactionAdapter, CoinStorageKey};

/// A simply way to track the overall execution info for optimization purpose.
Expand Down
Loading