Skip to content

Commit 662a3aa

Browse files
committed
Make it so that validate-failed blocks are forgotten (test)
1 parent a47210d commit 662a3aa

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

lib/blockchain_forget_validate_failed_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ func TestForgetValidateFailedBlocksAcrossRestart(t *testing.T) {
183183
require.True(t, before.IsValidateFailed(), "marker must be persisted before the restart")
184184
require.True(t, before.IsStored())
185185

186+
// A hypothetical child of the failed block, used to probe what the retry machinery would do
187+
// with it. Before the restart the failed ancestor poisons the lineage outright.
188+
childHeader := &MsgDeSoHeader{
189+
Version: HeaderVersion1,
190+
PrevBlockHash: failedNode.Hash,
191+
Height: uint64(failedNode.Height) + 1,
192+
}
193+
_, _, lineageErr := bc.getStoredLineageFromCommittedTip(childHeader)
194+
require.Equal(t, RuleErrorAncestorBlockValidationFailed, lineageErr,
195+
"before the restart, a descendant of the failed block must be rejected outright")
196+
186197
// Restart: a fresh Blockchain over the same DB, exactly as NewTestBlockchain builds one.
187198
restarted, err := NewBlockchain([]string{blockSignerPk}, 0, 0, params,
188199
chainlib.NewMedianTime(), db, nil, nil, nil, false, nil, MinBlockIndexSize)
@@ -199,4 +210,15 @@ func TestForgetValidateFailedBlocksAcrossRestart(t *testing.T) {
199210
failedNode.Hash, uint64(failedNode.Height))
200211
require.True(t, indexExists)
201212
require.False(t, fromIndex.IsValidateFailed())
213+
214+
// The behavioral payoff: the same descendant probe now reports the forgotten block as a
215+
// missing ancestor to be fetched, rather than a failed one. This is the state transition the
216+
// whole change exists to produce — it is what makes the node re-request and re-validate the
217+
// block instead of staying wedged.
218+
_, missingHashes, lineageErr := restarted.getStoredLineageFromCommittedTip(childHeader)
219+
require.Equal(t, RuleErrorMissingAncestorBlock, lineageErr,
220+
"after the restart, the forgotten block must read as missing, not failed")
221+
require.Len(t, missingHashes, 1)
222+
require.True(t, missingHashes[0].IsEqual(failedNode.Hash),
223+
"the forgotten block itself must be what gets re-requested")
202224
}

0 commit comments

Comments
 (0)