Skip to content

Commit

Permalink
Merge pull request #127 from SiaFoundation/nate/always-resolve-contract
Browse files Browse the repository at this point in the history
Increase log level for contract state changes
  • Loading branch information
n8maninger authored Jul 31, 2023
2 parents 1d46394 + 0bc226c commit 0fa355f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
6 changes: 3 additions & 3 deletions host/contracts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (cm *ContractManager) ProcessConsensusChange(cc modules.ConsensusChange) {
return fmt.Errorf("failed to apply formation: %w", err)
}

log.Debug("contract formation confirmed", zap.Stringer("contractID", applied.id), zap.Stringer("block", applied.index))
log.Info("contract formation confirmed", zap.Stringer("contractID", applied.id), zap.Stringer("block", applied.index))
cm.alerts.Dismiss(types.Hash256(applied.id)) // dismiss any lifecycle alerts for this contract
}

Expand All @@ -365,7 +365,7 @@ func (cm *ContractManager) ProcessConsensusChange(cc modules.ConsensusChange) {
return fmt.Errorf("failed to apply revision: %w", err)
}

log.Debug("contract revision confirmed", zap.Stringer("contractID", applied.ParentID), zap.Uint64("revisionNumber", applied.RevisionNumber))
log.Info("contract revision confirmed", zap.Stringer("contractID", applied.ParentID), zap.Uint64("revisionNumber", applied.RevisionNumber))
cm.alerts.Dismiss(types.Hash256(applied.ParentID)) // dismiss any lifecycle alerts for this contract
}

Expand All @@ -378,7 +378,7 @@ func (cm *ContractManager) ProcessConsensusChange(cc modules.ConsensusChange) {
return fmt.Errorf("failed to apply proof: %w", err)
}

log.Debug("contract resolution confirmed", zap.Stringer("contractID", applied.id), zap.Stringer("block", applied.index))
log.Info("contract resolution confirmed", zap.Stringer("contractID", applied.id), zap.Stringer("block", applied.index))
cm.alerts.Dismiss(types.Hash256(applied.id)) // dismiss any lifecycle alerts for this contract
}
return nil
Expand Down
10 changes: 5 additions & 5 deletions persist/sqlite/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func (u *updateContractsTxn) ConfirmFormation(id types.FileContractID) error {
}
}

// set the contract status to active only if the contract is pending or rejected
// if the contract is successful or failed, leave it as is.
if contract.Status == contracts.ContractStatusPending || contract.Status == contracts.ContractStatusRejected {
// skip updating the status for contracts that are already marked as
// successful or failed
if contract.Status != contracts.ContractStatusSuccessful && contract.Status != contracts.ContractStatusFailed {
if err := setContractStatus(u.tx, id, contracts.ContractStatusActive); err != nil {
return fmt.Errorf("failed to set contract status to active: %w", err)
}
Expand Down Expand Up @@ -778,8 +778,8 @@ func revisionContractActions(tx txn, height uint64) (actions []contractAction, _

func resolveContractActions(tx txn, height uint64) (actions []contractAction, _ error) {
// formation confirmed, resolution not confirmed, status active, in proof window
const query = `SELECT contract_id FROM contracts WHERE formation_confirmed=true AND resolution_height IS NULL AND window_start <= $1 AND window_end > $1 AND contract_status=$2`
rows, err := tx.Query(query, height, contracts.ContractStatusActive)
const query = `SELECT contract_id FROM contracts WHERE formation_confirmed=true AND resolution_height IS NULL AND window_start <= $1 AND window_end > $1`
rows, err := tx.Query(query, height)
if err != nil {
return nil, fmt.Errorf("failed to query contracts: %w", err)
}
Expand Down
8 changes: 2 additions & 6 deletions persist/sqlite/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ func (s *Store) transaction(ctx context.Context, fn func(txn) error) error {
if err != nil {
return fmt.Errorf("failed to begin transaction: %w", err)
}
defer func() {
if err != nil {
tx.Rollback()
}
}()
defer tx.Rollback()
ltx := &loggedTxn{
Tx: tx,
log: s.log.Named("transaction"),
Expand Down Expand Up @@ -144,7 +140,7 @@ func (s *Store) Close() error {

func sqliteFilepath(fp string) string {
params := []string{
"_busy_timeout=5000", // 5s
"_busy_timeout=30000", // 30s
"_foreign_keys=true",
"_journal_mode=WAL",
"_secure_delete=false",
Expand Down
4 changes: 2 additions & 2 deletions persist/sqlite/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ func TestTransactionRetry(t *testing.T) {

ch := make(chan struct{}, 1) // channel to synchronize the transaction goroutine

// start a transaction in a goroutine and hold it open for 8 seconds
// start a transaction in a goroutine and hold it open for 10 seconds
// this should allow for the next transaction to be retried once
go func() {
err := db.transaction(context.Background(), func(tx txn) error {
ch <- struct{}{}
time.Sleep(8 * time.Millisecond)
time.Sleep(10 * time.Second)
return nil
})
if err != nil {
Expand Down

0 comments on commit 0fa355f

Please sign in to comment.