Skip to content

Commit

Permalink
stores: add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Nov 9, 2023
1 parent 6af9206 commit 0160711
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions stores/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2366,20 +2366,29 @@ func (ss *SQLStore) processConsensusChangeContracts(cc modules.ConsensusChange)
fcid := txn.FileContractID(i)
if ss.isKnownContract(fcid) {
ss.unappliedContractState[fcid] = contractStatePending // revert from 'active' to 'pending'
ss.logger.Infow("contract state changed: active -> pending",
"fcid", fcid,
"reason", "contract reverted")
}
}
// handle contract revision
for _, rev := range txn.FileContractRevisions {
if ss.isKnownContract(rev.ParentID) {
if rev.RevisionNumber == math.MaxUint64 {
if rev.RevisionNumber == math.MaxUint64 && rev.Filesize == 0 {
ss.unappliedContractState[rev.ParentID] = contractStateActive // revert from 'complete' to 'active'
ss.logger.Infow("contract state changed: complete -> active",
"fcid", rev.ParentID,
"reason", "final revision reverted")
}
}
}
// handle storage proof
for _, sp := range txn.StorageProofs {
if ss.isKnownContract(sp.ParentID) {
ss.unappliedContractState[sp.ParentID] = contractStateActive // revert from 'complete' to 'active'
ss.logger.Infow("contract state changed: complete -> active",
"fcid", sp.ParentID,
"reason", "storage proof reverted")
}
}
}
Expand All @@ -2397,6 +2406,9 @@ func (ss *SQLStore) processConsensusChangeContracts(cc modules.ConsensusChange)
fcid := txn.FileContractID(i)
if ss.isKnownContract(fcid) {
ss.unappliedContractState[fcid] = contractStateActive // 'pending' -> 'active'
ss.logger.Infow("contract state changed: pending -> active",
"fcid", fcid,
"reason", "contract confirmed")
}
}
// handle contract revision
Expand All @@ -2407,8 +2419,11 @@ func (ss *SQLStore) processConsensusChangeContracts(cc modules.ConsensusChange)
number: rev.RevisionNumber,
size: rev.Filesize,
}
if rev.RevisionNumber == math.MaxUint64 {
if rev.RevisionNumber == math.MaxUint64 && rev.Filesize == 0 {
ss.unappliedContractState[rev.ParentID] = contractStateComplete // renewed: 'active' -> 'complete'
ss.logger.Infow("contract state changed: active -> complete",
"fcid", rev.ParentID,
"reason", "final revision confirmed")
}
}
}
Expand All @@ -2417,6 +2432,9 @@ func (ss *SQLStore) processConsensusChangeContracts(cc modules.ConsensusChange)
if ss.isKnownContract(sp.ParentID) {
ss.unappliedProofs[sp.ParentID] = height
ss.unappliedContractState[sp.ParentID] = contractStateComplete // storage proof: 'active' -> 'complete'
ss.logger.Infow("contract state changed: active -> complete",
"fcid", sp.ParentID,
"reason", "storage proof confirmed")
}
}
}
Expand Down

0 comments on commit 0160711

Please sign in to comment.