trezor / blockbook

:blue_book: Trezor address/account balance backend
https://trezor.io
GNU Affero General Public License v3.0
655 stars 648 forks source link

blst error - question about development build #882

Closed GBBx closed 1 year ago

GBBx commented 1 year ago

Hi,

I've been using Blockbook for a long time. I used to be able to follow the manual build steps but I run into an issue since I updated to 0.4.0. When I start blockbook I get this error message:

Caught SIGILL in blst_cgo_init, consult <blst>/bindings/go/README.md.

I found this discussion. They suggest to add CGO_CFLAGS=-O -D__BLST_PORTABLE__, so I tried this:

CFLAGS="-fPIC" CXXFLAGS="-fPIC" CGO_CFLAGS="-O -D__BLST_PORTABLE__" make release

when building rocksdb but it did not solve the issue.

I also tried to set CGO_CFLAGS="-O -D__BLST_PORTABLE__" make release globally but that failed, too.

I undertand blst is a dependency of a dependency of Blockbook but are you maybe familiar with this problem?

martinboehm commented 1 year ago

Hi, sorry, we do not have this build problem, neither in the manual build nor in the docker build. What version of go are you using? As it seems related to Avalanche dependencies, maybe @kaladinlight will have an idea.

GBBx commented 1 year ago

Hi @martinboehm , thanks for coming back to me. I try to build it with Go 1.19.2 on Ubuntu 20.04 (I also tried Ubuntu 22.04 - didn't help).

XK4MiLX commented 1 year ago

i got same issue on several diffrent configurations ... what i noticed ... i dont have that problem when CPU is AMD... Hit that error so far on:

kaladinlight commented 1 year ago

Interesting, I have not had any issues with the manual build or docker build either. Did you update your version of rocksdb to v7.7.2 as well? Also to clarify, you are seeing this error when running blockbook correct? I would think the blst flags would be for running blockbook, not rocksdb build.

The only other thing I saw when googling was a secondary flag: CGO_CFLAGS="-O -D__BLST_PORTABLE__" CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__" that you might try.

kaladinlight commented 1 year ago

I have an i7 and not seeing any issues. I am using go version go1.20 linux/amd64 locally if you want to give that a try? There was an additional -lzstd LDFLAG added with v0.4.0 as well just to make sure everything matches up.

GBBx commented 1 year ago

hi @kaladinlight, thanks for the hints. I've tried:

@XK4MiLX's finding is interesting. There are some comments about architecture at the bottom of the page I haven't tried yet.

kaladinlight commented 1 year ago

I would be curious about building and testing the blst go binding directly to reduce the scope of the problem a bit. https://github.com/supranational/blst/tree/master/bindings/go. According to https://github.com/supranational/blst#platform-and-language-compatibility it appears to have extensive os/platform support...

[~/github/blst] (master) $ ./build.sh 
+ cc -O2 -fno-builtin -fPIC -Wall -Wextra -Werror -D__ADX__ -mno-avx -c ./src/server.c
+ cc -O2 -fno-builtin -fPIC -Wall -Wextra -Werror -D__ADX__ -mno-avx -c ./build/assembly.S
+ ar rc libblst.a assembly.o server.o
[~/github/blst] (master) $ cd bindings/go/
[~/github/blst/bindings/go] (master) $ go build
[~/github/blst/bindings/go] (master) $ go test
PASS
ok      github.com/supranational/blst/bindings/go   2.037s

worst case scenario if we are unable to resolve this issue and it appears common enough, I can rip out the api/info module and manually replace it to rid the blst indirect dependency

XK4MiLX commented 1 year ago

i found something ;) Detect the case where a binary has been explicitly compiled with ADX support but it's missing at runtime, and report a nicer error than SIGILL. https://github.com/sigp/lighthouse/pull/1595 so... it look like that cpu not support ADX i checked PC where it work and where it not... cat /proc/cpuinfo | grep -o 'adx' | tail -n1 if output is empty not working as expected @GBBx can u confirm it? ;)

kaladinlight commented 1 year ago

Nice find! Confirmation on my side that my cpu does have ADX support.

martinboehm commented 1 year ago

@kaladinlight

worst case scenario if we are unable to resolve this issue and it appears common enough, I can rip out the api/info module and manually replace it to rid the blst indirect dependency

Wouldn't it be beneficial in any case? I would like to get rid of unnecessary dependencies. While I can build Blockbook on my Mac, I get these warnings, which also come from Avalanche dependencies

github.com/rjeczalik/notify
cgo-gcc-prolog:217:2: warning: 'FSEventStreamScheduleWithRunLoop' is deprecated: first deprecated in macOS 13.0 - Use FSEventStreamSetDispatchQueue instead. [-Wdeprecated-declarations]
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/FSEvents.framework/Headers/FSEvents.h:1138:1: note: 'FSEventStreamScheduleWithRunLoop' has been explicitly marked deprecated here
# github.com/trezor/blockbook
ld: warning: could not create compact unwind for _blst_sha256_block_data_order: does not use RBP or RSP based frame

github.com/ava-labs/avalanchego/api/info is used for GetNodeVersion only, if I understand it right. Could we call the info.getNodeVersion directly using Ethereum RPC?

kaladinlight commented 1 year ago

Yeah that would be the idea @martinboehm. I will go ahead and get a PR up to resolve this and reduce the dependency tree.

martinboehm commented 1 year ago

@GBBx @XK4MiLX Hi, can you try to build and run a new version from master? Thanks to a quick change by @kaladinlight, we were able to remove the blst dependecies from Blockbook.

XK4MiLX commented 1 year ago

i tested that fix on my fork working fine :) but yes i can test master ;) on sec

| Installed GOLANG [go1.20.1]...
| PATH: /opt/go
| Installing RocksDB [v7.7.2]...
| PATH: /opt/rocksdb
| RocksDB BUILD [OK]...
| Installing Blockbook [v0.4.0]...
| GITHUB URL: https://github.com/trezor/blockbook.git, BRANCH: master
| PATH: /opt/blockbook
| Blockbook BUILD [OK]...
| Generating config files for firo
| Moving blockchaincfg.json
| Moving firo.conf
 File: /root/blockbook.log
-----------------------------------------------------------------------------------------------
I0306 22:54:06.985865       7 mempool_bitcoin_type.go:207] mempool: resync finished in 501.258s, 0 transactions in mempool
I0306 22:54:08.014753       7 mempool_bitcoin_type.go:207] mempool: resync finished in 803.703s, 0 transactions in mempool
I0306 22:54:09.053184       7 mempool_bitcoin_type.go:207] mempool: resync finished in 443.306s, 0 transactions in mempool