Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alerts for failed contract resolutions #313

Merged
merged 2 commits into from Feb 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 36 additions & 3 deletions host/contracts/actions.go
Expand Up @@ -10,7 +10,6 @@ import (
"go.sia.tech/core/types"
"go.sia.tech/hostd/alerts"
"go.uber.org/zap"
"lukechampine.com/frand"
)

// An action determines what lifecycle event should be performed on a contract.
Expand Down Expand Up @@ -178,6 +177,17 @@ func (cm *ContractManager) handleContractAction(id types.FileContractID, height
sp, err := cm.buildStorageProof(contract.Revision.ParentID, contract.Revision.Filesize, leafIndex, log.Named("buildStorageProof"))
if err != nil {
log.Error("failed to build storage proof", zap.Error(err))
cm.alerts.Register(alerts.Alert{
n8maninger marked this conversation as resolved.
Show resolved Hide resolved
ID: types.Hash256(id),
Severity: alerts.SeverityError,
Message: "Failed to build storage proof",
Data: map[string]any{
"contractID": id,
"blockHeight": height,
"error": err.Error(),
},
Timestamp: time.Now(),
})
return
}

Expand All @@ -199,6 +209,17 @@ func (cm *ContractManager) handleContractAction(id types.FileContractID, height
intermediateToSign, discard, err := cm.wallet.FundTransaction(&resolutionTxnSet[0], fee)
if err != nil {
log.Error("failed to fund resolution transaction", zap.Error(err))
cm.alerts.Register(alerts.Alert{
ID: types.Hash256(id),
Severity: alerts.SeverityError,
Message: "Failed to fund resolution transaction",
Data: map[string]any{
"contractID": id,
"blockHeight": height,
"error": err.Error(),
},
Timestamp: time.Now(),
})
return
}
defer discard()
Expand All @@ -219,8 +240,20 @@ func (cm *ContractManager) handleContractAction(id types.FileContractID, height
} else if err := cm.tpool.AcceptTransactionSet(resolutionTxnSet); err != nil { // broadcast the transaction set
buf, _ := json.Marshal(resolutionTxnSet)
log.Error("failed to broadcast resolution transaction set", zap.Error(err), zap.ByteString("transactionSet", buf))
cm.alerts.Register(alerts.Alert{
ID: types.Hash256(id),
Severity: alerts.SeverityError,
Message: "Failed to broadcast resolution transaction",
Data: map[string]any{
"contractID": id,
"blockHeight": height,
"error": err.Error(),
},
Timestamp: time.Now(),
})
return
}
cm.alerts.Dismiss(types.Hash256(id)) // dismiss any previous failure alerts
log.Info("broadcast storage proof", zap.String("transactionID", resolutionTxnSet[1].ID().String()), zap.Duration("elapsed", time.Since(start)))
case ActionReject:
if err := cm.store.ExpireContract(id, ContractStatusRejected); err != nil {
Expand Down Expand Up @@ -255,8 +288,8 @@ func (cm *ContractManager) handleContractAction(id types.FileContractID, height
log.Error("failed to set contract status", zap.Error(err))
}
cm.alerts.Register(alerts.Alert{
ID: frand.Entropy256(),
Severity: alerts.SeverityWarning,
ID: types.Hash256(id),
Severity: alerts.SeverityError,
Message: "Contract failed without storage proof",
Data: map[string]any{
"contractID": id,
Expand Down