Skip to content

Commit a1ac83e

Browse files
committed
set successful v2 contracts to active status when reverted
1 parent 2f4c91d commit a1ac83e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: patch
3+
---
4+
5+
# Fixed an issue reverting renewed v2 contracts.

persist/sqlite/consensus.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,13 @@ func revertV2ContractFormation(tx *txn, reverted []types.V2FileContractElement)
14831483
return fmt.Errorf("failed to delete contract state element %q: %w", fce.ID, err)
14841484
}
14851485

1486-
if state.Status != contracts.V2ContractStatusActive {
1486+
if state.Status == contracts.V2ContractStatusRenewed || state.Status == contracts.V2ContractStatusSuccessful {
1487+
// note: special case due to a bug in revert handling. This should not happen, but we need to account for it
1488+
// in the revert logic.
1489+
if err := updateV2EarnedRevenueMetrics(state.Usage, true, incrementCurrencyStat); err != nil {
1490+
return fmt.Errorf("failed to update earned revenue metrics: %w", err)
1491+
}
1492+
} else if state.Status != contracts.V2ContractStatusActive {
14871493
// if the contract is not active, panic. Applies should have ensured
14881494
// that this never happens.
14891495
panic(fmt.Errorf("unexpected contract state transition %q -> %q", state.Status, contracts.ContractStatusPending))
@@ -1715,7 +1721,7 @@ func revertSuccessfulV2Contracts(tx *txn, status contracts.V2ContractStatus, suc
17151721
}
17161722

17171723
// update the contract's resolution index and status
1718-
if res, err := updateStmt.Exec(status, state.ID); err != nil {
1724+
if res, err := updateStmt.Exec(contracts.V2ContractStatusActive, state.ID); err != nil {
17191725
return fmt.Errorf("failed to update contract %q: %w", contractID, err)
17201726
} else if n, err := res.RowsAffected(); err != nil {
17211727
return fmt.Errorf("failed to get rows affected: %w", err)

0 commit comments

Comments
 (0)