Skip to content

Commit

Permalink
Merge tag 'v0.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alrighttt committed Jan 20, 2025
2 parents fbeb493 + d2eb5df commit 7169ebf
Show file tree
Hide file tree
Showing 25 changed files with 1,756 additions and 754 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Prepare Release
on:
push:
branches: [master]

permissions:
contents: write
pull-requests: write

jobs:
prepare-release:
if: "!contains(github.event.head_commit.message, 'chore: prepare release')" # Skip merges from releases
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Configure Git
run: |
git config --global user.name github-actions[bot]
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: knope-dev/action@407e9ef7c272d2dd53a4e71e39a7839e29933c48
- run: knope prepare-release --verbose
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release
on:
pull_request:
types:
- closed
branches:
- master

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Configure Git
run: |
git config --global user.name github-actions[bot]
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: knope-dev/action@407e9ef7c272d2dd53a4e71e39a7839e29933c48
- run: knope release --verbose
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode/settings.json

.DS_Store
.vscode
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## 0.9.0 (2024-12-18)

### Breaking Changes

- Add host public key to AccountToken

### Features

- Add helper for generating account tokens

### Fixes

- Allow v1 contracts to be resolved immediately

## 0.8.0 (2024-12-13)

### Breaking Changes

#### Add revisable to RPCLatestRevision

Adds two additional flags to the RPCLatestRevision response. The `Revisable` field indicates whether the host will accept further revisions to the contract. A host will not accept revisions too close to the proof window or revisions on contracts that have already been resolved. The `Renewed` field indicates whether the contract was renewed. If the contract was renewed, the renter can use `FileContractID.V2RenewalID` to get the ID of the new contract.

## 0.7.3 (2024-12-12)

### Features

- Update `golang.org/x/crypto` from 0.30.0 to 0.31.0

## 0.7.2 (2024-12-12)

### Features

#### Allow revisions to set MaxRevisionNumber

`MaxRevisionNumber` was previously used to finalize contracts, but that is not the case anymore, so the restriction can be removed.

### Fixes

- Include storage cost in renter renewal cost

## 0.7.1 (2024-12-04)

### Fixes

- Automate releases
105 changes: 74 additions & 31 deletions consensus/update.go → consensus/application.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 All @@ -495,12 +495,12 @@ func (ms *MidState) ApplyTransaction(txn types.Transaction, ts V1TransactionSupp
ms.reviseFileContractElement(fce, fcr.FileContract)
}
for _, sp := range txn.StorageProofs {
sps, ok := ts.storageProof(sp.ParentID)
fce, ok := ms.fileContractElement(ts, sp.ParentID)
if !ok {
panic("missing V1StorageProofSupplement")
}
ms.resolveFileContractElement(sps.FileContract, true, txid)
for i, sco := range sps.FileContract.FileContract.ValidProofOutputs {
ms.resolveFileContractElement(fce, true, txid)
for i, sco := range fce.FileContract.ValidProofOutputs {
ms.addImmatureSiacoinElement(sp.ParentID.ValidOutputID(i), sco)
}
}
Expand All @@ -509,8 +509,8 @@ func (ms *MidState) ApplyTransaction(txn types.Transaction, ts V1TransactionSupp
if bytes.HasPrefix(arb, types.SpecifierFoundation[:]) {
var update types.FoundationAddressUpdate
update.DecodeFrom(types.NewBufDecoder(arb[len(types.SpecifierFoundation):]))
ms.foundationPrimary = update.NewPrimary
ms.foundationFailsafe = update.NewFailsafe
ms.foundationSubsidy = update.NewPrimary
ms.foundationManagement = update.NewFailsafe
}
}
}
Expand All @@ -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).Div64(ms.base.SiafundCount()).Mul64(sfi.Parent.SiafundOutput.Value)
ms.addImmatureSiacoinElement(sfi.Parent.ID.V2ClaimOutputID(), types.SiacoinOutput{Value: claimPortion, Address: sfi.ClaimAddress})
}
for i, sfo := range txn.SiafundOutputs {
Expand All @@ -548,9 +548,7 @@ func (ms *MidState) ApplyV2Transaction(txn types.V2Transaction) {
var renter, host types.SiacoinOutput
switch r := fcr.Resolution.(type) {
case *types.V2FileContractRenewal:
renter, host = r.FinalRevision.RenterOutput, r.FinalRevision.HostOutput
renter.Value = renter.Value.Sub(r.RenterRollover)
host.Value = host.Value.Sub(r.HostRollover)
renter, host = r.FinalRenterOutput, r.FinalHostOutput
ms.addV2FileContractElement(fce.ID.V2RenewalID(), r.NewContract)
case *types.V2StorageProof:
renter, host = fc.RenterOutput, fc.HostOutput
Expand All @@ -568,8 +566,13 @@ func (ms *MidState) ApplyV2Transaction(txn types.V2Transaction) {
})
}
if txn.NewFoundationAddress != nil {
ms.foundationPrimary = *txn.NewFoundationAddress
ms.foundationFailsafe = *txn.NewFoundationAddress
// The subsidy may be waived by sending it to the void address. In this
// case, the management address is not updated (as this would
// permanently disable the subsidy).
ms.foundationSubsidy = *txn.NewFoundationAddress
if *txn.NewFoundationAddress != types.VoidAddress {
ms.foundationManagement = *txn.NewFoundationAddress
}
}
}

Expand Down Expand Up @@ -665,31 +668,49 @@ func (au ApplyUpdate) UpdateElementProof(e *types.StateElement) {
au.eau.updateElementProof(e)
}

// ForEachSiacoinElement calls fn on each siacoin element related to au.
// ForEachSiacoinElement calls fn on each siacoin element related to the applied
// block. The created and spent flags indicate whether the element was newly
// created in the block and/or spent in the block. Note that an element may be
// both created and spent in the the same block.
func (au ApplyUpdate) ForEachSiacoinElement(fn func(sce types.SiacoinElement, created, spent bool)) {
for _, sce := range au.ms.sces {
fn(sce, au.ms.isCreated(sce.ID), au.ms.isSpent(sce.ID))
}
}

// ForEachSiafundElement calls fn on each siafund element related to au.
// ForEachSiafundElement calls fn on each siafund element related to the applied
// block. The created and spent flags indicate whether the element was newly
// created in the block and/or spent in the block. Note that an element may be
// both created and spent in the the same block.
func (au ApplyUpdate) ForEachSiafundElement(fn func(sfe types.SiafundElement, created, spent bool)) {
for _, sfe := range au.ms.sfes {
fn(sfe, au.ms.isCreated(sfe.ID), au.ms.isSpent(sfe.ID))
}
}

// ForEachFileContractElement calls fn on each file contract element related to
// au. If the contract was revised, rev is non-nil.
// the applied block. The created flag indicates whether the contract was newly
// created. If the contract was revised, rev is non-nil and represents the state
// of the element post-application. If the block revised the contract multiple
// times, rev is the revision with the highest revision number. The resolved and
// valid flags indicate whether the contract was resolved, and if so, whether it
// was resolved via storage proof. Note that a contract may be created, revised,
// and resolved all within the same block.
func (au ApplyUpdate) ForEachFileContractElement(fn func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool)) {
for _, fce := range au.ms.fces {
fn(fce, au.ms.isCreated(fce.ID), au.ms.revs[fce.ID], au.ms.isSpent(fce.ID), au.ms.res[fce.ID])
}
}

// ForEachV2FileContractElement calls fn on each V2 file contract element
// related to au. If the contract was revised, rev is non-nil. If the contract
// was resolved, res is non-nil.
// ForEachV2FileContractElement calls fn on each v2 file contract element
// related to the applied block. The created flag indicates whether the contract
// was newly created. If the contract was revised, rev is non-nil and represents
// the state of the element post-application. If the block revised the contract
// multiple times, rev is the revision with the highest revision number. The
// resolved and valid flags indicate whether the contract was resolved, and if
// so, whether it was resolved via storage proof. Note that, within a block, a
// contract may be created and revised, or revised and resolved, but not created
// and resolved.
func (au ApplyUpdate) ForEachV2FileContractElement(fn func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType)) {
for _, fce := range au.ms.v2fces {
fn(fce, au.ms.isCreated(fce.ID), au.ms.v2revs[fce.ID], au.ms.v2res[fce.ID])
Expand Down Expand Up @@ -736,10 +757,10 @@ 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
s.FoundationSubsidyAddress = ms.foundationSubsidy
s.FoundationManagementAddress = ms.foundationManagement

// compute updated and added elements
var updated, added []elementLeaf
Expand All @@ -755,7 +776,11 @@ func ApplyBlock(s State, b types.Block, bs V1BlockSupplement, targetTimestamp ti
return s, ApplyUpdate{ms, eau}
}

// A RevertUpdate represents the effects of reverting to a prior state.
// A RevertUpdate represents the effects of reverting to a prior state. These
// are the same effects seen as when applying the block, but should be processed
// inversely. For example, if ForEachSiacoinElement reports an element with the
// created flag set, it means the block created that element when it was
// applied; thus, when the block is reverted, the element no longer exists.
type RevertUpdate struct {
ms *MidState
eru elementRevertUpdate
Expand All @@ -768,15 +793,21 @@ func (ru RevertUpdate) UpdateElementProof(e *types.StateElement) {
ru.eru.updateElementProof(e)
}

// ForEachSiacoinElement calls fn on each siacoin element related to ru.
// ForEachSiacoinElement calls fn on each siacoin element related to the reverted
// block. The created and spent flags indicate whether the element was newly
// created in the block and/or spent in the block. Note that an element may be
// both created and spent in the the same block.
func (ru RevertUpdate) ForEachSiacoinElement(fn func(sce types.SiacoinElement, created, spent bool)) {
for i := range ru.ms.sces {
sce := ru.ms.sces[len(ru.ms.sces)-i-1]
fn(sce, ru.ms.isCreated(sce.ID), ru.ms.isSpent(sce.ID))
}
}

// ForEachSiafundElement calls fn on each siafund element related to ru.
// ForEachSiafundElement calls fn on each siafund element related to the
// reverted block. The created and spent flags indicate whether the element was
// newly created in the block and/or spent in the block. Note that an element
// may be both created and spent in the the same block.
func (ru RevertUpdate) ForEachSiafundElement(fn func(sfe types.SiafundElement, created, spent bool)) {
for i := range ru.ms.sfes {
sfe := ru.ms.sfes[len(ru.ms.sfes)-i-1]
Expand All @@ -785,17 +816,29 @@ func (ru RevertUpdate) ForEachSiafundElement(fn func(sfe types.SiafundElement, c
}

// ForEachFileContractElement calls fn on each file contract element related to
// ru. If the contract was revised, rev is non-nil.
// the reverted block. The created flag indicates whether the contract was newly
// created. If the contract was revised, rev is non-nil and represents the state
// of the element post-application. If the block revised the contract multiple
// times, rev is the revision with the highest revision number. The resolved and
// valid flags indicate whether the contract was resolved, and if so, whether it
// was resolved via storage proof. Note that a contract may be created, revised,
// and resolved all within the same block.
func (ru RevertUpdate) ForEachFileContractElement(fn func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool)) {
for i := range ru.ms.fces {
fce := ru.ms.fces[len(ru.ms.fces)-i-1]
fn(fce, ru.ms.isCreated(fce.ID), ru.ms.revs[fce.ID], ru.ms.isSpent(fce.ID), ru.ms.res[fce.ID])
}
}

// ForEachV2FileContractElement calls fn on each V2 file contract element
// related to au. If the contract was revised, rev is non-nil. If the contract
// was resolved, res is non-nil.
// ForEachV2FileContractElement calls fn on each v2 file contract element
// related to the reverted block. The created flag indicates whether the
// contract was newly created. If the contract was revised, rev is non-nil and
// represents the state of the element post-application. If the block revised
// the contract multiple times, rev is the revision with the highest revision
// number. The resolved and valid flags indicate whether the contract was
// resolved, and if so, whether it was resolved via storage proof. Note that,
// within a block, a contract may be created and revised, or revised and
// resolved, but not created and resolved.
func (ru RevertUpdate) ForEachV2FileContractElement(fn func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType)) {
for i := range ru.ms.v2fces {
fce := ru.ms.v2fces[len(ru.ms.v2fces)-i-1]
Expand Down
Loading

0 comments on commit 7169ebf

Please sign in to comment.