2022-07-20 18:16:30 +02:00
// Copyright (c) 2022 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
# include <node/chainstatemanager_args.h>
2022-07-21 11:13:13 +02:00
# include <arith_uint256.h>
2023-03-23 12:23:29 +01:00
# include <common/args.h>
2023-07-07 10:33:11 +01:00
# include <common/system.h>
# include <logging.h>
2022-08-16 23:32:55 -04:00
# include <node/coins_view_args.h>
# include <node/database_args.h>
2022-07-21 11:13:13 +02:00
# include <tinyformat.h>
# include <uint256.h>
2022-09-01 15:35:23 -04:00
# include <util/result.h>
2022-07-21 11:13:13 +02:00
# include <util/strencodings.h>
# include <util/translation.h>
# include <validation.h>
2022-07-20 18:16:30 +02:00
2023-07-07 10:33:11 +01:00
# include <algorithm>
2022-07-20 18:16:30 +02:00
# include <chrono>
2022-07-21 11:13:13 +02:00
# include <string>
2022-07-20 18:16:30 +02:00
namespace node {
2022-09-01 15:35:23 -04:00
util : : Result < void > ApplyArgsManOptions ( const ArgsManager & args , ChainstateManager : : Options & opts )
2022-07-20 18:16:30 +02:00
{
2023-12-21 17:24:07 -05:00
if ( auto value { args . GetIntArg ( " -checkblockindex " ) } ) {
// Interpret bare -checkblockindex argument as 1 instead of 0.
opts . check_block_index = args . GetArg ( " -checkblockindex " ) - > empty ( ) ? 1 : * value ;
}
2022-07-26 12:59:48 +02:00
2022-07-26 13:52:48 +02:00
if ( auto value { args . GetBoolArg ( " -checkpoints " ) } ) opts . checkpoints_enabled = * value ;
2022-07-21 11:13:13 +02:00
if ( auto value { args . GetArg ( " -minimumchainwork " ) } ) {
2024-07-26 15:01:48 +01:00
if ( auto min_work { uint256 : : FromUserHex ( * value ) } ) {
opts . minimum_chain_work = UintToArith256 ( * min_work ) ;
} else {
return util : : Error { strprintf ( Untranslated ( " Invalid minimum work specified (%s), must be up to %d hex digits " ) , * value , uint256 : : size ( ) * 2 ) } ;
2022-07-21 11:13:13 +02:00
}
}
2024-07-26 15:10:25 +01:00
if ( auto value { args . GetArg ( " -assumevalid " ) } ) {
if ( auto block_hash { uint256 : : FromUserHex ( * value ) } ) {
opts . assumed_valid_block = * block_hash ;
} else {
return util : : Error { strprintf ( Untranslated ( " Invalid assumevalid block hash specified (%s), must be up to %d hex digits (or 0 to disable) " ) , * value , uint256 : : size ( ) * 2 ) } ;
}
}
2022-07-20 22:00:11 +02:00
2022-07-20 18:16:30 +02:00
if ( auto value { args . GetIntArg ( " -maxtipage " ) } ) opts . max_tip_age = std : : chrono : : seconds { * value } ;
2022-07-21 11:13:13 +02:00
2022-08-16 23:32:55 -04:00
ReadDatabaseArgs ( args , opts . block_tree_db ) ;
ReadDatabaseArgs ( args , opts . coins_db ) ;
ReadCoinsViewArgs ( args , opts . coins_view ) ;
2023-07-07 10:33:11 +01:00
int script_threads = args . GetIntArg ( " -par " , DEFAULT_SCRIPTCHECK_THREADS ) ;
if ( script_threads < = 0 ) {
// -par=0 means autodetect (number of cores - 1 script threads)
// -par=-n means "leave n cores free" (number of cores - n - 1 script threads)
script_threads + = GetNumCores ( ) ;
}
// Subtract 1 because the main thread counts towards the par threads.
opts . worker_threads_num = std : : clamp ( script_threads - 1 , 0 , MAX_SCRIPTCHECK_THREADS ) ;
LogPrintf ( " Script verification uses %d additional threads \n " , opts . worker_threads_num ) ;
2024-05-17 23:33:25 +02:00
if ( auto max_size = args . GetIntArg ( " -maxsigcachesize " ) ) {
// 1. When supplied with a max_size of 0, both the signature cache and
// script execution cache create the minimum possible cache (2
// elements). Therefore, we can use 0 as a floor here.
// 2. Multiply first, divide after to avoid integer truncation.
size_t clamped_size_each = std : : max < int64_t > ( * max_size , 0 ) * ( 1 < < 20 ) / 2 ;
opts . script_execution_cache_bytes = clamped_size_each ;
2024-05-18 11:18:44 +02:00
opts . signature_cache_bytes = clamped_size_each ;
2024-05-17 23:33:25 +02:00
}
2022-09-01 15:35:23 -04:00
return { } ;
2022-07-20 18:16:30 +02:00
}
} // namespace node