Skip to content

Commit

Permalink
add "Allow submit block when not synced" as "enable_unsynced_mining" …
Browse files Browse the repository at this point in the history
…command (kaspanet#187)

* allow_submit_block_when_not_synced

* fmt / lint fixes

* update comment, make less verbose.

* update command as well

* Update mod.rs

de -> un

* Update args.rs

unsynced mining

* Update service.rs

unsynced

* push renaming and things

---------

Co-authored-by: D-stacks <johndoe@example.com>
  • Loading branch information
D-Stacks and D-stacks authored May 29, 2023
1 parent 3834e53 commit 9411709
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 3 additions & 4 deletions consensus/core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ pub struct Config {
pub unsafe_rpc: bool,

/// Allow the node to accept blocks from RPC while not synced
/// (this flag is mainly used for testing)
// TODO: add and handle a matching kaspad command argument
pub allow_submit_block_when_not_synced: bool,
/// (required when initiating a new network from genesis)
pub enable_unsynced_mining: bool,

pub user_agent_comments: Vec<String>,
}
Expand All @@ -51,7 +50,7 @@ impl Config {
process_genesis: true,
utxoindex: false,
unsafe_rpc: false,
allow_submit_block_when_not_synced: false,
enable_unsynced_mining: false,
user_agent_comments: Default::default(),
}
}
Expand Down
8 changes: 8 additions & 0 deletions kaspad/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Defaults {
pub reset_db: bool,
pub outbound_target: usize,
pub inbound_limit: usize,
pub enable_unsynced_mining: bool,
pub testnet: bool,
pub devnet: bool,
pub simnet: bool,
Expand All @@ -34,6 +35,7 @@ impl Default for Defaults {
reset_db: false,
outbound_target: 8,
inbound_limit: 128,
enable_unsynced_mining: false,
testnet: false,
devnet: false,
simnet: false,
Expand Down Expand Up @@ -62,6 +64,7 @@ pub struct Args {
pub reset_db: bool,
pub outbound_target: usize,
pub inbound_limit: usize,
pub enable_unsynced_mining: bool,
pub testnet: bool,
pub devnet: bool,
pub simnet: bool,
Expand Down Expand Up @@ -165,6 +168,7 @@ pub fn cli(defaults: &Defaults) -> Command {
.help("Max number of inbound peers (default: 128)."),
)
.arg(arg!(--"reset-db" "Reset database before starting node. It's needed when switching between subnetworks."))
.arg(arg!(--"enable_unsynced_mining" "Allow the node to accept blocks from RPC while not synced (this flag is mainly used for testing)"))
.arg(arg!(--utxoindex "Enable the UTXO index"))
.arg(arg!(--testnet "Use the test network"))
.arg(arg!(--devnet "Use the development test network"))
Expand Down Expand Up @@ -198,6 +202,7 @@ impl Args {
outbound_target: m.get_one::<usize>("outpeers").cloned().unwrap_or(defaults.outbound_target),
inbound_limit: m.get_one::<usize>("maxinpeers").cloned().unwrap_or(defaults.inbound_limit),
reset_db: m.get_one::<bool>("reset-db").cloned().unwrap_or(defaults.reset_db),
enable_unsynced_mining: m.get_one::<bool>("enable_unsynced_mining").cloned().unwrap_or(defaults.enable_unsynced_mining),
utxoindex: m.get_one::<bool>("utxoindex").cloned().unwrap_or(defaults.utxoindex),
testnet: m.get_one::<bool>("testnet").cloned().unwrap_or(defaults.testnet),
devnet: m.get_one::<bool>("devnet").cloned().unwrap_or(defaults.devnet),
Expand All @@ -209,6 +214,7 @@ impl Args {
pub fn apply_to_config(&self, config: &mut Config) {
config.utxoindex = self.utxoindex;
config.unsafe_rpc = self.unsafe_rpc;
config.enable_unsynced_mining = self.enable_unsynced_mining;
config.user_agent_comments = self.user_agent_comments.clone();
}
}
Expand Down Expand Up @@ -287,6 +293,8 @@ impl Args {
--archival Run as an archival node: don't delete old block data when moving the
pruning point (Warning: heavy disk usage)'
--protocol-version= Use non default p2p protocol version (default: 5)
--enable_unsynced_mining Allow the node to accept blocks from RPC while not synced
(required when initiating a new network from genesis)
--testnet Use the test network
--simnet Use the simulation test network
--devnet Use the development test network
Expand Down
2 changes: 1 addition & 1 deletion rpc/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl RpcApi for RpcCoreService {
// TODO: consider adding an error field to SubmitBlockReport to document both the report and error fields
let is_synced: bool = self.flow_context.hub().has_peers() && session.is_nearly_synced();

if !self.config.allow_submit_block_when_not_synced && !is_synced {
if !self.config.enable_unsynced_mining && !is_synced {
// error = "Block not submitted - node is not synced"
return Ok(SubmitBlockResponse { report: SubmitBlockReport::Reject(SubmitBlockRejectReason::IsInIBD) });
}
Expand Down

0 comments on commit 9411709

Please sign in to comment.