Skip to content

Commit

Permalink
Enable signet chain configs
Browse files Browse the repository at this point in the history
This enables adding of signet chain configs in bitcoin.conf.
This enables running of multiple signets with diffrent configurations

i.e
chain=signet_xxxx

[signet_xxxx]
seednodes=x.x.x.x
signetchallenge=xxxxxxxxx
  • Loading branch information
BrandonOdiwuor committed Jun 7, 2024
1 parent 8d8a728 commit 2f762ba
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/common/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,33 @@ std::vector<common::SettingsValue> ArgsManager::GetSectionArg(const std::string&
return result;
}

template <typename Key, typename Value, typename SectionKey>
void ArgsManager::AddConfigArg(const Key& key, const Value& value, SectionKey sectionKey)
{
auto& section = m_settings.ro_config[sectionKey];
section[key].push_back(value);
}

void ArgsManager::UpdateConfigFromSection(const std::string& section, const std::string& strArg)
{
auto arg = GetSectionArg(section, strArg);
for(auto& sv : arg) {
LOCK(cs_args);
AddConfigArg(strArg, sv, m_network);
}
}

void ArgsManager::ReadSignetChainConfigs()
{
const std::string SIGNET_CHAIN_PREFIX = "signet_";

const std::string chain = GetArg("-chain", "");
if (chain.starts_with(SIGNET_CHAIN_PREFIX)){
UpdateConfigFromSection(chain, "signetchallenge");
UpdateConfigFromSection(chain, "seednode");
}
}

std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
{
std::vector<std::string> result;
Expand Down
23 changes: 23 additions & 0 deletions src/common/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,29 @@ class ArgsManager
*/
std::vector<common::SettingsValue> GetSectionArg(const std::string& section, const std::string& strArg) const;

/**
* Adds a configuration argument to a specified section in the configuration settings.
*
* @param key The key to be added to the configuration section.
* @param value The value to be associated with the specified key.
* @param sectionKey The section key identifying the section where the key-value pair will be added.
*/
template <typename Key, typename Value, typename SectionKey>
void AddConfigArg(const Key& key, const Value& value, SectionKey sectionKey);

/**
* Updates the configuration settings by adding arguments from a specified section.
*
* @param section The name of the section from which to retrieve arguments.
* @param strArg The key whose associated arguments are to be retrieved and added to the configuration settings.
*/
void UpdateConfigFromSection(const std::string& section, const std::string& strArg);

/**
* Read singnet chain args if signet chain arg is provided
*/
void ReadSignetChainConfigs();

/**
* Return a vector of strings of the given argument
*
Expand Down
3 changes: 3 additions & 0 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
for (const std::string& conf_file_name : conf_file_names) {
tfm::format(std::cerr, "warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", conf_file_name);
}

// Read signet args of the provided chain and update the signet config
ReadSignetChainConfigs();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/chaintype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::optional<ChainType> ChainTypeFromString(std::string_view chain)
return ChainType::MAIN;
} else if (chain == "test") {
return ChainType::TESTNET;
} else if (chain == "signet") {
} else if (chain == "signet" || chain.starts_with("signet_") ) {
return ChainType::SIGNET;
} else if (chain == "regtest") {
return ChainType::REGTEST;
Expand Down

0 comments on commit 2f762ba

Please sign in to comment.