Skip to content

Commit

Permalink
consensus: Rename SiafundPool -> SiafundTaxRevenue
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Nov 20, 2024
1 parent a6327d7 commit 4ee4b65
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
35 changes: 15 additions & 20 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ func (n *Network) GenesisState() State {
return State{
Network: n,

Index: types.ChainIndex{Height: ^uint64(0)},
PrevTimestamps: [11]time.Time{},
Depth: intToTarget(maxTarget),
ChildTarget: n.InitialTarget,
SiafundPool: types.ZeroCurrency,
Index: types.ChainIndex{Height: ^uint64(0)},
PrevTimestamps: [11]time.Time{},
Depth: intToTarget(maxTarget),
ChildTarget: n.InitialTarget,
SiafundTaxRevenue: types.ZeroCurrency,

OakTime: 0,
OakTarget: intToTarget(maxTarget),
Expand All @@ -111,11 +111,11 @@ func (n *Network) GenesisState() State {
type State struct {
Network *Network `json:"-"` // network parameters are not encoded

Index types.ChainIndex `json:"index"`
PrevTimestamps [11]time.Time `json:"prevTimestamps"` // newest -> oldest
Depth types.BlockID `json:"depth"`
ChildTarget types.BlockID `json:"childTarget"`
SiafundPool types.Currency `json:"siafundPool"`
Index types.ChainIndex `json:"index"`
PrevTimestamps [11]time.Time `json:"prevTimestamps"` // newest -> oldest
Depth types.BlockID `json:"depth"`
ChildTarget types.BlockID `json:"childTarget"`
SiafundTaxRevenue types.Currency `json:"siafundTaxRevenue"`

// Oak hardfork state
OakTime time.Duration `json:"oakTime"`
Expand All @@ -139,7 +139,7 @@ func (s State) EncodeTo(e *types.Encoder) {
}
s.Depth.EncodeTo(e)
s.ChildTarget.EncodeTo(e)
types.V2Currency(s.SiafundPool).EncodeTo(e)
types.V2Currency(s.SiafundTaxRevenue).EncodeTo(e)

e.WriteUint64(uint64(s.OakTime))
s.OakTarget.EncodeTo(e)
Expand All @@ -160,7 +160,7 @@ func (s *State) DecodeFrom(d *types.Decoder) {
}
s.Depth.DecodeFrom(d)
s.ChildTarget.DecodeFrom(d)
(*types.V2Currency)(&s.SiafundPool).DecodeFrom(d)
(*types.V2Currency)(&s.SiafundTaxRevenue).DecodeFrom(d)

s.OakTime = time.Duration(d.ReadUint64())
s.OakTarget.DecodeFrom(d)
Expand Down Expand Up @@ -370,12 +370,7 @@ func (s State) FileContractTax(fc types.FileContract) types.Currency {

// V2FileContractTax computes the tax levied on a given v2 contract.
func (s State) V2FileContractTax(fc types.V2FileContract) types.Currency {
sum := fc.RenterOutput.Value.Add(fc.HostOutput.Value)
tax := sum.Div64(25) // 4%
// round down to nearest multiple of SiafundCount
_, r := bits.Div64(0, tax.Hi, s.SiafundCount())
_, r = bits.Div64(r, tax.Lo, s.SiafundCount())
return tax.Sub(types.NewCurrency64(r))
return fc.RenterOutput.Value.Add(fc.HostOutput.Value).Div64(25) // 4%
}

// StorageProofLeafIndex returns the leaf index used when computing or
Expand Down Expand Up @@ -595,7 +590,7 @@ type MidState struct {
res map[types.FileContractID]bool
v2revs map[types.FileContractID]*types.V2FileContractElement
v2res map[types.FileContractID]types.V2FileContractResolutionType
siafundPool types.Currency
siafundTaxRevenue types.Currency
foundationPrimary types.Address
foundationFailsafe types.Address

Expand Down Expand Up @@ -657,7 +652,7 @@ func NewMidState(s State) *MidState {
res: make(map[types.FileContractID]bool),
v2revs: make(map[types.FileContractID]*types.V2FileContractElement),
v2res: make(map[types.FileContractID]types.V2FileContractResolutionType),
siafundPool: s.SiafundPool,
siafundTaxRevenue: s.SiafundTaxRevenue,
foundationPrimary: s.FoundationPrimaryAddress,
foundationFailsafe: s.FoundationFailsafeAddress,
}
Expand Down
12 changes: 6 additions & 6 deletions consensus/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (ms *MidState) addSiafundElement(id types.SiafundOutputID, sfo types.Siafun
StateElement: types.StateElement{LeafIndex: types.UnassignedLeafIndex},
ID: id,
SiafundOutput: sfo,
ClaimStart: ms.siafundPool,
ClaimStart: ms.siafundTaxRevenue,
}
ms.sfes = append(ms.sfes, sfe)
ms.created[ms.sfes[len(ms.sfes)-1].ID] = len(ms.sfes) - 1
Expand All @@ -389,7 +389,7 @@ func (ms *MidState) addFileContractElement(id types.FileContractID, fc types.Fil
}
ms.fces = append(ms.fces, fce)
ms.created[ms.fces[len(ms.fces)-1].ID] = len(ms.fces) - 1
ms.siafundPool = ms.siafundPool.Add(ms.base.FileContractTax(fce.FileContract))
ms.siafundTaxRevenue = ms.siafundTaxRevenue.Add(ms.base.FileContractTax(fce.FileContract))
}

func (ms *MidState) reviseFileContractElement(fce types.FileContractElement, rev types.FileContract) {
Expand Down Expand Up @@ -426,7 +426,7 @@ func (ms *MidState) addV2FileContractElement(id types.FileContractID, fc types.V
}
ms.v2fces = append(ms.v2fces, fce)
ms.created[ms.v2fces[len(ms.v2fces)-1].ID] = len(ms.v2fces) - 1
ms.siafundPool = ms.siafundPool.Add(ms.base.V2FileContractTax(fce.V2FileContract))
ms.siafundTaxRevenue = ms.siafundTaxRevenue.Add(ms.base.V2FileContractTax(fce.V2FileContract))
}

func (ms *MidState) reviseV2FileContractElement(fce types.V2FileContractElement, rev types.V2FileContract) {
Expand Down Expand Up @@ -477,7 +477,7 @@ func (ms *MidState) ApplyTransaction(txn types.Transaction, ts V1TransactionSupp
if !ok {
panic("missing SiafundElement")
}
claimPortion := ms.siafundPool.Sub(sfe.ClaimStart).Div64(ms.base.SiafundCount()).Mul64(sfe.SiafundOutput.Value)
claimPortion := ms.siafundTaxRevenue.Sub(sfe.ClaimStart).Div64(ms.base.SiafundCount()).Mul64(sfe.SiafundOutput.Value)
ms.spendSiafundElement(sfe, txid)
ms.addImmatureSiacoinElement(sfi.ParentID.ClaimOutputID(), types.SiacoinOutput{Value: claimPortion, Address: sfi.ClaimAddress})
}
Expand Down Expand Up @@ -528,7 +528,7 @@ func (ms *MidState) ApplyV2Transaction(txn types.V2Transaction) {
}
for _, sfi := range txn.SiafundInputs {
ms.spendSiafundElement(sfi.Parent, txid)
claimPortion := ms.siafundPool.Sub(sfi.Parent.ClaimStart).Div64(ms.base.SiafundCount()).Mul64(sfi.Parent.SiafundOutput.Value)
claimPortion := ms.siafundTaxRevenue.Sub(sfi.Parent.ClaimStart).Mul64(sfi.Parent.SiafundOutput.Value).Div64(ms.base.SiafundCount())
ms.addImmatureSiacoinElement(sfi.Parent.ID.V2ClaimOutputID(), types.SiacoinOutput{Value: claimPortion, Address: sfi.ClaimAddress})
}
for i, sfo := range txn.SiafundOutputs {
Expand Down Expand Up @@ -736,7 +736,7 @@ func ApplyBlock(s State, b types.Block, bs V1BlockSupplement, targetTimestamp ti

ms := NewMidState(s)
ms.ApplyBlock(b, bs)
s.SiafundPool = ms.siafundPool
s.SiafundTaxRevenue = ms.siafundTaxRevenue
s.Attestations += uint64(len(ms.aes))
s.FoundationPrimaryAddress = ms.foundationPrimary
s.FoundationFailsafeAddress = ms.foundationFailsafe
Expand Down
2 changes: 1 addition & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ type SiafundElement struct {
ID SiafundOutputID `json:"id"`
StateElement StateElement `json:"stateElement"`
SiafundOutput SiafundOutput `json:"siafundOutput"`
ClaimStart Currency `json:"claimStart"` // value of SiafundPool when element was created
ClaimStart Currency `json:"claimStart"` // value of SiafundTaxRevenue when element was created
}

// A FileContractElement is a record of a FileContract within the state
Expand Down

0 comments on commit 4ee4b65

Please sign in to comment.