Skip to content

Commit

Permalink
Merge pull request #272 from SiaFoundation/siafund-claim-fix
Browse files Browse the repository at this point in the history
consensus: Fix Siafund ClaimStart not being recorded
  • Loading branch information
n8maninger authored Feb 10, 2025
2 parents 3c6ca85 + 289fa55 commit bfa61b4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fix_siafund_claimstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

# Fix Siafund ClaimStart not being recorded
1 change: 1 addition & 0 deletions consensus/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ func (ms *MidState) createSiafundElement(id types.SiafundOutputID, sfo types.Sia
StateElement: types.StateElement{LeafIndex: types.UnassignedLeafIndex},
ID: id,
SiafundOutput: sfo,
ClaimStart: ms.siafundTaxRevenue,
}
sfed.Created = true
return sfed
Expand Down
31 changes: 29 additions & 2 deletions consensus/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,15 @@ func TestSiafunds(t *testing.T) {
},
}
genesisBlock.Transactions = []types.Transaction{giftTxn}
genesisBlock.V2 = &types.V2BlockData{
Transactions: []types.V2Transaction{{
FileContracts: []types.V2FileContract{{
RenterOutput: types.SiacoinOutput{
Value: types.Siacoins(1000), // ensure initial SiafundTaxRevenue is not 0
},
}},
}},
}
db, cs := newConsensusDB(n, genesisBlock)

signTxn := func(cs State, txn *types.V2Transaction) {
Expand Down Expand Up @@ -1196,6 +1205,24 @@ func TestSiafunds(t *testing.T) {
return
}

// roundtrip SF output, to reset its ClaimStart
sfe := db.sfes[giftTxn.SiafundOutputID(0)]
txn := types.V2Transaction{
SiafundInputs: []types.V2SiafundInput{{
Parent: sfe,
ClaimAddress: giftAddress,
}},
SiafundOutputs: []types.SiafundOutput{{
Address: giftAddress,
Value: giftAmountSF,
}},
}
signTxn(cs, &txn)
if _, err := mineTxns(nil, []types.V2Transaction{txn}); err != nil {
t.Fatal(err)
}
sfe = db.sfes[txn.SiafundOutputID(txn.ID(), 0)]

fc := types.V2FileContract{
ProofHeight: 20,
ExpirationHeight: 30,
Expand All @@ -1206,7 +1233,7 @@ func TestSiafunds(t *testing.T) {
}
fcValue := fc.RenterOutput.Value.Add(fc.HostOutput.Value).Add(cs.V2FileContractTax(fc))

txn := types.V2Transaction{
txn = types.V2Transaction{
SiacoinInputs: []types.V2SiacoinInput{{
Parent: db.sces[giftTxn.SiacoinOutputID(0)],
}},
Expand All @@ -1229,7 +1256,7 @@ func TestSiafunds(t *testing.T) {
// make a siafund claim
txn = types.V2Transaction{
SiafundInputs: []types.V2SiafundInput{{
Parent: db.sfes[giftTxn.SiafundOutputID(0)],
Parent: sfe,
ClaimAddress: giftAddress,
}},
SiafundOutputs: []types.SiafundOutput{{
Expand Down

0 comments on commit bfa61b4

Please sign in to comment.