Skip to content

Commit

Permalink
revert contract formation in the test as well
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Jun 13, 2024
1 parent c813828 commit f03fa84
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
3 changes: 0 additions & 3 deletions persist/sqlite/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log"

"go.sia.tech/core/consensus"
"go.sia.tech/core/types"
Expand Down Expand Up @@ -790,7 +789,6 @@ func addFileContractElements(tx *txn, revert bool, b types.Block, fces []explore
if err != nil {
return fmt.Errorf("failed to execute file_contract_elements statement: %w", err)
}
log.Printf("(%v) %v: (valid: %v, resolved: %v, rev: %d, lastRevision: %v)", b.ID(), fcID, valid, resolved, fc.RevisionNumber, lastRevision)

// only update if it's the most recent revision which will come from
// running ForEachFileContractElement on the update
Expand Down Expand Up @@ -1011,7 +1009,6 @@ func (ut *updateTx) ApplyIndex(state explorer.UpdateState) error {
}

func (ut *updateTx) RevertIndex(state explorer.UpdateState) error {
log.Println("Revert:", state.Index)
if err := updateMaturedBalances(ut.tx, true, state.Index.Height); err != nil {
return fmt.Errorf("RevertIndex: failed to update matured balances: %w", err)
} else if _, err := addSiacoinElements(
Expand Down
29 changes: 29 additions & 0 deletions persist/sqlite/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2578,4 +2578,33 @@ func TestMultipleReorgFileContract(t *testing.T) {
checkFC(false, false, revFC, dbFCs[0])
}
}

extra = cm.Tip().Height - genesisState.Index.Height + 1
for reorg := uint64(0); reorg < 2; reorg++ {
{
var blocks []types.Block
state := genesisState
for i := uint64(0); i < reorg+extra; i++ {
pk := types.GeneratePrivateKey()
addr := types.StandardUnlockHash(pk.PublicKey())

blocks = append(blocks, mineBlock(state, nil, addr))
state.Index.ID = blocks[len(blocks)-1].ID()
state.Index.Height++
}
if err := cm.AddBlocks(blocks); err != nil {
t.Fatal(err)
}
syncDB(t, db, cm)
}

// contract should no longer exist
{
dbFCs, err := db.Contracts([]types.FileContractID{fcID})
if err != nil {
t.Fatal(err)
}
check(t, "fcs", 0, len(dbFCs))
}
}
}

0 comments on commit f03fa84

Please sign in to comment.