chainntnfs: update impl independent functions to populate new block header
This commit is contained in:
1 file changed
+30
-8
+30
-8
@@ -492,8 +492,9 @@ func RewindChain(chainConn ChainConn, txNotifier *TxNotifier,
|
|||||||
currBestBlock BlockEpoch, targetHeight int32) (BlockEpoch, error) {
|
currBestBlock BlockEpoch, targetHeight int32) (BlockEpoch, error) {
|
||||||
|
|
||||||
newBestBlock := BlockEpoch{
|
newBestBlock := BlockEpoch{
|
||||||
Height: currBestBlock.Height,
|
Height: currBestBlock.Height,
|
||||||
Hash: currBestBlock.Hash,
|
Hash: currBestBlock.Hash,
|
||||||
|
BlockHeader: currBestBlock.BlockHeader,
|
||||||
}
|
}
|
||||||
|
|
||||||
for height := currBestBlock.Height; height > targetHeight; height-- {
|
for height := currBestBlock.Height; height > targetHeight; height-- {
|
||||||
@@ -503,6 +504,11 @@ func RewindChain(chainConn ChainConn, txNotifier *TxNotifier,
|
|||||||
"find blockhash for disconnected height=%d: %v",
|
"find blockhash for disconnected height=%d: %v",
|
||||||
height, err)
|
height, err)
|
||||||
}
|
}
|
||||||
|
header, err := chainConn.GetBlockHeader(hash)
|
||||||
|
if err != nil {
|
||||||
|
return newBestBlock, fmt.Errorf("unable to get block "+
|
||||||
|
"header for height=%v", height-1)
|
||||||
|
}
|
||||||
|
|
||||||
Log.Infof("Block disconnected from main chain: "+
|
Log.Infof("Block disconnected from main chain: "+
|
||||||
"height=%v, sha=%v", height, newBestBlock.Hash)
|
"height=%v, sha=%v", height, newBestBlock.Hash)
|
||||||
@@ -515,7 +521,9 @@ func RewindChain(chainConn ChainConn, txNotifier *TxNotifier,
|
|||||||
}
|
}
|
||||||
newBestBlock.Height = height - 1
|
newBestBlock.Height = height - 1
|
||||||
newBestBlock.Hash = hash
|
newBestBlock.Hash = hash
|
||||||
|
newBestBlock.BlockHeader = header
|
||||||
}
|
}
|
||||||
|
|
||||||
return newBestBlock, nil
|
return newBestBlock, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,8 +547,9 @@ func HandleMissedBlocks(chainConn ChainConn, txNotifier *TxNotifier,
|
|||||||
// If a reorg causes our best hash to be incorrect, rewind the
|
// If a reorg causes our best hash to be incorrect, rewind the
|
||||||
// chain so our best block is set to the closest common
|
// chain so our best block is set to the closest common
|
||||||
// ancestor, then dispatch notifications from there.
|
// ancestor, then dispatch notifications from there.
|
||||||
hashAtBestHeight, err :=
|
hashAtBestHeight, err := chainConn.GetBlockHash(
|
||||||
chainConn.GetBlockHash(int64(currBestBlock.Height))
|
int64(currBestBlock.Height),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return currBestBlock, nil, fmt.Errorf("unable to find "+
|
return currBestBlock, nil, fmt.Errorf("unable to find "+
|
||||||
"blockhash for height=%d: %v",
|
"blockhash for height=%d: %v",
|
||||||
@@ -555,8 +564,9 @@ func HandleMissedBlocks(chainConn ChainConn, txNotifier *TxNotifier,
|
|||||||
"common ancestor: %v", err)
|
"common ancestor: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
currBestBlock, err = RewindChain(chainConn, txNotifier,
|
currBestBlock, err = RewindChain(
|
||||||
currBestBlock, startingHeight)
|
chainConn, txNotifier, currBestBlock, startingHeight,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return currBestBlock, nil, fmt.Errorf("unable to "+
|
return currBestBlock, nil, fmt.Errorf("unable to "+
|
||||||
"rewind chain: %v", err)
|
"rewind chain: %v", err)
|
||||||
@@ -592,8 +602,20 @@ func getMissedBlocks(chainConn ChainConn, startingHeight,
|
|||||||
return nil, fmt.Errorf("unable to find blockhash for "+
|
return nil, fmt.Errorf("unable to find blockhash for "+
|
||||||
"height=%d: %v", height, err)
|
"height=%d: %v", height, err)
|
||||||
}
|
}
|
||||||
missedBlocks = append(missedBlocks,
|
header, err := chainConn.GetBlockHeader(hash)
|
||||||
BlockEpoch{Hash: hash, Height: height})
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to find block header "+
|
||||||
|
"for height=%d: %v", height, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
missedBlocks = append(
|
||||||
|
missedBlocks,
|
||||||
|
BlockEpoch{
|
||||||
|
Hash: hash,
|
||||||
|
Height: height,
|
||||||
|
BlockHeader: header,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return missedBlocks, nil
|
return missedBlocks, nil
|
||||||
|
|||||||
Reference in new issue
Block a user