avalanche-cli
avalanche-cli copied to clipboard
Support OpenBSD/adJ - amd64
From my OpenBSD/adJ 7.4 on amd64 when I run:
curl -sSfL https://raw.githubusercontent.com/ava-labs/avalanche-cli/main/scripts/install.sh | sh -s
It says
ava-labs/avalanche-cli crit platform openbsd/amd64 is not supported. Make sure this script is up-to-date and file request at https://github.com/ava-labs/avalanche-cli/issues/new
Following the README.md to build locally, after cloning the repository and running:
./scripts/build.sh
I obtain
./scripts/build.sh: bad interpreter: /bin/bash: no such file or directory
Easy to make portable by editing scripts/build.sh and changing /bin/bash with /usr/bin/env bash
Next compilation error is:
% scripts/build.sh
github.com/ava-labs/avalanchego/utils/storage
# github.com/ava-labs/avalanchego/utils/storage
../../../go/pkg/mod/github.com/ava-labs/[email protected]/utils/storage/storage_unix.go:17:16: stat.Bavail undefined (type syscall.Statfs_t has no field or me
thod Bavail)
../../../go/pkg/mod/github.com/ava-labs/[email protected]/utils/storage/storage_unix.go:17:37: stat.Bsize undefined (type syscall.Statfs_t has no field or met
hod Bsize)
As explained at https://github.com/golang/go/issues/47958 it happens because in OpenBSD syscall.Statfs_t has F_bsize and F_bavail instead of Bsize and Bavail. It can be fixed by using Build constraints
I solved temporarily in my ~/go directory by changing ~/go/pkg/mod/github.com/ava-labs/[email protected]/utils/storage/storage_unix.go:
@@ -1,8 +1,8 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
-//go:build !windows
-// +build !windows
+//go:build !windows && !openbsd
+// +build !windows,!openbsd
and adding the file utils/storage/storage_openbsd.go with:
// Public Domain
//go:build openbsd
// +build openbsd
package storage
import "syscall"
func AvailableBytes(storagePath string) (uint64, error) {
var stat syscall.Statfs_t
err := syscall.Statfs(storagePath, &stat)
if err != nil {
return 0, err
}
avail := uint64(stat.F_bavail) * uint64(stat.F_bsize)
return avail, nil
}
Next compilation problem is
# github.com/cockroachdb/pebble/vfs
../../../go/pkg/mod/github.com/cockroachdb/[email protected]/vfs/disk_usage_unix.go:18:27: stat.Bsize undefined (type "golang.org/x/sys/
unix".Statfs_t has no field or method Bsize)
../../../go/pkg/mod/github.com/cockroachdb/[email protected]/vfs/disk_usage_unix.go:18:48: stat.Bfree undefined (type "golang.org/x/sys/
unix".Statfs_t has no field or method Bfree)
../../../go/pkg/mod/github.com/cockroachdb/[email protected]/vfs/disk_usage_unix.go:19:28: stat.Bsize undefined (type "golang.org/x/sys/
unix".Statfs_t has no field or method Bsize)
../../../go/pkg/mod/github.com/cockroachdb/[email protected]/vfs/disk_usage_unix.go:19:49: stat.Bavail undefined (type "golang.org/x/sys
/unix".Statfs_t has no field or method Bavail)
../../../go/pkg/mod/github.com/cockroachdb/[email protected]/vfs/disk_usage_unix.go:20:28: stat.Bsize undefined (type "golang.org/x/sys/
unix".Statfs_t has no field or method Bsize)
../../../go/pkg/mod/github.com/cockroachdb/[email protected]/vfs/disk_usage_unix.go:20:49: stat.Blocks undefined (type "golang.org/x/sys
/unix".Statfs_t has no field or method Blocks)
This should be solved with a recent versions of pebble, i.e version 1.1.0 or greater. Because the file
vfs/disk_usage_openbsd.go was added in version 1.1.0, see it among Files Changed at https://github.com/cockroachdb/pebble/compare/v1.0.0...v1.1.0#diff-e80071db294208cc80f86aa6d7915a187eaa64a03a17ec7eec3a2d96bda5dbfb.
Updating pebble to v1.1.0 with go get [email protected] produces 4 new updating issues in avalanchego:
1. ../../../go/pkg/mod/github.com/ava-labs/[email protected]/database/pebble/batch.go:90:21: assignment mismatch: 4 variables but reader.Next returns 5 values
2. ../../../go/pkg/mod/github.com/ava-labs/[email protected]/database/pebble/db.go:91:32: cannot use cfg.MemTableSize (variable of type int) as uint64 value in struct literal
3. ../../../go/pkg/mod/github.com/ava-labs/[email protected]/database/pebble/db.go:206:9: assignment mismatch: 1 variable but db.pebbleDB.NewIter returns 2 values
4. ../../../go/pkg/mod/github.com/ava-labs/[email protected]/database/pebble/db.go:253:9: multiple-value db.pebbleDB.NewIter(keyRange(start, prefix)) (value of type (*"github.com/cockroachdb/pebble".Iterator, error)) in single-value context
- To solve
../../../go/pkg/mod/github.com/ava-labs/[email protected]/database/pebble/batch.go:90:21: assignment mismatch: 4 variables but reader.Next returns 5 valuesI checked the source code of https://github.com/cockroachdb/cockroach/ and found about the new fifht return value ofreader.Next():
% find . -name "*go" -exec grep -H "=.*reader\.Next()" {} ";"
./pkg/storage/batch.go: r.kind, r.key, r.value, ok, r.err = r.reader.Next()
./pkg/storage/bench_test.go: kind, key, value, ok, err := reader.Next()
./pkg/storage/bench_test.go: for ; ok; kind, key, value, ok, err = reader.Next() {
And changed temporarily at go/pkg/mod/github.com/ava-labs/[email protected]/database/pebble/batch.go
@@ -87,9 +87,9 @@
func (b *batch) Replay(w database.KeyValueWriterDeleter) error {
reader := b.batch.Reader()
for {
- kind, k, v, ok := reader.Next()
+ kind, k, v, ok, err := reader.Next()
if !ok {
- return nil
+ return err
}
switch kind {
case pebble.InternalKeyKindSet:
- To solve
../../../go/pkg/mod/github.com/ava-labs/[email protected]/database/pebble/db.go:91:32: cannot use cfg.MemTableSize (variable of type int) as uint64 value in struct literalI proposed a cast:
@@ -88,7 +88,7 @@
Comparer: pebble.DefaultComparer,
WALBytesPerSync: cfg.WALBytesPerSync,
MemTableStopWritesThreshold: cfg.MemTableStopWritesThreshold,
- MemTableSize: cfg.MemTableSize,
+ MemTableSize: uint64(cfg.MemTableSize),
MaxOpenFiles: cfg.MaxOpenFiles,
MaxConcurrentCompactions: func() int { return cfg.MaxConcurrentCompactions },
}
Trying to solve 3 and 4 I realized that maybe the binary format of pebble changed between the one used by avalanchego and the one used by recent versions of cockroachdb and the updating could require more planning and testing from the avalanche team.
Another approach with pebble would be to backport the support for OpenBSD to [email protected] that is the version used by avalanchego in this moment.
To test it, temporarily I make the changes of https://github.com/cockroachdb/pebble/compare/v1.0.0...v1.1.0#diff-e80071db294208cc80f86aa6d7915a187eaa64a03a17ec7eec3a2d96bda5dbfb to ~/go/pkg/mod/github.com/cockroachdb/[email protected]/vfs/disk_usage_openbsd.go and ~/go/pkg/mod/github.com/cockroachdb/[email protected]/vfs/disk_usage_unix.go
Doing that the compilation process finished and generated bin/avalanche however running it produces a segmentation fault with a long tail:
% bin/avalanche
SIGSEGV: segmentation violation
PC=0x44b8b29 m=0 sigcode=2 addr=0x44b9bc0
signal arrived during cgo execution
goroutine 1 gp=0xc0000061c0 m=0 mp=0x54c17e0 [syscall, locked to thread]:
runtime.cgocall(0x44a14d0, 0xc000ec1be0)
/usr/local/go/src/runtime/cgocall.go:157 +0x4b fp=0xc000ec1bb8 sp=0xc000ec1b80 pc=0x21f656b
github.com/supranational/blst/bindings/go._Cfunc_blst_keygen(0xc0003e0140, 0xc0003e0120, 0x20, 0x0, 0x0)
_cgo_gotypes.go:467 +0x45 fp=0xc000ec1be0 sp=0xc000ec1bb8 pc=0x28801c5
github.com/supranational/blst/bindings/go.KeyGen({0xc0003e0120, 0x20, 0xc0003ec150?}, {0x0, 0x0, 0xc0003ec138?})
/home/vtamara/go/pkg/mod/github.com/supranational/[email protected]/bindings/go/blst.go:225 +0x95 fp=0xc000ec1c20 sp=0xc000ec1be0 pc=0x2883335
github.com/ava-labs/avalanchego/utils/crypto/bls.NewSecretKey()
/home/vtamara/go/pkg/mod/github.com/ava-labs/[email protected]/utils/crypto/bls/secret.go:36 +0x52 fp=0xc000ec1c68 sp=0xc000ec1c20 pc=0x288df32
github.com/ava-labs/coreth/utils.TestSnowContext()
/home/vtamara/go/pkg/mod/github.com/ava-labs/[email protected]/utils/snow.go:15 +0x17 fp=0xc000ec1cc8 sp=0xc000ec1c68 pc=0x2a23d17
github.com/ava-labs/coreth/params.init()
/home/vtamara/go/pkg/mod/github.com/ava-labs/[email protected]/params/config.go:67 +0x295 fp=0xc000ec1e20 sp=0xc000ec1cc8 pc=0x2a393b5
runtime.doInit1(0x45897c0)
/usr/local/go/src/runtime/proc.go:7172 +0xd7 fp=0xc000ec1f50 sp=0xc000ec1e20 pc=0x223c857
runtime.doInit(...)
/usr/local/go/src/runtime/proc.go:7139
runtime.main()
/usr/local/go/src/runtime/proc.go:253 +0x345 fp=0xc000ec1fe0 sp=0xc000ec1f50 pc=0x222e305
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc000ec1fe8 sp=0xc000ec1fe0 pc=0x2266601
goroutine 2 gp=0xc000006c40 m=nil [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc000084fa8 sp=0xc000084f88 pc=0x222e68e
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:408
runtime.forcegchelper()
/usr/local/go/src/runtime/proc.go:326 +0xa5 fp=0xc000084fe0 sp=0xc000084fa8 pc=0x222e505
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc000084fe8 sp=0xc000084fe0 pc=0x2266601
created by runtime.init.6 in goroutine 1
/usr/local/go/src/runtime/proc.go:314 +0x1a
goroutine 3 gp=0xc000007180 m=nil [GC sweep wait]:
runtime.gopark(0x1?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc000085780 sp=0xc000085760 pc=0x222e68e
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:408
runtime.bgsweep(0xc0000a8000)
/usr/local/go/src/runtime/mgcsweep.go:318 +0xdf fp=0xc0000857c8 sp=0xc000085780 pc=0x22187bf
runtime.gcenable.gowrap1()
/usr/local/go/src/runtime/mgc.go:203 +0x25 fp=0xc0000857e0 sp=0xc0000857c8 pc=0x220d105
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc0000857e8 sp=0xc0000857e0 pc=0x2266601
created by runtime.gcenable in goroutine 1
/usr/local/go/src/runtime/mgc.go:203 +0x66
goroutine 4 gp=0xc000007340 m=nil [GC scavenge wait]:
runtime.gopark(0x10000?, 0xec9cf0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc000085f78 sp=0xc000085f58 pc=0x222e68e
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:408
runtime.(*scavengerState).park(0x54be6e0)
/usr/local/go/src/runtime/mgcscavenge.go:425 +0x49 fp=0xc000085fa8 sp=0xc000085f78 pc=0x2216189
runtime.bgscavenge(0xc0000a8000)
/usr/local/go/src/runtime/mgcscavenge.go:658 +0x59 fp=0xc000085fc8 sp=0xc000085fa8 pc=0x2216719
runtime.gcenable.gowrap2()
/usr/local/go/src/runtime/mgc.go:204 +0x25 fp=0xc000085fe0 sp=0xc000085fc8 pc=0x220d0a5
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc000085fe8 sp=0xc000085fe0 pc=0x2266601
created by runtime.gcenable in goroutine 1
/usr/local/go/src/runtime/mgc.go:204 +0xa5
goroutine 5 gp=0xc000007c00 m=nil [finalizer wait]: 13:44:12 [55/1148]
runtime.gopark(0xc000084648?, 0x2200625?, 0xa8?, 0x1?, 0xc0000061c0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc000084620 sp=0xc000084600 pc=0x222e68e
runtime.runfinq()
/usr/local/go/src/runtime/mfinal.go:194 +0x107 fp=0xc0000847e0 sp=0xc000084620 pc=0x220c147
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc0000847e8 sp=0xc0000847e0 pc=0x2266601
created by runtime.createfing in goroutine 1
/usr/local/go/src/runtime/mfinal.go:164 +0x3d
goroutine 18 gp=0xc000102380 m=nil [GC worker (idle)]:
runtime.gopark(0xc0000807b8?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc000080750 sp=0xc000080730 pc=0x222e68e
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1310 +0xe5 fp=0xc0000807e0 sp=0xc000080750 pc=0x220f165
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc0000807e8 sp=0xc0000807e0 pc=0x2266601
created by runtime.gcBgMarkStartWorkers in goroutine 1
/usr/local/go/src/runtime/mgc.go:1234 +0x1c
goroutine 6 gp=0xc0002e08c0 m=nil [GC worker (idle)]:
runtime.gopark(0xc0000867b8?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc000086750 sp=0xc000086730 pc=0x222e68e
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1310 +0xe5 fp=0xc0000867e0 sp=0xc000086750 pc=0x220f165
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc0000867e8 sp=0xc0000867e0 pc=0x2266601
created by runtime.gcBgMarkStartWorkers in goroutine 1
/usr/local/go/src/runtime/mgc.go:1234 +0x1c
goroutine 7 gp=0xc0002e0a80 m=nil [GC worker (idle)]:
runtime.gopark(0xc000086fb8?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc000086f50 sp=0xc000086f30 pc=0x222e68e
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1310 +0xe5 fp=0xc000086fe0 sp=0xc000086f50 pc=0x220f165
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc000086fe8 sp=0xc000086fe0 pc=0x2266601
created by runtime.gcBgMarkStartWorkers in goroutine 1
/usr/local/go/src/runtime/mgc.go:1234 +0x1c
goroutine 19 gp=0xc000102540 m=nil [GC worker (idle)]:
runtime.gopark(0xc000080fb8?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc000080f50 sp=0xc000080f30 pc=0x222e68e
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1310 +0xe5 fp=0xc000080fe0 sp=0xc000080f50 pc=0x220f165
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc000080fe8 sp=0xc000080fe0 pc=0x2266601
created by runtime.gcBgMarkStartWorkers in goroutine 1
/usr/local/go/src/runtime/mgc.go:1234 +0x1c
goroutine 34 gp=0xc000007dc0 m=nil [select]:
runtime.gopark(0xc000081778?, 0x3?, 0x8?, 0x5?, 0xc000081772?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc000081618 sp=0xc0000815f8 pc=0x222e68e
runtime.selectgo(0xc000081778, 0xc00008176c, 0xc0000e0100?, 0x0, 0x0?, 0x1)
/usr/local/go/src/runtime/select.go:327 +0x725 fp=0xc000081738 sp=0xc000081618 pc=0x2240225
go.opencensus.io/stats/view.(*worker).start(0xc0000e0100)
/home/vtamara/go/pkg/mod/[email protected]/stats/view/worker.go:292 +0x9f fp=0xc0000817c8 sp=0xc000081738 pc=0x443d3bf
go.opencensus.io/stats/view.init.0.gowrap1()
/home/vtamara/go/pkg/mod/[email protected]/stats/view/worker.go:34 +0x25 fp=0xc0000817e0 sp=0xc0000817c8 pc=0x443c725
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc0000817e8 sp=0xc0000817e0 pc=0x2266601
created by go.opencensus.io/stats/view.init.0 in goroutine 1
/home/vtamara/go/pkg/mod/[email protected]/stats/view/worker.go:34 +0x8d
goroutine 20 gp=0xc0002e0fc0 m=nil [chan receive]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc00115fef8 sp=0xc00115fed8 pc=0x222e68e
runtime.chanrecv(0xc0002b8540, 0xc00115ffb8, 0x1)
/usr/local/go/src/runtime/chan.go:583 +0x3bf fp=0xc00115ff70 sp=0xc00115fef8 pc=0x21f8b7f
runtime.chanrecv2(0x0?, 0x0?)
/usr/local/go/src/runtime/chan.go:447 +0x12 fp=0xc00115ff98 sp=0xc00115ff70 pc=0x21f87b2
github.com/ava-labs/coreth/metrics.(*meterArbiter).tick(...)
/home/vtamara/go/pkg/mod/github.com/ava-labs/[email protected]/metrics/meter.go:293
github.com/ava-labs/coreth/metrics.NewMeter.gowrap2()
/home/vtamara/go/pkg/mod/github.com/ava-labs/[email protected]/metrics/meter.go:56 +0x65 fp=0xc00115ffe0 sp=0xc00115ff98 pc=0x2a185a5
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc00115ffe8 sp=0xc00115ffe0 pc=0x2266601
created by github.com/ava-labs/coreth/metrics.NewMeter in goroutine 1
/home/vtamara/go/pkg/mod/github.com/ava-labs/[email protected]/metrics/meter.go:56 +0xc5
rax 0x6a09e667
rbx 0xbb67ae85
rcx 0x3c6ef372
rdx 0xa54ff53a
rdi 0x87095df7
rsi 0x706e4b1e20e8
rbp 0x44b9bc0
rsp 0x706e4b1e1fe0
r8 0x510e527f
r9 0x9b05688c
r10 0x1f83d9ab
r11 0x5be0cd19
r12 0xbdb2e9d2
r13 0x61c9cacd
r14 0x528b379c
r15 0x6a09e667
rip 0x44b8b29
rflags 0x10296
cs 0x2b
fs 0x0
gs 0x0
thank you for pointing our attention to this.
I suggest reopening this issue in https://github.com/ava-labs/avalanchego as this is cli repo to get attention from avalanchego developers.
Speaking about cli support for BSD OS, we can consider adding it after https://github.com/ava-labs/avalanchego supports it.