Locate when it’s protected to ‘forestall’ the Bitcoin Core Daemon, bitcoind

on

|

views

and

comments


Up to now, I saved the Bitcoin Core daemon operating 24×7, alternatively not too long ago I have turn into much less focused on conserving it operating at all times, and would really like as a substitute to run it for as a lot time because it takes to make sure the blockchain is not any quite a lot of hours in the back of.

I am the usage of a Powershell script to hook up with the Bitcoin Core daemon operating on Home windows. The script gathers the output from bitcoin-cli.exe getblockchaininfo right into a json object to test blockchain verification development.

I have scheduled a role to start out the bitcoind procedure, and my Powershell script assessments the output from bitcoin-cli each 30 seconds, ready till verificationprogress is no less than 0.999999 sooner than shutting down the daemon.

As soon as verificationprogress is at 0.999999 or upper, the script shuts down the daemon, till the following time it runs about 4 hours later. I have spotted that the following time bitcoind begins, it’s re-downloading blocks it downloaded the ultimate time it ran.

Is there one thing else I will have to take a look at rather then the verificationprogress output from bitcoin-cli.exe getblockchaininfo ?

That is the Powershell script, in case any individual is :

Param
(
    [System.Boolean]$debug_mode = $false,
    [System.Boolean]$display_blockchain_info = $false
);
Set-Location "E:BitcoinCoreBin";
### if Bitcoin Daemon is not operating, get started it.
$Processes = (Get-Procedure -Title bitcoind -ErrorAction SilentlyContinue);
If ($Processes.Duration -eq 0) 
{
    $ServiceState = (Get-Provider -Title BitcoinCoreDaemon -ErrorAction SilentlyContinue).Standing;
    If ($ServiceState -ne "Operating")
    {
        Write-Output "$((Get-Date).ToString('s')) - Beginning the Bitcoin Core Daemon Provider.";
        Get started-Provider -Title BitcoinCoreDaemon -ErrorAction SilentlyContinue;
    }
    Else
    {
        ### the provider standing is operating, however one thing has killed the bitcoin daemon procedure, so we will restart it.
        Write-Output "$((Get-Date).ToString('s')) - Beginning the Bitcoin Core Daemon Procedure.";
        (Get started-Procedure -FilePath ".bitcoind.exe" -ArgumentList "--conf=E:BitcoinCorebitcoin.conf" -ErrorAction SilentlyContinue);
    };
}
Else
{
    If ($debug_mode -eq $true)
    {
        $Processes;
    };
    Get started-Sleep -Seconds 3;
};
[System.Boolean]$is_complete = $false;
[System.Double]$development = 0;
[System.Int32]$blocks_downloaded_at_start = 0;
[System.Int32]$blocks_downloaded = 0;
[System.Int32]$blocks_available = 0;
[System.DateTime]$start_time = (Get-Date);
Whilst ($is_complete -eq $false)
{
    If ($Processes.Duration -eq 0)
    {
        Write-Output "$((Get-Date).ToString('s')) - Slumbering for 30 seconds.";
        Get started-Sleep -Seconds 30;
    }
    Else
    {
        $Processes = @();
    };
    [System.String]$block_chain_info = (.bitcoin-cli.exe --datadir=E:BitcoinCoreData getblockchaininfo)
    If ($block_chain_info -ne $null)
    {
        $bci = (ConvertFrom-Json $block_chain_info -ErrorAction SilentlyContinue);
        If ($display_blockchain_info -eq $true)
        {
            Write-Output "$($block_chain_info)";
        };
        $is_complete = -No longer ($bci.initialblockdownload -eq $true);
        $blocks_available = $bci.headers;
        $blocks_downloaded = $bci.blocks;
        If ($debug_mode -eq $true)
        {
            Write-Output "$($blocks_downloaded) of $($blocks_available) blocks downloaded.";
        };
        IF ($blocks_downloaded_at_start -eq 0)
        {
            $blocks_downloaded_at_start = $blocks_downloaded;
        };
        $development = $bci.verificationprogress;
        If (($blocks_downloaded -lt $blocks_available) -or ($development -lt 0.999999))
        {
            If ($debug_mode -eq $true)
            {
                Write-Output "Surroundings `$is_complete to `$false.  `$development is $($development).  `$start_time + 180 seconds is $(($start_time.AddSeconds(180)).ToString('s')).  `$development is $($development).";
            };
            $is_complete = $false;
        };
        If ($start_time.AddSeconds(180) -gt (Get-Date))
        {
            Write-Output "Ready till no less than $($start_time.AddSeconds(180).ToString('s')) sooner than exiting.";
            $is_complete = $false;
        };
        If ($is_complete -eq $false)
        {
            Write-Output "Sync is $($development) whole.  $($blocks_downloaded - $blocks_downloaded_at_start) blocks downloaded...";
        }
        Else
        {
            Write-Output "Sync whole (progess is $($development)).  $($blocks_downloaded - $blocks_downloaded_at_start) blocks downloaded.";
        };
    };
};
### forestall Bitcoin Core Daemon after which the Provider
(.bitcoin-cli.exe --datadir=E:BitcoinCoreData forestall);
[System.DateTime]$start_of_shutdown = (Get-Date);
Whilst (((Get-Procedure -Title bitcoind -ErrorAction SilentlyContinue).Duration -gt 0) -and ($start_of_shutdown.AddSeconds(30) -lt (Get-Date)))
{
    Get started-Sleep -Seconds 1;
};
Forestall-Provider -Title "BitcoinCoreDaemon" -ErrorAction SilentlyContinue;
Write-Output "$((Get-Date).ToString('s')) - Bitcoin Core Daemon and Provider had been stopped.";

Share this
Tags

Must-read

Tesla Govt Says Repair For Vampire Drain In Sentry Mode Coming In Q2: ‘Energy Intake Wishes Development’ – Tesla (NASDAQ:TSLA)

Tesla Inc TSLA govt, Drew Baglino, on Thursday printed that the corporate is operating on liberating a device replace for decreasing energy intake...

Dividend Kings In Focal point: Phone & Information Techniques

Printed on February twenty second, 2024 through Bob Ciura The Dividend Kings consist of businesses that experience raised their dividends for a minimum of...

Tyler Perry Calls On Leisure Trade, Executive To Corral AI Prior to Everybody Is Out Of Trade

Tyler Perry has observed demonstrations of what AI can do. Whilst he's astonished, he’s additionally sounding an alarm. Perry is already balloting together...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here