Roasbeef / btcd

An alternative full node bitcoin implementation written in Go (golang)
ISC License
71 stars 29 forks source link

btcd testnet panics on start #27

Closed cbarraford closed 6 years ago

cbarraford commented 6 years ago

While following the instructions, i get the following error while running btcd testnet.

btcd --testnet --txindex --rpcuser=cbarraford --rpcpass=<password>                                                  2 ↵  02:16  12:17:43
2018-07-04 12:18:33.074 [INF] BTCD: Version 0.12.0-beta
2018-07-04 12:18:33.075 [INF] BTCD: Loading block database from '/Users/cbarraford/Library/Application Support/Btcd/data/testnet/blocks_ffldb'
2018-07-04 12:18:33.107 [INF] BCDB: Detected unclean shutdown - Repairing...
2018-07-04 12:18:33.109 [INF] BCDB: Database sync complete
2018-07-04 12:18:33.109 [INF] BTCD: Block database loaded
2018-07-04 12:18:33.117 [INF] INDX: Transaction index is enabled
2018-07-04 12:18:33.117 [INF] INDX: cf index is enabled
2018-07-04 12:18:33.117 [INF] CHAN: Loading block index.  This might take a while...
2018-07-04 12:19:31.147 [INF] CHAN: Chain state (height 1126006, hash 0000000000032fb64bbd363ad62c9c8819187956ce851b755b3de8c39e2b8812, totaltx 13928880, work 671665688970348490798)
2018-07-04 12:19:31.157 [INF] RPCS: RPC server listening on 127.0.0.1:18334
2018-07-04 12:19:31.157 [INF] RPCS: RPC server listening on [::1]:18334
2018-07-04 12:19:31.157 [INF] RPCS: RPC server listening on [fe80::1%lo0]:18334
2018-07-04 12:19:31.178 [INF] AMGR: Loaded 3262 addresses from file '/Users/cbarraford/Library/Application Support/Btcd/data/testnet/peers.json'
2018-07-04 12:19:31.179 [INF] CMGR: Server listening on [::]:18333
2018-07-04 12:19:31.180 [INF] CMGR: Server listening on 0.0.0.0:18333
2018-07-04 12:19:31.185 [INF] CMGR: 36 addresses found from DNS seed testnet-seed.bitcoin.jonasschnelli.ch
2018-07-04 12:19:31.185 [INF] CMGR: 38 addresses found from DNS seed seed.tbtc.petertodd.org
2018-07-04 12:19:31.266 [INF] CMGR: 3 addresses found from DNS seed testnet-seed.bluematt.me
2018-07-04 12:19:31.511 [INF] SYNC: New valid peer 93.190.142.127:18333 (outbound) (/Satoshi:0.15.0/)
2018-07-04 12:19:31.511 [INF] SYNC: Syncing to block height 1350093 from peer 93.190.142.127:18333
2018-07-04 12:19:31.528 [INF] SYNC: New valid peer 34.252.91.57:18333 (outbound) (/Satoshi:0.16.0/)
2018-07-04 12:19:31.563 [INF] SYNC: New valid peer 217.16.185.175:18333 (outbound) (/Satoshi:0.15.0.1/)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x1383503]

goroutine 53 [running]:
github.com/roasbeef/btcd/database/ffldb.rollbackOnPanic(0xc4292a41b0)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/database/ffldb/db.go:1889 +0x77
panic(0x159cae0, 0x1ab1040)
    /usr/local/Cellar/go/1.10.3/libexec/src/runtime/panic.go:502 +0x229
github.com/roasbeef/btcd/blockchain/indexers.dbStoreFilterIdxEntry(0x17fdd00, 0xc4292a41b0, 0x1a81d90, 0x10, 0x10, 0xc43942bb00, 0xc4396fe360, 0x20, 0x20, 0x0, ...)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/blockchain/indexers/cfindex.go:71 +0xb3
github.com/roasbeef/btcd/blockchain/indexers.storeFilter(0x17fdd00, 0xc4292a41b0, 0xc42b8b64d0, 0xc4325a5ef0, 0x0, 0x24, 0xc42e243170)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/blockchain/indexers/cfindex.go:171 +0x2b1
github.com/roasbeef/btcd/blockchain/indexers.(*CfIndex).ConnectBlock(0xc42013c820, 0x17fdd00, 0xc4292a41b0, 0xc42b8b64d0, 0xc431204cc0, 0xc439329d00, 0x112e76)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/blockchain/indexers/cfindex.go:212 +0x76
github.com/roasbeef/btcd/blockchain/indexers.dbIndexConnectBlock(0x17fdd00, 0xc4292a41b0, 0x17fb900, 0xc42013c820, 0xc42b8b64d0, 0xc431204cc0, 0x0, 0x0)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/blockchain/indexers/manager.go:87 +0x128
github.com/roasbeef/btcd/blockchain/indexers.(*Manager).ConnectBlock(0xc420144690, 0x17fdd00, 0xc4292a41b0, 0xc42b8b64d0, 0xc431204cc0, 0xc1, 0x0)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/blockchain/indexers/manager.go:535 +0xa0
github.com/roasbeef/btcd/blockchain.(*BlockChain).connectBlock.func1(0x17fdd00, 0xc4292a41b0, 0xc4292a41b0, 0x0)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/blockchain/chain.go:647 +0x1d6
github.com/roasbeef/btcd/database/ffldb.(*db).Update(0xc4201362c0, 0xc438cba640, 0x0, 0x0)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/database/ffldb/db.go:1946 +0x9b
github.com/roasbeef/btcd/blockchain.(*BlockChain).connectBlock(0xc420067380, 0xc42bfce230, 0xc42b8b64d0, 0xc431204cc0, 0xc4202e6a00, 0xc1, 0xc1, 0x0, 0x3d00000000000003)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/blockchain/chain.go:614 +0x2f8
github.com/roasbeef/btcd/blockchain.(*BlockChain).connectBestChain(0xc420067380, 0xc42bfce230, 0xc42b8b64d0, 0xc400000000, 0x0, 0x0, 0xc4329fbad8)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/blockchain/chain.go:1072 +0x1de
github.com/roasbeef/btcd/blockchain.(*BlockChain).maybeAcceptBlock(0xc420067380, 0xc42b8b64d0, 0x0, 0x0, 0x0, 0x1ac5a20)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/blockchain/accept.go:78 +0x21b
github.com/roasbeef/btcd/blockchain.(*BlockChain).ProcessBlock(0xc420067380, 0xc42b8b64d0, 0xc400000000, 0xc432b90000, 0x0, 0x0)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/blockchain/process.go:228 +0x2b5
github.com/roasbeef/btcd/netsync.(*SyncManager).handleBlockMsg(0xc42016a370, 0xc42e45d200)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/netsync/manager.go:569 +0x205
github.com/roasbeef/btcd/netsync.(*SyncManager).blockHandler(0xc42016a370)
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/netsync/manager.go:1152 +0x548
created by github.com/roasbeef/btcd/netsync.(*SyncManager).Start
    /Users/cbarraford/go/src/github.com/roasbeef/btcd/netsync/manager.go:1374 +0xe3
cbarraford commented 6 years ago

Ok, after a bit of painstaking debugging, here's the issue...

line 71 panics because the previous line (line 70) return nil for the idx value. And the current code doesn't do anything to check for nil values which eventually causes a panic.

Taking an even deeper dive into why my dev env is getting a nil value at all, is because of line 322 where we generate the error

leveldb: not found

We then swallow the error, print nothing, and just return nil. Which as you can imagine, doesn't give the user much insight/knowledge into what the actual problem is.

Proposal

At line 322, we add a error print statement with the error so its more obvious what the problem is. Thoughts? If people agree, i can open an PR.

cbarraford commented 6 years ago

Well, "not found" isn't referencing leveldb not being installed itself, its refering to a key not being found in the database. Back to the drawing board...

cbarraford commented 6 years ago

I finally figured out my issue, there seems to be some bad data files in the block database folder. Rm'ing all the files in the testnet (~/Library/Application Support/Btcd/data/testnet/blocks_ffldb)