Skip to content

Conversation

@n8mgr
Copy link
Member

@n8mgr n8mgr commented Dec 23, 2025

Currently if a host with existing contracts instant syncs, it can leave their contracts in a bad state if the checkpoint is before their first v2 contract. This adjusts the checkpoint based on the negotiation height of the first active or pending contract.

Copilot AI review requested due to automatic review settings December 23, 2025 14:54
@github-project-automation github-project-automation bot moved this to In Progress in Sia Dec 23, 2025
@n8mgr n8mgr requested review from ChrisSchinnerl, chris124567 and peterjan and removed request for Copilot December 23, 2025 14:54
@n8mgr n8mgr requested a review from Copilot December 23, 2025 15:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes an issue where hosts with existing contracts performing instant sync could leave their contracts in a bad state if the checkpoint is before their first v2 contract. The solution adjusts the checkpoint based on the negotiation height of the first active or pending contract.

Key Changes:

  • Added FirstContractHeight() database method to retrieve the earliest negotiation height of active or pending v2 contracts
  • Modified instant sync logic to consider contract heights when determining the sync checkpoint
  • Added new explorer API method TipHeight() to retrieve chain index at a specific height

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
persist/sqlite/contracts.go Implements FirstContractHeight() to query the minimum negotiation height of active/pending contracts
persist/sqlite/contracts_test.go Adds test coverage for the new FirstContractHeight() method with various contract statuses
explorer/explorer.go Adds TipHeight() method to retrieve chain index at a given height from the explorer API
cmd/hostd/run.go Updates instant sync logic to adjust checkpoint based on contract heights, falling back one day of blocks before the first contract

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@n8mgr n8mgr force-pushed the nate/consider-contracts-for-checkpoint branch from 8a0553e to d3fbd2f Compare January 2, 2026 16:25
@n8mgr n8mgr requested review from Copilot and peterjan January 2, 2026 16:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

log.Debug("using earlier checkpoint height from contracts", zap.Uint64("height", checkpointHeight))
}

blocksPerDay := uint64(24 * time.Hour / network.BlockInterval)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just a leeway?

Copy link
Member

@peterjan peterjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a changelog entry but otherwise LGTM 👍

@n8mgr n8mgr force-pushed the nate/consider-contracts-for-checkpoint branch from d3fbd2f to c1c0323 Compare January 5, 2026 14:17
@n8mgr n8mgr merged commit be7c222 into master Jan 5, 2026
10 of 11 checks passed
@n8mgr n8mgr deleted the nate/consider-contracts-for-checkpoint branch January 5, 2026 14:17
@github-project-automation github-project-automation bot moved this from In Progress to Done in Sia Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants