Skip to content

Commit

Permalink
feat(cluster): v2 transition support
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Feb 3, 2025
1 parent 1f07d98 commit 53c8c33
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slow-flowers-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/clusterd': minor
---

Added transition network mode.
5 changes: 5 additions & 0 deletions .changeset/stale-pillows-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/clusterd': minor
---

Added mineToHeight and getCurrentHeight APIs.
5 changes: 4 additions & 1 deletion internal/cluster/cmd/clusterd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
flag.StringVar(&dir, "dir", "", "directory to store renter data")
flag.StringVar(&apiAddr, "api", ":3001", "API address")
flag.StringVar(&logLevel, "log", "info", "logging level")
flag.StringVar(&network, "network", "v1", "network to use (v1 or v2)")
flag.StringVar(&network, "network", "v1", "network to use (v1, v2, or transition)")
flag.StringVar(&siafundAddr, "siafund", "", "address to send siafunds to")

flag.IntVar(&renterdCount, "renterd", 0, "number of renter daemons to run")
Expand Down Expand Up @@ -127,6 +127,9 @@ func main() {
case "v2":
n.HardforkV2.AllowHeight = 2
n.HardforkV2.RequireHeight = 3
case "transition":
n.HardforkV2.AllowHeight = 400
n.HardforkV2.RequireHeight = 500
default:
log.Fatal("invalid network", zap.String("network", network))
}
Expand Down
22 changes: 22 additions & 0 deletions libs/clusterd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Node = {
apiAddress: string
password: string
}
type NetworkVersion = 'v1' | 'v2' | 'transition'

export const clusterd = {
process: undefined as child.ChildProcessWithoutNullStreams | undefined,
Expand All @@ -25,11 +26,18 @@ export async function setupCluster({
renterdCount = 0,
hostdCount = 0,
walletdCount = 0,
networkVersion = 'v1',
}: {
renterdCount?: number
hostdCount?: number
walletdCount?: number
networkVersion?: NetworkVersion
} = {}) {
clusterd.managementPort = random(10000, 65535)
console.log('Starting cluster on port', clusterd.managementPort)

clusterd.process = child.spawn('internal/cluster/bin/clusterd', [
`-network=${networkVersion}`,
`-renterd=${renterdCount}`,
`-hostd=${hostdCount}`,
`-walletd=${walletdCount}`,
Expand Down Expand Up @@ -174,6 +182,20 @@ export async function mine(blocks: number) {
})
}

export async function mineToHeight(height: number) {
console.log(`Mining to height ${height}...`)
await Axios.post(`http://localhost:${clusterd.managementPort}/mine/to`, {
targetHeight: height,
})
}

export async function getCurrentHeight() {
const response = await Axios.get(
`http://localhost:${clusterd.managementPort}/height`
)
return response.data?.height
}

export async function teardownCluster() {
console.log('stopping cluster')
clusterd.process?.kill()
Expand Down

0 comments on commit 53c8c33

Please sign in to comment.