Update for btcchain ProcessBlock behavior flags.

ok @jrick
This commit is contained in:
Dave Collins 2014-06-26 17:02:45 -05:00
parent 21872ecdaa
commit 48c6806b24
3 changed files with 10 additions and 9 deletions

View file

@ -113,6 +113,7 @@ type processBlockResponse struct {
// way to call ProcessBlock on the internal block chain instance.
type processBlockMsg struct {
block *btcutil.Block
flags btcchain.BehaviorFlags
reply chan processBlockResponse
}
@ -559,13 +560,13 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) {
// since it is needed to verify the next round of headers links
// properly.
isCheckpointBlock := false
fastAdd := false
behaviorFlags := btcchain.BFNone
if b.headersFirstMode {
firstNodeEl := b.headerList.Front()
if firstNodeEl != nil {
firstNode := firstNodeEl.Value.(*headerNode)
if blockSha.IsEqual(firstNode.sha) {
fastAdd = true
behaviorFlags |= btcchain.BFFastAdd
if firstNode.sha.IsEqual(b.nextCheckpoint.Hash) {
isCheckpointBlock = true
} else {
@ -583,7 +584,7 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) {
// Process the block to include validation, best chain selection, orphan
// handling, etc.
isOrphan, err := b.blockChain.ProcessBlock(bmsg.block, fastAdd)
isOrphan, err := b.blockChain.ProcessBlock(bmsg.block, behaviorFlags)
if err != nil {
// When the error is a rule error, it means the block was simply
// rejected as opposed to something actually going wrong, so log
@ -1029,7 +1030,7 @@ out:
case processBlockMsg:
isOrphan, err := b.blockChain.ProcessBlock(
msg.block, false)
msg.block, msg.flags)
if err != nil {
msg.reply <- processBlockResponse{
isOrphan: false,
@ -1277,9 +1278,9 @@ func (b *blockManager) CalcNextRequiredDifficulty(timestamp time.Time) (uint32,
// ProcessBlock makes use of ProcessBlock on an internal instance of a block
// chain. It is funneled through the block manager since btcchain is not safe
// for concurrent access.
func (b *blockManager) ProcessBlock(block *btcutil.Block) (bool, error) {
func (b *blockManager) ProcessBlock(block *btcutil.Block, flags btcchain.BehaviorFlags) (bool, error) {
reply := make(chan processBlockResponse, 1)
b.msgChan <- processBlockMsg{block: block, reply: reply}
b.msgChan <- processBlockMsg{block: block, flags: flags, reply: reply}
response := <-reply
return response.isOrphan, response.err
}

View file

@ -127,7 +127,7 @@ func (m *CPUMiner) submitBlock(block *btcutil.Block) bool {
// Process this block using the same rules as blocks coming from other
// nodes. This will in turn relay it to the network like normal.
isOrphan, err := m.server.blockManager.ProcessBlock(block)
isOrphan, err := m.server.blockManager.ProcessBlock(block, btcchain.BFNone)
if err != nil {
// Anything other than a rule violation is an unexpected error,
// so log that error as an internal error.

View file

@ -1750,7 +1750,7 @@ func handleGetWorkSubmission(s *rpcServer, hexData string) (interface{}, error)
// Process this block using the same rules as blocks coming from other
// nodes. This will in turn relay it to the network like normal.
isOrphan, err := s.server.blockManager.ProcessBlock(block)
isOrphan, err := s.server.blockManager.ProcessBlock(block, btcchain.BFNone)
if err != nil || isOrphan {
// Anything other than a rule violation is an unexpected error,
// so return that error as an internal error.
@ -1988,7 +1988,7 @@ func handleSubmitBlock(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) {
return nil, err
}
_, err = s.server.blockManager.ProcessBlock(block)
_, err = s.server.blockManager.ProcessBlock(block, btcchain.BFNone)
if err != nil {
return fmt.Sprintf("rejected: %s", err.Error()), nil
}