Skip to content
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
4 changes: 4 additions & 0 deletions node-lib/src/regtest_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub struct RegtestOptions {

#[derive(Args, Clone, Debug)]
pub struct ChainConfigOptions {
/// Magic bytes.
#[clap(long)]
pub chain_magic_bytes: Option<String>,

/// The maximum future block offset in seconds.
#[clap(long)]
pub chain_max_future_block_time_offset: Option<u64>,
Expand Down
12 changes: 11 additions & 1 deletion node-lib/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::{
time::Duration,
};

use anyhow::{anyhow, Context, Result};
use anyhow::{anyhow, ensure, Context, Result};
use blockprod::rpc::BlockProductionRpcServer;
use chainstate_launcher::StorageBackendConfig;
use paste::paste;
Expand Down Expand Up @@ -331,6 +331,7 @@ fn regtest_chain_config(command: &Command, options: &ChainConfigOptions) -> Resu
};

let ChainConfigOptions {
chain_magic_bytes,
chain_max_future_block_time_offset,
chain_version,
chain_target_block_spacing,
Expand Down Expand Up @@ -365,6 +366,15 @@ fn regtest_chain_config(command: &Command, options: &ChainConfigOptions) -> Resu
};
}

let magic_bytes_from_string = |magic_string: String| -> Result<[u8; 4]> {
ensure!(magic_string.len() == 4, "Invalid size of magic_bytes");
let mut result: [u8; 4] = [0; 4];
for (i, byte) in magic_string.bytes().enumerate() {
result[i] = byte;
}
Ok(result)
};
update_builder!(magic_bytes, magic_bytes_from_string, map_err);
update_builder!(max_future_block_time_offset, Duration::from_secs);
update_builder!(version, SemVer::try_from, map_err);
update_builder!(target_block_spacing, Duration::from_secs);
Expand Down
57 changes: 57 additions & 0 deletions test/functional/feature_db_reinit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
# Copyright (c) 2023 RBB S.r.l
# [email protected]
# SPDX-License-Identifier: MIT
# Licensed under the MIT License;
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from scalecodec.base import RuntimeConfiguration
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
)

block_input_data_obj = RuntimeConfiguration().create_scale_object('GenerateBlockInputData')


class RestartWithDifferentMagicBytes(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
self.extra_args = [[
"--blockprod-min-peers-to-produce-blocks=0"
]]

def run_test(self):
# generate and process block to update chainstate db
block_input_data = block_input_data_obj.encode({"PoW": {"reward_destination": "AnyoneCanSpend"}}
).to_hex()[2:]

block = self.nodes[0].blockprod_generate_block(block_input_data, [])
self.nodes[0].chainstate_submit_block(block)

tip_height = self.nodes[0].chainstate_best_block_height()
assert_equal(1, tip_height)

# restart the node and check that the db hasn't changed
self.restart_node(0)
tip_height = self.nodes[0].chainstate_best_block_height()
assert_equal(1, tip_height)

# restart the node with different magic bytes and check that db was cleaned up
self.restart_node(0, extra_args=["--chain-magic-bytes=ffff"])
tip_height = self.nodes[0].chainstate_best_block_height()
assert_equal(0, tip_height)


if __name__ == '__main__':
RestartWithDifferentMagicBytes().main()
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class UnicodeOnWindowsError(ValueError):
'p2p_submit_orphan.py',
'p2p_syncing_test.py',
'p2p_relay_transactions.py',
'feature_db_reinit.py',
'feature_lmdb_backend_test.py',
'mempool_basic_reorg.py',
'mempool_eviction.py',
Expand Down