btcsuite / btcchain Goto Github PK
View Code? Open in Web Editor NEWPackage btcchain implements bitcoin block handling and chain selection rules - a package from btcd
Package btcchain implements bitcoin block handling and chain selection rules - a package from btcd
I received the following error in btcd:
06:07:08 2014-01-28 [INF] BMGR: Processed 1 block in the last 4m23.26s (213 transactions, height 282872, 2014-01-28 06:09:02 -0500 EST)
06:16:47 2014-01-28 [INF] BMGR: Processed 1 block in the last 9m39.17s (472 transactions, height 282873, 2014-01-28 06:16:34 -0500 EST)
06:20:15 2014-01-28 [ERR] BMGR: Failed to process block 00000000000000015151fe4c165e0cb0aa40f6afeda65653cdd35972eb90de8b: removeBlockNode must be called with a node at the front of the chain - node 0000000000000000f828169b0b1416d4c568b6204ddf8aaffca90fdb1a57fad0
06:25:56 2014-01-28 [INF] CHAN: Adding orphan block 00000000000000017b916aaf3430e5b9678e53bd5f3d4bbcaf63d2c023a58bc4 with parent 00000000000000015151fe4c165e0cb0aa40f6afeda65653cdd35972eb90de8b
06:25:56 2014-01-28 [INF] BMGR: Processed 1 block in the last 9m9.02s (241 transactions, height 282873, 2014-01-28 06:16:34 -0500 EST)
06:30:53 2014-01-28 [INF] CHAN: Adding orphan block 00000000000000016e30a8993bdb6c8f1da2e2003ffdced97baec98b4dc372f1 with parent 00000000000000017b916aaf3430e5b9678e53bd5f3d4bbcaf63d2c023a58bc4
06:30:53 2014-01-28 [INF] BMGR: Processed 1 block in the last 4m56.63s (225 transactions, height 282873, 2014-01-28 06:16:34 -0500 EST)
06:32:54 2014-01-28 [INF] CHAN: Adding orphan block 0000000000000000bec1ee6417bea3819a0c22c679ff8a86a0b2c1e6af94a5d5 with parent 00000000000000016e30a8993bdb6c8f1da2e2003ffdced97baec98b4dc372f1
Looks like the pruneBlockNodes() calls removeBlockNode() as it tries to prune old blocks. I believe there is a subtle bug the chain reorg that causes the parent/child links to not be as expected. The referenced block that can't be cleaned is #280857 / 0000000000000000f828169b0b1416d4c568b6204ddf8aaffca90fdb1a57fad0, and it looks like I had a chain reorg that happened there earlier:
12:53:02 2014-01-16 [INF] BMGR: Processed 1 block in the last 11m56.2s (600 transactions, height 280855, 2014-01-16 12:52:30 -0500 EST)
12:57:12 2014-01-16 [INF] BMGR: Processed 1 block in the last 4m10.14s (180 transactions, height 280856, 2014-01-16 12:56:31 -0500 EST)
13:21:27 2014-01-16 [INF] CHAN: Adding orphan block 0000000000000000f828169b0b1416d4c568b6204ddf8aaffca90fdb1a57fad0 with parent 00000000000000022523d34eb24d113483380e22d190c2fb3da6764b6a623cbd
13:21:27 2014-01-16 [INF] BMGR: Processed 1 block in the last 24m14.78s (20 transactions, height 280856, 2014-01-16 12:56:31 -0500 EST)
13:21:27 2014-01-16 [INF] CHAN: FORK: Block 00000000000000022523d34eb24d113483380e22d190c2fb3da6764b6a623cbd forks the chain at height 280855/block 00000000000000013262988187eb10d1ce3d5fdf65add44037e4329d705f6fb3, but does not cause a reorganize
13:21:27 2014-01-16 [INF] CHAN: REORGANIZE: Block 0000000000000000f828169b0b1416d4c568b6204ddf8aaffca90fdb1a57fad0 is causing a reorganize.
13:21:28 2014-01-16 [INF] CHAN: REORGANIZE: Chain forks at 00000000000000013262988187eb10d1ce3d5fdf65add44037e4329d705f6fb3
13:21:28 2014-01-16 [INF] CHAN: REORGANIZE: Old best chain head was 000000000000000194c8b3b6f9fe2840e5f6f391a3706adf18f97549da866c55
13:21:28 2014-01-16 [INF] CHAN: REORGANIZE: New best chain head is 0000000000000000f828169b0b1416d4c568b6204ddf8aaffca90fdb1a57fad0
13:40:39 2014-01-16 [INF] BMGR: Processed 2 blocks in the last 19m12.31s (1572 transactions, height 280858, 2014-01-16 13:39:53 -0500 EST)
13:41:59 2014-01-16 [INF] BMGR: Processed 1 block in the last 1m19.15s (205 transactions, height 280859, 2014-01-16 13:41:47 -0500 EST)
When running btcd on testnet block chain download gets stuck on block 21066 with the following error message:
[16:51:24 2013-10-06] [INF] [BTCD] [BMGR] Rejected block 0000000004053156021d8e42459d284220a7f6e087bf78f30179c3703ca4eefa: the coinbase signature script serialized block height is 152138 when 21066 was expected
Interesting to note 152138 = 0x02524a and 21066 = 0x524a. It seems that some kind of length byte gets taken into the value.
I have not looked in detail into block coinbase structure and don't know if it is the appropriate way to fix this, but following change to btcchain/validate.go allows btcd to get past this block:
diff --git a/validate.go b/validate.go
index b1e9a35..c39606e 100644
--- a/validate.go
+++ b/validate.go
@@ -507,7 +507,7 @@ func checkSerializedHeight(coinbaseTx *btcwire.MsgTx, wantHeight int64) error {
}
serializedHeightBytes := make([]byte, 4, 4)
- copy(serializedHeightBytes, sigScript[1:4])
+ copy(serializedHeightBytes, sigScript[1:sigScript[0] + 1])
serializedHeight := binary.LittleEndian.Uint32(serializedHeightBytes)
if int64(serializedHeight) != wantHeight {
str := fmt.Sprintf("the coinbase signature script serialized "+
In order to support getblocktemplate block proposals, the chain code needs to be able to handle running the exact same checks on a proposed block as a normal block submission, but without actually accepting it or modifying the state in any way.
There is already an internal branch which implements this. I'm only creating this ticket for tracking purposes.
Rather than having to recreate the node index on every load, which is a bit time consuming and makes startup take longer, it would be nice to save the index to disk.
A few key points:
Profiling has shown that the duplicate input transaction check is taking around 6% of the total CheckTransactionSanity processing time. This is much higher than it should be.
The test suite is broken for any fork of this repository due to some weird directory structure assumption.
$ mkdir -p GOPATH/src/github.com/conformal
$ cd $GOPATH/src/github.com/conformal
$ git clone [email protected]/btcchain.git
$ cd btcchain
$ go test
PASS
ok github.com/conformal/btcchain 0.045s
After this, if you clone your repo within a different parent directory...
$ mkdir -p GOPATH/src/github.com/foobar
$ cd $GOPATH/src/github.com/foobar
$ git clone [email protected]/btcchain.git
$ cd btcchain
$ go test
# github.com/foobar/btcchain_test
./chain_test.go:48: undefined: btcchain.TstSetCoinbaseMaturity
./reorganization_test.go:58: undefined: btcchain.TstSetCoinbaseMaturity
./timesorter_test.go:44: undefined: btcchain.TstTimeSorter
./validate_test.go:108: undefined: btcchain.TstCheckSerializedHeight
FAIL github.com/foobar/btcchain [build failed]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.