From 0a7543516ced23c7f8f80d5c09ee344511adc263 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 2 May 2014 19:52:15 -0500 Subject: [PATCH] Update block manager chainstate for all sources. This commit updates the block manager's local chain state when a block processed by submitting it directly to the block manager as opposed to only when it comes from the network. Also, it modifies the submitblock RPC to use the concurrent safe block manager process block instead of the unsafe btcchain version. The combination of these two fixes ensure the internal block manager chain state is properly synced with the actual btcchain state regardless of how blocks are added. --- blockmanager.go | 6 ++++++ rpcserver.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/blockmanager.go b/blockmanager.go index 71331437..f328cf3e 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -1028,6 +1028,12 @@ out: } } + // Query the db for the latest best block since + // the block that was processed could be on a + // side chain or have caused a reorg. + newestSha, newestHeight, _ := b.server.db.NewestSha() + b.updateChainState(newestSha, newestHeight) + blockSha, _ := msg.block.Sha() msg.reply <- processBlockResponse{ isOrphan: b.blockChain.IsKnownOrphan( diff --git a/rpcserver.go b/rpcserver.go index c1dcf3d0..fe53432c 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1870,7 +1870,7 @@ func handleSubmitBlock(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) { return nil, err } - err = s.server.blockManager.blockChain.ProcessBlock(block, false) + _, err = s.server.blockManager.ProcessBlock(block) if err != nil { return fmt.Sprintf("rejected: %s", err.Error()), nil }