Skip to content

Commit 8653d04

Browse files
committed
cmd/network: Consider max checkpoint creation time for trust
Prevents a problem where the most recent checkpoint target height is still being created on the remote nodes, but second oldest target height would be already older than the suggested trust. This is only relevant when configuring runtime where state is much bigger. In such case if you are connected to remote nodes that preserve many runtime state versions, checkpoint creation time is significant.
1 parent 78f432b commit 8653d04

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cmd/network/trust.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const (
2020
// be able to fetch and verify light headers and finally detect and penalize a possible
2121
// byzantine behavior. This value intentionally overestimates the actual time required.
2222
maxVerificationTime = 24 * time.Hour
23+
24+
// maxCpCreationTime defines the upper bound within which remote node must produce
25+
// checkpoint. This value intentionally overestimates the actual time required,
26+
// assuming nodes with very bulky NodeDB, where checkpoint creation is slow.
27+
maxCpCreationTime = 36 * time.Hour
2328
)
2429

2530
var trustCmd = &cobra.Command{
@@ -94,9 +99,9 @@ func calcTrust(ctx context.Context, conn connection.Connection) (config.TrustCon
9499
}
95100
trustPeriod := calcTrustPeriod(debondingPeriod)
96101

97-
// Going back the whole checkpoint interval guarantees there should be at least
98-
// one target checkpoint height inside this interval.
99-
candidate, err := conn.Consensus().Core().GetBlock(ctx, latest.Height-cpInterval)
102+
// Going back the whole checkpoint interval plus max checkpoint creation time guarantees there wil be at least
103+
// one target checkpoint height from the trust height onwards, for which remote nodes already created a checkpoint.
104+
candidate, err := conn.Consensus().Core().GetBlock(ctx, latest.Height-cpInterval-int64(maxCpCreationTime/blkTime))
100105
if err != nil {
101106
return config.TrustConfig{}, fmt.Errorf("failed to get candidate trust (height: %d): %w", candidate.Height, err)
102107
}

0 commit comments

Comments
 (0)