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
2 changes: 2 additions & 0 deletions boot.tests/NodeSetupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public void SetupModeAllowsOnlySetupAndHealthPaths()
{
Assert.IsTrue(NodeSetupPolicy.IsAllowedSetupPath("/setup"));
Assert.IsTrue(NodeSetupPolicy.IsAllowedSetupPath("/setup.css"));
Assert.IsTrue(NodeSetupPolicy.IsAllowedSetupPath("/setup.js"));
Assert.IsTrue(NodeSetupPolicy.IsAllowedSetupPath("/health/live"));
Assert.IsTrue(NodeSetupPolicy.IsAllowedSetupPath("/health/ready"));
Assert.IsFalse(NodeSetupPolicy.IsAllowedSetupPath("/api/mining/share"));
Assert.IsFalse(NodeSetupPolicy.IsAllowedSetupPath("/api/peer/session"));
Assert.IsFalse(NodeSetupPolicy.IsAllowedSetupPath("/dashboardHub"));
Expand Down
14 changes: 14 additions & 0 deletions boot.tests/ShareAttributionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,20 @@ public async Task V22SiblingBoundaryRaceConvergesWithoutBranchVotingAndV21DoesNo
Assert.AreNotEqual(v21Alice.StateService.GetNetworkStatus().ActiveSnapshotId, v21Bob.StateService.GetNetworkStatus().ActiveSnapshotId);
}

[TestMethod]
public void FullReserveImportAllowsOneSnapshotContextPerBoundedProof()
{
var config = new PoolConfig
{
WinnersListSize = 299,
WorkSetReserveMultiplier = 3,
MaxStateBundleHistory = 8
};

Assert.AreEqual(1198, BootProtocolStateService.GetMaxImportedSnapshotContextCount(config));
Assert.IsTrue(BootProtocolStateService.GetMaxImportedSnapshotContextCount(config) >= 396);
}

[TestMethod]
public async Task RegtestSiblingImportAcceptsProofRecordedAgainstExplicitEmptyBootstrapSnapshotAsync()
{
Expand Down
3 changes: 3 additions & 0 deletions boot_portal/Models/PoolConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class PoolConfig
[JsonPropertyName("pool_payout_script")]
public string PoolPayoutScript { get; set; } = string.Empty;

[JsonPropertyName("restart_after_setup")]
public bool RestartAfterSetup { get; set; } = false;

[JsonPropertyName("winners_list_size")]
public int WinnersListSize { get; set; } = 299;

Expand Down
22 changes: 20 additions & 2 deletions boot_portal/Pages/Setup.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,26 @@

@if (Model.RestartRequired)
{
<p class="lede">The payout address is stored. Restart the GridPool app to start networking and mining services with this configuration.</p>
@if (Model.AutomaticRestart)
{
<p class="lede">The payout address is stored. GridPool is restarting with mining and peer services enabled.</p>
}
else
{
<p class="lede">The payout address is stored. Restart the GridPool app to start networking and mining services with this configuration.</p>
}
<div class="address-summary">
<span>Locked payout address</span>
<code>@Model.SavedAddress</code>
</div>
<p class="safety-note">GridPool will remain in setup-only mode until it restarts. No mining work or peer relay is active yet.</p>
@if (Model.AutomaticRestart)
{
<p class="safety-note" id="restart-status">Waiting for the node to become ready. This page will open the dashboard automatically.</p>
}
else
{
<p class="safety-note">GridPool will remain in setup-only mode until it restarts. No mining work or peer relay is active yet.</p>
}
}
else
{
Expand All @@ -49,5 +63,9 @@
}
</section>
</main>
@if (Model.AutomaticRestart)
{
<script src="/setup.js" defer></script>
}
</body>
</html>
13 changes: 13 additions & 0 deletions boot_portal/Pages/Setup.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
using boot_portal.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Hosting;

namespace boot_portal.Pages;

public sealed class SetupModel(
PoolConfig poolConfig,
NodeSetupState setupState,
IHostApplicationLifetime applicationLifetime,
ILogger<SetupModel> logger) : PageModel
{
private readonly PoolConfig _poolConfig = poolConfig;
private readonly NodeSetupState _setupState = setupState;
private readonly IHostApplicationLifetime _applicationLifetime = applicationLifetime;
private readonly ILogger<SetupModel> _logger = logger;

[BindProperty]
Expand All @@ -24,6 +27,8 @@ public sealed class SetupModel(

public bool RestartRequired => _setupState.RestartRequired;

public bool AutomaticRestart => RestartRequired && _poolConfig.RestartAfterSetup;

public string BitcoinNetwork => BitcoinScript.NormalizeNetwork(_poolConfig.BitcoinNetwork);

public IActionResult OnGet()
Expand Down Expand Up @@ -73,6 +78,14 @@ public IActionResult OnPost()
_poolConfig.PoolPayoutScript = payoutAddress;
_setupState.MarkSaved(payoutAddress);
SavedAddress = payoutAddress;
if (_poolConfig.RestartAfterSetup)
{
HttpContext.Response.OnCompleted(() =>
{
_applicationLifetime.StopApplication();
return Task.CompletedTask;
});
}
}
catch (Exception ex)
{
Expand Down
37 changes: 29 additions & 8 deletions boot_portal/Services/BootProtocolStateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4463,10 +4463,7 @@ public async Task<bool> TryImportCandidateStateAsync(BootStateBundle bundle, str
return false;
}

foreach (BootPayoutSnapshotContext context in bundle.SnapshotContexts)
{
UpsertSnapshotContextNoLock(context);
}
UpsertSnapshotContextsNoLock(bundle.SnapshotContexts);
_state.OnDeckProofs = mergedCanonicalProofs;
RebuildOnDeckListNoLock();
SetAcceptedParentBlockHashesNoLock(GetCanonicalParentBlockHashesForReserveNoLock(), _state.CurrentTipBlockHash);
Expand Down Expand Up @@ -4524,7 +4521,7 @@ public async Task<bool> TryAdoptCurrentStateAsync(BootStateBundle bundle, string
if (bundle.WinnersList.Count > _poolConfig.WinnersListSize ||
bundle.ShareProofs.Count > _poolConfig.SnapshotProofSlotCount ||
bundle.WorkSetProofs.Count > _poolConfig.WorkSetReserveLimit ||
bundle.SnapshotContexts.Count > GetMaxSnapshotContextCountNoLock() ||
bundle.SnapshotContexts.Count > GetMaxImportedSnapshotContextCount(_poolConfig) ||
(bundle.SnapshotFamilyMember?.BoundaryReserveProofs.Count ?? 0) > _poolConfig.WorkSetReserveLimit)
{
return false;
Expand Down Expand Up @@ -4758,13 +4755,13 @@ public async Task<bool> TryAdoptCurrentStateAsync(BootStateBundle bundle, string
{
_state.ActiveSnapshotProofIds = validatedProofs.Select(proof => proof.ShareId).ToList();
}
_state.OnDeckProofs = SortAndTrimProofs(
validatedWorkSetProofs.Count > 0 ? validatedWorkSetProofs : _state.OnDeckProofs,
_poolConfig.WorkSetReserveLimit);
foreach (BootPayoutSnapshotContext context in bundle.SnapshotContexts)
{
UpsertSnapshotContextNoLock(context);
}
_state.OnDeckProofs = SortAndTrimProofs(
validatedWorkSetProofs.Count > 0 ? validatedWorkSetProofs : _state.OnDeckProofs,
_poolConfig.WorkSetReserveLimit);
RebuildOnDeckListNoLock();
foreach (var proof in validatedProofs)
{
Expand Down Expand Up @@ -6295,6 +6292,23 @@ private void UpsertSnapshotContextNoLock(BootPayoutSnapshotContext context)
PruneSnapshotContextsNoLock();
}

private void UpsertSnapshotContextsNoLock(IEnumerable<BootPayoutSnapshotContext> contexts)
{
foreach (BootPayoutSnapshotContext context in contexts)
{
if (string.IsNullOrWhiteSpace(context.SnapshotId))
{
continue;
}

_state.SnapshotContexts.RemoveAll(existing =>
string.Equals(existing.SnapshotId, context.SnapshotId, StringComparison.OrdinalIgnoreCase));
_state.SnapshotContexts.Insert(0, CloneSnapshotContext(context));
}

PruneSnapshotContextsNoLock();
}

private void PruneSnapshotContextsNoLock()
{
HashSet<string> protectedIds = new(StringComparer.OrdinalIgnoreCase);
Expand Down Expand Up @@ -6348,6 +6362,13 @@ private int GetMaxSnapshotContextCountNoLock()
return Math.Max(_poolConfig.MaxStateBundleHistory, _poolConfig.WorkSetReserveMultiplier * 16);
}

internal static int GetMaxImportedSnapshotContextCount(PoolConfig config)
{
// A full reserve can legitimately contain proofs created against many payout snapshots.
// Bound imports by the proof capacity, not by the much smaller local history-retention cap.
return config.SnapshotProofSlotCount + config.WorkSetReserveLimit + 2;
}

private int RepairMissingWorkSetSnapshotContextsNoLock(DateTime nowUtc)
{
HashSet<string> existingContextIds = _state.SnapshotContexts
Expand Down
1 change: 1 addition & 0 deletions boot_portal/Utils/NodeSetupPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public static bool IsAllowedSetupPath(PathString path)
{
return path.StartsWithSegments("/setup", StringComparison.OrdinalIgnoreCase) ||
path.Equals("/setup.css", StringComparison.OrdinalIgnoreCase) ||
path.Equals("/setup.js", StringComparison.OrdinalIgnoreCase) ||
path.Equals("/health/live", StringComparison.OrdinalIgnoreCase) ||
path.Equals("/health/ready", StringComparison.OrdinalIgnoreCase);
}
Expand Down
27 changes: 27 additions & 0 deletions boot_portal/wwwroot/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(() => {
const status = document.getElementById("restart-status");
if (!status) return;

const startedAt = Date.now();

async function waitForReady() {
try {
const response = await fetch("/health/ready", { cache: "no-store" });
const payload = await response.json();
if (response.ok && payload.status === "ready") {
window.location.replace("/");
return;
}
} catch {
// The expected connection drop confirms that the container is restarting.
}

if (Date.now() - startedAt > 120000) {
status.textContent = "GridPool is taking longer than expected to restart. Restart the app from Umbrel, then reopen it.";
return;
}
window.setTimeout(waitForReady, 1000);
}

window.setTimeout(waitForReady, 1000);
})();
Loading