forked from kaspanet/rusty-kaspa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kaspad with mining support (kaspanet#86)
* Make addresses::Address serializable * Remove unneeded second protobuf file in build * Impl from &Address for String and impl Error for AddressError * Extend RpcApi with SubmitBlock & GetBlockTemplate * Add ConsensusApi * Change GetBlockTemplateRequest extra_data type to Vec<u8> * Implement a rpc-core get_block_template handler * Add todos for RpcBlockHeader * Turn gRPC server into a kaspa_core service * Add AsyncRuntime that runs the grpc server * Limit the AsyncRuntime to 2 worker threads * Clean the protowire builder * Update Extending RpcApi instructions * Some minor adjustments in GrpcServer * Add consensus-core <-> rpc-core tx converters, make verbose data optional, add hash to RpcBlockHeader * Make addresses::Address serializable * Remove unneeded second protobuf file in build * Impl from &Address for String and impl Error for AddressError * Extend RpcApi with SubmitBlock & GetBlockTemplate * Add ConsensusApi * Change GetBlockTemplateRequest extra_data type to Vec<u8> * Implement a rpc-core get_block_template handler * Add todos for RpcBlockHeader * Turn gRPC server into a kaspa_core service * Add AsyncRuntime that runs the grpc server * Limit the AsyncRuntime to 2 worker threads * Clean the protowire builder * Update Extending RpcApi instructions * Some minor adjustments in GrpcServer * Add consensus-core <-> rpc-core tx converters, make verbose data optional, add hash to RpcBlockHeader * Implement ConsensusApi for Consensus and TestConsensus & remove stubs * cargo update * Add a consensus and a gRPC server to kaspad, remove the block emitter * Fix reopening an existing DB * Add NewBlockTemplate notification * Refactor AsyncRuntime & add RpcCoreServer * Rely on AsyncRuntime to spawn tokio tasks * Add validate_and_insert_block to ConsensusApi * Implement a rpc-core submit_block handler * Raise a NewBlockTemplateNotification when validate_and_insert_block has been processed * Apply Michael's patch * Add transactions to RpcBlock to Block converter * Temporarily disable NewBlockTemplate notifications * Disable monitoring and change default port to reflect devnet defaults * Convert tx inputs and outputs from rpc-core to consensus-core * Some tracing commands * Change devnet genesis bits,, lower tracing verbosity, re-enable NewBlockTemplate notification * Apply real genesis bits observed on testnet to devnet params * Adapting some more traces * Move BlockStatus to consensus-core and use it in ConsensusApi validate_and_insert_block * Rename rpc-core RpcBlockHeader to RpcHeader and make it binary closer to consensus Header * Add a basic logger * Fix ConsensusMonitor and its usage in Consensus * Fix typo * Cleaning some minor details * Change monitor log interval to 10 seconds + fix typos * Fix spelling errors * Apply review requests * Update readme (for kaspad) * Update readme (adding simpa plus some edits) * Restructure readme sectoins and add a warning to simpa * Correct typo Co-authored-by: msutton <mikisiton2@gmail.com>
- Loading branch information
1 parent
34cadf6
commit d43974f
Showing
76 changed files
with
1,670 additions
and
586 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use futures_util::future::BoxFuture; | ||
use std::sync::Arc; | ||
|
||
use crate::{ | ||
block::{Block, BlockTemplate}, | ||
blockstatus::BlockStatus, | ||
coinbase::MinerData, | ||
tx::Transaction, | ||
}; | ||
|
||
/// Abstracts the consensus external API | ||
pub trait ConsensusApi: Send + Sync { | ||
fn build_block_template(self: Arc<Self>, miner_data: MinerData, txs: Vec<Transaction>) -> BlockTemplate; | ||
|
||
fn validate_and_insert_block( | ||
self: Arc<Self>, | ||
block: Block, | ||
update_virtual: bool, | ||
) -> BoxFuture<'static, Result<BlockStatus, String>>; | ||
} | ||
|
||
pub type DynConsensus = Arc<dyn ConsensusApi>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Debug)] | ||
pub enum BlockStatus { | ||
/// StatusInvalid indicates that the block is invalid. | ||
StatusInvalid, | ||
|
||
/// StatusUTXOValid indicates the block is valid from any UTXO related aspects and has passed all the other validations as well. | ||
StatusUTXOValid, | ||
|
||
/// StatusUTXOPendingVerification indicates that the block is pending verification against its past UTXO-Set, either | ||
/// because it was not yet verified since the block was never in the selected parent chain, or if the | ||
/// block violates finality. | ||
StatusUTXOPendingVerification, | ||
|
||
/// StatusDisqualifiedFromChain indicates that the block is not eligible to be a selected parent. | ||
StatusDisqualifiedFromChain, | ||
|
||
/// StatusHeaderOnly indicates that the block transactions are not held (pruned or wasn't added yet) | ||
StatusHeaderOnly, | ||
} | ||
|
||
impl BlockStatus { | ||
pub fn has_block_body(self) -> bool { | ||
matches!(self, Self::StatusUTXOValid | Self::StatusUTXOPendingVerification | Self::StatusDisqualifiedFromChain) | ||
} | ||
|
||
pub fn is_utxo_valid_or_pending(self) -> bool { | ||
matches!(self, Self::StatusUTXOValid | Self::StatusUTXOPendingVerification) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.