Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1043 from NebulousLabs/miner-debug
Browse files Browse the repository at this point in the history
additional debugging and sanity for miner
  • Loading branch information
lukechampine committed Mar 30, 2016
2 parents a3a591e + 7ae8dc1 commit 2a2029d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (m *Miner) startupRescan() error {
m.mu.Lock()
defer m.mu.Unlock()

m.log.Println("Performing a miner rescan.")
m.persist.RecentChange = modules.ConsensusChangeID{}
m.persist.Height = 0
m.persist.Target = types.Target{}
Expand Down
12 changes: 11 additions & 1 deletion modules/miner/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,29 @@ func (m *Miner) ProcessConsensusChange(cc modules.ConsensusChange) {
for _, block := range cc.RevertedBlocks {
if block.ID() != types.GenesisBlock.ID() {
m.persist.Height--
} else if m.persist.Height != 0 {
// Sanity check - if the current block is the genesis block, the
// miner height should be set to zero.
m.log.Critical("Miner has detected a genesis block, but the height of the miner is set to ", m.persist.Height)
m.persist.Height = 0
}
}
for _, block := range cc.AppliedBlocks {
if block.ID() != types.GenesisBlock.ID() {
m.persist.Height++
} else if m.persist.Height != 0 {
// Sanity check - if the current block is the genesis block, the
// miner height should be set to zero.
m.log.Critical("Miner has detected a genesis block, but the height of the miner is set to ", m.persist.Height)
m.persist.Height = 0
}
}
// Sanity check - if the most recent block in the miner is the same as the
// most recent block in the consensus set, then the height of the consensus
// set and the height of the miner should be the same.
if cc.AppliedBlocks[len(cc.AppliedBlocks)-1].ID() == m.cs.CurrentBlock().ID() {
if m.persist.Height != m.cs.Height() {
m.log.Critical("miner has a height mismatch: have ", m.persist.Height, " expected ", m.cs.Height())
m.log.Critical("Miner has a height mismatch: expecting ", m.cs.Height(), " but got ", m.persist.Height, ". Recent update had ", len(cc.RevertedBlocks), " reverted blocks, and ", len(cc.AppliedBlocks), " applied blocks.")
m.persist.Height = m.cs.Height()
}
}
Expand Down

0 comments on commit 2a2029d

Please sign in to comment.