diff --git a/consensus/state.go b/consensus/state.go index 85757d8..c252983 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -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), @@ -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"` @@ -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) @@ -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) @@ -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 @@ -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 @@ -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, } diff --git a/consensus/update.go b/consensus/update.go index a383a81..a658bc8 100644 --- a/consensus/update.go +++ b/consensus/update.go @@ -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 @@ -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) { @@ -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) { @@ -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}) } @@ -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 { @@ -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 diff --git a/types/types.go b/types/types.go index 981721f..cf72fd7 100644 --- a/types/types.go +++ b/types/types.go @@ -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