Skip to content

Commit

Permalink
Fix README.md and disallow mining on mainnet (#171)
Browse files Browse the repository at this point in the history
* Fix README.md and disallow mining on mainnet

* minor edits

---------

Co-authored-by: Michael Sutton <[email protected]>
  • Loading branch information
someone235 and michaelsutton authored Apr 16, 2023
1 parent 412f921 commit f9878d7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kaspa on Rust

Work in progress to implement the Kaspa full-node and related libraries in the Rust programming language.
This repository contains the implementation of the Kaspa full-node and related libraries in the Rust programming language. This is an Alpha version at the initial testing phase, however the node is expected to be fully functional and capable as a drop-in replacement for the Kaspa golang node.

## Getting started

Expand All @@ -23,24 +23,35 @@ $ git clone https://github.com/kaspanet/rusty-kaspa
$ cd rusty-kaspa
```

## Experimenting with the node
## Running the node

The `kaspad` rust executable is currently at the initial stage where a devnet consensus instance can be built and mined locally through the RPC interface. The P2P network is not supported yet. To see it in action, perform the following:
Run the node through the following command:

```bash
$ cargo run --bin kaspad --release -- --devnet
$ (cargo run --release --bin kaspad) 2>&1 | tee ~/rusty-kaspa.log
```

And if you want to setup a test node, run the following command instead:

```bash
$ (cargo run --release --bin kaspad -- --testnet) 2>&1 | tee ~/rusty-kaspa-testnet.log
```

## Mining
Mining is currently supported only on testnet, so once you've setup a test node, follow these instructions:

- Download and unzip the latest binaries bundle of [kaspanet/kaspad](https://github.com/kaspanet/kaspad/releases).

- In a separate terminal run the kaspanet/kaspad miner:

```bash
$ kaspaminer --rpcserver 127.0.0.1:16610 --devnet --miningaddr kaspadev:qrcqat6l9zcjsu7swnaztqzrv0s7hu04skpaezxk43y4etj8ncwfkuhy0zmax
$ kaspaminer --testnet --miningaddr kaspatest:qrcqat6l9zcjsu7swnaztqzrv0s7hu04skpaezxk43y4etj8ncwfk308jlcew
```

- This will create and feed a DAG with the miner getting block templates from the node and submitting them back when mined. The node processes and stores the blocks while applying all currently implemented logic. Execution can be stopped and resumed, the data is persisted in a database.

- You can replace the above mining address with your own address by creating one as described [here](https://github.com/kaspanet/docs/blob/main/Getting%20Started/Full%20Node%20Installation.md#creating-a-wallet-optional).

## Simulation framework (Simpa)

Additionally, the current codebase supports a full in-process network simulation, building an actual DAG over virtual time with virtual delay and benchmarking validation time (following the simulation generation). Execute
Expand All @@ -58,7 +69,7 @@ $ cargo run --release --bin simpa -- -t=200 -d=2 -b=8 -n=1000
Logging in `kaspad` and `simpa` can be [filtered](https://docs.rs/env_logger/0.10.0/env_logger/#filtering-results) either by defining the environment variable `RUST_LOG` and/or by adding a `--loglevel` argument to the command, ie.:

```bash
$ cargo run --bin kaspad -- --loglevel info,kaspa_rpc_core=trace,kaspa_grpc_core=trace,consensus=trace,kaspa_core=trace
$ (cargo run --bin kaspad -- --loglevel info,kaspa_rpc_core=trace,kaspa_grpc_core=trace,consensus=trace,kaspa_core=trace) 2>&1 | tee ~/rusty-kaspa.log
```


Expand Down
2 changes: 1 addition & 1 deletion consensus/core/src/networktype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub enum NetworkTypeError {
InvalidNetworkType(String),
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum NetworkType {
Mainnet,
Expand Down
5 changes: 5 additions & 0 deletions rpc/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use kaspa_consensus_core::{
coinbase::MinerData,
config::Config,
constants::MAX_SOMPI,
networktype::NetworkType,
tx::{Transaction, COINBASE_TRANSACTION_INDEX},
};
use kaspa_consensus_notify::{
Expand Down Expand Up @@ -190,6 +191,10 @@ impl RpcApi<ChannelConnection> for RpcCoreService {
async fn get_block_template_call(&self, request: GetBlockTemplateRequest) -> RpcResult<GetBlockTemplateResponse> {
trace!("incoming GetBlockTemplate request");

if self.config.net == NetworkType::Mainnet {
return Err(RpcError::General("Mining on mainnet is not supported for the Rust Alpha version".to_owned()));
}

// Make sure the pay address prefix matches the config network type
if request.pay_address.prefix != self.config.prefix() {
return Err(kaspa_addresses::AddressError::InvalidPrefix(request.pay_address.prefix.to_string()))?;
Expand Down

0 comments on commit f9878d7

Please sign in to comment.