Update for btcchain ProcessBlock behavior flags.
ok @jrick
This commit is contained in:
parent
21872ecdaa
commit
48c6806b24
3 changed files with 10 additions and 9 deletions
|
@ -113,6 +113,7 @@ type processBlockResponse struct {
|
||||||
// way to call ProcessBlock on the internal block chain instance.
|
// way to call ProcessBlock on the internal block chain instance.
|
||||||
type processBlockMsg struct {
|
type processBlockMsg struct {
|
||||||
block *btcutil.Block
|
block *btcutil.Block
|
||||||
|
flags btcchain.BehaviorFlags
|
||||||
reply chan processBlockResponse
|
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
|
// since it is needed to verify the next round of headers links
|
||||||
// properly.
|
// properly.
|
||||||
isCheckpointBlock := false
|
isCheckpointBlock := false
|
||||||
fastAdd := false
|
behaviorFlags := btcchain.BFNone
|
||||||
if b.headersFirstMode {
|
if b.headersFirstMode {
|
||||||
firstNodeEl := b.headerList.Front()
|
firstNodeEl := b.headerList.Front()
|
||||||
if firstNodeEl != nil {
|
if firstNodeEl != nil {
|
||||||
firstNode := firstNodeEl.Value.(*headerNode)
|
firstNode := firstNodeEl.Value.(*headerNode)
|
||||||
if blockSha.IsEqual(firstNode.sha) {
|
if blockSha.IsEqual(firstNode.sha) {
|
||||||
fastAdd = true
|
behaviorFlags |= btcchain.BFFastAdd
|
||||||
if firstNode.sha.IsEqual(b.nextCheckpoint.Hash) {
|
if firstNode.sha.IsEqual(b.nextCheckpoint.Hash) {
|
||||||
isCheckpointBlock = true
|
isCheckpointBlock = true
|
||||||
} else {
|
} else {
|
||||||
|
@ -583,7 +584,7 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) {
|
||||||
|
|
||||||
// Process the block to include validation, best chain selection, orphan
|
// Process the block to include validation, best chain selection, orphan
|
||||||
// handling, etc.
|
// handling, etc.
|
||||||
isOrphan, err := b.blockChain.ProcessBlock(bmsg.block, fastAdd)
|
isOrphan, err := b.blockChain.ProcessBlock(bmsg.block, behaviorFlags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// When the error is a rule error, it means the block was simply
|
// When the error is a rule error, it means the block was simply
|
||||||
// rejected as opposed to something actually going wrong, so log
|
// rejected as opposed to something actually going wrong, so log
|
||||||
|
@ -1029,7 +1030,7 @@ out:
|
||||||
|
|
||||||
case processBlockMsg:
|
case processBlockMsg:
|
||||||
isOrphan, err := b.blockChain.ProcessBlock(
|
isOrphan, err := b.blockChain.ProcessBlock(
|
||||||
msg.block, false)
|
msg.block, msg.flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg.reply <- processBlockResponse{
|
msg.reply <- processBlockResponse{
|
||||||
isOrphan: false,
|
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
|
// 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
|
// chain. It is funneled through the block manager since btcchain is not safe
|
||||||
// for concurrent access.
|
// 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)
|
reply := make(chan processBlockResponse, 1)
|
||||||
b.msgChan <- processBlockMsg{block: block, reply: reply}
|
b.msgChan <- processBlockMsg{block: block, flags: flags, reply: reply}
|
||||||
response := <-reply
|
response := <-reply
|
||||||
return response.isOrphan, response.err
|
return response.isOrphan, response.err
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ func (m *CPUMiner) submitBlock(block *btcutil.Block) bool {
|
||||||
|
|
||||||
// Process this block using the same rules as blocks coming from other
|
// Process this block using the same rules as blocks coming from other
|
||||||
// nodes. This will in turn relay it to the network like normal.
|
// 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 {
|
if err != nil {
|
||||||
// Anything other than a rule violation is an unexpected error,
|
// Anything other than a rule violation is an unexpected error,
|
||||||
// so log that error as an internal error.
|
// so log that error as an internal error.
|
||||||
|
|
|
@ -1750,7 +1750,7 @@ func handleGetWorkSubmission(s *rpcServer, hexData string) (interface{}, error)
|
||||||
|
|
||||||
// Process this block using the same rules as blocks coming from other
|
// Process this block using the same rules as blocks coming from other
|
||||||
// nodes. This will in turn relay it to the network like normal.
|
// 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 {
|
if err != nil || isOrphan {
|
||||||
// Anything other than a rule violation is an unexpected error,
|
// Anything other than a rule violation is an unexpected error,
|
||||||
// so return that error as an internal 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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.server.blockManager.ProcessBlock(block)
|
_, err = s.server.blockManager.ProcessBlock(block, btcchain.BFNone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Sprintf("rejected: %s", err.Error()), nil
|
return fmt.Sprintf("rejected: %s", err.Error()), nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue