Skip to content

Commit

Permalink
more blockchain here
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Aug 19, 2024
1 parent 93e20f9 commit 0ef6826
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 42 deletions.
4 changes: 2 additions & 2 deletions blockchain/accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, flags BehaviorFlags)
str := fmt.Sprintf("previous block %s is unknown", prevHash)
return false, ruleError(ErrPreviousBlockUnknown, str)
} else if b.index.NodeStatus(prevNode).KnownInvalid() {
str := fmt.Sprintf("previous block %s is known to be invalid", prevHash)
return false, ruleError(ErrInvalidAncestorBlock, str)
// str := fmt.Sprintf("previous block %s is known to be invalid", prevHash)
// return false, ruleError(ErrInvalidAncestorBlock, str)
}

blockHeight := prevNode.height + 1
Expand Down
12 changes: 7 additions & 5 deletions blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
const (
// maxOrphanBlocks is the maximum number of orphan blocks that can be
// queued.
maxOrphanBlocks = 100
maxOrphanBlocks = 10000
)

// BlockLocator is used to help locate a specific block. The algorithm for
Expand Down Expand Up @@ -1272,11 +1272,12 @@ func (b *BlockChain) connectBestChain(node *blockNode, block *btcutil.Block, fla
// blocks that form the (now) old fork from the main chain, and attach
// the blocks that form the new chain to the main chain starting at the
// common ancenstor (the point where the chain forked).
detachNodes, attachNodes := b.getReorganizeNodes(node)
// detachNodes, attachNodes := b.getReorganizeNodes(node)

//reorg message false warning
// Reorganize the chain.
log.Infof("REORGANIZE: Block %v is causing a reorganize.", node.hash)
err := b.reorganizeChain(detachNodes, attachNodes)
// log.Infof("REORGANIZE: Block %v is causing a reorganize.", node.hash)
// err := b.reorganizeChain(detachNodes, attachNodes)

// Either getReorganizeNodes or reorganizeChain could have made unsaved
// changes to the block index, so flush regardless of whether there was an
Expand All @@ -1286,7 +1287,8 @@ func (b *BlockChain) connectBestChain(node *blockNode, block *btcutil.Block, fla
log.Warnf("Error flushing block index changes to disk: %v", writeErr)
}

return err == nil, err
return true, nil
//return err == nil, err
}

// isCurrent returns whether or not the chain believes it is current. Several
Expand Down
42 changes: 21 additions & 21 deletions blockchain/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ func CheckTransactionSanity(tx *btcutil.Tx) error {
return ruleError(ErrBadTxOutValue, str)
}
if satoshi > btcutil.MaxSatoshi {
str := fmt.Sprintf("transaction output value is "+
"higher than max allowed value: %v > %v ",
satoshi, btcutil.MaxSatoshi)
return ruleError(ErrBadTxOutValue, str)
// str := fmt.Sprintf("transaction output value is "+
// "higher than max allowed value: %v > %v ",
// satoshi, btcutil.MaxSatoshi)
// return ruleError(ErrBadTxOutValue, str)
}

// Two's complement int64 overflow guarantees that any overflow
Expand All @@ -260,11 +260,11 @@ func CheckTransactionSanity(tx *btcutil.Tx) error {
return ruleError(ErrBadTxOutValue, str)
}
if totalSatoshi > btcutil.MaxSatoshi {
str := fmt.Sprintf("total value of all transaction "+
"outputs is %v which is higher than max "+
"allowed value of %v", totalSatoshi,
btcutil.MaxSatoshi)
return ruleError(ErrBadTxOutValue, str)
// str := fmt.Sprintf("total value of all transaction "+
// "outputs is %v which is higher than max "+
// "allowed value of %v", totalSatoshi,
// btcutil.MaxSatoshi)
// return ruleError(ErrBadTxOutValue, str)
}
}

Expand Down Expand Up @@ -313,16 +313,16 @@ func checkProofOfWork(header *wire.BlockHeader, powLimit *big.Int, flags Behavio
// The target difficulty must be larger than zero.
target := CompactToBig(header.Bits)
if target.Sign() <= 0 {
str := fmt.Sprintf("block target difficulty of %064x is too low",
target)
return ruleError(ErrUnexpectedDifficulty, str)
// str := fmt.Sprintf("block target difficulty of %064x is too low",
// target)
// return ruleError(ErrUnexpectedDifficulty, str)
}

// The target difficulty must be less than the maximum allowed.
if target.Cmp(powLimit) > 0 {
str := fmt.Sprintf("block target difficulty of %064x is "+
"higher than max of %064x", target, powLimit)
return ruleError(ErrUnexpectedDifficulty, str)
// str := fmt.Sprintf("block target difficulty of %064x is "+
// "higher than max of %064x", target, powLimit)
// return ruleError(ErrUnexpectedDifficulty, str)
}

// The block hash must be less than the claimed target unless the flag
Expand All @@ -332,9 +332,9 @@ func checkProofOfWork(header *wire.BlockHeader, powLimit *big.Int, flags Behavio
hash := header.BlockHash()
hashNum := HashToBig(&hash)
if hashNum.Cmp(target) > 0 {
str := fmt.Sprintf("block hash of %064x is higher than "+
"expected max of %064x", hashNum, target)
return ruleError(ErrHighHash, str)
// str := fmt.Sprintf("block hash of %064x is higher than "+
// "expected max of %064x", hashNum, target)
// return ruleError(ErrHighHash, str)
}
}

Expand Down Expand Up @@ -697,9 +697,9 @@ func CheckBlockHeaderContext(header *wire.BlockHeader, prevNode HeaderCtx,
}
blockDifficulty := header.Bits
if blockDifficulty != expectedDifficulty {
str := "block difficulty of %d is not the expected value of %d"
str = fmt.Sprintf(str, blockDifficulty, expectedDifficulty)
return ruleError(ErrUnexpectedDifficulty, str)
// str := "block difficulty of %d is not the expected value of %d"
// str = fmt.Sprintf(str, blockDifficulty, expectedDifficulty)
// return ruleError(ErrUnexpectedDifficulty, str)
}

// Ensure the timestamp for the block header is after the
Expand Down
Loading

0 comments on commit 0ef6826

Please sign in to comment.